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

Function buildHierarchyModel

ui/src/lib/hierarchy-model.ts:100–194  ·  view source on GitHub ↗
(
  hierarchy: WireHierarchy,
  focus: WireNodeDetail
)

Source from the content-addressed store, hash-verified

98 * deepest, least relevant end.
99 */
100export function buildHierarchyModel(
101 hierarchy: WireHierarchy,
102 focus: WireNodeDetail
103): HierarchyModel {
104 const rows: HierarchyRow[] = [];
105
106 const ancestors = [...hierarchy.ancestors.items].sort(
107 (a, b) => b.depth - a.depth || a.name.localeCompare(b.name)
108 );
109 for (const entry of ancestors) {
110 rows.push({
111 entry,
112 node: entry,
113 side: 'ancestor',
114 indent: 0,
115 index: rows.length,
116 // The plain relation word, on both halves of the tree. It reads off the
117 // connector: this row is what the row below it extends or implements.
118 // The block's header says which half is which.
119 word: entry.relation,
120 });
121 }
122
123 const focusIndex = rows.length;
124 rows.push({ entry: null, node: focus, side: 'focus', indent: 0, index: focusIndex, word: '' });
125
126 for (const entry of hierarchy.descendants.items) {
127 rows.push({
128 entry,
129 node: entry,
130 side: 'descendant',
131 indent: entry.depth * HIER_INDENT,
132 index: rows.length,
133 word: entry.relation,
134 });
135 }
136
137 // Descendant elbows look their parent up here. Ancestors are deliberately
138 // excluded: a type that is somehow both above and below the focus (a cycle in
139 // generated code) must not make a subtype hang off a supertype row.
140 const byId = new Map(
141 rows.filter((r) => r.side !== 'ancestor').map((row) => [row.node.id, row] as const)
142 );
143 const connectors: HierarchyConnector[] = [];
144
145 // Ancestors: every row at indent 0, so each segment is a plain vertical to
146 // the row below it. The relation is carried by the row's own word as well —
147 // with two direct parents the line alone could not say which is which, and a
148 // connector is structure, not the claim.
149 for (let i = 0; i < focusIndex; i++) {
150 const row = rows[i];
151 const next = rows[i + 1];
152 if (!row?.entry || !next) continue;
153 connectors.push({
154 fromIndex: i,
155 toIndex: i + 1,
156 x: HIER_PORT_X,
157 toX: HIER_PORT_X,

Callers 1

Calls 6

nounForFunction · 0.85
headlineForFunction · 0.85
noteForFunction · 0.85
pushMethod · 0.80
mapMethod · 0.80
getMethod · 0.65

Tested by

no test coverage detected