@molecule/app-feature-graph-view-vue 0.0.0-stage → 1.1.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.
@@ -0,0 +1,66 @@
1
+ /**
2
+ * Vue force-directed graph view: the Vue counterpart of
3
+ * `@molecule/app-feature-graph-view-react`'s `<GraphView>` — the same props
4
+ * (React names), the same classes, and the same DOM for the same input.
5
+ *
6
+ * @module
7
+ */
8
+ import { type PropType, type VNode } from 'vue';
9
+ import { type ForceLayoutOptions } from './layout.js';
10
+ import type { GraphEdge, GraphEdgeRenderer, GraphLayout, GraphNode, GraphNodeRenderer } from './types.js';
11
+ /**
12
+ * Force-directed graph view (Obsidian-style).
13
+ *
14
+ * Renders nodes + edges into an SVG, computing positions via a built-in
15
+ * minimal velocity-Verlet simulation. Three layouts are supported —
16
+ * `force` (default), `circular` and `grid` — and either nodes or edges
17
+ * can be overridden via custom renderers.
18
+ *
19
+ * Style is driven by `getClassMap()`. Inline styles are reserved for
20
+ * SVG geometry — `transform`, viewBox computation, stroke widths — which
21
+ * classes can't express.
22
+ *
23
+ * @returns The graph-view component.
24
+ */
25
+ export declare const GraphView: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
26
+ nodes: {
27
+ type: PropType<GraphNode[]>;
28
+ required: true;
29
+ };
30
+ edges: {
31
+ type: PropType<GraphEdge[]>;
32
+ required: true;
33
+ };
34
+ onNodeClick: PropType<(node: GraphNode) => void>;
35
+ selectedNodeId: StringConstructor;
36
+ layout: {
37
+ type: PropType<GraphLayout>;
38
+ default: string;
39
+ };
40
+ nodeRenderer: PropType<GraphNodeRenderer>;
41
+ edgeRenderer: PropType<GraphEdgeRenderer>;
42
+ forceOptions: PropType<ForceLayoutOptions>;
43
+ className: StringConstructor;
44
+ }>, () => VNode, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
45
+ nodes: {
46
+ type: PropType<GraphNode[]>;
47
+ required: true;
48
+ };
49
+ edges: {
50
+ type: PropType<GraphEdge[]>;
51
+ required: true;
52
+ };
53
+ onNodeClick: PropType<(node: GraphNode) => void>;
54
+ selectedNodeId: StringConstructor;
55
+ layout: {
56
+ type: PropType<GraphLayout>;
57
+ default: string;
58
+ };
59
+ nodeRenderer: PropType<GraphNodeRenderer>;
60
+ edgeRenderer: PropType<GraphEdgeRenderer>;
61
+ forceOptions: PropType<ForceLayoutOptions>;
62
+ className: StringConstructor;
63
+ }>> & Readonly<{}>, {
64
+ layout: GraphLayout;
65
+ }, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
66
+ //# sourceMappingURL=GraphView.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"GraphView.d.ts","sourceRoot":"","sources":["../src/GraphView.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAgC,KAAK,QAAQ,EAAE,KAAK,KAAK,EAAE,MAAM,KAAK,CAAA;AAK7E,OAAO,EAAe,KAAK,kBAAkB,EAAe,MAAM,aAAa,CAAA;AAC/E,OAAO,KAAK,EACV,SAAS,EACT,iBAAiB,EACjB,WAAW,EACX,SAAS,EACT,iBAAiB,EAElB,MAAM,YAAY,CAAA;AA8CnB;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,SAAS;;cAGM,QAAQ,CAAC,SAAS,EAAE,CAAC;;;;cACrB,QAAQ,CAAC,SAAS,EAAE,CAAC;;;iBACpB,QAAQ,CAAC,CAAC,IAAI,EAAE,SAAS,KAAK,IAAI,CAAC;;;cAElC,QAAQ,CAAC,WAAW,CAAC;;;kBACrB,QAAQ,CAAC,iBAAiB,CAAC;kBAC3B,QAAQ,CAAC,iBAAiB,CAAC;kBAC7B,QAAQ,CAAC,kBAAkB,CAAC;;UAiGzC,KAAK;;cAxGQ,QAAQ,CAAC,SAAS,EAAE,CAAC;;;;cACrB,QAAQ,CAAC,SAAS,EAAE,CAAC;;;iBACpB,QAAQ,CAAC,CAAC,IAAI,EAAE,SAAS,KAAK,IAAI,CAAC;;;cAElC,QAAQ,CAAC,WAAW,CAAC;;;kBACrB,QAAQ,CAAC,iBAAiB,CAAC;kBAC3B,QAAQ,CAAC,iBAAiB,CAAC;kBAC7B,QAAQ,CAAC,kBAAkB,CAAC;;;;4EA2ItD,CAAA"}
@@ -0,0 +1,180 @@
1
+ /**
2
+ * Vue force-directed graph view: the Vue counterpart of
3
+ * `@molecule/app-feature-graph-view-react`'s `<GraphView>` — the same props
4
+ * (React names), the same classes, and the same DOM for the same input.
5
+ *
6
+ * @module
7
+ */
8
+ import { computed, defineComponent, h } from 'vue';
9
+ import { getClassMap } from '@molecule/app-ui';
10
+ import { useTranslation } from '@molecule/app-vue';
11
+ import { boundingBox, layoutNodes } from './layout.js';
12
+ /** Default base radius (world units) of an unweighted node. */
13
+ const NODE_RADIUS = 8;
14
+ /**
15
+ * Render the default circle + label for one node. Pulled out so the
16
+ * component stays small.
17
+ *
18
+ * @param node - The positioned node.
19
+ * @param isSelected - Whether the node is currently selected.
20
+ * @returns The default node SVG markup.
21
+ */
22
+ function defaultNode(node, isSelected) {
23
+ const r = NODE_RADIUS * Math.sqrt(Math.max(0.25, node.weight ?? 1));
24
+ return h('g', {
25
+ 'data-mol-id': `graph-view-node-${node.id}`,
26
+ 'data-selected': isSelected ? 'true' : 'false',
27
+ transform: `translate(${node.x}, ${node.y})`,
28
+ }, [
29
+ h('circle', {
30
+ r,
31
+ fill: 'currentColor',
32
+ opacity: isSelected ? 1 : 0.85,
33
+ stroke: 'currentColor',
34
+ 'stroke-width': isSelected ? 2 : 0,
35
+ }),
36
+ h('text', {
37
+ x: r + 4,
38
+ y: 4,
39
+ 'font-size': 11,
40
+ fill: 'currentColor',
41
+ opacity: isSelected ? 1 : 0.75,
42
+ style: { pointerEvents: 'none', userSelect: 'none' },
43
+ }, [node.label]),
44
+ ]);
45
+ }
46
+ /**
47
+ * Force-directed graph view (Obsidian-style).
48
+ *
49
+ * Renders nodes + edges into an SVG, computing positions via a built-in
50
+ * minimal velocity-Verlet simulation. Three layouts are supported —
51
+ * `force` (default), `circular` and `grid` — and either nodes or edges
52
+ * can be overridden via custom renderers.
53
+ *
54
+ * Style is driven by `getClassMap()`. Inline styles are reserved for
55
+ * SVG geometry — `transform`, viewBox computation, stroke widths — which
56
+ * classes can't express.
57
+ *
58
+ * @returns The graph-view component.
59
+ */
60
+ export const GraphView = defineComponent({
61
+ name: 'GraphView',
62
+ props: {
63
+ nodes: { type: Array, required: true },
64
+ edges: { type: Array, required: true },
65
+ onNodeClick: Function,
66
+ selectedNodeId: String,
67
+ layout: { type: String, default: 'force' },
68
+ nodeRenderer: Function,
69
+ edgeRenderer: Function,
70
+ forceOptions: Object,
71
+ className: String,
72
+ },
73
+ setup(props) {
74
+ const cm = getClassMap();
75
+ const { t } = useTranslation();
76
+ // Positions depend only on (nodes, edges, layout, forceOptions), and the
77
+ // simulation is deterministic given a fixed seed — the same computation
78
+ // React memoizes, recomputed here only when one of its inputs changes.
79
+ const positioned = computed(() => layoutNodes(props.nodes, props.edges, props.layout ?? 'force', props.forceOptions));
80
+ const nodeById = computed(() => {
81
+ const m = new Map();
82
+ for (const n of positioned.value)
83
+ m.set(n.id, n);
84
+ return m;
85
+ });
86
+ // Compute viewBox so the graph always fits the SVG bounds, regardless of
87
+ // the world-space size produced by the layout.
88
+ const viewBox = computed(() => {
89
+ const box = boundingBox(positioned.value, 40);
90
+ return box
91
+ ? `${box.minX} ${box.minY} ${Math.max(1, box.maxX - box.minX)} ${Math.max(1, box.maxY - box.minY)}`
92
+ : '-100 -100 200 200';
93
+ });
94
+ const ariaLabel = computed(() => t('graphView.aria.canvas', {}, { defaultValue: 'Graph view' }));
95
+ const emptyLabel = computed(() => t('graphView.empty', {}, { defaultValue: 'No nodes to display' }));
96
+ /**
97
+ * One edge: a custom renderer's nodes inside a per-edge group, or the
98
+ * default `<line>`. An edge whose endpoints are missing renders nothing.
99
+ *
100
+ * @param edge - The edge.
101
+ * @returns The edge's vnode, or null when an endpoint is missing.
102
+ */
103
+ const renderEdge = (edge) => {
104
+ const src = nodeById.value.get(edge.source);
105
+ const tgt = nodeById.value.get(edge.target);
106
+ if (!src || !tgt)
107
+ return null;
108
+ if (props.edgeRenderer)
109
+ return h('g', { key: edge.id, 'data-mol-id': `graph-view-edge-${edge.id}` }, [
110
+ props.edgeRenderer(edge, src, tgt),
111
+ ]);
112
+ return h('line', {
113
+ key: edge.id,
114
+ 'data-mol-id': `graph-view-edge-${edge.id}`,
115
+ x1: src.x,
116
+ y1: src.y,
117
+ x2: tgt.x,
118
+ y2: tgt.y,
119
+ stroke: 'currentColor',
120
+ 'stroke-width': 1,
121
+ opacity: 0.4,
122
+ });
123
+ };
124
+ /**
125
+ * One node's keyboard-activatable hit group, containing the custom
126
+ * renderer's node or the default circle + label.
127
+ *
128
+ * @param node - The positioned node.
129
+ * @returns The node's hit-group vnode.
130
+ */
131
+ const renderNode = (node) => {
132
+ const isSelected = node.id === props.selectedNodeId;
133
+ const aria = t('graphView.aria.node', { label: node.label }, { defaultValue: 'Node {{label}}' });
134
+ return h('g', {
135
+ key: node.id,
136
+ 'data-mol-id': `graph-view-node-hit-${node.id}`,
137
+ role: 'button',
138
+ 'aria-label': aria,
139
+ tabindex: 0,
140
+ onClick: () => props.onNodeClick?.(node),
141
+ onKeydown: (event) => {
142
+ if (event.key === 'Enter' || event.key === ' ') {
143
+ event.preventDefault();
144
+ props.onNodeClick?.(node);
145
+ }
146
+ },
147
+ style: { cursor: props.onNodeClick ? 'pointer' : 'default', outline: 'none' },
148
+ }, [props.nodeRenderer ? props.nodeRenderer(node) : defaultNode(node, isSelected)]);
149
+ };
150
+ return () => h('div', {
151
+ role: 'application',
152
+ 'aria-label': ariaLabel.value,
153
+ 'data-mol-id': 'graph-view',
154
+ class: cm.cn(cm.position('relative'), cm.surfaceSecondary, props.className),
155
+ style: { width: '100%', height: '100%', overflow: 'hidden' },
156
+ }, positioned.value.length === 0
157
+ ? [
158
+ h('div', {
159
+ 'data-mol-id': 'graph-view-empty',
160
+ role: 'status',
161
+ class: cm.cn(cm.position('absolute'), cm.sp('p', 6)),
162
+ style: { inset: 0, display: 'grid', placeItems: 'center' },
163
+ }, [emptyLabel.value]),
164
+ ]
165
+ : [
166
+ h('svg', {
167
+ 'data-mol-id': 'graph-view-svg',
168
+ width: '100%',
169
+ height: '100%',
170
+ viewBox: viewBox.value,
171
+ preserveAspectRatio: 'xMidYMid meet',
172
+ style: { display: 'block' },
173
+ }, [
174
+ h('g', { 'data-mol-id': 'graph-view-edges' }, props.edges.map(renderEdge)),
175
+ h('g', { 'data-mol-id': 'graph-view-nodes' }, positioned.value.map(renderNode)),
176
+ ]),
177
+ ]);
178
+ },
179
+ });
180
+ //# sourceMappingURL=GraphView.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"GraphView.js","sourceRoot":"","sources":["../src/GraphView.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,CAAC,EAA6B,MAAM,KAAK,CAAA;AAE7E,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAC9C,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AAElD,OAAO,EAAE,WAAW,EAA2B,WAAW,EAAE,MAAM,aAAa,CAAA;AAU/E,+DAA+D;AAC/D,MAAM,WAAW,GAAG,CAAC,CAAA;AAErB;;;;;;;GAOG;AACH,SAAS,WAAW,CAAC,IAAoB,EAAE,UAAmB;IAC5D,MAAM,CAAC,GAAG,WAAW,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC,MAAM,IAAI,CAAC,CAAC,CAAC,CAAA;IACnE,OAAO,CAAC,CACN,GAAG,EACH;QACE,aAAa,EAAE,mBAAmB,IAAI,CAAC,EAAE,EAAE;QAC3C,eAAe,EAAE,UAAU,CAAC,CAAC,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AAE,KAAK,CAAC,SAAS,CAAC;YAC3E,KAAK,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE;SAC7D,EACD,UAAU,CAAC,KAAK,CAAC,MAAM,KAAK,CAAC;YAC3B,CAAC,CAAC;gBACE,CAAC,CACC,KAAK,EACL;oBACE,aAAa,EAAE,kBAAkB;oBACjC,IAAI,EAAE,QAAQ;oBACd,KAAK,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC;oBACpD,KAAK,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,QAAQ,EAAE;iBAC3D,EACD,CAAC,UAAU,CAAC,KAAK,CAAC,CACnB;aACF;YACH,CAAC,CAAC;gBACE,CAAC,CACC,KAAK,EACL;oBACE,aAAa,EAAE,gBAAgB;oBAC/B,KAAK,EAAE,MAAM;oBACb,MAAM,EAAE,MAAM;oBACd,OAAO,EAAE,OAAO,CAAC,KAAK;oBACtB,mBAAmB,EAAE,eAAe;oBACpC,KAAK,EAAE,EAAE,OAAO,EAAE,OAAO,EAAE;iBAC5B,EACD;oBACE,CAAC,CAAC,GAAG,EAAE,EAAE,aAAa,EAAE,kBAAkB,EAAE,EAAE,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;oBAC1E,CAAC,CAAC,GAAG,EAAE,EAAE,aAAa,EAAE,kBAAkB,EAAE,EAAE,UAAU,CAAC,KAAK,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;iBAChF,CACF;aACF,CACN,CAAA;IACL,CAAC;CACF,CAAC,CAAA"}
@@ -0,0 +1,64 @@
1
+ /**
2
+ * Vue force-directed graph view (Obsidian-style) — the Vue counterpart of
3
+ * `@molecule/app-feature-graph-view-react`: the same exports, the same props
4
+ * (React names), and the same DOM for the same input.
5
+ *
6
+ * Exports:
7
+ * - `<GraphView>` — top-level node-and-edge visualization with built-in
8
+ * `force`, `circular`, and `grid` layouts, click + selection support,
9
+ * and pluggable node / edge renderers.
10
+ * - `GraphNode`, `GraphEdge`, `GraphLayout`, `GraphPoint`, `PositionedNode`,
11
+ * `GraphNodeRenderer`, `GraphEdgeRenderer`, `GraphViewProps` types.
12
+ * - Pure layout helpers (`forceLayout`, `circularLayout`, `gridLayout`,
13
+ * `layoutNodes`, `boundingBox`, `createRng`).
14
+ *
15
+ * Used by note-taking and other apps to visualize page / note linkages
16
+ * the same way Obsidian does — a force-directed map of which notes link
17
+ * to which.
18
+ *
19
+ * @example
20
+ * ```ts
21
+ * import { createApp, defineComponent, h } from 'vue'
22
+ * import { GraphView, type GraphEdge, type GraphNode } from '@molecule/app-feature-graph-view-vue'
23
+ *
24
+ * const nodes: GraphNode[] = [
25
+ * { id: 'a', label: 'Alpha' },
26
+ * { id: 'b', label: 'Beta', group: 'project', weight: 2 },
27
+ * ]
28
+ * const edges: GraphEdge[] = [{ id: 'e1', source: 'a', target: 'b' }]
29
+ *
30
+ * const NoteGraph = defineComponent({
31
+ * setup() {
32
+ * return () =>
33
+ * h(GraphView, {
34
+ * nodes,
35
+ * edges,
36
+ * onNodeClick: (node: GraphNode) => console.log(`open ${node.id}`),
37
+ * })
38
+ * },
39
+ * })
40
+ *
41
+ * createApp(NoteGraph).mount('#app')
42
+ * ```
43
+ *
44
+ * @remarks
45
+ * The root element fills 100% of its parent — the PARENT must have an
46
+ * explicit height (e.g. a fixed-height panel or a flex/grid track) or
47
+ * the graph renders zero-tall and appears blank.
48
+ *
49
+ * Interaction surface is click / keyboard-activate + `selectedNodeId`
50
+ * highlighting only. Nodes are NOT draggable and there is no built-in
51
+ * pan / zoom — the SVG `viewBox` auto-fits the layout bounds. For a
52
+ * pannable / zoomable surface, compose with
53
+ * `@molecule/app-feature-canvas-vue` instead.
54
+ *
55
+ * Layout is deterministic (seeded RNG), computed once per
56
+ * `(nodes, edges, layout, forceOptions)` change. `forceOptions` is
57
+ * ignored by the `circular` and `grid` layouts.
58
+ *
59
+ * @module
60
+ */
61
+ export * from './GraphView.js';
62
+ export * from './layout.js';
63
+ export * from './types.js';
64
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2DG;AAEH,cAAc,gBAAgB,CAAA;AAC9B,cAAc,aAAa,CAAA;AAC3B,cAAc,YAAY,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,64 @@
1
+ /**
2
+ * Vue force-directed graph view (Obsidian-style) — the Vue counterpart of
3
+ * `@molecule/app-feature-graph-view-react`: the same exports, the same props
4
+ * (React names), and the same DOM for the same input.
5
+ *
6
+ * Exports:
7
+ * - `<GraphView>` — top-level node-and-edge visualization with built-in
8
+ * `force`, `circular`, and `grid` layouts, click + selection support,
9
+ * and pluggable node / edge renderers.
10
+ * - `GraphNode`, `GraphEdge`, `GraphLayout`, `GraphPoint`, `PositionedNode`,
11
+ * `GraphNodeRenderer`, `GraphEdgeRenderer`, `GraphViewProps` types.
12
+ * - Pure layout helpers (`forceLayout`, `circularLayout`, `gridLayout`,
13
+ * `layoutNodes`, `boundingBox`, `createRng`).
14
+ *
15
+ * Used by note-taking and other apps to visualize page / note linkages
16
+ * the same way Obsidian does — a force-directed map of which notes link
17
+ * to which.
18
+ *
19
+ * @example
20
+ * ```ts
21
+ * import { createApp, defineComponent, h } from 'vue'
22
+ * import { GraphView, type GraphEdge, type GraphNode } from '@molecule/app-feature-graph-view-vue'
23
+ *
24
+ * const nodes: GraphNode[] = [
25
+ * { id: 'a', label: 'Alpha' },
26
+ * { id: 'b', label: 'Beta', group: 'project', weight: 2 },
27
+ * ]
28
+ * const edges: GraphEdge[] = [{ id: 'e1', source: 'a', target: 'b' }]
29
+ *
30
+ * const NoteGraph = defineComponent({
31
+ * setup() {
32
+ * return () =>
33
+ * h(GraphView, {
34
+ * nodes,
35
+ * edges,
36
+ * onNodeClick: (node: GraphNode) => console.log(`open ${node.id}`),
37
+ * })
38
+ * },
39
+ * })
40
+ *
41
+ * createApp(NoteGraph).mount('#app')
42
+ * ```
43
+ *
44
+ * @remarks
45
+ * The root element fills 100% of its parent — the PARENT must have an
46
+ * explicit height (e.g. a fixed-height panel or a flex/grid track) or
47
+ * the graph renders zero-tall and appears blank.
48
+ *
49
+ * Interaction surface is click / keyboard-activate + `selectedNodeId`
50
+ * highlighting only. Nodes are NOT draggable and there is no built-in
51
+ * pan / zoom — the SVG `viewBox` auto-fits the layout bounds. For a
52
+ * pannable / zoomable surface, compose with
53
+ * `@molecule/app-feature-canvas-vue` instead.
54
+ *
55
+ * Layout is deterministic (seeded RNG), computed once per
56
+ * `(nodes, edges, layout, forceOptions)` change. `forceOptions` is
57
+ * ignored by the `circular` and `grid` layouts.
58
+ *
59
+ * @module
60
+ */
61
+ export * from './GraphView.js';
62
+ export * from './layout.js';
63
+ export * from './types.js';
64
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2DG;AAEH,cAAc,gBAAgB,CAAA;AAC9B,cAAc,aAAa,CAAA;AAC3B,cAAc,YAAY,CAAA"}
@@ -0,0 +1,101 @@
1
+ import type { GraphEdge, GraphLayout, GraphNode, PositionedNode } from './types.js';
2
+ /**
3
+ * Pure (framework-free) layout helpers for `<GraphView>`. Extracted so the
4
+ * math is unit-testable without a component library or jsdom.
5
+ *
6
+ * @module
7
+ */
8
+ /** Default cap on force-layout iterations. */
9
+ export declare const DEFAULT_FORCE_ITERATIONS = 200;
10
+ /** Default repulsion strength used by `forceLayout`. */
11
+ export declare const DEFAULT_REPULSION = 800;
12
+ /** Default spring stiffness used by `forceLayout`. */
13
+ export declare const DEFAULT_SPRING = 0.05;
14
+ /** Default ideal edge length used by `forceLayout`. */
15
+ export declare const DEFAULT_REST_LENGTH = 80;
16
+ /** Default velocity damping used by `forceLayout`. */
17
+ export declare const DEFAULT_DAMPING = 0.85;
18
+ /** Convergence threshold (max per-node displacement squared). */
19
+ export declare const CONVERGENCE_EPSILON = 0.01;
20
+ /** Force-layout tunables. */
21
+ export interface ForceLayoutOptions {
22
+ /** Hard cap on iterations. Defaults to {@link DEFAULT_FORCE_ITERATIONS}. */
23
+ iterations?: number;
24
+ /** Repulsive constant between every pair of nodes. */
25
+ repulsion?: number;
26
+ /** Spring (Hooke) constant for edges. */
27
+ spring?: number;
28
+ /** Ideal edge length (rest distance). */
29
+ restLength?: number;
30
+ /** Velocity damping per step (0–1). */
31
+ damping?: number;
32
+ /** Optional deterministic seed (for tests). Defaults to a fixed value. */
33
+ seed?: number;
34
+ }
35
+ /**
36
+ * Tiny deterministic PRNG (mulberry32). Allows reproducible initial
37
+ * positions in tests without depending on `Math.random()`.
38
+ *
39
+ * @param seed - 32-bit unsigned seed.
40
+ * @returns A function returning floats in `[0, 1)`.
41
+ */
42
+ export declare function createRng(seed: number): () => number;
43
+ /**
44
+ * Place nodes evenly around the unit circle (scaled by `radius`).
45
+ *
46
+ * @param nodes - Nodes to position.
47
+ * @param radius - Circle radius in world units.
48
+ * @returns Positioned nodes, in input order.
49
+ */
50
+ export declare function circularLayout(nodes: GraphNode[], radius: number): PositionedNode[];
51
+ /**
52
+ * Place nodes on a square-ish grid, centred on the origin.
53
+ *
54
+ * @param nodes - Nodes to position.
55
+ * @param spacing - Pixel spacing between adjacent grid cells.
56
+ * @returns Positioned nodes, in input order.
57
+ */
58
+ export declare function gridLayout(nodes: GraphNode[], spacing: number): PositionedNode[];
59
+ /**
60
+ * Run a minimal velocity-Verlet force-directed simulation.
61
+ *
62
+ * Implements:
63
+ * - Pairwise repulsion (Coulomb-like, O(n²)) between every node pair.
64
+ * - Spring (Hooke) attraction along each edge toward `restLength`.
65
+ * - Per-step velocity damping for stability.
66
+ *
67
+ * Stops early once the maximum per-node displacement-squared drops below
68
+ * {@link CONVERGENCE_EPSILON}, or after `iterations` steps — whichever
69
+ * comes first.
70
+ *
71
+ * @param nodes - Nodes to lay out.
72
+ * @param edges - Edges (used only for attractive springs).
73
+ * @param options - Force-layout tunables.
74
+ * @returns Positioned nodes, in input order.
75
+ */
76
+ export declare function forceLayout(nodes: GraphNode[], edges: GraphEdge[], options?: ForceLayoutOptions): PositionedNode[];
77
+ /**
78
+ * Compute world-space positions for every node using the chosen layout.
79
+ *
80
+ * @param nodes - Nodes to position.
81
+ * @param edges - Edges (consumed only by `force`).
82
+ * @param layout - Layout strategy.
83
+ * @param options - Optional force-layout tunables (ignored for non-force).
84
+ * @returns Positioned nodes.
85
+ */
86
+ export declare function layoutNodes(nodes: GraphNode[], edges: GraphEdge[], layout: GraphLayout, options?: ForceLayoutOptions): PositionedNode[];
87
+ /**
88
+ * Compute the world-space bounding box of a set of positioned nodes,
89
+ * with a small padding for visual breathing room.
90
+ *
91
+ * @param nodes - Positioned nodes.
92
+ * @param padding - Padding (world units) added to every side. Default 40.
93
+ * @returns Bounding box `{ minX, minY, maxX, maxY }` — or `null` if empty.
94
+ */
95
+ export declare function boundingBox(nodes: PositionedNode[], padding?: number): {
96
+ minX: number;
97
+ minY: number;
98
+ maxX: number;
99
+ maxY: number;
100
+ } | null;
101
+ //# sourceMappingURL=layout.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"layout.d.ts","sourceRoot":"","sources":["../src/layout.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAEnF;;;;;GAKG;AAEH,8CAA8C;AAC9C,eAAO,MAAM,w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