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

Function packRegions

ui/src/lib/steps-model.ts:710–1120  ·  view source on GitHub ↗

* The layout of a screen's picture: each region a small column of lines — * a box above what it sets in motion, a line wrapping when it grows past the * width its shape earns (REGION_WIDTHS) — and the regions tiled left to right, wrapping * into bands, in the order the walk met them: the

(
  steps: WireStep[],
  infos: Map<string, StepNodeInfo>,
  modules: WireMapModule[],
  links: WireMapLink[]
)

Source from the content-addressed store, hash-verified

708 * the pills, the pointer — is the same machinery over the same shapes.
709 */
710function packRegions(
711 steps: WireStep[],
712 infos: Map<string, StepNodeInfo>,
713 modules: WireMapModule[],
714 links: WireMapLink[]
715): { layout: MapLayout; zones: StepRegionZone[] } {
716 const anchor = steps.find((s) => s.anchor)!;
717 const members = steps.filter((s) => !s.anchor);
718 const moduleOf = new Map(modules.map((m) => [m.id, m]));
719
720 // A box is wide enough for its words and for its ports — the anchor touches
721 // most of the picture, and its lines need somewhere to leave from.
722 const degree = new Map<string, number>();
723 for (const l of links) {
724 degree.set(l.source, (degree.get(l.source) ?? 0) + 1);
725 degree.set(l.target, (degree.get(l.target) ?? 0) + 1);
726 }
727 const widthOf = (id: string): number => {
728 const info = infos.get(id);
729 // A cut step wears ` …` after its name and the anchor its ● mark before
730 // it; size for both, or the CSS ellipsis eats the name's tail instead
731 // (`/scan-to-verif…` for `/scan-to-verify …`).
732 const cut = info?.step.cut != null ? ' …' : '';
733 const mark = info?.step.anchor ? '● ' : '';
734 return Math.max(
735 nodeWidth(mark + (info?.label ?? id) + cut, info?.sub ?? ''),
736 ((degree.get(id) ?? 0) + 1) * PORT_PITCH
737 );
738 };
739
740 // Regions in the order the walk met them — the screen's own source order.
741 interface Region {
742 id: string;
743 label: string;
744 members: WireStep[];
745 }
746 const regions = new Map<string, Region>();
747 for (const s of members) {
748 const id = s.region?.id ?? anchor.id;
749 const region = regions.get(id) ?? { id, label: s.region?.label ?? anchor.label, members: [] };
750 region.members.push(s);
751 regions.set(id, region);
752 }
753
754 // Within a region, a step goes under the steps that lead to it — minus the
755 // links that close a cycle. Relaxation over a cyclic graph never settles: it
756 // adds a row per pass until the bound, so a region holding one cycle sent
757 // sixty-five of its boxes to rows 294-301 while the rest sat at 0-2, and the
758 // order they were then packed in had nothing to do with what leads to what.
759 // The order reading learned this first ({@link withoutBackEdges} there); the
760 // cycle is still drawn, it just cannot stretch the picture.
761 const regionOf = new Map(members.map((s) => [s.id, s.region?.id ?? anchor.id]));
762 const intra = links.filter(
763 (l) =>
764 l.source !== anchor.id &&
765 l.target !== anchor.id &&
766 l.source !== l.target &&
767 regionOf.get(l.source) === regionOf.get(l.target)

Callers 1

buildStepsModelFunction · 0.85

Calls 15

linkIdFunction · 0.90
strokeWidthForFunction · 0.90
forwardLinksFunction · 0.85
layoutAtFunction · 0.85
canvasCostFunction · 0.85
widthOfFunction · 0.85
bySideFunction · 0.85
centreOfFunction · 0.85
mapMethod · 0.80
pushMethod · 0.80
hasMethod · 0.80
placeFunction · 0.70

Tested by

no test coverage detected