MCPcopy Index your code
hub / github.com/microsoft/SandDance / labelLayout

Function labelLayout

docs/app/js/sanddance-app.js:139064–139097  ·  view source on GitHub ↗
(texts, size, compare, offset, anchor, avoidMarks, avoidBaseMark, lineAnchor, markIndex, padding, method)

Source from the content-addressed store, hash-verified

139062 "floodfill": placeAreaLabelFloodFill
139063};
139064function labelLayout(texts, size, compare, offset, anchor, avoidMarks, avoidBaseMark, lineAnchor, markIndex, padding, method) {
139065 // early exit for empty data
139066 if (!texts.length) return texts;
139067 const positions = Math.max(offset.length, anchor.length), offsets = getOffsets(offset, positions), anchors = getAnchors(anchor, positions), marktype = markType(texts[0].datum), grouptype = marktype === "group" && texts[0].datum.items[markIndex].marktype, isGroupArea = grouptype === "area", boundary = markBoundary(marktype, grouptype, lineAnchor, markIndex), $ = scaler(size[0], size[1], padding), isNaiveGroupArea = isGroupArea && method === "naive"; // prepare text mark data for placing
139068 const data = texts.map((d)=>({
139069 datum: d,
139070 opacity: 0,
139071 x: undefined,
139072 y: undefined,
139073 align: undefined,
139074 baseline: undefined,
139075 boundary: boundary(d)
139076 }));
139077 let bitmaps;
139078 if (!isNaiveGroupArea) {
139079 // sort labels in priority order, if comparator is provided
139080 if (compare) data.sort((a, b)=>compare(a.datum, b.datum));
139081 // flag indicating if label can be placed inside its base mark
139082 let labelInside = false;
139083 for(let i8 = 0; i8 < anchors.length && !labelInside; ++i8)// label inside if anchor is at center
139084 // label inside if offset to be inside the mark bound
139085 labelInside = anchors[i8] === 0x5 || offsets[i8] < 0;
139086 // extract data information from base mark when base mark is to be avoided
139087 // base mark is implicitly avoided if it is a group area
139088 if (marktype && (avoidBaseMark || isGroupArea)) avoidMarks = [
139089 texts.map((d)=>d.datum)
139090 ].concat(avoidMarks);
139091 // generate bitmaps for layout calculation
139092 bitmaps = avoidMarks.length ? markBitmaps($, avoidMarks, labelInside, isGroupArea) : baseBitmaps($, avoidBaseMark && data);
139093 } // generate label placement function
139094 const place = isGroupArea ? placeAreaLabel[method]($, bitmaps, avoidBaseMark, markIndex) : placeMarkLabel($, bitmaps, anchors, offsets); // place all labels
139095 data.forEach((d)=>d.opacity = +place(d));
139096 return data;
139097}
139098function getOffsets(_, count) {
139099 const offsets = new Float64Array(count), n = _.length;
139100 for(let i10 = 0; i10 < n; ++i10)offsets[i10] = _[i10] || 0;

Callers 1

transformFunction · 0.70

Calls 12

getOffsetsFunction · 0.70
getAnchorsFunction · 0.70
markTypeFunction · 0.70
markBoundaryFunction · 0.70
scalerFunction · 0.70
compareFunction · 0.70
markBitmapsFunction · 0.70
baseBitmapsFunction · 0.70
placeMarkLabelFunction · 0.70
placeFunction · 0.70
maxMethod · 0.45
forEachMethod · 0.45

Tested by

no test coverage detected