@diagrammo/dgmo 0.47.0 → 0.48.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/auto.js +1 -1
- package/dist/auto.mjs +1 -1
- package/dist/element.js +1 -1
- package/dist/element.mjs +1 -1
- package/package.json +19 -70
- package/dist/advanced.cjs +0 -71648
- package/dist/advanced.d.cts +0 -5719
- package/dist/auto.cjs +0 -70648
- package/dist/auto.d.cts +0 -54
- package/dist/block.cjs +0 -70208
- package/dist/block.d.cts +0 -115
- package/dist/editor.cjs +0 -526
- package/dist/editor.d.cts +0 -26
- package/dist/element.cjs +0 -70530
- package/dist/element.d.cts +0 -62
- package/dist/highlight.cjs +0 -852
- package/dist/highlight.d.cts +0 -49
- package/dist/index.cjs +0 -70491
- package/dist/index.d.cts +0 -160
- package/dist/pert.cjs +0 -325
- package/dist/pert.d.cts +0 -559
- package/dist/themes-1-CuKpeH.d.cts +0 -908
- package/src/advanced.ts +0 -873
- package/src/arc/parser.ts +0 -15
- package/src/arc/renderer.ts +0 -633
- package/src/auto/index.ts +0 -621
- package/src/auto/shared.ts +0 -370
- package/src/auto/styles.ts +0 -73
- package/src/block/layout.ts +0 -198
- package/src/block/parser.ts +0 -427
- package/src/block/renderer.ts +0 -484
- package/src/block/types.ts +0 -67
- package/src/boxes-and-lines/collapse.ts +0 -96
- package/src/boxes-and-lines/focus.ts +0 -257
- package/src/boxes-and-lines/label-placement.ts +0 -339
- package/src/boxes-and-lines/layout-grouped.ts +0 -912
- package/src/boxes-and-lines/layout-layered.ts +0 -722
- package/src/boxes-and-lines/layout-search.ts +0 -1678
- package/src/boxes-and-lines/layout.ts +0 -398
- package/src/boxes-and-lines/parser.ts +0 -1181
- package/src/boxes-and-lines/renderer.ts +0 -1465
- package/src/boxes-and-lines/types.ts +0 -66
- package/src/c4/layout.ts +0 -2441
- package/src/c4/parser.ts +0 -1158
- package/src/c4/renderer.ts +0 -2008
- package/src/c4/types.ts +0 -89
- package/src/chart-type-registry.ts +0 -529
- package/src/chart-types.ts +0 -225
- package/src/chart.ts +0 -685
- package/src/charts-d3/bar.ts +0 -338
- package/src/charts-d3/chord.ts +0 -140
- package/src/charts-d3/function.ts +0 -147
- package/src/charts-d3/funnel.ts +0 -104
- package/src/charts-d3/heatmap.ts +0 -145
- package/src/charts-d3/index.ts +0 -337
- package/src/charts-d3/interactions.ts +0 -477
- package/src/charts-d3/line.ts +0 -344
- package/src/charts-d3/mount.ts +0 -151
- package/src/charts-d3/pie.ts +0 -117
- package/src/charts-d3/polar.ts +0 -89
- package/src/charts-d3/radar.ts +0 -0
- package/src/charts-d3/sankey.ts +0 -0
- package/src/charts-d3/scatter.ts +0 -185
- package/src/charts-d3/shared.ts +0 -208
- package/src/class/layout.ts +0 -326
- package/src/class/parser.ts +0 -635
- package/src/class/renderer.ts +0 -793
- package/src/class/types.ts +0 -58
- package/src/cli-banner.ts +0 -106
- package/src/cli.ts +0 -1080
- package/src/colors-diagnostics.ts +0 -35
- package/src/colors.ts +0 -379
- package/src/completion-types.ts +0 -27
- package/src/completion.ts +0 -2668
- package/src/cycle/layout.ts +0 -1026
- package/src/cycle/parser.ts +0 -387
- package/src/cycle/renderer.ts +0 -653
- package/src/cycle/types.ts +0 -101
- package/src/d3.ts +0 -1434
- package/src/data-chart-parser.ts +0 -1007
- package/src/dgmo-router.ts +0 -296
- package/src/diagnostics-registry.ts +0 -108
- package/src/diagnostics.ts +0 -0
- package/src/dimensions.ts +0 -20
- package/src/directives-registry.ts +0 -396
- package/src/editor/dgmo.grammar +0 -76
- package/src/editor/dgmo.grammar.d.ts +0 -2
- package/src/editor/dgmo.grammar.js +0 -18
- package/src/editor/dgmo.grammar.terms.d.ts +0 -5
- package/src/editor/dgmo.grammar.terms.js +0 -35
- package/src/editor/highlight-api.ts +0 -596
- package/src/editor/highlight.ts +0 -36
- package/src/editor/index.ts +0 -27
- package/src/editor/keywords.ts +0 -128
- package/src/editor/tokens.ts +0 -30
- package/src/element/index.ts +0 -432
- package/src/embed/css.ts +0 -312
- package/src/embed/escape.ts +0 -15
- package/src/embed/index.ts +0 -280
- package/src/er/classify.ts +0 -228
- package/src/er/layout.ts +0 -530
- package/src/er/parser.ts +0 -750
- package/src/er/renderer.ts +0 -725
- package/src/er/types.ts +0 -52
- package/src/error-card.ts +0 -269
- package/src/event-line/diagnostics.ts +0 -117
- package/src/event-line/parser.ts +0 -643
- package/src/event-line/renderer.ts +0 -1742
- package/src/event-line/types.ts +0 -74
- package/src/fonts.ts +0 -3
- package/src/gantt/calculator.ts +0 -979
- package/src/gantt/parser.ts +0 -1641
- package/src/gantt/renderer.ts +0 -3787
- package/src/gantt/resolver.ts +0 -172
- package/src/gantt/types.ts +0 -206
- package/src/graph/diagnostics.ts +0 -64
- package/src/graph/edge-spline.ts +0 -29
- package/src/graph/flowchart-parser.ts +0 -759
- package/src/graph/flowchart-renderer.ts +0 -817
- package/src/graph/layout.ts +0 -472
- package/src/graph/notes.ts +0 -21
- package/src/graph/state-collapse.ts +0 -78
- package/src/graph/state-parser.ts +0 -574
- package/src/graph/state-renderer.ts +0 -653
- package/src/graph/types.ts +0 -65
- package/src/index.ts +0 -261
- package/src/infra/compute.ts +0 -1385
- package/src/infra/layout.ts +0 -888
- package/src/infra/parser.ts +0 -1234
- package/src/infra/renderer.ts +0 -2534
- package/src/infra/roles.ts +0 -75
- package/src/infra/types.ts +0 -216
- package/src/infra/validation.ts +0 -201
- package/src/journey-map/layout.ts +0 -490
- package/src/journey-map/parser.ts +0 -557
- package/src/journey-map/renderer.ts +0 -1580
- package/src/journey-map/types.ts +0 -47
- package/src/kanban/mutations.ts +0 -175
- package/src/kanban/parser.ts +0 -509
- package/src/kanban/renderer.ts +0 -1449
- package/src/kanban/types.ts +0 -39
- package/src/label-layout.ts +0 -368
- package/src/map/colorize.ts +0 -54
- package/src/map/completion.ts +0 -316
- package/src/map/context-labels.ts +0 -609
- package/src/map/data/PROVENANCE.json +0 -1
- package/src/map/data/README.md +0 -40
- package/src/map/data/airport-collisions.json +0 -1
- package/src/map/data/airports.json +0 -1
- package/src/map/data/gazetteer.json +0 -1
- package/src/map/data/lakes.json +0 -1
- package/src/map/data/mountain-ranges.json +0 -1
- package/src/map/data/na-lakes.json +0 -1
- package/src/map/data/na-land.json +0 -1
- package/src/map/data/region-names.json +0 -1
- package/src/map/data/rivers.json +0 -1
- package/src/map/data/types.ts +0 -121
- package/src/map/data/us-states.json +0 -1
- package/src/map/data/water-bodies.json +0 -1
- package/src/map/data/world-coarse.json +0 -1
- package/src/map/data/world-detail.json +0 -1
- package/src/map/diagnostics.ts +0 -134
- package/src/map/dimensions.ts +0 -150
- package/src/map/geo-query.ts +0 -295
- package/src/map/geo.ts +0 -438
- package/src/map/invert.ts +0 -111
- package/src/map/layout.ts +0 -5069
- package/src/map/legend-band.ts +0 -127
- package/src/map/load-data.ts +0 -186
- package/src/map/parser.ts +0 -783
- package/src/map/renderer.ts +0 -1445
- package/src/map/resolved-types.ts +0 -160
- package/src/map/resolver.ts +0 -1146
- package/src/map/types.ts +0 -194
- package/src/mindmap/collapse.ts +0 -67
- package/src/mindmap/layout.ts +0 -649
- package/src/mindmap/parser.ts +0 -430
- package/src/mindmap/renderer.ts +0 -637
- package/src/mindmap/text-wrap.ts +0 -218
- package/src/mindmap/types.ts +0 -56
- package/src/org/collapse.ts +0 -151
- package/src/org/layout.ts +0 -1262
- package/src/org/parser.ts +0 -519
- package/src/org/renderer.ts +0 -866
- package/src/org/resolver.ts +0 -636
- package/src/palettes/atlas.ts +0 -77
- package/src/palettes/blueprint.ts +0 -73
- package/src/palettes/catppuccin.ts +0 -84
- package/src/palettes/color-utils.ts +0 -443
- package/src/palettes/index.ts +0 -67
- package/src/palettes/nord.ts +0 -67
- package/src/palettes/registry.ts +0 -114
- package/src/palettes/slate.ts +0 -73
- package/src/palettes/tidewater.ts +0 -73
- package/src/palettes/tokyo-night.ts +0 -86
- package/src/palettes/types.ts +0 -88
- package/src/pert/analyzer.ts +0 -1183
- package/src/pert/diagnostics.ts +0 -110
- package/src/pert/index.ts +0 -43
- package/src/pert/internal.ts +0 -252
- package/src/pert/layout.ts +0 -971
- package/src/pert/monte-carlo.ts +0 -446
- package/src/pert/parser.ts +0 -1606
- package/src/pert/renderer.ts +0 -4009
- package/src/pert/share-normalize.ts +0 -62
- package/src/pert/types.ts +0 -604
- package/src/pyramid/parser.ts +0 -185
- package/src/pyramid/renderer.ts +0 -768
- package/src/pyramid/types.ts +0 -28
- package/src/quadrant/parser.ts +0 -18
- package/src/quadrant/renderer.ts +0 -638
- package/src/raci/diagnostics.ts +0 -213
- package/src/raci/index.ts +0 -23
- package/src/raci/mutations.ts +0 -321
- package/src/raci/parser.ts +0 -699
- package/src/raci/renderer.ts +0 -1627
- package/src/raci/types.ts +0 -82
- package/src/raci/variants.ts +0 -320
- package/src/render.ts +0 -268
- package/src/ring/parser.ts +0 -212
- package/src/ring/renderer.ts +0 -490
- package/src/ring/types.ts +0 -27
- package/src/sequence/collapse.ts +0 -174
- package/src/sequence/parser.ts +0 -1596
- package/src/sequence/participant-inference.ts +0 -152
- package/src/sequence/renderer.ts +0 -3168
- package/src/sequence/tag-resolution.ts +0 -164
- package/src/sharing.ts +0 -211
- package/src/sitemap/collapse.ts +0 -100
- package/src/sitemap/layout.ts +0 -925
- package/src/sitemap/parser.ts +0 -755
- package/src/sitemap/renderer.ts +0 -828
- package/src/sitemap/types.ts +0 -42
- package/src/slope/parser.ts +0 -18
- package/src/slope/renderer.ts +0 -378
- package/src/swimlane/diagnostics.ts +0 -94
- package/src/swimlane/layout.ts +0 -597
- package/src/swimlane/parser.ts +0 -613
- package/src/swimlane/renderer.ts +0 -681
- package/src/swimlane/types.ts +0 -151
- package/src/tech-radar/interactive.ts +0 -1129
- package/src/tech-radar/layout.ts +0 -197
- package/src/tech-radar/parser.ts +0 -436
- package/src/tech-radar/renderer.ts +0 -1239
- package/src/tech-radar/shared.ts +0 -151
- package/src/tech-radar/types.ts +0 -86
- package/src/themes.ts +0 -22
- package/src/timeline/parser.ts +0 -472
- package/src/timeline/renderer.ts +0 -3024
- package/src/timeline/types.ts +0 -33
- package/src/timeline/viz-parser.ts +0 -21
- package/src/treemap/diagnostics.ts +0 -62
- package/src/treemap/layout-radial.ts +0 -233
- package/src/treemap/layout.ts +0 -189
- package/src/treemap/parser.ts +0 -463
- package/src/treemap/renderer-radial.ts +0 -438
- package/src/treemap/renderer.ts +0 -572
- package/src/treemap/treemap-shared.ts +0 -309
- package/src/treemap/types.ts +0 -60
- package/src/utils/arrow-markers.ts +0 -51
- package/src/utils/arrows-diagnostics.ts +0 -62
- package/src/utils/arrows.ts +0 -227
- package/src/utils/brand.ts +0 -61
- package/src/utils/card.ts +0 -183
- package/src/utils/collapse-engine/tree-edges.ts +0 -115
- package/src/utils/collapse-engine/tree.ts +0 -117
- package/src/utils/d3-helpers.ts +0 -219
- package/src/utils/d3-types.ts +0 -9
- package/src/utils/description-helpers.ts +0 -38
- package/src/utils/duration.ts +0 -312
- package/src/utils/export-container.ts +0 -41
- package/src/utils/expr-eval.ts +0 -27
- package/src/utils/fit-canvas.ts +0 -64
- package/src/utils/hover-styles.ts +0 -673
- package/src/utils/inline-markdown.ts +0 -96
- package/src/utils/legend-constants.ts +0 -48
- package/src/utils/legend-d3.ts +0 -618
- package/src/utils/legend-integration.ts +0 -107
- package/src/utils/legend-layout.ts +0 -776
- package/src/utils/legend-svg.ts +0 -214
- package/src/utils/legend-types.ts +0 -272
- package/src/utils/name-normalize.ts +0 -163
- package/src/utils/note-box/constants.ts +0 -25
- package/src/utils/note-box/index.ts +0 -11
- package/src/utils/note-box/metrics.ts +0 -90
- package/src/utils/note-box/svg.ts +0 -331
- package/src/utils/notes/bounds.ts +0 -30
- package/src/utils/notes/build.ts +0 -131
- package/src/utils/notes/index.ts +0 -18
- package/src/utils/notes/model.ts +0 -19
- package/src/utils/notes/parse.ts +0 -131
- package/src/utils/notes/place.ts +0 -177
- package/src/utils/notes/resolve.ts +0 -88
- package/src/utils/number-format.ts +0 -36
- package/src/utils/parsing.ts +0 -953
- package/src/utils/reserved-key-registry.ts +0 -239
- package/src/utils/safe-href.ts +0 -38
- package/src/utils/scaling.ts +0 -97
- package/src/utils/svg-embed.ts +0 -251
- package/src/utils/tag-groups.ts +0 -607
- package/src/utils/text-measure.ts +0 -122
- package/src/utils/time-ticks.ts +0 -253
- package/src/utils/title-constants.ts +0 -24
- package/src/utils/visual-conventions.ts +0 -61
- package/src/utils/wrapped-desc.ts +0 -87
- package/src/venn/parser.ts +0 -18
- package/src/venn/renderer.ts +0 -1047
- package/src/version-control/diagnostics.ts +0 -67
- package/src/version-control/parser.ts +0 -544
- package/src/version-control/renderer.ts +0 -724
- package/src/version-control/types.ts +0 -100
- package/src/visualizations/parse.ts +0 -1560
- package/src/visualizations/types.ts +0 -262
- package/src/wireframe/layout.ts +0 -479
- package/src/wireframe/parser.ts +0 -1114
- package/src/wireframe/renderer.ts +0 -1318
- package/src/wireframe/types.ts +0 -110
- package/src/wordcloud/parser.ts +0 -18
- package/src/wordcloud/renderer.ts +0 -357
package/src/org/layout.ts
DELETED
|
@@ -1,1262 +0,0 @@
|
|
|
1
|
-
// ============================================================
|
|
2
|
-
// Org Chart Tree Layout Engine (d3-hierarchy)
|
|
3
|
-
// ============================================================
|
|
4
|
-
|
|
5
|
-
import { tagAttrKey } from '../utils/tag-groups';
|
|
6
|
-
import { hierarchy, tree } from 'd3-hierarchy';
|
|
7
|
-
import type { ParsedOrg, OrgNode } from './parser';
|
|
8
|
-
import type { Writable } from '../utils/brand';
|
|
9
|
-
import type { TagGroup } from '../utils/tag-groups';
|
|
10
|
-
import { resolveTagColor, injectDefaultTagMetadata } from '../utils/tag-groups';
|
|
11
|
-
import {
|
|
12
|
-
LEGEND_PILL_FONT_SIZE,
|
|
13
|
-
LEGEND_ENTRY_FONT_SIZE,
|
|
14
|
-
LEGEND_HEIGHT,
|
|
15
|
-
LEGEND_PILL_PAD,
|
|
16
|
-
LEGEND_CAPSULE_PAD,
|
|
17
|
-
LEGEND_DOT_R,
|
|
18
|
-
LEGEND_ENTRY_DOT_GAP,
|
|
19
|
-
LEGEND_ENTRY_TRAIL,
|
|
20
|
-
LEGEND_GROUP_GAP,
|
|
21
|
-
LEGEND_EYE_SIZE,
|
|
22
|
-
LEGEND_EYE_GAP,
|
|
23
|
-
measureLegendText,
|
|
24
|
-
} from '../utils/legend-constants';
|
|
25
|
-
import { measureText } from '../utils/text-measure';
|
|
26
|
-
|
|
27
|
-
// ============================================================
|
|
28
|
-
// Types
|
|
29
|
-
// ============================================================
|
|
30
|
-
|
|
31
|
-
export interface OrgLayoutNode {
|
|
32
|
-
readonly id: string;
|
|
33
|
-
readonly label: string;
|
|
34
|
-
readonly metadata: Readonly<Record<string, string>>;
|
|
35
|
-
/** Original (unfiltered) metadata — used for tag-based hover dimming even when the group is hidden */
|
|
36
|
-
readonly tagMetadata: Readonly<Record<string, string>>;
|
|
37
|
-
readonly isContainer: boolean;
|
|
38
|
-
readonly lineNumber: number;
|
|
39
|
-
readonly color?: string;
|
|
40
|
-
readonly x: number;
|
|
41
|
-
readonly y: number;
|
|
42
|
-
readonly width: number;
|
|
43
|
-
readonly height: number;
|
|
44
|
-
/** Count of hidden descendants when this node is collapsed */
|
|
45
|
-
readonly hiddenCount?: number;
|
|
46
|
-
/** True if node has children (expanded or collapsed) — drives toggle UI */
|
|
47
|
-
readonly hasChildren?: boolean;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export interface OrgLayoutEdge {
|
|
51
|
-
readonly sourceId: string;
|
|
52
|
-
readonly targetId: string;
|
|
53
|
-
readonly points: ReadonlyArray<{ readonly x: number; readonly y: number }>;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
export interface OrgContainerBounds {
|
|
57
|
-
readonly nodeId: string;
|
|
58
|
-
readonly label: string;
|
|
59
|
-
readonly lineNumber: number;
|
|
60
|
-
readonly color?: string;
|
|
61
|
-
readonly metadata: Readonly<Record<string, string>>;
|
|
62
|
-
/** Original (unfiltered) metadata — used for tag-based hover dimming even when the group is hidden */
|
|
63
|
-
readonly tagMetadata: Readonly<Record<string, string>>;
|
|
64
|
-
readonly x: number;
|
|
65
|
-
readonly y: number;
|
|
66
|
-
readonly width: number;
|
|
67
|
-
readonly height: number;
|
|
68
|
-
readonly labelHeight: number;
|
|
69
|
-
/** Count of hidden descendants when this container is collapsed */
|
|
70
|
-
readonly hiddenCount?: number;
|
|
71
|
-
/** True if container has children (expanded or collapsed) — drives toggle UI */
|
|
72
|
-
readonly hasChildren?: boolean;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
export interface OrgLegendEntry {
|
|
76
|
-
readonly value: string;
|
|
77
|
-
readonly color: string;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
export interface OrgLegendGroup {
|
|
81
|
-
readonly name: string;
|
|
82
|
-
readonly alias?: string;
|
|
83
|
-
readonly entries: readonly OrgLegendEntry[];
|
|
84
|
-
readonly x: number;
|
|
85
|
-
readonly y: number;
|
|
86
|
-
readonly width: number;
|
|
87
|
-
readonly height: number;
|
|
88
|
-
readonly minifiedWidth: number;
|
|
89
|
-
readonly minifiedHeight: number;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
export interface OrgLayoutResult {
|
|
93
|
-
readonly nodes: readonly OrgLayoutNode[];
|
|
94
|
-
readonly edges: readonly OrgLayoutEdge[];
|
|
95
|
-
readonly containers: readonly OrgContainerBounds[];
|
|
96
|
-
readonly legend: readonly OrgLegendGroup[];
|
|
97
|
-
readonly width: number;
|
|
98
|
-
readonly height: number;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
// ============================================================
|
|
102
|
-
// Constants
|
|
103
|
-
// ============================================================
|
|
104
|
-
|
|
105
|
-
// Card text font sizes — MUST match the renderer (LABEL_FONT_SIZE / META_FONT_SIZE)
|
|
106
|
-
// so node sizing measures text at the exact size it is drawn.
|
|
107
|
-
const LABEL_FONT_SIZE = 13;
|
|
108
|
-
const META_FONT_SIZE = 11;
|
|
109
|
-
const META_LINE_HEIGHT = 16;
|
|
110
|
-
const HEADER_HEIGHT = 28;
|
|
111
|
-
const SEPARATOR_GAP = 6;
|
|
112
|
-
const CARD_H_PAD = 20;
|
|
113
|
-
const CARD_V_PAD = 10;
|
|
114
|
-
const MIN_CARD_WIDTH = 140;
|
|
115
|
-
const H_GAP = 30;
|
|
116
|
-
const V_GAP = 50;
|
|
117
|
-
const MARGIN = 40;
|
|
118
|
-
const CONTAINER_PAD_X = 24;
|
|
119
|
-
const CONTAINER_PAD_BOTTOM = 24;
|
|
120
|
-
const CONTAINER_LABEL_HEIGHT = 28;
|
|
121
|
-
const CONTAINER_META_LINE_HEIGHT = 16;
|
|
122
|
-
const STACK_V_GAP = 20;
|
|
123
|
-
|
|
124
|
-
// Legend (kanban-style pills)
|
|
125
|
-
|
|
126
|
-
// ============================================================
|
|
127
|
-
// Helpers
|
|
128
|
-
// ============================================================
|
|
129
|
-
|
|
130
|
-
/** Count all non-container descendants recursively, including hidden (collapsed) ones. */
|
|
131
|
-
function countDescendantNodes(
|
|
132
|
-
node: OrgNode,
|
|
133
|
-
hiddenCounts?: Map<string, number>
|
|
134
|
-
): number {
|
|
135
|
-
let count = 0;
|
|
136
|
-
for (const child of node.children) {
|
|
137
|
-
count +=
|
|
138
|
-
(child.isContainer ? 0 : 1) + countDescendantNodes(child, hiddenCounts);
|
|
139
|
-
const hc = hiddenCounts?.get(child.id);
|
|
140
|
-
if (hc) count += hc;
|
|
141
|
-
}
|
|
142
|
-
return count;
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
// ============================================================
|
|
146
|
-
// Card Sizing
|
|
147
|
-
// ============================================================
|
|
148
|
-
|
|
149
|
-
function filterMetadata(
|
|
150
|
-
metadata: Record<string, string>,
|
|
151
|
-
hiddenAttributes?: Set<string>
|
|
152
|
-
): Record<string, string> {
|
|
153
|
-
if (!hiddenAttributes || hiddenAttributes.size === 0) return metadata;
|
|
154
|
-
const filtered: Record<string, string> = {};
|
|
155
|
-
for (const [key, value] of Object.entries(metadata)) {
|
|
156
|
-
if (!hiddenAttributes.has(key)) {
|
|
157
|
-
filtered[key] = value;
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
return filtered;
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
function computeCardWidth(label: string, meta: Record<string, string>): number {
|
|
164
|
-
// Label is drawn bold at LABEL_FONT_SIZE; meta rows at META_FONT_SIZE.
|
|
165
|
-
let maxTextWidth = measureText(label, LABEL_FONT_SIZE);
|
|
166
|
-
|
|
167
|
-
for (const [key, value] of Object.entries(meta)) {
|
|
168
|
-
const lineWidth = measureText(`${key}: ${value}`, META_FONT_SIZE);
|
|
169
|
-
if (lineWidth > maxTextWidth) maxTextWidth = lineWidth;
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
return Math.max(MIN_CARD_WIDTH, Math.ceil(maxTextWidth) + CARD_H_PAD * 2);
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
function computeCardHeight(meta: Record<string, string>): number {
|
|
176
|
-
const metaCount = Object.keys(meta).length;
|
|
177
|
-
if (metaCount === 0) return HEADER_HEIGHT + CARD_V_PAD;
|
|
178
|
-
return (
|
|
179
|
-
HEADER_HEIGHT + SEPARATOR_GAP + metaCount * META_LINE_HEIGHT + CARD_V_PAD
|
|
180
|
-
);
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
// ============================================================
|
|
184
|
-
// Tag Group Color Resolution
|
|
185
|
-
// ============================================================
|
|
186
|
-
|
|
187
|
-
function resolveNodeColor(
|
|
188
|
-
node: OrgNode,
|
|
189
|
-
tagGroups: readonly TagGroup[],
|
|
190
|
-
activeGroupName: string | null
|
|
191
|
-
): string | undefined {
|
|
192
|
-
// Explicit inline (color) always wins — handled before tag resolution
|
|
193
|
-
if (node.color) return node.color;
|
|
194
|
-
return resolveTagColor(
|
|
195
|
-
node.metadata,
|
|
196
|
-
[...tagGroups],
|
|
197
|
-
activeGroupName,
|
|
198
|
-
node.isContainer
|
|
199
|
-
);
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
// ============================================================
|
|
203
|
-
// Hierarchy Helpers
|
|
204
|
-
// ============================================================
|
|
205
|
-
|
|
206
|
-
interface TreeNode {
|
|
207
|
-
orgNode: OrgNode;
|
|
208
|
-
children: TreeNode[];
|
|
209
|
-
width: number;
|
|
210
|
-
height: number;
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
function buildTreeNodes(
|
|
214
|
-
nodes: readonly OrgNode[],
|
|
215
|
-
hiddenCounts?: Map<string, number>,
|
|
216
|
-
hiddenAttributes?: Set<string>,
|
|
217
|
-
subNodeLabel?: string,
|
|
218
|
-
showSubNodeCount?: boolean
|
|
219
|
-
): TreeNode[] {
|
|
220
|
-
return nodes.map((orgNode) => {
|
|
221
|
-
const meta = filterMetadata(orgNode.metadata, hiddenAttributes);
|
|
222
|
-
const hc = hiddenCounts?.get(orgNode.id);
|
|
223
|
-
if (!orgNode.isContainer && showSubNodeCount && !(hc != null && hc > 0)) {
|
|
224
|
-
const count = countDescendantNodes(orgNode, hiddenCounts);
|
|
225
|
-
if (count > 0) {
|
|
226
|
-
meta[subNodeLabel ?? 'Sub-node Count'] = String(count);
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
return {
|
|
230
|
-
orgNode,
|
|
231
|
-
children: buildTreeNodes(
|
|
232
|
-
orgNode.children,
|
|
233
|
-
hiddenCounts,
|
|
234
|
-
hiddenAttributes,
|
|
235
|
-
subNodeLabel,
|
|
236
|
-
showSubNodeCount
|
|
237
|
-
),
|
|
238
|
-
width: computeCardWidth(orgNode.label, meta),
|
|
239
|
-
height: computeCardHeight(meta),
|
|
240
|
-
};
|
|
241
|
-
});
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
/**
|
|
245
|
-
* Count total descendants (children + grandchildren + ...) of a TreeNode.
|
|
246
|
-
*/
|
|
247
|
-
function countDescendants(node: TreeNode): number {
|
|
248
|
-
let count = 0;
|
|
249
|
-
for (const child of node.children) {
|
|
250
|
-
count += 1 + countDescendants(child);
|
|
251
|
-
}
|
|
252
|
-
return count;
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
/**
|
|
256
|
-
* Recursively reorder children so subtrees with the most descendants
|
|
257
|
-
* occupy center positions. Produces a balanced, symmetrical layout.
|
|
258
|
-
* Skips nodes with ≤2 children (no meaningful center to target).
|
|
259
|
-
*/
|
|
260
|
-
function centerHeavyChildren(node: TreeNode): void {
|
|
261
|
-
for (const child of node.children) {
|
|
262
|
-
centerHeavyChildren(child);
|
|
263
|
-
}
|
|
264
|
-
if (node.children.length <= 2) return;
|
|
265
|
-
|
|
266
|
-
const weighted = node.children
|
|
267
|
-
.map((child) => ({ child, weight: countDescendants(child) }))
|
|
268
|
-
.sort((a, b) => b.weight - a.weight);
|
|
269
|
-
|
|
270
|
-
const result: TreeNode[] = new Array(weighted.length);
|
|
271
|
-
const mid = Math.floor((weighted.length - 1) / 2);
|
|
272
|
-
let left = mid;
|
|
273
|
-
let right = mid;
|
|
274
|
-
|
|
275
|
-
for (let i = 0; i < weighted.length; i++) {
|
|
276
|
-
// In-bounds by loop guard.
|
|
277
|
-
const w = weighted[i]!;
|
|
278
|
-
if (i === 0) {
|
|
279
|
-
result[mid] = w.child;
|
|
280
|
-
} else if (i % 2 === 1) {
|
|
281
|
-
right++;
|
|
282
|
-
result[right] = w.child;
|
|
283
|
-
} else {
|
|
284
|
-
left--;
|
|
285
|
-
result[left] = w.child;
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
node.children = result;
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
// ============================================================
|
|
293
|
-
// Layout
|
|
294
|
-
// ============================================================
|
|
295
|
-
|
|
296
|
-
function computeLegendGroups(
|
|
297
|
-
tagGroups: readonly TagGroup[],
|
|
298
|
-
showEyeIcons: boolean,
|
|
299
|
-
usedValuesByGroup?: Map<string, Set<string>>
|
|
300
|
-
): Writable<OrgLegendGroup>[] {
|
|
301
|
-
const groups: Writable<OrgLegendGroup>[] = [];
|
|
302
|
-
|
|
303
|
-
for (const group of tagGroups) {
|
|
304
|
-
if (group.entries.length === 0) continue;
|
|
305
|
-
|
|
306
|
-
// Filter entries to only values actually used by nodes (if provided)
|
|
307
|
-
const usedValues = usedValuesByGroup?.get(tagAttrKey(group.name));
|
|
308
|
-
const visibleEntries = usedValues
|
|
309
|
-
? group.entries.filter((e) => usedValues.has(e.value.toLowerCase()))
|
|
310
|
-
: group.entries;
|
|
311
|
-
if (visibleEntries.length === 0) continue;
|
|
312
|
-
|
|
313
|
-
// Pill label shows just the group name (alias is for DSL shorthand only)
|
|
314
|
-
const pillWidth =
|
|
315
|
-
measureLegendText(group.name, LEGEND_PILL_FONT_SIZE) + LEGEND_PILL_PAD;
|
|
316
|
-
const minPillWidth = pillWidth;
|
|
317
|
-
|
|
318
|
-
// Capsule: pad + pill + gap + entries + pad
|
|
319
|
-
let entriesWidth = 0;
|
|
320
|
-
for (const entry of visibleEntries) {
|
|
321
|
-
entriesWidth +=
|
|
322
|
-
LEGEND_DOT_R * 2 +
|
|
323
|
-
LEGEND_ENTRY_DOT_GAP +
|
|
324
|
-
measureLegendText(entry.value, LEGEND_ENTRY_FONT_SIZE) +
|
|
325
|
-
LEGEND_ENTRY_TRAIL;
|
|
326
|
-
}
|
|
327
|
-
const eyeSpace = showEyeIcons ? LEGEND_EYE_SIZE + LEGEND_EYE_GAP : 0;
|
|
328
|
-
const capsuleWidth =
|
|
329
|
-
LEGEND_CAPSULE_PAD * 2 + pillWidth + 4 + eyeSpace + entriesWidth;
|
|
330
|
-
|
|
331
|
-
groups.push({
|
|
332
|
-
name: group.name,
|
|
333
|
-
...(group.alias !== undefined && { alias: group.alias }),
|
|
334
|
-
entries: visibleEntries.map((e) => ({
|
|
335
|
-
value: e.value,
|
|
336
|
-
color: e.color,
|
|
337
|
-
})),
|
|
338
|
-
x: 0,
|
|
339
|
-
y: 0,
|
|
340
|
-
width: capsuleWidth,
|
|
341
|
-
height: LEGEND_HEIGHT,
|
|
342
|
-
minifiedWidth: minPillWidth,
|
|
343
|
-
minifiedHeight: LEGEND_HEIGHT,
|
|
344
|
-
});
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
return groups;
|
|
348
|
-
}
|
|
349
|
-
|
|
350
|
-
/**
|
|
351
|
-
* Inject default tag group values into non-container node metadata.
|
|
352
|
-
* Delegates to shared `injectDefaultTagMetadata` with org-specific skip logic.
|
|
353
|
-
*/
|
|
354
|
-
function injectDefaultMetadata(
|
|
355
|
-
roots: readonly OrgNode[],
|
|
356
|
-
tagGroups: readonly TagGroup[]
|
|
357
|
-
): void {
|
|
358
|
-
// Flatten all nodes (recursive) for the shared utility
|
|
359
|
-
const allNodes: OrgNode[] = [];
|
|
360
|
-
const collect = (node: OrgNode) => {
|
|
361
|
-
allNodes.push(node);
|
|
362
|
-
for (const child of node.children) collect(child);
|
|
363
|
-
};
|
|
364
|
-
for (const root of roots) collect(root);
|
|
365
|
-
|
|
366
|
-
injectDefaultTagMetadata(
|
|
367
|
-
allNodes,
|
|
368
|
-
tagGroups,
|
|
369
|
-
(entity) => (entity as OrgNode).isContainer
|
|
370
|
-
);
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
export function layoutOrg(
|
|
374
|
-
parsed: ParsedOrg,
|
|
375
|
-
hiddenCounts?: Map<string, number>,
|
|
376
|
-
activeTagGroup?: string | null,
|
|
377
|
-
hiddenAttributes?: Set<string>,
|
|
378
|
-
expandAllLegend?: boolean
|
|
379
|
-
): OrgLayoutResult {
|
|
380
|
-
if (parsed.roots.length === 0) {
|
|
381
|
-
// Legend-only: compute and position legend groups even without nodes
|
|
382
|
-
const showEyeIcons = hiddenAttributes !== undefined;
|
|
383
|
-
const legendGroups = computeLegendGroups(parsed.tagGroups, showEyeIcons);
|
|
384
|
-
if (legendGroups.length === 0) {
|
|
385
|
-
return {
|
|
386
|
-
nodes: [],
|
|
387
|
-
edges: [],
|
|
388
|
-
containers: [],
|
|
389
|
-
legend: [],
|
|
390
|
-
width: 0,
|
|
391
|
-
height: 0,
|
|
392
|
-
};
|
|
393
|
-
}
|
|
394
|
-
|
|
395
|
-
// Legend-only mode: stack groups vertically, all expanded
|
|
396
|
-
let cy = MARGIN;
|
|
397
|
-
let maxWidth = 0;
|
|
398
|
-
for (const g of legendGroups) {
|
|
399
|
-
g.x = MARGIN;
|
|
400
|
-
g.y = cy;
|
|
401
|
-
cy += LEGEND_HEIGHT + LEGEND_GROUP_GAP;
|
|
402
|
-
if (g.width > maxWidth) maxWidth = g.width;
|
|
403
|
-
}
|
|
404
|
-
return {
|
|
405
|
-
nodes: [],
|
|
406
|
-
edges: [],
|
|
407
|
-
containers: [],
|
|
408
|
-
legend: legendGroups,
|
|
409
|
-
width: maxWidth + MARGIN * 2,
|
|
410
|
-
height: cy - LEGEND_GROUP_GAP + MARGIN,
|
|
411
|
-
};
|
|
412
|
-
}
|
|
413
|
-
|
|
414
|
-
// Inject default tag group values into node metadata for display.
|
|
415
|
-
// Must happen before buildTreeNodes so card sizing accounts for extra rows.
|
|
416
|
-
injectDefaultMetadata(parsed.roots, parsed.tagGroups);
|
|
417
|
-
|
|
418
|
-
// Build tree structure
|
|
419
|
-
const subNodeLabel = parsed.options['sub-node-label'] ?? undefined;
|
|
420
|
-
const showSubNodeCount = ['yes', 'on'].includes(
|
|
421
|
-
parsed.options['show-sub-node-count']?.toLowerCase() ?? ''
|
|
422
|
-
);
|
|
423
|
-
const treeNodes = buildTreeNodes(
|
|
424
|
-
parsed.roots,
|
|
425
|
-
hiddenCounts,
|
|
426
|
-
hiddenAttributes,
|
|
427
|
-
subNodeLabel,
|
|
428
|
-
showSubNodeCount
|
|
429
|
-
);
|
|
430
|
-
|
|
431
|
-
// Single root or virtual root for multiple roots
|
|
432
|
-
let root: TreeNode;
|
|
433
|
-
if (treeNodes.length === 1) {
|
|
434
|
-
// In-bounds by length === 1 guard.
|
|
435
|
-
root = treeNodes[0]!;
|
|
436
|
-
} else {
|
|
437
|
-
root = {
|
|
438
|
-
orgNode: {
|
|
439
|
-
id: '__virtual_root__',
|
|
440
|
-
label: '',
|
|
441
|
-
metadata: {},
|
|
442
|
-
children: parsed.roots,
|
|
443
|
-
parentId: null,
|
|
444
|
-
isContainer: false,
|
|
445
|
-
lineNumber: 0,
|
|
446
|
-
},
|
|
447
|
-
children: treeNodes,
|
|
448
|
-
width: 0,
|
|
449
|
-
height: 0,
|
|
450
|
-
};
|
|
451
|
-
}
|
|
452
|
-
|
|
453
|
-
// Pre-compute max card dimensions for node separation
|
|
454
|
-
let maxWidth = 0;
|
|
455
|
-
let maxHeight = 0;
|
|
456
|
-
const allTreeNodes: TreeNode[] = [];
|
|
457
|
-
const collectNodes = (tn: TreeNode) => {
|
|
458
|
-
if (tn.orgNode.id !== '__virtual_root__') {
|
|
459
|
-
allTreeNodes.push(tn);
|
|
460
|
-
if (tn.width > maxWidth) maxWidth = tn.width;
|
|
461
|
-
if (tn.height > maxHeight) maxHeight = tn.height;
|
|
462
|
-
}
|
|
463
|
-
for (const child of tn.children) collectNodes(child);
|
|
464
|
-
};
|
|
465
|
-
collectNodes(root);
|
|
466
|
-
|
|
467
|
-
// Standardize all cards to the widest width for uniform appearance
|
|
468
|
-
for (const tn of allTreeNodes) {
|
|
469
|
-
tn.width = maxWidth;
|
|
470
|
-
}
|
|
471
|
-
|
|
472
|
-
// Collapse leaf containers: when a container's children are ALL leaves
|
|
473
|
-
// (no grandchildren), replace them with a single virtual stack node so
|
|
474
|
-
// the d3 tree allocates a narrow column instead of a wide row.
|
|
475
|
-
const leafStacks = new Map<
|
|
476
|
-
string,
|
|
477
|
-
{ children: TreeNode[]; placeholderId: string }
|
|
478
|
-
>();
|
|
479
|
-
|
|
480
|
-
const collapseLeafContainers = (tn: TreeNode): void => {
|
|
481
|
-
for (const child of tn.children) collapseLeafContainers(child);
|
|
482
|
-
|
|
483
|
-
if (
|
|
484
|
-
tn.orgNode.isContainer &&
|
|
485
|
-
tn.children.length > 0 &&
|
|
486
|
-
tn.children.every((c) => c.children.length === 0)
|
|
487
|
-
) {
|
|
488
|
-
const placeholderId = `__stack_${tn.orgNode.id}`;
|
|
489
|
-
leafStacks.set(tn.orgNode.id, {
|
|
490
|
-
children: [...tn.children],
|
|
491
|
-
placeholderId,
|
|
492
|
-
});
|
|
493
|
-
|
|
494
|
-
const maxW = Math.max(...tn.children.map((c) => c.width));
|
|
495
|
-
// Standardize all children to the widest card width
|
|
496
|
-
for (const child of tn.children) {
|
|
497
|
-
child.width = maxW;
|
|
498
|
-
}
|
|
499
|
-
const totalH =
|
|
500
|
-
tn.children.reduce((s, c) => s + c.height, 0) +
|
|
501
|
-
(tn.children.length - 1) * STACK_V_GAP;
|
|
502
|
-
|
|
503
|
-
tn.children = [
|
|
504
|
-
{
|
|
505
|
-
orgNode: {
|
|
506
|
-
id: placeholderId,
|
|
507
|
-
label: '',
|
|
508
|
-
metadata: {},
|
|
509
|
-
children: [],
|
|
510
|
-
parentId: tn.orgNode.id,
|
|
511
|
-
isContainer: false,
|
|
512
|
-
lineNumber: 0,
|
|
513
|
-
},
|
|
514
|
-
children: [],
|
|
515
|
-
width: maxW,
|
|
516
|
-
height: totalH,
|
|
517
|
-
},
|
|
518
|
-
];
|
|
519
|
-
}
|
|
520
|
-
};
|
|
521
|
-
collapseLeafContainers(root);
|
|
522
|
-
|
|
523
|
-
// Reorder children: heaviest subtrees in center positions
|
|
524
|
-
centerHeavyChildren(root);
|
|
525
|
-
|
|
526
|
-
// Build d3 hierarchy
|
|
527
|
-
const h = hierarchy<TreeNode>(root, (d) => d.children);
|
|
528
|
-
|
|
529
|
-
// Run Reingold-Tilford tree layout with nodeSize
|
|
530
|
-
// x = horizontal spread, y = vertical (depth)
|
|
531
|
-
const treeLayout = tree<TreeNode>().nodeSize([
|
|
532
|
-
maxWidth + H_GAP,
|
|
533
|
-
maxHeight + V_GAP,
|
|
534
|
-
]);
|
|
535
|
-
treeLayout(h);
|
|
536
|
-
|
|
537
|
-
// Post-layout: compact vertical spacing per depth level.
|
|
538
|
-
// D3 tree uses uniform nodeSize (maxHeight + V_GAP) for every level, which
|
|
539
|
-
// creates disproportionate gaps when short nodes (no metadata) are placed at
|
|
540
|
-
// the same level-spacing as tall nodes (multiple metadata rows). Recompute
|
|
541
|
-
// Y positions so each level's gap is based on the actual max height at that
|
|
542
|
-
// level rather than the global max.
|
|
543
|
-
{
|
|
544
|
-
const descendants = h
|
|
545
|
-
.descendants()
|
|
546
|
-
.filter((d) => d.data.orgNode.id !== '__virtual_root__');
|
|
547
|
-
|
|
548
|
-
// Collect max actual card height per depth level.
|
|
549
|
-
// Exclude __stack_ placeholders — their aggregate height (multiple
|
|
550
|
-
// stacked cards) would inflate the level max and push sibling
|
|
551
|
-
// subtrees' deeper children far below where they need to be.
|
|
552
|
-
const levelMaxHeight = new Map<number, number>();
|
|
553
|
-
for (const d of descendants) {
|
|
554
|
-
if (d.data.orgNode.id.startsWith('__stack_')) continue;
|
|
555
|
-
const cur = levelMaxHeight.get(d.depth) ?? 0;
|
|
556
|
-
if (d.data.height > cur) levelMaxHeight.set(d.depth, d.data.height);
|
|
557
|
-
}
|
|
558
|
-
|
|
559
|
-
// Compute compacted Y position for each depth level
|
|
560
|
-
const maxDepth = Math.max(...levelMaxHeight.keys(), 0);
|
|
561
|
-
const compactedY = new Map<number, number>();
|
|
562
|
-
// Virtual root (depth 0 in hierarchy) stays at y=0
|
|
563
|
-
// First real level starts at depth 1 for multi-root or depth 0 for single root.
|
|
564
|
-
// We compute based on the d3 hierarchy's depth numbering.
|
|
565
|
-
const rootDepth = treeNodes.length === 1 ? 0 : 1;
|
|
566
|
-
compactedY.set(rootDepth, 0);
|
|
567
|
-
for (let d = rootDepth + 1; d <= maxDepth; d++) {
|
|
568
|
-
const parentH = levelMaxHeight.get(d - 1) ?? maxHeight;
|
|
569
|
-
const prevY = compactedY.get(d - 1) ?? 0;
|
|
570
|
-
compactedY.set(d, prevY + parentH + V_GAP);
|
|
571
|
-
}
|
|
572
|
-
|
|
573
|
-
// Shift each node from uniform Y to compacted Y (top-aligned).
|
|
574
|
-
// Siblings share the same Y so connecting edges align cleanly.
|
|
575
|
-
for (const d of h.descendants()) {
|
|
576
|
-
if (d.data.orgNode.id === '__virtual_root__') continue;
|
|
577
|
-
d.y = compactedY.get(d.depth) ?? d.y!;
|
|
578
|
-
}
|
|
579
|
-
}
|
|
580
|
-
|
|
581
|
-
// Post-layout: tighten vertical spacing inside containers.
|
|
582
|
-
// Container-with-children nodes render as background boxes (not cards),
|
|
583
|
-
// so their children can sit closer to the container header.
|
|
584
|
-
for (const d of h.descendants()) {
|
|
585
|
-
if (d.data.orgNode.id === '__virtual_root__') continue;
|
|
586
|
-
if (!d.data.orgNode.isContainer) continue;
|
|
587
|
-
if (!d.children || d.children.length === 0) continue;
|
|
588
|
-
|
|
589
|
-
// Actual gap between this container and its direct children — in-bounds by length > 0 guard above.
|
|
590
|
-
const childY = d.children[0]!.y!;
|
|
591
|
-
const actualLevelGap = childY - d.y!;
|
|
592
|
-
|
|
593
|
-
const metaCount = Object.keys(d.data.orgNode.metadata).length;
|
|
594
|
-
const headerHeight =
|
|
595
|
-
CONTAINER_LABEL_HEIGHT + metaCount * CONTAINER_META_LINE_HEIGHT;
|
|
596
|
-
const desiredGap = headerHeight + 15;
|
|
597
|
-
const shiftUp = actualLevelGap - desiredGap;
|
|
598
|
-
if (shiftUp <= 0) continue;
|
|
599
|
-
|
|
600
|
-
// Shift all descendants upward
|
|
601
|
-
const shift = (node: typeof d) => {
|
|
602
|
-
if (node.children) {
|
|
603
|
-
for (const child of node.children) {
|
|
604
|
-
child.y! -= shiftUp;
|
|
605
|
-
shift(child);
|
|
606
|
-
}
|
|
607
|
-
}
|
|
608
|
-
};
|
|
609
|
-
shift(d);
|
|
610
|
-
}
|
|
611
|
-
|
|
612
|
-
// Post-layout: tighten gap between non-container parents and their
|
|
613
|
-
// container children. Containers render as header boxes (not full cards),
|
|
614
|
-
// so the standard inter-level gap is visually excessive.
|
|
615
|
-
for (const d of h.descendants()) {
|
|
616
|
-
if (d.data.orgNode.id === '__virtual_root__') continue;
|
|
617
|
-
if (d.data.orgNode.isContainer) continue; // only non-container parents
|
|
618
|
-
if (!d.children || d.children.length === 0) continue;
|
|
619
|
-
|
|
620
|
-
// Only apply when ALL direct children are containers — mixed children
|
|
621
|
-
// need standard spacing so siblings stay aligned.
|
|
622
|
-
if (!d.children.every((c) => c.data.orgNode.isContainer)) continue;
|
|
623
|
-
|
|
624
|
-
const parentBottomY = d.y! + d.data.height;
|
|
625
|
-
const firstChildY = Math.min(...d.children.map((c) => c.y!));
|
|
626
|
-
const currentGap = firstChildY - parentBottomY;
|
|
627
|
-
const desiredGap = V_GAP * 0.6;
|
|
628
|
-
const shiftUp = currentGap - desiredGap;
|
|
629
|
-
if (shiftUp <= 0) continue;
|
|
630
|
-
|
|
631
|
-
// Shift all container children and their descendants up
|
|
632
|
-
const shiftDown = (node: typeof d) => {
|
|
633
|
-
node.y! -= shiftUp;
|
|
634
|
-
if (node.children) {
|
|
635
|
-
for (const child of node.children) {
|
|
636
|
-
shiftDown(child);
|
|
637
|
-
}
|
|
638
|
-
}
|
|
639
|
-
};
|
|
640
|
-
for (const child of d.children) {
|
|
641
|
-
shiftDown(child);
|
|
642
|
-
}
|
|
643
|
-
}
|
|
644
|
-
|
|
645
|
-
// Post-layout: compact sibling spacing based on actual subtree widths.
|
|
646
|
-
// D3 uses uniform nodeSize so narrow stacks get the same gap as wide
|
|
647
|
-
// subtrees. Process bottom-up so inner subtrees are compact first.
|
|
648
|
-
{
|
|
649
|
-
type HNode = typeof h;
|
|
650
|
-
const subtreeExtent = (node: HNode): { minX: number; maxX: number } => {
|
|
651
|
-
// Start with this node's own card/header bounds
|
|
652
|
-
let min = node.x! - node.data.width / 2;
|
|
653
|
-
let max = node.x! + node.data.width / 2;
|
|
654
|
-
|
|
655
|
-
// Include children's subtree extents
|
|
656
|
-
if (node.children) {
|
|
657
|
-
for (const child of node.children) {
|
|
658
|
-
const childExt = subtreeExtent(child);
|
|
659
|
-
if (childExt.minX < min) min = childExt.minX;
|
|
660
|
-
if (childExt.maxX > max) max = childExt.maxX;
|
|
661
|
-
}
|
|
662
|
-
}
|
|
663
|
-
|
|
664
|
-
// Container boxes wrap their content with padding — mirror the
|
|
665
|
-
// actual bounding-box computation so compaction sees the true width.
|
|
666
|
-
if (node.data.orgNode.isContainer) {
|
|
667
|
-
min -= CONTAINER_PAD_X;
|
|
668
|
-
max += CONTAINER_PAD_X;
|
|
669
|
-
}
|
|
670
|
-
|
|
671
|
-
return { minX: min, maxX: max };
|
|
672
|
-
};
|
|
673
|
-
|
|
674
|
-
const shiftX = (node: HNode, dx: number) => {
|
|
675
|
-
node.x! += dx;
|
|
676
|
-
if (node.children) node.children.forEach((c) => shiftX(c, dx));
|
|
677
|
-
};
|
|
678
|
-
|
|
679
|
-
const internalNodes = h
|
|
680
|
-
.descendants()
|
|
681
|
-
.filter((d) => d.children && d.children.length >= 2)
|
|
682
|
-
.sort((a, b) => b.depth - a.depth);
|
|
683
|
-
|
|
684
|
-
for (const parent of internalNodes) {
|
|
685
|
-
const children = parent.children!;
|
|
686
|
-
|
|
687
|
-
const extents = children.map((child) => {
|
|
688
|
-
const ext = subtreeExtent(child);
|
|
689
|
-
return {
|
|
690
|
-
relLeft: ext.minX - child.x!,
|
|
691
|
-
relRight: ext.maxX - child.x!,
|
|
692
|
-
};
|
|
693
|
-
});
|
|
694
|
-
|
|
695
|
-
// children filtered to length >= 2 above, so first and last are in-bounds.
|
|
696
|
-
const currentCenter =
|
|
697
|
-
(children[0]!.x! + children[children.length - 1]!.x!) / 2;
|
|
698
|
-
|
|
699
|
-
const positions: number[] = [0];
|
|
700
|
-
for (let i = 1; i < children.length; i++) {
|
|
701
|
-
// In-bounds: i >= 1 so i-1 >= 0, and extents is parallel to children.
|
|
702
|
-
const prevRight = positions[i - 1]! + extents[i - 1]!.relRight;
|
|
703
|
-
positions[i] = prevRight + H_GAP - extents[i]!.relLeft;
|
|
704
|
-
}
|
|
705
|
-
|
|
706
|
-
// positions has at least one element (initialized with [0]).
|
|
707
|
-
const newCenter = (positions[0]! + positions[positions.length - 1]!) / 2;
|
|
708
|
-
const centerShift = currentCenter - newCenter;
|
|
709
|
-
|
|
710
|
-
for (let i = 0; i < children.length; i++) {
|
|
711
|
-
// In-bounds by loop guard.
|
|
712
|
-
const newX = positions[i]! + centerShift;
|
|
713
|
-
const dx = newX - children[i]!.x!;
|
|
714
|
-
if (Math.abs(dx) > 0.001) {
|
|
715
|
-
shiftX(children[i]!, dx);
|
|
716
|
-
}
|
|
717
|
-
}
|
|
718
|
-
}
|
|
719
|
-
}
|
|
720
|
-
|
|
721
|
-
// Post-layout: center each parent exactly over its direct children.
|
|
722
|
-
// d3-hierarchy centers over the subtree centroid, which drifts when
|
|
723
|
-
// grandchildren have asymmetric widths. Process bottom-up so parents
|
|
724
|
-
// see already-adjusted child positions.
|
|
725
|
-
{
|
|
726
|
-
const parentNodes = h
|
|
727
|
-
.descendants()
|
|
728
|
-
.filter(
|
|
729
|
-
(d) =>
|
|
730
|
-
d.children &&
|
|
731
|
-
d.children.length >= 1 &&
|
|
732
|
-
d.data.orgNode.id !== '__virtual_root__'
|
|
733
|
-
)
|
|
734
|
-
.sort((a, b) => b.depth - a.depth);
|
|
735
|
-
|
|
736
|
-
for (const parent of parentNodes) {
|
|
737
|
-
const childXs = parent.children!.map((c) => c.x!);
|
|
738
|
-
const desiredX = (Math.min(...childXs) + Math.max(...childXs)) / 2;
|
|
739
|
-
parent.x = desiredX;
|
|
740
|
-
}
|
|
741
|
-
}
|
|
742
|
-
|
|
743
|
-
// Collect positioned nodes and edges
|
|
744
|
-
const layoutNodes: Writable<OrgLayoutNode>[] = [];
|
|
745
|
-
const layoutEdges: Writable<OrgLayoutEdge>[] = [];
|
|
746
|
-
|
|
747
|
-
// Find bounding box and build outputs
|
|
748
|
-
let minX = Infinity;
|
|
749
|
-
let maxX = -Infinity;
|
|
750
|
-
let minY = Infinity;
|
|
751
|
-
let maxY = -Infinity;
|
|
752
|
-
|
|
753
|
-
// Expand leaf container stacks: compute individual child positions
|
|
754
|
-
// in d3 coordinate space (before offset) so bounding box is correct
|
|
755
|
-
interface ExpandedChild {
|
|
756
|
-
orgNode: OrgNode;
|
|
757
|
-
width: number;
|
|
758
|
-
height: number;
|
|
759
|
-
cx: number;
|
|
760
|
-
cy: number;
|
|
761
|
-
}
|
|
762
|
-
const expandedChildren: ExpandedChild[] = [];
|
|
763
|
-
|
|
764
|
-
for (const d of h.descendants()) {
|
|
765
|
-
if (d.data.orgNode.id === '__virtual_root__') continue;
|
|
766
|
-
if (!d.data.orgNode.id.startsWith('__stack_')) continue;
|
|
767
|
-
|
|
768
|
-
const containerId = d.data.orgNode.id.replace('__stack_', '');
|
|
769
|
-
const stack = leafStacks.get(containerId);
|
|
770
|
-
if (!stack) continue;
|
|
771
|
-
|
|
772
|
-
let currentY = d.y!;
|
|
773
|
-
for (const child of stack.children) {
|
|
774
|
-
expandedChildren.push({
|
|
775
|
-
orgNode: child.orgNode,
|
|
776
|
-
width: child.width,
|
|
777
|
-
height: child.height,
|
|
778
|
-
cx: d.x!,
|
|
779
|
-
cy: currentY,
|
|
780
|
-
});
|
|
781
|
-
currentY += child.height + STACK_V_GAP;
|
|
782
|
-
}
|
|
783
|
-
}
|
|
784
|
-
|
|
785
|
-
for (const d of h.descendants()) {
|
|
786
|
-
if (d.data.orgNode.id === '__virtual_root__') continue;
|
|
787
|
-
if (d.data.orgNode.id.startsWith('__stack_')) continue;
|
|
788
|
-
|
|
789
|
-
const w = d.data.width;
|
|
790
|
-
const ht = d.data.height;
|
|
791
|
-
const cx = d.x!;
|
|
792
|
-
const cy = d.y!;
|
|
793
|
-
|
|
794
|
-
if (cx - w / 2 < minX) minX = cx - w / 2;
|
|
795
|
-
if (cx + w / 2 > maxX) maxX = cx + w / 2;
|
|
796
|
-
if (cy < minY) minY = cy;
|
|
797
|
-
if (cy + ht > maxY) maxY = cy + ht;
|
|
798
|
-
}
|
|
799
|
-
|
|
800
|
-
for (const ec of expandedChildren) {
|
|
801
|
-
if (ec.cx - ec.width / 2 < minX) minX = ec.cx - ec.width / 2;
|
|
802
|
-
if (ec.cx + ec.width / 2 > maxX) maxX = ec.cx + ec.width / 2;
|
|
803
|
-
if (ec.cy < minY) minY = ec.cy;
|
|
804
|
-
if (ec.cy + ec.height > maxY) maxY = ec.cy + ec.height;
|
|
805
|
-
}
|
|
806
|
-
|
|
807
|
-
// Translate so all coordinates are positive, starting at MARGIN
|
|
808
|
-
const offsetX = -minX + MARGIN;
|
|
809
|
-
const offsetY = -minY + MARGIN;
|
|
810
|
-
|
|
811
|
-
// Add expanded stack children as layout nodes
|
|
812
|
-
const subNodeKey = subNodeLabel ?? 'Sub-node Count';
|
|
813
|
-
for (const ec of expandedChildren) {
|
|
814
|
-
const hc = hiddenCounts?.get(ec.orgNode.id);
|
|
815
|
-
const meta = filterMetadata(ec.orgNode.metadata, hiddenAttributes);
|
|
816
|
-
if (
|
|
817
|
-
!ec.orgNode.isContainer &&
|
|
818
|
-
showSubNodeCount &&
|
|
819
|
-
!(hc != null && hc > 0)
|
|
820
|
-
) {
|
|
821
|
-
const count = countDescendantNodes(ec.orgNode, hiddenCounts);
|
|
822
|
-
if (count > 0) meta[subNodeKey] = String(count);
|
|
823
|
-
}
|
|
824
|
-
const ecColor = resolveNodeColor(
|
|
825
|
-
ec.orgNode,
|
|
826
|
-
parsed.tagGroups,
|
|
827
|
-
activeTagGroup ?? null
|
|
828
|
-
);
|
|
829
|
-
const ecHasChildren =
|
|
830
|
-
ec.orgNode.children.length > 0 || (hc != null && hc > 0) || undefined;
|
|
831
|
-
layoutNodes.push({
|
|
832
|
-
id: ec.orgNode.id,
|
|
833
|
-
label: ec.orgNode.label,
|
|
834
|
-
metadata: meta,
|
|
835
|
-
tagMetadata: { ...ec.orgNode.metadata },
|
|
836
|
-
isContainer: ec.orgNode.isContainer,
|
|
837
|
-
lineNumber: ec.orgNode.lineNumber,
|
|
838
|
-
...(ecColor !== undefined && { color: ecColor }),
|
|
839
|
-
x: ec.cx + offsetX,
|
|
840
|
-
y: ec.cy + offsetY,
|
|
841
|
-
width: ec.width,
|
|
842
|
-
height: ec.height,
|
|
843
|
-
...(hc !== undefined && { hiddenCount: hc }),
|
|
844
|
-
...(ecHasChildren !== undefined && { hasChildren: ecHasChildren }),
|
|
845
|
-
});
|
|
846
|
-
}
|
|
847
|
-
|
|
848
|
-
// Map parent ID → { parentX, parentBottomY, children[] } for bus-style edges
|
|
849
|
-
const busGroups = new Map<
|
|
850
|
-
string,
|
|
851
|
-
{
|
|
852
|
-
parentX: number;
|
|
853
|
-
parentBottomY: number;
|
|
854
|
-
children: { id: string; x: number; topY: number }[];
|
|
855
|
-
}
|
|
856
|
-
>();
|
|
857
|
-
|
|
858
|
-
for (const d of h.descendants()) {
|
|
859
|
-
if (d.data.orgNode.id === '__virtual_root__') continue;
|
|
860
|
-
if (d.data.orgNode.id.startsWith('__stack_')) continue;
|
|
861
|
-
|
|
862
|
-
const orgNode = d.data.orgNode;
|
|
863
|
-
const w = d.data.width;
|
|
864
|
-
const ht = d.data.height;
|
|
865
|
-
const x = d.x! + offsetX;
|
|
866
|
-
const y = d.y! + offsetY;
|
|
867
|
-
|
|
868
|
-
const hc = hiddenCounts?.get(orgNode.id);
|
|
869
|
-
const nodeMeta = filterMetadata(orgNode.metadata, hiddenAttributes);
|
|
870
|
-
if (!orgNode.isContainer && showSubNodeCount && !(hc != null && hc > 0)) {
|
|
871
|
-
const count = countDescendantNodes(orgNode, hiddenCounts);
|
|
872
|
-
if (count > 0) nodeMeta[subNodeKey] = String(count);
|
|
873
|
-
}
|
|
874
|
-
const nodeColor = resolveNodeColor(
|
|
875
|
-
orgNode,
|
|
876
|
-
parsed.tagGroups,
|
|
877
|
-
activeTagGroup ?? null
|
|
878
|
-
);
|
|
879
|
-
const nodeHasChildren =
|
|
880
|
-
(d.children != null && d.children.length > 0) ||
|
|
881
|
-
(hc != null && hc > 0) ||
|
|
882
|
-
undefined;
|
|
883
|
-
layoutNodes.push({
|
|
884
|
-
id: orgNode.id,
|
|
885
|
-
label: orgNode.label,
|
|
886
|
-
metadata: nodeMeta,
|
|
887
|
-
tagMetadata: { ...orgNode.metadata },
|
|
888
|
-
isContainer: orgNode.isContainer,
|
|
889
|
-
lineNumber: orgNode.lineNumber,
|
|
890
|
-
...(nodeColor !== undefined && { color: nodeColor }),
|
|
891
|
-
x,
|
|
892
|
-
y,
|
|
893
|
-
width: w,
|
|
894
|
-
height: ht,
|
|
895
|
-
...(hc !== undefined && { hiddenCount: hc }),
|
|
896
|
-
...(nodeHasChildren !== undefined && { hasChildren: nodeHasChildren }),
|
|
897
|
-
});
|
|
898
|
-
|
|
899
|
-
// Collect children per parent for bus-style edge generation
|
|
900
|
-
const parentIsContainerBox =
|
|
901
|
-
d.parent?.data.orgNode.isContainer &&
|
|
902
|
-
d.parent.children &&
|
|
903
|
-
d.parent.children.length > 0;
|
|
904
|
-
if (
|
|
905
|
-
d.parent &&
|
|
906
|
-
d.parent.data.orgNode.id !== '__virtual_root__' &&
|
|
907
|
-
!parentIsContainerBox
|
|
908
|
-
) {
|
|
909
|
-
const parentId = d.parent.data.orgNode.id;
|
|
910
|
-
if (!busGroups.has(parentId)) {
|
|
911
|
-
const px = d.parent.x! + offsetX;
|
|
912
|
-
const py = d.parent.y! + offsetY;
|
|
913
|
-
const parentH = d.parent.data.height;
|
|
914
|
-
busGroups.set(parentId, {
|
|
915
|
-
parentX: px,
|
|
916
|
-
parentBottomY: py + parentH,
|
|
917
|
-
children: [],
|
|
918
|
-
});
|
|
919
|
-
}
|
|
920
|
-
busGroups.get(parentId)!.children.push({
|
|
921
|
-
id: orgNode.id,
|
|
922
|
-
x,
|
|
923
|
-
topY: y,
|
|
924
|
-
});
|
|
925
|
-
}
|
|
926
|
-
}
|
|
927
|
-
|
|
928
|
-
// Generate non-overlapping edges using bus pattern
|
|
929
|
-
for (const [parentId, group] of busGroups) {
|
|
930
|
-
const { parentX, parentBottomY, children } = group;
|
|
931
|
-
|
|
932
|
-
if (children.length === 1) {
|
|
933
|
-
// Single child: simple elbow (no overlap possible) — in-bounds by length === 1.
|
|
934
|
-
const child = children[0]!;
|
|
935
|
-
const midY = (parentBottomY + child.topY) / 2;
|
|
936
|
-
layoutEdges.push({
|
|
937
|
-
sourceId: parentId,
|
|
938
|
-
targetId: child.id,
|
|
939
|
-
points: [
|
|
940
|
-
{ x: parentX, y: parentBottomY },
|
|
941
|
-
{ x: parentX, y: midY },
|
|
942
|
-
{ x: child.x, y: midY },
|
|
943
|
-
{ x: child.x, y: child.topY },
|
|
944
|
-
],
|
|
945
|
-
});
|
|
946
|
-
} else {
|
|
947
|
-
// Bus pattern: trunk + horizontal bar + per-child drops — length >= 2 here.
|
|
948
|
-
const midY = (parentBottomY + children[0]!.topY) / 2;
|
|
949
|
-
const childXs = children.map((c) => c.x);
|
|
950
|
-
const leftX = Math.min(...childXs);
|
|
951
|
-
const rightX = Math.max(...childXs);
|
|
952
|
-
|
|
953
|
-
// Trunk: parent bottom → midY
|
|
954
|
-
layoutEdges.push({
|
|
955
|
-
sourceId: parentId,
|
|
956
|
-
targetId: parentId,
|
|
957
|
-
points: [
|
|
958
|
-
{ x: parentX, y: parentBottomY },
|
|
959
|
-
{ x: parentX, y: midY },
|
|
960
|
-
],
|
|
961
|
-
});
|
|
962
|
-
|
|
963
|
-
// Horizontal bus: leftmost child → rightmost child at midY
|
|
964
|
-
layoutEdges.push({
|
|
965
|
-
sourceId: parentId,
|
|
966
|
-
targetId: parentId,
|
|
967
|
-
points: [
|
|
968
|
-
{ x: leftX, y: midY },
|
|
969
|
-
{ x: rightX, y: midY },
|
|
970
|
-
],
|
|
971
|
-
});
|
|
972
|
-
|
|
973
|
-
// Drops: midY → child top for each child
|
|
974
|
-
for (const child of children) {
|
|
975
|
-
layoutEdges.push({
|
|
976
|
-
sourceId: parentId,
|
|
977
|
-
targetId: child.id,
|
|
978
|
-
points: [
|
|
979
|
-
{ x: child.x, y: midY },
|
|
980
|
-
{ x: child.x, y: child.topY },
|
|
981
|
-
],
|
|
982
|
-
});
|
|
983
|
-
}
|
|
984
|
-
}
|
|
985
|
-
}
|
|
986
|
-
|
|
987
|
-
// Compute container bounds from d3 hierarchy (bottom-up so inner
|
|
988
|
-
// container boxes are available when computing outer containers)
|
|
989
|
-
const allContainerNodes = h
|
|
990
|
-
.descendants()
|
|
991
|
-
.filter(
|
|
992
|
-
(d) =>
|
|
993
|
-
d.data.orgNode.id !== '__virtual_root__' && d.data.orgNode.isContainer
|
|
994
|
-
);
|
|
995
|
-
|
|
996
|
-
// Map from node ID to computed visual bounds (offset-space)
|
|
997
|
-
const containerBoundsMap = new Map<
|
|
998
|
-
string,
|
|
999
|
-
{ minX: number; maxX: number; minY: number; maxY: number }
|
|
1000
|
-
>();
|
|
1001
|
-
|
|
1002
|
-
const containers: Writable<OrgContainerBounds>[] = [];
|
|
1003
|
-
|
|
1004
|
-
// First pass: childless containers — simple boxes at their own position.
|
|
1005
|
-
// Must be computed before parent containers so their bounds are available.
|
|
1006
|
-
const EMPTY_CONTAINER_MIN_HEIGHT = 60;
|
|
1007
|
-
for (const d of allContainerNodes) {
|
|
1008
|
-
if (d.children && d.children.length > 0) continue;
|
|
1009
|
-
|
|
1010
|
-
const cx = d.x! + offsetX;
|
|
1011
|
-
const cy = d.y! + offsetY;
|
|
1012
|
-
const metaCount = Object.keys(d.data.orgNode.metadata).length;
|
|
1013
|
-
const labelHeight =
|
|
1014
|
-
CONTAINER_LABEL_HEIGHT + metaCount * CONTAINER_META_LINE_HEIGHT;
|
|
1015
|
-
const boxWidth = d.data.width;
|
|
1016
|
-
const boxHeight = Math.max(
|
|
1017
|
-
labelHeight + CONTAINER_PAD_BOTTOM,
|
|
1018
|
-
EMPTY_CONTAINER_MIN_HEIGHT
|
|
1019
|
-
);
|
|
1020
|
-
const boxX = cx - boxWidth / 2;
|
|
1021
|
-
const boxY = cy;
|
|
1022
|
-
|
|
1023
|
-
containerBoundsMap.set(d.data.orgNode.id, {
|
|
1024
|
-
minX: boxX,
|
|
1025
|
-
maxX: boxX + boxWidth,
|
|
1026
|
-
minY: boxY,
|
|
1027
|
-
maxY: boxY + boxHeight,
|
|
1028
|
-
});
|
|
1029
|
-
|
|
1030
|
-
const chc = hiddenCounts?.get(d.data.orgNode.id);
|
|
1031
|
-
const cMeta = filterMetadata(d.data.orgNode.metadata, hiddenAttributes);
|
|
1032
|
-
const cColor = resolveNodeColor(
|
|
1033
|
-
d.data.orgNode,
|
|
1034
|
-
parsed.tagGroups,
|
|
1035
|
-
activeTagGroup ?? null
|
|
1036
|
-
);
|
|
1037
|
-
const cHasChildren = (chc != null && chc > 0) || undefined;
|
|
1038
|
-
containers.push({
|
|
1039
|
-
nodeId: d.data.orgNode.id,
|
|
1040
|
-
label: d.data.orgNode.label,
|
|
1041
|
-
lineNumber: d.data.orgNode.lineNumber,
|
|
1042
|
-
...(cColor !== undefined && { color: cColor }),
|
|
1043
|
-
metadata: cMeta,
|
|
1044
|
-
tagMetadata: { ...d.data.orgNode.metadata },
|
|
1045
|
-
x: boxX,
|
|
1046
|
-
y: boxY,
|
|
1047
|
-
width: boxWidth,
|
|
1048
|
-
height: boxHeight,
|
|
1049
|
-
labelHeight,
|
|
1050
|
-
...(chc !== undefined && { hiddenCount: chc }),
|
|
1051
|
-
...(cHasChildren !== undefined && { hasChildren: cHasChildren }),
|
|
1052
|
-
});
|
|
1053
|
-
}
|
|
1054
|
-
|
|
1055
|
-
// Second pass: containers with children, deepest first
|
|
1056
|
-
const containerCandidates = allContainerNodes.filter(
|
|
1057
|
-
(d) => d.children && d.children.length > 0
|
|
1058
|
-
);
|
|
1059
|
-
containerCandidates.sort((a, b) => b.depth - a.depth);
|
|
1060
|
-
|
|
1061
|
-
for (const d of containerCandidates) {
|
|
1062
|
-
// Collect all descendants (not just direct children)
|
|
1063
|
-
const allDesc: (typeof d)[] = [];
|
|
1064
|
-
const collectDesc = (node: typeof d) => {
|
|
1065
|
-
if (node.children) {
|
|
1066
|
-
for (const child of node.children) {
|
|
1067
|
-
allDesc.push(child);
|
|
1068
|
-
collectDesc(child);
|
|
1069
|
-
}
|
|
1070
|
-
}
|
|
1071
|
-
};
|
|
1072
|
-
collectDesc(d);
|
|
1073
|
-
|
|
1074
|
-
if (allDesc.length === 0) continue;
|
|
1075
|
-
|
|
1076
|
-
// Compute bounding box from all descendants, using inner container
|
|
1077
|
-
// bounds when available (so nested boxes don't overlap)
|
|
1078
|
-
let descMinX = Infinity;
|
|
1079
|
-
let descMaxX = -Infinity;
|
|
1080
|
-
let descMaxY = -Infinity;
|
|
1081
|
-
|
|
1082
|
-
for (const desc of allDesc) {
|
|
1083
|
-
const innerBounds = containerBoundsMap.get(desc.data.orgNode.id);
|
|
1084
|
-
if (innerBounds) {
|
|
1085
|
-
// Use the inner container's expanded box
|
|
1086
|
-
if (innerBounds.minX < descMinX) descMinX = innerBounds.minX;
|
|
1087
|
-
if (innerBounds.maxX > descMaxX) descMaxX = innerBounds.maxX;
|
|
1088
|
-
if (innerBounds.maxY > descMaxY) descMaxY = innerBounds.maxY;
|
|
1089
|
-
} else if (desc.data.orgNode.id.startsWith('__stack_')) {
|
|
1090
|
-
// Use expanded children positions for stack placeholders
|
|
1091
|
-
const cid = desc.data.orgNode.id.replace('__stack_', '');
|
|
1092
|
-
const stack = leafStacks.get(cid);
|
|
1093
|
-
if (stack) {
|
|
1094
|
-
for (const ec of expandedChildren) {
|
|
1095
|
-
if (ec.orgNode.parentId !== cid) continue;
|
|
1096
|
-
const ex = ec.cx + offsetX;
|
|
1097
|
-
const ey = ec.cy + offsetY;
|
|
1098
|
-
if (ex - ec.width / 2 < descMinX) descMinX = ex - ec.width / 2;
|
|
1099
|
-
if (ex + ec.width / 2 > descMaxX) descMaxX = ex + ec.width / 2;
|
|
1100
|
-
if (ey + ec.height > descMaxY) descMaxY = ey + ec.height;
|
|
1101
|
-
}
|
|
1102
|
-
}
|
|
1103
|
-
} else {
|
|
1104
|
-
// Use card dimensions
|
|
1105
|
-
const dw = desc.data.width;
|
|
1106
|
-
const dh = desc.data.height;
|
|
1107
|
-
const dx = desc.x! + offsetX;
|
|
1108
|
-
const dy = desc.y! + offsetY;
|
|
1109
|
-
|
|
1110
|
-
if (dx - dw / 2 < descMinX) descMinX = dx - dw / 2;
|
|
1111
|
-
if (dx + dw / 2 > descMaxX) descMaxX = dx + dw / 2;
|
|
1112
|
-
if (dy + dh > descMaxY) descMaxY = dy + dh;
|
|
1113
|
-
}
|
|
1114
|
-
}
|
|
1115
|
-
|
|
1116
|
-
const containerX = d.x! + offsetX;
|
|
1117
|
-
const containerY = d.y! + offsetY;
|
|
1118
|
-
const metaCount = Object.keys(d.data.orgNode.metadata).length;
|
|
1119
|
-
const labelHeight =
|
|
1120
|
-
CONTAINER_LABEL_HEIGHT + metaCount * CONTAINER_META_LINE_HEIGHT;
|
|
1121
|
-
|
|
1122
|
-
// Box top = container's own y, extends to cover all children
|
|
1123
|
-
const boxY = containerY;
|
|
1124
|
-
const boxHeight = descMaxY - containerY + CONTAINER_PAD_BOTTOM;
|
|
1125
|
-
|
|
1126
|
-
// Tight-fit box around content with padding
|
|
1127
|
-
const boxX = descMinX - CONTAINER_PAD_X;
|
|
1128
|
-
const contentWidth = descMaxX - descMinX + CONTAINER_PAD_X * 2;
|
|
1129
|
-
const finalBoxWidth = Math.max(contentWidth, d.data.width);
|
|
1130
|
-
// Center the box if the label is wider than the content
|
|
1131
|
-
const centeredBoxX =
|
|
1132
|
-
finalBoxWidth > contentWidth ? containerX - finalBoxWidth / 2 : boxX;
|
|
1133
|
-
|
|
1134
|
-
// Store bounds for parent containers to reference
|
|
1135
|
-
containerBoundsMap.set(d.data.orgNode.id, {
|
|
1136
|
-
minX: centeredBoxX,
|
|
1137
|
-
maxX: centeredBoxX + finalBoxWidth,
|
|
1138
|
-
minY: boxY,
|
|
1139
|
-
maxY: boxY + boxHeight,
|
|
1140
|
-
});
|
|
1141
|
-
|
|
1142
|
-
const chc2 = hiddenCounts?.get(d.data.orgNode.id);
|
|
1143
|
-
const cMeta2 = filterMetadata(d.data.orgNode.metadata, hiddenAttributes);
|
|
1144
|
-
const c2Color = resolveNodeColor(
|
|
1145
|
-
d.data.orgNode,
|
|
1146
|
-
parsed.tagGroups,
|
|
1147
|
-
activeTagGroup ?? null
|
|
1148
|
-
);
|
|
1149
|
-
containers.push({
|
|
1150
|
-
nodeId: d.data.orgNode.id,
|
|
1151
|
-
label: d.data.orgNode.label,
|
|
1152
|
-
lineNumber: d.data.orgNode.lineNumber,
|
|
1153
|
-
...(c2Color !== undefined && { color: c2Color }),
|
|
1154
|
-
metadata: cMeta2,
|
|
1155
|
-
tagMetadata: { ...d.data.orgNode.metadata },
|
|
1156
|
-
x: centeredBoxX,
|
|
1157
|
-
y: boxY,
|
|
1158
|
-
width: finalBoxWidth,
|
|
1159
|
-
height: boxHeight,
|
|
1160
|
-
labelHeight,
|
|
1161
|
-
...(chc2 !== undefined && { hiddenCount: chc2 }),
|
|
1162
|
-
hasChildren: true,
|
|
1163
|
-
});
|
|
1164
|
-
}
|
|
1165
|
-
|
|
1166
|
-
// Reverse so outer containers render first (behind inner containers)
|
|
1167
|
-
containers.reverse();
|
|
1168
|
-
|
|
1169
|
-
// Bounding box — expand for container backgrounds that may extend beyond nodes
|
|
1170
|
-
// Convert container coords (offset space) back to pre-offset space for comparison
|
|
1171
|
-
let finalMinX = minX;
|
|
1172
|
-
let finalMaxX = maxX;
|
|
1173
|
-
let finalMaxY = maxY;
|
|
1174
|
-
for (const c of containers) {
|
|
1175
|
-
const cLeft = c.x - offsetX;
|
|
1176
|
-
const cRight = cLeft + c.width;
|
|
1177
|
-
const cBottom = c.y - offsetY + c.height;
|
|
1178
|
-
if (cLeft < finalMinX) finalMinX = cLeft;
|
|
1179
|
-
if (cRight > finalMaxX) finalMaxX = cRight;
|
|
1180
|
-
if (cBottom > finalMaxY) finalMaxY = cBottom;
|
|
1181
|
-
}
|
|
1182
|
-
|
|
1183
|
-
const totalWidth = finalMaxX - finalMinX + MARGIN * 2;
|
|
1184
|
-
const totalHeight = finalMaxY - minY + MARGIN * 2;
|
|
1185
|
-
|
|
1186
|
-
// Collect which tag group values are actually used by nodes
|
|
1187
|
-
const usedValuesByGroup = new Map<string, Set<string>>();
|
|
1188
|
-
for (const group of parsed.tagGroups) {
|
|
1189
|
-
const key = tagAttrKey(group.name);
|
|
1190
|
-
const used = new Set<string>();
|
|
1191
|
-
const walk = (node: OrgNode) => {
|
|
1192
|
-
if (!node.isContainer && node.metadata[key]) {
|
|
1193
|
-
used.add(node.metadata[key].toLowerCase());
|
|
1194
|
-
}
|
|
1195
|
-
for (const child of node.children) walk(child);
|
|
1196
|
-
};
|
|
1197
|
-
for (const root of parsed.roots) walk(root);
|
|
1198
|
-
usedValuesByGroup.set(key, used);
|
|
1199
|
-
}
|
|
1200
|
-
|
|
1201
|
-
// Compute legend for tag groups
|
|
1202
|
-
const showEyeIcons = hiddenAttributes !== undefined;
|
|
1203
|
-
const legendGroups = computeLegendGroups(
|
|
1204
|
-
parsed.tagGroups,
|
|
1205
|
-
showEyeIcons,
|
|
1206
|
-
usedValuesByGroup
|
|
1207
|
-
);
|
|
1208
|
-
let finalWidth = totalWidth;
|
|
1209
|
-
let finalHeight = totalHeight;
|
|
1210
|
-
|
|
1211
|
-
// When a tag group is active, only that group is laid out (full size).
|
|
1212
|
-
// When none is active, all groups are laid out minified — unless
|
|
1213
|
-
// expandAllLegend is set (export mode), which shows all groups expanded.
|
|
1214
|
-
const visibleGroups =
|
|
1215
|
-
activeTagGroup != null
|
|
1216
|
-
? legendGroups.filter(
|
|
1217
|
-
(g) => g.name.toLowerCase() === activeTagGroup.toLowerCase()
|
|
1218
|
-
)
|
|
1219
|
-
: legendGroups;
|
|
1220
|
-
const allExpanded = expandAllLegend && activeTagGroup == null;
|
|
1221
|
-
const effectiveW = (g: OrgLegendGroup) =>
|
|
1222
|
-
activeTagGroup != null || allExpanded ? g.width : g.minifiedWidth;
|
|
1223
|
-
|
|
1224
|
-
if (visibleGroups.length > 0) {
|
|
1225
|
-
// Top: horizontal row above chart content, left-aligned
|
|
1226
|
-
const legendShift = LEGEND_HEIGHT + LEGEND_GROUP_GAP;
|
|
1227
|
-
|
|
1228
|
-
// Push all chart content down
|
|
1229
|
-
for (const n of layoutNodes) n.y += legendShift;
|
|
1230
|
-
for (const c of containers) c.y += legendShift;
|
|
1231
|
-
for (const e of layoutEdges) {
|
|
1232
|
-
for (const p of e.points as Writable<(typeof e.points)[number]>[])
|
|
1233
|
-
p.y += legendShift;
|
|
1234
|
-
}
|
|
1235
|
-
|
|
1236
|
-
const totalGroupsWidth =
|
|
1237
|
-
visibleGroups.reduce((s, g) => s + effectiveW(g), 0) +
|
|
1238
|
-
(visibleGroups.length - 1) * LEGEND_GROUP_GAP;
|
|
1239
|
-
|
|
1240
|
-
let cx = MARGIN;
|
|
1241
|
-
for (const g of visibleGroups) {
|
|
1242
|
-
g.x = cx;
|
|
1243
|
-
g.y = MARGIN;
|
|
1244
|
-
cx += effectiveW(g) + LEGEND_GROUP_GAP;
|
|
1245
|
-
}
|
|
1246
|
-
|
|
1247
|
-
finalHeight += legendShift;
|
|
1248
|
-
const neededWidth = totalGroupsWidth + MARGIN * 2;
|
|
1249
|
-
if (neededWidth > finalWidth) {
|
|
1250
|
-
finalWidth = neededWidth;
|
|
1251
|
-
}
|
|
1252
|
-
}
|
|
1253
|
-
|
|
1254
|
-
return {
|
|
1255
|
-
nodes: layoutNodes,
|
|
1256
|
-
edges: layoutEdges,
|
|
1257
|
-
containers,
|
|
1258
|
-
legend: legendGroups,
|
|
1259
|
-
width: finalWidth,
|
|
1260
|
-
height: finalHeight,
|
|
1261
|
-
};
|
|
1262
|
-
}
|