MCPcopy Create free account
hub / github.com/ScriptedAlchemy/tracedecay / selectLabels

Function selectLabels

dashboard/graph/src/labelLayout.ts:49–69  ·  view source on GitHub ↗
(boxes: LabelBox[], cap: number)

Source from the content-addressed store, hash-verified

47
48/** Returns the ids whose labels should render, in placement order. */
49export function selectLabels(boxes: LabelBox[], cap: number): string[] {
50 const ordered = [...boxes].sort(
51 (a, b) => a.priority - b.priority || b.degree - a.degree || a.id.localeCompare(b.id),
52 );
53 const placed: LabelBox[] = [];
54 const chosen: string[] = [];
55 let capped = 0;
56 for (const box of ordered) {
57 if (box.sticky) {
58 placed.push(box);
59 chosen.push(box.id);
60 continue;
61 }
62 if (capped >= cap) continue;
63 if (placed.some((other) => overlaps(box, other))) continue;
64 placed.push(box);
65 chosen.push(box.id);
66 capped++;
67 }
68 return chosen;
69}

Callers 1

renderFunction · 0.90

Calls 2

pushMethod · 0.80
overlapsFunction · 0.70

Tested by

no test coverage detected