apexsankey 1.4.0 → 1.6.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.
Files changed (40) hide show
  1. package/README.md +1 -1
  2. package/apexsankey.es.min.js +1 -7931
  3. package/apexsankey.min.js +1 -1
  4. package/demo/basic-sankey.html +2 -2
  5. package/demo/css-theming.html +438 -0
  6. package/demo/sankey-alternate-node.html +1 -2
  7. package/demo/sankey-custom-fonts.html +3 -2
  8. package/demo/sankey-edge-options.html +3 -2
  9. package/demo/sankey-node-customization.html +3 -3
  10. package/demo/sankey-node-overlapping.html +3 -2
  11. package/demo/sankey-path-highlight.html +199 -0
  12. package/lib/a11y/SankeyA11y.d.ts +51 -0
  13. package/lib/graph/Graph.d.ts +35 -0
  14. package/lib/layout/edgeOrdering/orderEdges.d.ts +4 -3
  15. package/lib/layout/edgePositioning/linkLayout.d.ts +2 -1
  16. package/lib/layout/edgePositioning/utils.d.ts +5 -3
  17. package/lib/layout/layout.d.ts +54 -27
  18. package/lib/layout/nodeOrdering/addDummyNodes.d.ts +4 -2
  19. package/lib/layout/nodeOrdering/countCrossings.d.ts +5 -4
  20. package/lib/layout/nodeOrdering/initialOrdering.d.ts +3 -1
  21. package/lib/layout/nodeOrdering/ordering.d.ts +3 -2
  22. package/lib/layout/nodeOrdering/swapNodes.d.ts +3 -1
  23. package/lib/layout/nodeOrdering/weightedMedian.d.ts +6 -4
  24. package/lib/layout/nodePositioning/horizontal.d.ts +4 -2
  25. package/lib/layout/nodePositioning/justified.d.ts +53 -5
  26. package/lib/layout/rankAssignment/assignRanks.d.ts +3 -1
  27. package/lib/layout/rankAssignment/groupedGraph.d.ts +2 -2
  28. package/lib/layout/rankAssignment/initialRank.d.ts +3 -1
  29. package/lib/layout/rankAssignment/makeAcyclic.d.ts +4 -4
  30. package/lib/layout/types.d.ts +99 -0
  31. package/lib/layout/utils.d.ts +12 -2
  32. package/lib/models/Edge.d.ts +17 -2
  33. package/lib/models/Graph.d.ts +13 -6
  34. package/lib/models/Node.d.ts +15 -3
  35. package/lib/models/Options.d.ts +60 -4
  36. package/lib/models/Paper.d.ts +2 -3
  37. package/lib/models/PathHighlighter.d.ts +28 -0
  38. package/lib/models/SankeyAnimation.d.ts +12 -0
  39. package/lib/utils/cssVars.d.ts +29 -0
  40. package/package.json +5 -5
@@ -0,0 +1,199 @@
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8" />
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
+ <title>Sankey – Connected Path Highlight on Hover</title>
7
+ <link href="https://fonts.googleapis.com/css2?family=Quicksand:wght@400;600&display=swap" rel="stylesheet" />
8
+ <script src="../apexsankey.min.js"></script>
9
+ <style>
10
+ body {
11
+ font-family: 'Quicksand', sans-serif;
12
+ margin: 0;
13
+ padding: 24px;
14
+ background: #f5f6fa;
15
+ color: #212121;
16
+ }
17
+
18
+ h1 {
19
+ font-size: 1.4rem;
20
+ font-weight: 600;
21
+ margin: 0 0 4px;
22
+ }
23
+
24
+ p.subtitle {
25
+ margin: 0 0 20px;
26
+ font-size: 0.9rem;
27
+ color: #555;
28
+ }
29
+
30
+ .controls {
31
+ display: flex;
32
+ flex-wrap: wrap;
33
+ gap: 24px;
34
+ align-items: center;
35
+ background: #fff;
36
+ border: 1px solid #dde1e7;
37
+ border-radius: 8px;
38
+ padding: 16px 20px;
39
+ margin-bottom: 20px;
40
+ max-width: 860px;
41
+ }
42
+
43
+ .control-group {
44
+ display: flex;
45
+ align-items: center;
46
+ gap: 10px;
47
+ }
48
+
49
+ .control-group label {
50
+ font-weight: 600;
51
+ font-size: 0.875rem;
52
+ white-space: nowrap;
53
+ }
54
+
55
+ .toggle-btn {
56
+ cursor: pointer;
57
+ padding: 6px 16px;
58
+ border-radius: 6px;
59
+ border: 2px solid #008ffb;
60
+ background: #008ffb;
61
+ color: #fff;
62
+ font-family: 'Quicksand', sans-serif;
63
+ font-weight: 600;
64
+ font-size: 0.875rem;
65
+ transition:
66
+ background 0.15s,
67
+ color 0.15s;
68
+ }
69
+
70
+ .toggle-btn.off {
71
+ background: #fff;
72
+ color: #008ffb;
73
+ }
74
+
75
+ input[type='range'] {
76
+ width: 140px;
77
+ accent-color: #008ffb;
78
+ }
79
+
80
+ #opacity-value {
81
+ font-weight: 600;
82
+ min-width: 36px;
83
+ text-align: right;
84
+ }
85
+
86
+ .hint {
87
+ font-size: 0.8rem;
88
+ color: #777;
89
+ margin-bottom: 12px;
90
+ }
91
+
92
+ #svg-sankey {
93
+ margin: 0 auto;
94
+ }
95
+ </style>
96
+ </head>
97
+ <body>
98
+ <h1>Connected Path Highlight on Hover</h1>
99
+ <p class="subtitle">
100
+ Hover over any <strong>node</strong> or <strong>edge</strong> to highlight its connected flow path and dim
101
+ unrelated elements. Use the controls below to explore the options.
102
+ </p>
103
+
104
+ <div class="controls">
105
+ <div class="control-group">
106
+ <label for="toggle-highlight">highlightConnectedPath</label>
107
+ <button id="toggle-highlight" class="toggle-btn" aria-pressed="true">Enabled</button>
108
+ </div>
109
+ <div class="control-group">
110
+ <label for="dim-opacity">dimOpacity</label>
111
+ <input type="range" id="dim-opacity" min="0" max="0.5" step="0.05" value="0.15" />
112
+ <span id="opacity-value">0.15</span>
113
+ </div>
114
+ </div>
115
+
116
+ <p class="hint">💡 Hover a node or an edge in the diagram to see the effect.</p>
117
+
118
+ <div id="svg-sankey"></div>
119
+
120
+ <script>
121
+ const data = {
122
+ nodes: [
123
+ {id: 'Solar', title: 'Solar'},
124
+ {id: 'Wind', title: 'Wind'},
125
+ {id: 'Hydro', title: 'Hydro'},
126
+ {id: 'Gas', title: 'Gas'},
127
+ {id: 'Coal', title: 'Coal'},
128
+ {id: 'Electricity', title: 'Electricity'},
129
+ {id: 'Heat', title: 'Heat'},
130
+ {id: 'Transport', title: 'Transport'},
131
+ {id: 'Industry', title: 'Industry'},
132
+ {id: 'Homes', title: 'Homes'},
133
+ {id: 'Losses', title: 'Losses'},
134
+ ],
135
+ edges: [
136
+ {source: 'Solar', target: 'Electricity', value: 30},
137
+ {source: 'Wind', target: 'Electricity', value: 25},
138
+ {source: 'Hydro', target: 'Electricity', value: 20},
139
+ {source: 'Gas', target: 'Electricity', value: 15},
140
+ {source: 'Gas', target: 'Heat', value: 20},
141
+ {source: 'Coal', target: 'Electricity', value: 10},
142
+ {source: 'Coal', target: 'Heat', value: 10},
143
+ {source: 'Electricity', target: 'Transport', value: 25},
144
+ {source: 'Electricity', target: 'Industry', value: 35},
145
+ {source: 'Electricity', target: 'Homes', value: 25},
146
+ {source: 'Electricity', target: 'Losses', value: 15},
147
+ {source: 'Heat', target: 'Industry', value: 18},
148
+ {source: 'Heat', target: 'Homes', value: 12},
149
+ ],
150
+ };
151
+
152
+ let highlightEnabled = true;
153
+ let dimOpacity = 0.2;
154
+ let sankeyInstance = null;
155
+
156
+ function buildOptions() {
157
+ return {
158
+ nodeWidth: 20,
159
+ fontFamily: 'Quicksand, sans-serif',
160
+ fontWeight: '600',
161
+ height: 520,
162
+ width: 860,
163
+ edgeOpacity: 0.4,
164
+ enableToolbar: false,
165
+ highlightConnectedPath: highlightEnabled,
166
+ dimOpacity: dimOpacity,
167
+ };
168
+ }
169
+
170
+ function render() {
171
+ const container = document.getElementById('svg-sankey');
172
+ container.innerHTML = '';
173
+ sankeyInstance = new ApexSankey(container, buildOptions());
174
+ sankeyInstance.render(data);
175
+ }
176
+
177
+ render();
178
+
179
+ // Toggle button
180
+ const toggleBtn = document.getElementById('toggle-highlight');
181
+ toggleBtn.addEventListener('click', () => {
182
+ highlightEnabled = !highlightEnabled;
183
+ toggleBtn.textContent = highlightEnabled ? 'Enabled' : 'Disabled';
184
+ toggleBtn.classList.toggle('off', !highlightEnabled);
185
+ toggleBtn.setAttribute('aria-pressed', String(highlightEnabled));
186
+ render();
187
+ });
188
+
189
+ // Opacity slider
190
+ const opacitySlider = document.getElementById('dim-opacity');
191
+ const opacityValue = document.getElementById('opacity-value');
192
+ opacitySlider.addEventListener('input', () => {
193
+ dimOpacity = parseFloat(opacitySlider.value);
194
+ opacityValue.textContent = dimOpacity.toFixed(2);
195
+ render();
196
+ });
197
+ </script>
198
+ </body>
199
+ </html>
@@ -0,0 +1,51 @@
1
+ import { PathHighlighter } from '../models/PathHighlighter';
2
+ import { SankeyGraph } from '../layout/types';
3
+
4
+ /** ARIA / accessibility options passed from SankeyOptions.a11y */
5
+ export interface A11yOptions {
6
+ enabled?: boolean;
7
+ diagramLabel?: string;
8
+ description?: string;
9
+ }
10
+ /**
11
+ * Injects WCAG 2.1 AA accessibility attributes into a rendered Sankey diagram:
12
+ * - ARIA roles and labels on the SVG root, node groups, and edge paths
13
+ * - `<title>` and optional `<desc>` elements inside the SVG
14
+ * - Keyboard navigation (Enter / Space to activate, Escape to dismiss)
15
+ * - Visible focus ring via JS (robust across browsers)
16
+ * - `forced-colors` CSS class on the SVG root when the system is in High Contrast Mode
17
+ */
18
+ export declare class SankeyA11y {
19
+ private readonly svgEl;
20
+ private readonly graph;
21
+ private readonly options;
22
+ private readonly tooltipId?;
23
+ private readonly pathHighlighter?;
24
+ private nodeGroups;
25
+ private edgePaths;
26
+ /** Maps node id → its outgoing edge paths, in DOM order */
27
+ private nodeOutEdges;
28
+ /** Maps edge element → source node id (for Escape-to-return) */
29
+ private edgeSourceNode;
30
+ private mediaQuery;
31
+ private forcedColorsHandler;
32
+ private isKeyboardUser;
33
+ constructor(svgEl: SVGSVGElement, graph: SankeyGraph, options?: A11yOptions, tooltipId?: string | undefined, pathHighlighter?: PathHighlighter | null | undefined);
34
+ /** Apply all accessibility enhancements. Safe to call on every render. */
35
+ apply(): void;
36
+ /**
37
+ * Remove media-query listener. Should be called before the diagram is
38
+ * destroyed or before a new SankeyA11y is created for the same SVG.
39
+ */
40
+ destroy(): void;
41
+ private injectAriaAttributes;
42
+ private setupKeyboardNavigation;
43
+ private hideTooltip;
44
+ /**
45
+ * Applies a visible focus ring by overriding the rect's stroke attributes.
46
+ * More reliable than CSS outline on SVG elements across all browsers.
47
+ */
48
+ private applyFocusRing;
49
+ private restoreFocusRing;
50
+ private setupHighContrastMode;
51
+ }
@@ -0,0 +1,35 @@
1
+ export interface GraphOptions {
2
+ directed?: boolean;
3
+ multigraph?: boolean;
4
+ }
5
+ export interface EdgeObj {
6
+ v: string;
7
+ w: string;
8
+ name?: string;
9
+ }
10
+ export declare class Graph {
11
+ private _nodes;
12
+ private _edges;
13
+ private _graphLabel;
14
+ private _out;
15
+ private _in;
16
+ private _isMultigraph;
17
+ constructor(opts?: GraphOptions);
18
+ graph(): unknown;
19
+ setGraph(label: unknown): this;
20
+ setNode(id: string, label?: unknown): this;
21
+ node(id: string): unknown;
22
+ hasNode(id: string): boolean;
23
+ nodes(): string[];
24
+ removeNode(id: string): this;
25
+ sources(): string[];
26
+ successors(v: string): string[];
27
+ setEdge(vOrEdge: string | EdgeObj, wOrLabel?: unknown, label?: unknown, name?: string): this;
28
+ edge(eOrV: EdgeObj | string, w?: string, name?: string): unknown;
29
+ hasEdge(v: string, w: string, name?: string): boolean;
30
+ edges(): EdgeObj[];
31
+ removeEdge(e: EdgeObj): this;
32
+ outEdges(v: string): EdgeObj[];
33
+ inEdges(v: string): EdgeObj[];
34
+ nodeEdges(a: string, b: string): EdgeObj[];
35
+ }
@@ -1,4 +1,5 @@
1
- /** @module edge-ordering */
1
+ import { SankeyGraph } from '../types';
2
+
2
3
  /**
3
4
  * Assign incoming and outgoing edge lists to each node.
4
5
  *
@@ -8,6 +9,6 @@
8
9
  * @param {Graph} G - The graph. Nodes must have `x` and `y` attributes.
9
10
  *
10
11
  */
11
- export declare function orderEdges(G: any, { alignLinkTypes }?: {
12
- alignLinkTypes?: boolean;
12
+ export declare function orderEdges(G: SankeyGraph, { alignLinkTypes: _alignLinkTypes }?: {
13
+ alignLinkTypes?: boolean | undefined;
13
14
  }): void;
@@ -1,3 +1,4 @@
1
1
  import { SankeyOptions } from '../../models/Options';
2
+ import { EdgeLabel, SankeyGraph } from '../types';
2
3
 
3
- export declare function linkLayout(options: Partial<SankeyOptions>): (G: any) => any[];
4
+ export declare function linkLayout(options: Partial<SankeyOptions>): (G: SankeyGraph) => EdgeLabel[];
@@ -1,8 +1,10 @@
1
- export declare function findFirst(links: any, p: any): any;
1
+ import { EdgeLabel, SankeyGraph } from '../types';
2
+
3
+ export declare function findFirst(links: EdgeLabel[], p: (link: EdgeLabel) => boolean): number | null;
2
4
  /**
3
5
  * Adjust radii of curvature to avoid overlaps, as much as possible.
4
6
  * @param links - the list of links, ordered from outside to inside of bend
5
7
  * @param rr - "r0" or "r1", the side to work on
6
8
  */
7
- export declare function sweepCurvatureInwards(links: any, rr: any): void;
8
- export declare function addLinkEndpoints(G: any): void;
9
+ export declare function sweepCurvatureInwards(links: EdgeLabel[], rr: 'r0' | 'r1'): void;
10
+ export declare function addLinkEndpoints(G: SankeyGraph): void;
@@ -1,44 +1,71 @@
1
+ import { EdgeLabel, RankSet, SankeyGraph } from './types';
2
+ import { LayoutGraph, LayoutNode } from './nodePositioning/justified';
1
3
  import { SankeyOptions } from '../models/Options';
2
4
 
5
+ /** Data passed to the layout function for controlling graph layout */
6
+ interface LayoutData {
7
+ order?: string[][][] | string[][];
8
+ rankSets?: RankSet[];
9
+ alignLinkTypes?: boolean;
10
+ }
11
+ /** Input edge data shape (from user-provided graph data) */
12
+ interface InputEdge {
13
+ source: string;
14
+ target: string;
15
+ type: string;
16
+ }
17
+ /** Input node data shape (from user-provided graph data) */
18
+ interface InputNode {
19
+ id: string;
20
+ direction?: string;
21
+ }
3
22
  /**
4
23
  * Sankey layout
5
24
  * @constructor sankey
6
25
  */
7
26
  export declare function sankey(options: Partial<SankeyOptions>): {
8
- (linksIn?: any, nodesIn?: any, data?: any): import('graphlib').Graph;
9
- nodes(): any[];
10
- links(): any[];
11
- order(): any;
27
+ (linksIn?: InputEdge[], nodesIn?: InputNode[], data?: LayoutData): SankeyGraph;
28
+ nodes(): LayoutNode[];
29
+ links(): EdgeLabel[];
30
+ order(): string[][] | string[][][] | null;
12
31
  /**
13
32
  * Set size of layout.
14
33
  * @method size
15
34
  * @param size {[width, height]} - size
16
35
  * @returns {sankeyLayout|Number[]}
17
36
  */
18
- size(x: any): number[] | {
19
- (G: any, order: any, edgeGap?: number): any[];
20
- scaleToFit(G: any, order: any, edgeGap?: number): void;
21
- size(x?: any): number[] | any;
22
- separation(x?: any): ((a: any, b: any, c: any) => number) | any;
23
- whitespace(x?: number): number | any;
24
- scale(x?: number): any;
37
+ size(x?: number[]): number[] | {
38
+ (G: LayoutGraph, order: string[][][], edgeGap?: number): LayoutNode[];
39
+ scaleToFit(G: LayoutGraph, order: string[][][], edgeGap?: number): void;
40
+ size(x?: number[] | undefined): number[] | any;
41
+ separation(x?: number | ((a: string, b: string, G: LayoutGraph) => number) | undefined): ((a: string, b: string, G: LayoutGraph) => number) | any;
42
+ whitespace(x?: number | undefined): number | any;
43
+ scale(x?: number | undefined): number | any | null;
25
44
  } | any;
26
- separation(x: any): ((a: any, b: any, c: any) => number) | {
27
- (G: any, order: any, edgeGap?: number): any[];
28
- scaleToFit(G: any, order: any, edgeGap?: number): void;
29
- size(x?: any): number[] | any;
30
- separation(x?: any): ((a: any, b: any, c: any) => number) | any;
31
- whitespace(x?: number): number | any;
32
- scale(x?: number): any;
45
+ separation(x?: number): ((a: string, b: string, G: LayoutGraph) => number) | {
46
+ (G: LayoutGraph, order: string[][][], edgeGap?: number): LayoutNode[];
47
+ scaleToFit(G: LayoutGraph, order: string[][][], edgeGap?: number): void;
48
+ size(x?: number[] | undefined): number[] | any;
49
+ separation(x?: number | ((a: string, b: string, G: LayoutGraph) => number) | undefined): ((a: string, b: string, G: LayoutGraph) => number) | any;
50
+ whitespace(x?: number | undefined): number | any;
51
+ scale(x?: number | undefined): number | any | null;
33
52
  } | any;
34
- whitespace(x: any): number | {
35
- (G: any, order: any, edgeGap?: number): any[];
36
- scaleToFit(G: any, order: any, edgeGap?: number): void;
37
- size(x?: any): number[] | any;
38
- separation(x?: any): ((a: any, b: any, c: any) => number) | any;
39
- whitespace(x?: number): number | any;
40
- scale(x?: number): any;
53
+ whitespace(x?: number): number | {
54
+ (G: LayoutGraph, order: string[][][], edgeGap?: number): LayoutNode[];
55
+ scaleToFit(G: LayoutGraph, order: string[][][], edgeGap?: number): void;
56
+ size(x?: number[] | undefined): number[] | any;
57
+ separation(x?: number | ((a: string, b: string, G: LayoutGraph) => number) | undefined): ((a: string, b: string, G: LayoutGraph) => number) | any;
58
+ whitespace(x?: number | undefined): number | any;
59
+ scale(x?: number | undefined): number | any | null;
41
60
  } | any;
42
- edgeValue(_x: any): any;
43
- scale(x: any): any;
61
+ edgeValue(_x?: unknown): any;
62
+ scale(x?: number): number | {
63
+ (G: LayoutGraph, order: string[][][], edgeGap?: number): LayoutNode[];
64
+ scaleToFit(G: LayoutGraph, order: string[][][], edgeGap?: number): void;
65
+ size(x?: number[] | undefined): number[] | any;
66
+ separation(x?: number | ((a: string, b: string, G: LayoutGraph) => number) | undefined): ((a: string, b: string, G: LayoutGraph) => number) | any;
67
+ whitespace(x?: number | undefined): number | any;
68
+ scale(x?: number | undefined): number | any | null;
69
+ } | any | null;
44
70
  };
71
+ export {};
@@ -1,2 +1,4 @@
1
- export declare function addDummyNodes(G: any): any;
2
- export declare function removeDummyNodes(G: any): void;
1
+ import { SankeyGraph } from '../types';
2
+
3
+ export declare function addDummyNodes(G: SankeyGraph): SankeyGraph;
4
+ export declare function removeDummyNodes(G: SankeyGraph): void;
@@ -1,4 +1,5 @@
1
- /** @module node-ordering/count-crossings */
1
+ import { SankeyGraph } from '../types';
2
+
2
3
  /**
3
4
  * Count the total number of crossings between 2 layers.
4
5
  *
@@ -8,7 +9,7 @@
8
9
  * @param {Array} orderA - List of node ids on left side.
9
10
  * @param {Array} orderB - List of node ids on right side.
10
11
  */
11
- export declare function countCrossings(G: any, orderA: any, orderB: any): number;
12
+ export declare function countCrossings(G: SankeyGraph, orderA: string[], orderB: string[]): number;
12
13
  /**
13
14
  * Count the number of crossings of edges passing between 2 layers.
14
15
  *
@@ -19,7 +20,7 @@ export declare function countCrossings(G: any, orderA: any, orderB: any): number
19
20
  * @param {Array} orderA - List of node ids on left side.
20
21
  * @param {Array} orderB - List of node ids on right side.
21
22
  */
22
- export declare function countBetweenCrossings(G: any, orderA: any, orderB: any): number;
23
+ export declare function countBetweenCrossings(G: SankeyGraph, orderA: string[], orderB: string[]): number;
23
24
  /**
24
25
  * Count the number of crossings from within-layer edges.
25
26
  *
@@ -27,4 +28,4 @@ export declare function countBetweenCrossings(G: any, orderA: any, orderB: any):
27
28
  * @param {Array} orderA - List of node ids on left side.
28
29
  * @param {Array} orderB - List of node ids on right side.
29
30
  */
30
- export declare function countLoopCrossings(G: any, orderA: any, orderB: any): number;
31
+ export declare function countLoopCrossings(G: SankeyGraph, orderA: string[], orderB: string[]): number;
@@ -1 +1,3 @@
1
- export declare function initialOrdering(G: any): any[];
1
+ import { SankeyGraph } from '../types';
2
+
3
+ export declare function initialOrdering(G: SankeyGraph): string[][];
@@ -1,4 +1,5 @@
1
- /** @module node-ordering */
1
+ import { SankeyGraph } from '../types';
2
+
2
3
  /**
3
4
  * Return an ordering for the graph G.
4
5
  *
@@ -8,4 +9,4 @@
8
9
  * @param {Graph} G - The graph. Nodes must have a `rank` attribute.
9
10
  *
10
11
  */
11
- export declare function ordering(G: any, maxIterations?: number): any[];
12
+ export declare function ordering(G: SankeyGraph, maxIterations?: number): string[][][];
@@ -1 +1,3 @@
1
- export declare function swapNodes(G: any, order: any): void;
1
+ import { SankeyGraph } from '../types';
2
+
3
+ export declare function swapNodes(G: SankeyGraph, order: string[][]): void;
@@ -1,7 +1,9 @@
1
- export declare function medianValue(positions: any): any;
2
- export declare function sortNodes(G: any, order: any, sweepDirection?: number, includeLoops?: boolean): void;
3
- export declare function neighbourPositions(G: any, order: any, i: any, j: any, u: any, includeLoops?: boolean): any[];
1
+ import { SankeyGraph } from '../types';
2
+
3
+ export declare function medianValue(positions: number[]): number;
4
+ export declare function sortNodes(G: SankeyGraph, order: string[][], sweepDirection?: number, includeLoops?: boolean): void;
5
+ export declare function neighbourPositions(G: SankeyGraph, order: string[][], i: number, j: number, u: string, includeLoops?: boolean): number[];
4
6
  /**
5
7
  * Sort arr according to order. -1 in order means stay in same position.
6
8
  */
7
- export declare function sortByPositions(arr: any, order: any): void;
9
+ export declare function sortByPositions(arr: string[], order: Map<string, number>): void;
@@ -1,2 +1,4 @@
1
- export declare function spanMinWidths(G: any, order: any): any[];
2
- export declare function positionHorizontally(G: any, order: any, width: any, minWidths: any): void;
1
+ import { LayoutGraph } from './justified';
2
+
3
+ export declare function spanMinWidths(G: LayoutGraph, order: string[][][]): number[];
4
+ export declare function positionHorizontally(G: LayoutGraph, order: string[][][], width: number, minWidths: number[]): void;
@@ -5,11 +5,59 @@
5
5
  *
6
6
  * @module node-positioning/justified
7
7
  */
8
+ /** Shape of the mutable node object the layout algorithm reads and writes */
9
+ export interface LayoutNode {
10
+ value: number;
11
+ dy: number;
12
+ y: number;
13
+ x: number;
14
+ id: string;
15
+ spaceAbove: number;
16
+ spaceBelow: number;
17
+ direction?: string;
18
+ data?: {
19
+ direction?: string;
20
+ forceY?: number;
21
+ };
22
+ }
23
+ /** Shape of the mutable edge object the layout algorithm reads and writes */
24
+ interface LayoutEdge {
25
+ data: {
26
+ value: number;
27
+ };
28
+ value: number;
29
+ dy: number;
30
+ }
31
+ /** Minimal structural interface for the graph object used by the layout algorithms */
32
+ export interface LayoutGraph {
33
+ nodes(): string[];
34
+ node(id: string): LayoutNode;
35
+ setNode(id: string, label: LayoutNode): void;
36
+ inEdges(id: string): Array<{
37
+ v: string;
38
+ w: string;
39
+ }>;
40
+ outEdges(id: string): Array<{
41
+ v: string;
42
+ w: string;
43
+ }>;
44
+ edges(): Array<{
45
+ v: string;
46
+ w: string;
47
+ }>;
48
+ edge(e: {
49
+ v: string;
50
+ w: string;
51
+ }): LayoutEdge;
52
+ }
53
+ type NodeId = string;
54
+ type SeparationFn = (a: NodeId, b: NodeId, G: LayoutGraph) => number;
8
55
  export declare function justifiedPositioning(): {
9
- (G: any, order: any, edgeGap?: number): any[];
10
- scaleToFit(G: any, order: any, edgeGap?: number): void;
11
- size(x?: any): number[] | any;
12
- separation(x?: any): ((a: any, b: any, c: any) => number) | any;
56
+ (G: LayoutGraph, order: NodeId[][][], edgeGap?: number): LayoutNode[];
57
+ scaleToFit(G: LayoutGraph, order: NodeId[][][], edgeGap?: number): void;
58
+ size(x?: number[]): number[] | any;
59
+ separation(x?: SeparationFn | number): SeparationFn | any;
13
60
  whitespace(x?: number): number | any;
14
- scale(x?: number): any;
61
+ scale(x?: number): number | any | null;
15
62
  };
63
+ export {};
@@ -1,4 +1,6 @@
1
+ import { RankSet, SankeyGraph } from '../types';
2
+
1
3
  /**
2
4
  * Assign ranks to the nodes in graph, according to rankSets.
3
5
  */
4
- export declare function assignRanks(graph: any, rankSets: any): void;
6
+ export declare function assignRanks(graph: SankeyGraph, rankSets: RankSet[]): void;
@@ -1,4 +1,4 @@
1
- import { Graph } from 'graphlib';
1
+ import { RankSet, SankeyGraph } from '../types';
2
2
 
3
3
  /**
4
4
  * Create a new graph where nodes in the same rank set are merged into one node.
@@ -7,4 +7,4 @@ import { Graph } from 'graphlib';
7
7
  * atribute of the edges.
8
8
  *
9
9
  */
10
- export declare function groupedGraph(G: any, rankSets: any): Graph;
10
+ export declare function groupedGraph(G: SankeyGraph, rankSets: RankSet[]): SankeyGraph;
@@ -1,4 +1,6 @@
1
+ import { SankeyGraph } from '../types';
2
+
1
3
  /**
2
4
  * Take an acyclic graph and assign initial ranks to the nodes
3
5
  */
4
- export declare function assignInitialRanks(G: any): void;
6
+ export declare function assignInitialRanks(G: SankeyGraph): void;
@@ -1,12 +1,12 @@
1
- import { Graph } from 'graphlib';
1
+ import { SankeyGraph } from '../types';
2
2
 
3
3
  /**
4
4
  * Reverse edges in G to make it acyclic
5
5
  */
6
- export declare function makeAcyclic(G: any, v0: any): any;
7
- export declare function findSpanningTree(G: any, v0: any): Graph;
6
+ export declare function makeAcyclic(G: SankeyGraph, v0: string): SankeyGraph;
7
+ export declare function findSpanningTree(G: SankeyGraph, v0: string): SankeyGraph;
8
8
  /**
9
9
  * Returns 1 if w is a descendent of v, -1 if v is a descendent of w, and 0 if
10
10
  * they are unrelated.
11
11
  */
12
- export declare function nodeRelationship(tree: any, v: any, w: any): 0 | 1 | -1;
12
+ export declare function nodeRelationship(tree: SankeyGraph, v: string, w: string): number;