MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / packStubs

Function packStubs

ui/src/lib/steps-model.ts:558–611  ·  view source on GitHub ↗
(
  layout: MapLayout,
  infos: Map<string, StepNodeInfo>,
  layerGap: number,
  entries: ReadonlySet<string> | null
)

Source from the content-addressed store, hash-verified

556}
557
558function packStubs(
559 layout: MapLayout,
560 infos: Map<string, StepNodeInfo>,
561 layerGap: number,
562 entries: ReadonlySet<string> | null
563): { stubs: Map<string, StepStub[]>; stubbed: ReadonlySet<string> } {
564 const stubs = new Map<string, StepStub[]>();
565 const stubbed = new Set<string>();
566 const nodeById = new Map(layout.nodes.map((n) => [n.id, n]));
567 const pitch = NODE_HEIGHT + layerGap;
568 const add = (id: string, stub: StepStub): void => {
569 stubs.set(id, [...(stubs.get(id) ?? []), stub]);
570 };
571 for (const edge of layout.edges) {
572 const from = nodeById.get(edge.source);
573 const to = nodeById.get(edge.target);
574 if (!from || !to) continue;
575 // On a regioned picture the anchor's fan is already stood in for by one
576 // link into each region ({@link StepsModel.regionEntries}); only THAT link
577 // is a line worth keeping or words worth saying, and the rest of the fan
578 // stays quiet as it was. An unregioned picture has no stand-in, so its
579 // anchor's links follow the same rule as every other.
580 if (entries !== null && infos.get(edge.source)?.step.anchor && !entries.has(edge.target)) continue;
581 const lines = Math.abs(to.y - from.y) / pitch;
582 const across = Math.abs(to.x + to.width / 2 - (from.x + from.width / 2));
583 // A back edge points up the layering: it is not a local hop however near
584 // it is, and it was already drawing nothing at rest — now it says so.
585 const near = !edge.back && !edge.thin && lines <= STUB_SPAN_LINES + 0.01 && across <= REGION_LINE_MIN;
586 if (near) continue;
587 stubbed.add(edge.id);
588 add(edge.source, {
589 edge: edge.id,
590 other: edge.target,
591 label: stubLabel(infos.get(edge.target)?.label ?? edge.target),
592 dir: 'out',
593 });
594 add(edge.target, {
595 edge: edge.id,
596 other: edge.source,
597 label: stubLabel(infos.get(edge.source)?.label ?? edge.source),
598 dir: 'in',
599 });
600 }
601 // What a box leads to reads before what reaches it, and each side in the
602 // order the picture puts the other end — down the page, then across.
603 const place = (id: string): number => {
604 const n = nodeById.get(id);
605 return n ? n.y * 100000 + n.x : 0;
606 };
607 for (const list of stubs.values()) {
608 list.sort((a, b) => (a.dir === b.dir ? place(a.other) - place(b.other) : a.dir === 'out' ? -1 : 1));
609 }
610 return { stubs, stubbed };
611}
612
613/* --------------------------------------------------------------- regions -- */
614

Callers 1

buildStepsModelFunction · 0.85

Calls 7

stubLabelFunction · 0.85
mapMethod · 0.80
hasMethod · 0.80
addFunction · 0.70
placeFunction · 0.70
getMethod · 0.65
addMethod · 0.45

Tested by

no test coverage detected