@darajs/ui-causal-graph-editor 1.4.4 → 1.5.1
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/graph-viewer/causal-graph-editor.d.ts +2 -0
- package/dist/graph-viewer/causal-graph-editor.d.ts.map +1 -1
- package/dist/graph-viewer/causal-graph-editor.js +42 -8
- package/dist/graph-viewer/causal-graph-editor.js.map +1 -1
- package/dist/graph-viewer/utils/stories-utils.d.ts +322 -0
- package/dist/graph-viewer/utils/stories-utils.d.ts.map +1 -0
- package/dist/graph-viewer/utils/stories-utils.js +338 -0
- package/dist/graph-viewer/utils/stories-utils.js.map +1 -0
- package/dist/shared/graph-layout/common.d.ts +5 -1
- package/dist/shared/graph-layout/common.d.ts.map +1 -1
- package/dist/shared/graph-layout/fcose-layout.d.ts +26 -2
- package/dist/shared/graph-layout/fcose-layout.d.ts.map +1 -1
- package/dist/shared/graph-layout/fcose-layout.js +111 -0
- package/dist/shared/graph-layout/fcose-layout.js.map +1 -1
- package/dist/shared/graph-layout/marketing-layout.d.ts +14 -2
- package/dist/shared/graph-layout/marketing-layout.d.ts.map +1 -1
- package/dist/shared/graph-layout/marketing-layout.js +18 -0
- package/dist/shared/graph-layout/marketing-layout.js.map +1 -1
- package/dist/shared/graph-layout/planar-layout.d.ts +10 -3
- package/dist/shared/graph-layout/planar-layout.d.ts.map +1 -1
- package/dist/shared/graph-layout/planar-layout.js +67 -12
- package/dist/shared/graph-layout/planar-layout.js.map +1 -1
- package/dist/shared/graph-layout/spring-layout.d.ts +43 -2
- package/dist/shared/graph-layout/spring-layout.d.ts.map +1 -1
- package/dist/shared/graph-layout/spring-layout.js +101 -0
- package/dist/shared/graph-layout/spring-layout.js.map +1 -1
- package/dist/shared/parsers.d.ts +12 -5
- package/dist/shared/parsers.d.ts.map +1 -1
- package/dist/shared/parsers.js +33 -6
- package/dist/shared/parsers.js.map +1 -1
- package/dist/shared/rendering/engine.d.ts +4 -1
- package/dist/shared/rendering/engine.d.ts.map +1 -1
- package/dist/shared/rendering/engine.js +43 -10
- package/dist/shared/rendering/engine.js.map +1 -1
- package/dist/shared/rendering/use-render-engine.d.ts +2 -1
- package/dist/shared/rendering/use-render-engine.d.ts.map +1 -1
- package/dist/shared/rendering/use-render-engine.js +2 -2
- package/dist/shared/rendering/use-render-engine.js.map +1 -1
- package/dist/shared/rendering/utils.d.ts +2 -0
- package/dist/shared/rendering/utils.d.ts.map +1 -1
- package/dist/shared/rendering/utils.js +3 -0
- package/dist/shared/rendering/utils.js.map +1 -1
- package/dist/shared/use-causal-graph-editor.d.ts +3 -1
- package/dist/shared/use-causal-graph-editor.d.ts.map +1 -1
- package/dist/shared/use-causal-graph-editor.js +20 -1
- package/dist/shared/use-causal-graph-editor.js.map +1 -1
- package/dist/shared/utils.d.ts +27 -1
- package/dist/shared/utils.d.ts.map +1 -1
- package/dist/shared/utils.js +106 -0
- package/dist/shared/utils.js.map +1 -1
- package/dist/types.d.ts +18 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +12 -12
|
@@ -1,15 +1,24 @@
|
|
|
1
1
|
import { LayoutMapping, XYPosition } from 'graphology-layout/utils';
|
|
2
|
-
import { SimulationGraph } from '../../types';
|
|
2
|
+
import { DirectionType, GraphTiers, SimulationGraph, TieredGraphLayoutBuilder } from '../../types';
|
|
3
3
|
import { GraphLayout, GraphLayoutBuilder } from './common';
|
|
4
4
|
export type TargetLocation = 'center' | 'bottom';
|
|
5
|
-
declare class MarketingLayoutBuilder extends GraphLayoutBuilder<MarketingLayout> {
|
|
5
|
+
declare class MarketingLayoutBuilder extends GraphLayoutBuilder<MarketingLayout> implements TieredGraphLayoutBuilder {
|
|
6
6
|
_targetLocation: TargetLocation;
|
|
7
|
+
_tierSeparation: number;
|
|
8
|
+
orientation: DirectionType;
|
|
9
|
+
tiers: GraphTiers;
|
|
7
10
|
/**
|
|
8
11
|
* Sets the target location and returns the builder
|
|
9
12
|
*
|
|
10
13
|
* @param location location of the target node
|
|
11
14
|
*/
|
|
12
15
|
targetLocation(location: TargetLocation): this;
|
|
16
|
+
/**
|
|
17
|
+
* Set tier separation
|
|
18
|
+
*
|
|
19
|
+
* @param separation separation
|
|
20
|
+
*/
|
|
21
|
+
tierSeparation(separation: number): this;
|
|
13
22
|
build(): MarketingLayout;
|
|
14
23
|
}
|
|
15
24
|
/**
|
|
@@ -20,6 +29,9 @@ declare class MarketingLayoutBuilder extends GraphLayoutBuilder<MarketingLayout>
|
|
|
20
29
|
*/
|
|
21
30
|
export default class MarketingLayout extends GraphLayout {
|
|
22
31
|
targetLocation: TargetLocation;
|
|
32
|
+
tierSeparation: number;
|
|
33
|
+
orientation: DirectionType;
|
|
34
|
+
tiers: GraphTiers;
|
|
23
35
|
constructor(builder: MarketingLayoutBuilder);
|
|
24
36
|
applyLayout(graph: SimulationGraph): Promise<{
|
|
25
37
|
layout: LayoutMapping<XYPosition>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"marketing-layout.d.ts","sourceRoot":"","sources":["../../../src/shared/graph-layout/marketing-layout.tsx"],"names":[],"mappings":"AAkBA,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAEpE,OAAO,
|
|
1
|
+
{"version":3,"file":"marketing-layout.d.ts","sourceRoot":"","sources":["../../../src/shared/graph-layout/marketing-layout.tsx"],"names":[],"mappings":"AAkBA,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAEpE,OAAO,EACH,aAAa,EACb,UAAU,EACV,eAAe,EAEf,wBAAwB,EAC3B,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAG3D,MAAM,MAAM,cAAc,GAAG,QAAQ,GAAG,QAAQ,CAAC;AAEjD,cAAM,sBAAuB,SAAQ,kBAAkB,CAAC,eAAe,CAAE,YAAW,wBAAwB;IACxG,eAAe,EAAE,cAAc,CAAY;IAE3C,eAAe,SAAO;IAEtB,WAAW,EAAE,aAAa,CAAgB;IAE1C,KAAK,EAAE,UAAU,CAAC;IAElB;;;;OAIG;IACH,cAAc,CAAC,QAAQ,EAAE,cAAc,GAAG,IAAI;IAK9C;;;;OAIG;IACH,cAAc,CAAC,UAAU,EAAE,MAAM,GAAG,IAAI;IAKxC,KAAK,IAAI,eAAe;CAI3B;AAED;;;;;GAKG;AACH,MAAM,CAAC,OAAO,OAAO,eAAgB,SAAQ,WAAW;IAC7C,cAAc,EAAE,cAAc,CAAY;IAE1C,cAAc,EAAE,MAAM,CAAC;IAEvB,WAAW,EAAE,aAAa,CAAC;IAE3B,KAAK,EAAE,UAAU,CAAC;gBAEb,OAAO,EAAE,sBAAsB;IAQ3C,WAAW,CAAC,KAAK,EAAE,eAAe,GAAG,OAAO,CAAC;QACzC,MAAM,EAAE,aAAa,CAAC,UAAU,CAAC,CAAC;KACrC,CAAC;IAyEF,MAAM,KAAK,OAAO,IAAI,sBAAsB,CAE3C;CACJ"}
|
|
@@ -17,10 +17,13 @@
|
|
|
17
17
|
import * as d3 from 'd3';
|
|
18
18
|
import { getD3Data, nodesToLayout } from '../parsers';
|
|
19
19
|
import { GraphLayout, GraphLayoutBuilder } from './common';
|
|
20
|
+
import { applyTierForces } from './spring-layout';
|
|
20
21
|
class MarketingLayoutBuilder extends GraphLayoutBuilder {
|
|
21
22
|
constructor() {
|
|
22
23
|
super(...arguments);
|
|
23
24
|
this._targetLocation = 'bottom';
|
|
25
|
+
this._tierSeparation = 300;
|
|
26
|
+
this.orientation = 'horizontal';
|
|
24
27
|
}
|
|
25
28
|
/**
|
|
26
29
|
* Sets the target location and returns the builder
|
|
@@ -31,6 +34,15 @@ class MarketingLayoutBuilder extends GraphLayoutBuilder {
|
|
|
31
34
|
this._targetLocation = location;
|
|
32
35
|
return this;
|
|
33
36
|
}
|
|
37
|
+
/**
|
|
38
|
+
* Set tier separation
|
|
39
|
+
*
|
|
40
|
+
* @param separation separation
|
|
41
|
+
*/
|
|
42
|
+
tierSeparation(separation) {
|
|
43
|
+
this._tierSeparation = separation;
|
|
44
|
+
return this;
|
|
45
|
+
}
|
|
34
46
|
build() {
|
|
35
47
|
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
36
48
|
return new MarketingLayout(this);
|
|
@@ -47,6 +59,9 @@ export default class MarketingLayout extends GraphLayout {
|
|
|
47
59
|
super(builder);
|
|
48
60
|
this.targetLocation = 'bottom';
|
|
49
61
|
this.targetLocation = builder._targetLocation;
|
|
62
|
+
this.tierSeparation = builder._tierSeparation;
|
|
63
|
+
this.orientation = builder.orientation;
|
|
64
|
+
this.tiers = builder.tiers;
|
|
50
65
|
}
|
|
51
66
|
applyLayout(graph) {
|
|
52
67
|
const [edges, nodes] = getD3Data(graph);
|
|
@@ -95,6 +110,9 @@ export default class MarketingLayout extends GraphLayout {
|
|
|
95
110
|
return node.group === 'other' ? 0.7 : 1;
|
|
96
111
|
}))
|
|
97
112
|
.stop();
|
|
113
|
+
if (this.tiers) {
|
|
114
|
+
applyTierForces(simulation, graph, nodes, this.tiers, this.tierSeparation, this.orientation);
|
|
115
|
+
}
|
|
98
116
|
simulation.tick(1000);
|
|
99
117
|
return Promise.resolve({ layout: nodesToLayout(simulation.nodes()) });
|
|
100
118
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"marketing-layout.js","sourceRoot":"","sources":["../../../src/shared/graph-layout/marketing-layout.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;
|
|
1
|
+
{"version":3,"file":"marketing-layout.js","sourceRoot":"","sources":["../../../src/shared/graph-layout/marketing-layout.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AAWzB,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,YAAY,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KAAK,QAAQ,EAAE;gBACzB,OAAO,CAAC,CAAC;aACZ;YACD,IAAI,IAAI,CAAC,KAAK,KAAK,QAAQ,EAAE;gBACzB,OAAO,IAAI,CAAC,QAAQ,GAAG,CAAC,CAAC;aAC5B;YAED,OAAO,IAAI,CAAC,QAAQ,GAAG,CAAC,CAAC;QAC7B,CAAC,EACD,GAAG,EACH,GAAG,CACN;aACA,QAAQ,CAAC,CAAC,IAAI,EAAE,EAAE;YACf,IAAI,IAAI,CAAC,cAAc,KAAK,QAAQ,EAAE;gBAClC,OAAO,CAAC,CAAC;aACZ;YACD,OAAO,IAAI,CAAC,KAAK,KAAK,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;QAC5C,CAAC,CAAC,CACT;aACA,IAAI,EAAE,CAAC;QAEZ,IAAI,IAAI,CAAC,KAAK,EAAE;YACZ,eAAe,CAAC,UAAU,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,cAAc,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC;SAChG;QAED,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAEtB,OAAO,OAAO,CAAC,OAAO,CAAC,EAAE,MAAM,EAAE,aAAa,CAAC,UAAU,CAAC,KAAK,EAAE,CAAC,EAAE,CAAC,CAAC;IAC1E,CAAC;IAED,MAAM,KAAK,OAAO;QACd,OAAO,IAAI,sBAAsB,EAAE,CAAC;IACxC,CAAC;CACJ"}
|
|
@@ -1,23 +1,30 @@
|
|
|
1
1
|
import { LayoutMapping, XYPosition } from 'graphology-layout/utils';
|
|
2
|
-
import { SimulationGraph } from '../../types';
|
|
2
|
+
import { DirectionType, GraphTiers, SimulationGraph, TieredGraphLayoutBuilder } from '../../types';
|
|
3
3
|
import { GraphLayout, GraphLayoutBuilder } from './common';
|
|
4
|
-
export type DirectionType = 'horizontal' | 'vertical';
|
|
5
4
|
declare class PlanarLayoutBuilder extends GraphLayoutBuilder<PlanarLayout> {
|
|
6
5
|
_orientation: DirectionType;
|
|
6
|
+
_tiers: GraphTiers;
|
|
7
7
|
/**
|
|
8
8
|
* Sets the nodes orientation
|
|
9
9
|
*
|
|
10
10
|
* @param direction vertical or horizontal
|
|
11
11
|
*/
|
|
12
12
|
orientation(direction: DirectionType): this;
|
|
13
|
+
/**
|
|
14
|
+
* Sets the tiers for the graph
|
|
15
|
+
*
|
|
16
|
+
* @param tiers the tiers to use
|
|
17
|
+
*/
|
|
18
|
+
tiers(tiers: GraphTiers): this;
|
|
13
19
|
build(): PlanarLayout;
|
|
14
20
|
}
|
|
15
21
|
/**
|
|
16
22
|
* The Planar layout utilises the sugiyama algorithm to lay out nodes in a way that minimises
|
|
17
23
|
* edge crossings.
|
|
18
24
|
*/
|
|
19
|
-
export default class PlanarLayout extends GraphLayout {
|
|
25
|
+
export default class PlanarLayout extends GraphLayout implements TieredGraphLayoutBuilder {
|
|
20
26
|
orientation: DirectionType;
|
|
27
|
+
tiers: GraphTiers;
|
|
21
28
|
constructor(builder: PlanarLayoutBuilder);
|
|
22
29
|
get supportsDrag(): boolean;
|
|
23
30
|
applyLayout(graph: SimulationGraph, forceUpdate?: (layout: LayoutMapping<XYPosition>, edgePoints: LayoutMapping<XYPosition[]>) => void): Promise<{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"planar-layout.d.ts","sourceRoot":"","sources":["../../../src/shared/graph-layout/planar-layout.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"planar-layout.d.ts","sourceRoot":"","sources":["../../../src/shared/graph-layout/planar-layout.tsx"],"names":[],"mappings":"AA0BA,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAEpE,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,eAAe,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAC;AAEnG,OAAO,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAE3D,cAAM,mBAAoB,SAAQ,kBAAkB,CAAC,YAAY,CAAC;IAC9D,YAAY,EAAE,aAAa,CAAgB;IAE3C,MAAM,EAAE,UAAU,CAAC;IAEnB;;;;OAIG;IACH,WAAW,CAAC,SAAS,EAAE,aAAa,GAAG,IAAI;IAK3C;;;;OAIG;IACH,KAAK,CAAC,KAAK,EAAE,UAAU,GAAG,IAAI;IAK9B,KAAK,IAAI,YAAY;CAIxB;AAqCD;;;GAGG;AACH,MAAM,CAAC,OAAO,OAAO,YAAa,SAAQ,WAAY,YAAW,wBAAwB;IAC9E,WAAW,EAAE,aAAa,CAAgB;IAE1C,KAAK,EAAE,UAAU,CAAC;gBAEb,OAAO,EAAE,mBAAmB;IAOxC,IAAI,YAAY,IAAI,OAAO,CAE1B;IAED,WAAW,CACP,KAAK,EAAE,eAAe,EACtB,WAAW,CAAC,EAAE,CAAC,MAAM,EAAE,aAAa,CAAC,UAAU,CAAC,EAAE,UAAU,EAAE,aAAa,CAAC,UAAU,EAAE,CAAC,KAAK,IAAI,GACnG,OAAO,CAAC;QACP,UAAU,CAAC,EAAE,aAAa,CAAC,UAAU,EAAE,CAAC,CAAC;QACzC,MAAM,EAAE,aAAa,CAAC,UAAU,CAAC,CAAC;QAClC,SAAS,CAAC,EAAE,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;QACvC,SAAS,CAAC,EAAE,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;KAC1C,CAAC;IAyEF,MAAM,KAAK,OAAO,IAAI,mBAAmB,CAExC;CACJ"}
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
* See the License for the specific language governing permissions and
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
*/
|
|
17
|
-
import { coordQuad, sugiyama } from 'd3-dag';
|
|
17
|
+
import { coordQuad, decrossTwoLayer, layeringSimplex, sugiyama, } from 'd3-dag';
|
|
18
18
|
import { dagGraphParser } from '../parsers';
|
|
19
19
|
import { GraphLayout, GraphLayoutBuilder } from './common';
|
|
20
20
|
class PlanarLayoutBuilder extends GraphLayoutBuilder {
|
|
@@ -31,11 +31,50 @@ class PlanarLayoutBuilder extends GraphLayoutBuilder {
|
|
|
31
31
|
this._orientation = direction;
|
|
32
32
|
return this;
|
|
33
33
|
}
|
|
34
|
+
/**
|
|
35
|
+
* Sets the tiers for the graph
|
|
36
|
+
*
|
|
37
|
+
* @param tiers the tiers to use
|
|
38
|
+
*/
|
|
39
|
+
tiers(tiers) {
|
|
40
|
+
this._tiers = tiers;
|
|
41
|
+
return this;
|
|
42
|
+
}
|
|
34
43
|
build() {
|
|
35
44
|
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
36
45
|
return new PlanarLayout(this);
|
|
37
46
|
}
|
|
38
47
|
}
|
|
48
|
+
/**
|
|
49
|
+
* Gets the order value for a given node or link data
|
|
50
|
+
*
|
|
51
|
+
* @param data the data of a pure node or link
|
|
52
|
+
*/
|
|
53
|
+
function getOrdValue(data) {
|
|
54
|
+
if (data.role === 'node') {
|
|
55
|
+
return Number(data.node.data.ord) || 0;
|
|
56
|
+
}
|
|
57
|
+
// Here we define which order the edges connecting nodes from previous layer should appear in
|
|
58
|
+
// As a crude approach we define that their order should follow the mean of the source and target nodes.
|
|
59
|
+
const sourceOrd = Number.isNaN(Number(data.link.source.data.ord)) ? 0 : Number(data.link.source.data.ord);
|
|
60
|
+
const targetOrd = Number.isNaN(Number(data.link.target.data.ord)) ? 0 : Number(data.link.target.data.ord);
|
|
61
|
+
return (sourceOrd + targetOrd) / 2;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* customDecross function that takes ordering of nodes into account
|
|
65
|
+
*
|
|
66
|
+
* @param layers the layers defined by the layering step
|
|
67
|
+
*/
|
|
68
|
+
function customDecross(layers) {
|
|
69
|
+
const vals = new Map();
|
|
70
|
+
layers.forEach((layer) => {
|
|
71
|
+
layer.forEach((node) => {
|
|
72
|
+
const val = getOrdValue(node.data);
|
|
73
|
+
vals.set(node, val);
|
|
74
|
+
});
|
|
75
|
+
layer.sort((a, b) => vals.get(a) - vals.get(b));
|
|
76
|
+
});
|
|
77
|
+
}
|
|
39
78
|
/**
|
|
40
79
|
* The Planar layout utilises the sugiyama algorithm to lay out nodes in a way that minimises
|
|
41
80
|
* edge crossings.
|
|
@@ -45,6 +84,7 @@ export default class PlanarLayout extends GraphLayout {
|
|
|
45
84
|
super(builder);
|
|
46
85
|
this.orientation = 'horizontal';
|
|
47
86
|
this.orientation = builder._orientation;
|
|
87
|
+
this.tiers = builder._tiers;
|
|
48
88
|
}
|
|
49
89
|
// eslint-disable-next-line class-methods-use-this
|
|
50
90
|
get supportsDrag() {
|
|
@@ -53,26 +93,41 @@ export default class PlanarLayout extends GraphLayout {
|
|
|
53
93
|
applyLayout(graph, forceUpdate) {
|
|
54
94
|
// define an inner method so it can be called repeatedly when nodes or edges are added
|
|
55
95
|
const computeLayout = (currentGraph) => {
|
|
56
|
-
const dag = dagGraphParser(currentGraph);
|
|
96
|
+
const dag = dagGraphParser(currentGraph, this.tiers);
|
|
57
97
|
/**
|
|
58
98
|
* The nodeSize is scaled for consistent spacing in the horizontal layout
|
|
59
99
|
*/
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
100
|
+
let newDagLayout;
|
|
101
|
+
try {
|
|
102
|
+
function groupAccessor(node) {
|
|
103
|
+
return node.data.group;
|
|
104
|
+
}
|
|
105
|
+
function rankAccessor(node) {
|
|
106
|
+
return node.data.rank;
|
|
107
|
+
}
|
|
108
|
+
newDagLayout = sugiyama()
|
|
109
|
+
.nodeSize(() => [this.nodeSize * 3, this.nodeSize * 6])
|
|
110
|
+
.coord(coordQuad())
|
|
111
|
+
.layering(this.tiers ? layeringSimplex().group(groupAccessor).rank(rankAccessor) : layeringSimplex())
|
|
112
|
+
.decross(this.tiers ? customDecross : decrossTwoLayer());
|
|
113
|
+
newDagLayout(dag);
|
|
114
|
+
}
|
|
115
|
+
catch (e) {
|
|
116
|
+
throw new Error('d3-dag failed to resolve the layering of graph nodes for PlanarLayout.');
|
|
117
|
+
}
|
|
118
|
+
const edgePoints = Array.from(dag.links()).reduce((acc, link) => {
|
|
119
|
+
acc[`${link.source.data.id}||${link.target.data.id}`] = link.points.map((point) => ({
|
|
120
|
+
x: this.orientation === 'vertical' ? point[0] : point[1],
|
|
121
|
+
y: this.orientation === 'vertical' ? point[1] : point[0],
|
|
67
122
|
}));
|
|
68
123
|
return acc;
|
|
69
124
|
}, {});
|
|
70
|
-
const newLayout =
|
|
71
|
-
|
|
125
|
+
const newLayout = Array.from(dag.nodes()).reduce((layout, node) => {
|
|
126
|
+
layout[node.data.id] = {
|
|
72
127
|
x: this.orientation === 'vertical' ? node.x : node.y,
|
|
73
128
|
y: this.orientation === 'vertical' ? node.y : node.x,
|
|
74
129
|
};
|
|
75
|
-
return
|
|
130
|
+
return layout;
|
|
76
131
|
}, {});
|
|
77
132
|
return { edgePoints, newLayout };
|
|
78
133
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"planar-layout.js","sourceRoot":"","sources":["../../../src/shared/graph-layout/planar-layout.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,
|
|
1
|
+
{"version":3,"file":"planar-layout.js","sourceRoot":"","sources":["../../../src/shared/graph-layout/planar-layout.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,EAKH,SAAS,EACT,eAAe,EACf,eAAe,EACf,QAAQ,GACX,MAAM,QAAQ,CAAC;AAIhB,OAAO,EAAe,cAAc,EAAE,MAAM,YAAY,CAAC;AACzD,OAAO,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAE3D,MAAM,mBAAoB,SAAQ,kBAAgC;IAAlE;;QACI,iBAAY,GAAkB,YAAY,CAAC;IA4B/C,CAAC;IAxBG;;;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ed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
import * as d3 from 'd3';
|
|
1
18
|
import { LayoutMapping, XYPosition } from 'graphology-layout/utils';
|
|
2
|
-
import { SimulationGraph } from '../../types';
|
|
19
|
+
import { D3SimulationEdge, DirectionType, GraphTiers, SimulationGraph, SimulationNode, SimulationNodeWithGroup, TieredGraphLayoutBuilder } from '../../types';
|
|
3
20
|
import { GraphLayout, GraphLayoutBuilder } from './common';
|
|
4
|
-
declare class SpringLayoutBuilder extends GraphLayoutBuilder<SpringLayout> {
|
|
21
|
+
declare class SpringLayoutBuilder extends GraphLayoutBuilder<SpringLayout> implements TieredGraphLayoutBuilder {
|
|
5
22
|
_collisionForce: number;
|
|
6
23
|
_gravity: number;
|
|
7
24
|
_linkForce: number;
|
|
8
25
|
_warmupTicks: number;
|
|
26
|
+
_tierSeparation: number;
|
|
27
|
+
orientation: DirectionType;
|
|
28
|
+
tiers: GraphTiers;
|
|
9
29
|
/**
|
|
10
30
|
* Set the multiplier for collision force
|
|
11
31
|
*
|
|
@@ -30,8 +50,26 @@ declare class SpringLayoutBuilder extends GraphLayoutBuilder<SpringLayout> {
|
|
|
30
50
|
* @param ticks number of ticks to run before display
|
|
31
51
|
*/
|
|
32
52
|
warmupTicks(ticks: number): this;
|
|
53
|
+
/**
|
|
54
|
+
* Set tier separation
|
|
55
|
+
*
|
|
56
|
+
* @param separation separation
|
|
57
|
+
*/
|
|
58
|
+
tierSeparation(separation: number): this;
|
|
33
59
|
build(): SpringLayout;
|
|
34
60
|
}
|
|
61
|
+
/**
|
|
62
|
+
* Apply forces which are needed as part of a tiered layout.
|
|
63
|
+
* There is one force which snaps the nodes to the relevant layers and another force ordering the nodes within the layers.
|
|
64
|
+
*
|
|
65
|
+
* @param simulation the D3 simulation
|
|
66
|
+
* @param graph the simulation graph
|
|
67
|
+
* @param nodes array of the nodes
|
|
68
|
+
* @param tiers the tiers passed to the layout
|
|
69
|
+
* @param tiersSeparation the separation between the tiers
|
|
70
|
+
* @param orientation the orientation of the layout
|
|
71
|
+
*/
|
|
72
|
+
export declare function applyTierForces(simulation: d3.Simulation<SimulationNode, D3SimulationEdge>, graph: SimulationGraph, nodes: SimulationNodeWithGroup[], tiers: GraphTiers, tiersSeparation: number, orientation: DirectionType): void;
|
|
35
73
|
/**
|
|
36
74
|
* The Spring layout uses a force simulation to position nodes.
|
|
37
75
|
* The layout keeps the simulation running as nodes are being dragged which produces the spring behaviour of edges.
|
|
@@ -41,6 +79,9 @@ export default class SpringLayout extends GraphLayout {
|
|
|
41
79
|
gravity: number;
|
|
42
80
|
linkForce: number;
|
|
43
81
|
warmupTicks: number;
|
|
82
|
+
tierSeparation: number;
|
|
83
|
+
orientation: DirectionType;
|
|
84
|
+
tiers: GraphTiers;
|
|
44
85
|
constructor(builder: SpringLayoutBuilder);
|
|
45
86
|
applyLayout(graph: SimulationGraph, forceUpdate: (layout: LayoutMapping<XYPosition>) => void): Promise<{
|
|
46
87
|
layout: LayoutMapping<XYPosition>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"spring-layout.d.ts","sourceRoot":"","sources":["../../../src/shared/graph-layout/spring-layout.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"spring-layout.d.ts","sourceRoot":"","sources":["../../../src/shared/graph-layout/spring-layout.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,KAAK,EAAE,MAAM,IA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,SAAS,EAAE,MAAM,CAAC;IAElB,WAAW,EAAE,MAAM,CAAC;IAEpB,cAAc,EAAE,MAAM,CAAC;IAEvB,WAAW,EAAE,aAAa,CAAC;IAE3B,KAAK,EAAE,UAAU,CAAC;gBAEb,OAAO,EAAE,mBAAmB;IAWxC,WAAW,CACP,KAAK,EAAE,eAAe,EACtB,WAAW,EAAE,CAAC,MAAM,EAAE,aAAa,CAAC,UAAU,CAAC,KAAK,IAAI,GACzD,OAAO,CAAC;QACP,MAAM,EAAE,aAAa,CAAC,UAAU,CAAC,CAAC;QAClC,SAAS,CAAC,EAAE,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;QACvC,SAAS,CAAC,EAAE,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;QACvC,SAAS,CAAC,EAAE,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;QACvC,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;QACxD,WAAW,CAAC,EAAE,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;KAC5C,CAAC;IAgFF,MAAM,KAAK,OAAO,IAAI,mBAAmB,CAExC;CACJ"}
|
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
import * as d3 from 'd3';
|
|
18
18
|
import debounce from 'lodash/debounce';
|
|
19
19
|
import { getD3Data, nodesToLayout } from '../parsers';
|
|
20
|
+
import { getNodeOrder, getTiersArray } from '../utils';
|
|
20
21
|
import { GraphLayout, GraphLayoutBuilder } from './common';
|
|
21
22
|
class SpringLayoutBuilder extends GraphLayoutBuilder {
|
|
22
23
|
constructor() {
|
|
@@ -25,6 +26,8 @@ class SpringLayoutBuilder extends GraphLayoutBuilder {
|
|
|
25
26
|
this._gravity = -50;
|
|
26
27
|
this._linkForce = 5;
|
|
27
28
|
this._warmupTicks = 100;
|
|
29
|
+
this._tierSeparation = 300;
|
|
30
|
+
this.orientation = 'horizontal';
|
|
28
31
|
}
|
|
29
32
|
/**
|
|
30
33
|
* Set the multiplier for collision force
|
|
@@ -62,11 +65,103 @@ class SpringLayoutBuilder extends GraphLayoutBuilder {
|
|
|
62
65
|
this._warmupTicks = ticks;
|
|
63
66
|
return this;
|
|
64
67
|
}
|
|
68
|
+
/**
|
|
69
|
+
* Set tier separation
|
|
70
|
+
*
|
|
71
|
+
* @param separation separation
|
|
72
|
+
*/
|
|
73
|
+
tierSeparation(separation) {
|
|
74
|
+
this._tierSeparation = separation;
|
|
75
|
+
return this;
|
|
76
|
+
}
|
|
65
77
|
build() {
|
|
66
78
|
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
67
79
|
return new SpringLayout(this);
|
|
68
80
|
}
|
|
69
81
|
}
|
|
82
|
+
/**
|
|
83
|
+
* Apply force that orders nodes based on the tier order_nodes_by values
|
|
84
|
+
*
|
|
85
|
+
* @param simulation the D3 simulation
|
|
86
|
+
* @param tiers the tiers passed to the layout
|
|
87
|
+
* @param graph the simulation graph
|
|
88
|
+
* @param orientation the orientation of the layout
|
|
89
|
+
* @param nodesMap a map of node name to node object
|
|
90
|
+
*/
|
|
91
|
+
function applyOrderNodesForce(simulation, tiers, graph, orientation, nodesMap) {
|
|
92
|
+
if (!Array.isArray(tiers)) {
|
|
93
|
+
const { order_nodes_by } = tiers;
|
|
94
|
+
if (order_nodes_by) {
|
|
95
|
+
const simNodes = graph.nodes();
|
|
96
|
+
const nodesOrder = getNodeOrder(simNodes, order_nodes_by, graph);
|
|
97
|
+
const sortedNodesOrderArray = Object.entries(nodesOrder)
|
|
98
|
+
.sort((a, b) => Number(a[1]) - Number(b[1]))
|
|
99
|
+
.map((entry) => entry[0]);
|
|
100
|
+
const nodeSeparation = 200;
|
|
101
|
+
function forceOrder() {
|
|
102
|
+
function force(alpha) {
|
|
103
|
+
sortedNodesOrderArray.forEach((nodeName, index) => {
|
|
104
|
+
const targetPosition = index * nodeSeparation;
|
|
105
|
+
const targettedNode = nodesMap.get(nodeName);
|
|
106
|
+
if (targettedNode) {
|
|
107
|
+
if (orientation === 'horizontal') {
|
|
108
|
+
// Apply a nudge towards the target y position
|
|
109
|
+
targettedNode.vy += (targetPosition - targettedNode.y) * alpha;
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
// Apply a nudge towards the target x position
|
|
113
|
+
targettedNode.vx += (targetPosition - targettedNode.x) * alpha;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
return force;
|
|
119
|
+
}
|
|
120
|
+
// apply layer force
|
|
121
|
+
simulation.force('order', forceOrder());
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Apply forces which are needed as part of a tiered layout.
|
|
127
|
+
* There is one force which snaps the nodes to the relevant layers and another force ordering the nodes within the layers.
|
|
128
|
+
*
|
|
129
|
+
* @param simulation the D3 simulation
|
|
130
|
+
* @param graph the simulation graph
|
|
131
|
+
* @param nodes array of the nodes
|
|
132
|
+
* @param tiers the tiers passed to the layout
|
|
133
|
+
* @param tiersSeparation the separation between the tiers
|
|
134
|
+
* @param orientation the orientation of the layout
|
|
135
|
+
*/
|
|
136
|
+
export function applyTierForces(simulation, graph, nodes, tiers, tiersSeparation, orientation) {
|
|
137
|
+
const tiersArray = getTiersArray(tiers, graph);
|
|
138
|
+
const nodesMapping = new Map();
|
|
139
|
+
nodes.forEach((node) => nodesMapping.set(node.id, node));
|
|
140
|
+
applyOrderNodesForce(simulation, tiers, graph, orientation, nodesMapping);
|
|
141
|
+
function forceLayer() {
|
|
142
|
+
function force(alpha) {
|
|
143
|
+
tiersArray.forEach((tier, index) => {
|
|
144
|
+
const targetPosition = index * tiersSeparation;
|
|
145
|
+
tier.forEach((nodeName) => {
|
|
146
|
+
const targettedNode = nodesMapping.get(nodeName);
|
|
147
|
+
if (targettedNode) {
|
|
148
|
+
if (orientation === 'horizontal') {
|
|
149
|
+
// Directly set the x position
|
|
150
|
+
targettedNode.x = targetPosition + (targettedNode.x - targetPosition) * alpha;
|
|
151
|
+
}
|
|
152
|
+
else {
|
|
153
|
+
// Directly set the y position
|
|
154
|
+
targettedNode.y = targetPosition + (targettedNode.y - targetPosition) * alpha;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
return force;
|
|
161
|
+
}
|
|
162
|
+
// apply layer force
|
|
163
|
+
simulation.force('layer', forceLayer());
|
|
164
|
+
}
|
|
70
165
|
/**
|
|
71
166
|
* The Spring layout uses a force simulation to position nodes.
|
|
72
167
|
* The layout keeps the simulation running as nodes are being dragged which produces the spring behaviour of edges.
|
|
@@ -78,6 +173,9 @@ export default class SpringLayout extends GraphLayout {
|
|
|
78
173
|
this.linkForce = builder._linkForce;
|
|
79
174
|
this.gravity = builder._gravity;
|
|
80
175
|
this.warmupTicks = builder._warmupTicks;
|
|
176
|
+
this.tierSeparation = builder._tierSeparation;
|
|
177
|
+
this.orientation = builder.orientation;
|
|
178
|
+
this.tiers = builder.tiers;
|
|
81
179
|
}
|
|
82
180
|
applyLayout(graph, forceUpdate) {
|
|
83
181
|
// We're modifying edges/nodes
|
|
@@ -96,6 +194,9 @@ export default class SpringLayout extends GraphLayout {
|
|
|
96
194
|
// The center force keeps nodes in the middle of the viewport
|
|
97
195
|
.force('center', d3.forceCenter())
|
|
98
196
|
.stop(); // don't start just yet
|
|
197
|
+
if (this.tiers) {
|
|
198
|
+
applyTierForces(simulation, graph, nodes, this.tiers, this.tierSeparation, this.orientation);
|
|
199
|
+
}
|
|
99
200
|
// Warm-up the simulation so the jump to the center isn't visible
|
|
100
201
|
simulation.tick(this.warmupTicks);
|
|
101
202
|
simulation
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"spring-layout.js","sourceRoot":"","sources":["../../../src/shared/graph-layout/spring-layout.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AAGzB,OAAO,QAAQ,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"spring-layout.js","sourceRoot":"","sources":["../../../src/shared/graph-layout/spring-layout.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AAGzB,OAAO,QAAQ,MAAM,iBAAiB,CAAC;AAWvC,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACvD,OAAO,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAE3D,MAAM,mBAAoB,SAAQ,kBAAgC;IAAlE;;QACI,oBAAe,GAAG,CAAC,CAAC;QAEpB,aAAQ,GAAG,CAAC,EAAE,CAAC;QAEf,eAAU,GAAG,CAAC,CAAC;QAEf,iBAAY,GAAG,GAAG,CAAC;QAEnB,oBAAe,GAAG,GAAG,CAAC;QAEtB,gBAAW,GAAkB,YAAY,CAAC;IA0D9C,CAAC;IAtDG;;;;OAIG;IACH,cAAc,CAAC,KAAa;QACxB,IAAI,CAAC,eAAe,GAAG,KAAK,CAAC;QAC7B,OAAO,IAAI,CAAC;IAChB,CAAC;IAED;;;;OAIG;IACH,SAAS,CAAC,KAAa;QACnB,IAAI,CAAC,UAAU,GAAG,KAAK,CAAC;QACxB,OAAO,IAAI,CAAC;IAChB,CAAC;IAED;;;;OAIG;IACH,OAAO,CAAC,KAAa;QACjB,IAAI,CAAC,QAAQ,GAAG,KAAK,CAAC;QACtB,OAAO,IAAI,CAAC;IAChB,CAAC;IAED;;;;OAIG;IACH,WAAW,CAAC,KAAa;QACrB,IAAI,CAAC,YAAY,GAAG,KAAK,CAAC;QAC1B,OAAO,IAAI,CAAC;I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AC;IACrC,CAAC;CACJ"}
|
package/dist/shared/parsers.d.ts
CHANGED
|
@@ -14,18 +14,24 @@
|
|
|
14
14
|
* See the License for the specific language governing permissions and
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
*/
|
|
17
|
-
import {
|
|
17
|
+
import { MutGraph } from 'd3-dag';
|
|
18
18
|
import { LayoutMapping, XYPosition } from 'graphology-layout/utils';
|
|
19
|
-
import { CausalGraph, CausalGraphEdge, CausalGraphNode, D3SimulationEdge, SimulationEdge, SimulationGraph, SimulationNode, SimulationNodeWithGroup } from '../types';
|
|
20
|
-
|
|
19
|
+
import { CausalGraph, CausalGraphEdge, CausalGraphNode, D3SimulationEdge, GraphTiers, SimulationEdge, SimulationGraph, SimulationNode, SimulationNodeWithGroup } from '../types';
|
|
20
|
+
interface NodeOrder {
|
|
21
|
+
group: string;
|
|
22
|
+
order: string;
|
|
23
|
+
rank: number;
|
|
24
|
+
}
|
|
25
|
+
export type DagNodeData = SimulationNode & Partial<NodeOrder> & {
|
|
21
26
|
parentIds: string[];
|
|
22
27
|
};
|
|
23
28
|
/**
|
|
24
29
|
* This parses the graph structure into a Dag structure that the d3-dag library can understand
|
|
25
30
|
*
|
|
26
|
-
* @param
|
|
31
|
+
* @param graph The SimulationGraph
|
|
32
|
+
* @param tiers Any tiers passed to the layout
|
|
27
33
|
*/
|
|
28
|
-
export declare function dagGraphParser(graph: SimulationGraph):
|
|
34
|
+
export declare function dagGraphParser(graph: SimulationGraph, tiers?: GraphTiers): MutGraph<DagNodeData, any>;
|
|
29
35
|
/**
|
|
30
36
|
* Get graph edges in d3 expected format
|
|
31
37
|
*
|
|
@@ -60,4 +66,5 @@ export declare function parseGraphEdge(edgeData: CausalGraphEdge): SimulationEdg
|
|
|
60
66
|
* @param availableInputs names of input nodes
|
|
61
67
|
*/
|
|
62
68
|
export declare function causalGraphParser(data: CausalGraph, availableInputs?: string[], initialGraph?: SimulationGraph): SimulationGraph;
|
|
69
|
+
export {};
|
|
63
70
|
//# sourceMappingURL=parsers.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parsers.d.ts","sourceRoot":"","sources":["../../src/shared/parsers.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"parsers.d.ts","sourceRoot":"","sources":["../../src/shared/parsers.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,EAAE,QAAQ,EAAiB,MAAM,QAAQ,CAAC;AAEjD,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAIpE,OAAO,EACH,WAAW,EACX,eAAe,EACf,eAAe,EACf,gBAAgB,EAGhB,UAAU,EAEV,cAAc,EACd,eAAe,EACf,cAAc,EACd,uBAAuB,EAC1B,MAAM,UAAU,CAAC;AAGlB,UAAU,SAAS;IACf,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,MAAM,WAAW,GAAG,cAAc,GACpC,OAAO,CAAC,SAAS,CAAC,GAAG;IACjB,SAAS,EAAE,MAAM,EAAE,CAAC;CACvB,CAAC;AAEN;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,eAAe,EAAE,KAAK,CAAC,EAAE,UAAU,GAAG,QAAQ,CAAC,WAAW,EAAE,GAAG,CAAC,CA6CrG;AAED;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,eAAe,GAAG,CAAC,KAAK,EAAE,gBAAgB,EAAE,EAAE,KAAK,EAAE,uBAAuB,EAAE,CAAC,CAqB/G;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,cAAc,EAAE,GAAG,aAAa,CAAC,UAAU,CAAC,CAShF;AAaD;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAC1B,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,eAAe,EACzB,IAAI,EAAE,WAAW,EACjB,eAAe,CAAC,EAAE,MAAM,EAAE,GAC3B,cAAc,CAoChB;AAaD;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,QAAQ,EAAE,eAAe,GAAG,cAAc,CAoBxE;AAiBD;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAC7B,IAAI,EAAE,WAAW,EACjB,eAAe,CAAC,EAAE,MAAM,EAAE,EAC1B,YAAY,CAAC,EAAE,eAAe,GAC/B,eAAe,CA2EjB"}
|
package/dist/shared/parsers.js
CHANGED
|
@@ -25,22 +25,49 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
25
25
|
* See the License for the specific language governing permissions and
|
|
26
26
|
* limitations under the License.
|
|
27
27
|
*/
|
|
28
|
-
import {
|
|
28
|
+
import { graphStratify } from 'd3-dag';
|
|
29
29
|
import { DirectedGraph } from 'graphology';
|
|
30
30
|
import isEqual from 'lodash/isEqual';
|
|
31
31
|
import { generate } from 'shortid';
|
|
32
|
-
import { getNodeGroup } from './utils';
|
|
32
|
+
import { getNodeGroup, getNodeOrder, getTiersArray } from './utils';
|
|
33
33
|
/**
|
|
34
34
|
* This parses the graph structure into a Dag structure that the d3-dag library can understand
|
|
35
35
|
*
|
|
36
|
-
* @param
|
|
36
|
+
* @param graph The SimulationGraph
|
|
37
|
+
* @param tiers Any tiers passed to the layout
|
|
37
38
|
*/
|
|
38
|
-
export function dagGraphParser(graph) {
|
|
39
|
+
export function dagGraphParser(graph, tiers) {
|
|
40
|
+
const nodeTiersMap = new Map();
|
|
41
|
+
let nodesOrder = {};
|
|
42
|
+
// If there are tiers we need to add group and ord properties to the node for PlanarLayout algo to consider them
|
|
43
|
+
if (tiers) {
|
|
44
|
+
const nodeTiersArray = getTiersArray(tiers, graph);
|
|
45
|
+
if (!Array.isArray(tiers)) {
|
|
46
|
+
const { order_nodes_by } = tiers;
|
|
47
|
+
nodesOrder = order_nodes_by ? getNodeOrder(graph.nodes(), order_nodes_by, graph) : {};
|
|
48
|
+
}
|
|
49
|
+
nodeTiersArray.forEach((innerArray, index) => {
|
|
50
|
+
innerArray.forEach((node) => {
|
|
51
|
+
nodeTiersMap.set(node, { group: String(index), order: nodesOrder[node], rank: index });
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
}
|
|
39
55
|
const nodes = graph.mapNodes((id, attributes) => {
|
|
40
56
|
const parentIds = graph.inboundNeighbors(id);
|
|
41
|
-
|
|
57
|
+
let nodeGroup = 'latent';
|
|
58
|
+
let nodeOrder;
|
|
59
|
+
let nodeRank;
|
|
60
|
+
if (tiers) {
|
|
61
|
+
const nodeData = nodeTiersMap.get(id);
|
|
62
|
+
// in the case of e.g. a new node group etc may be undefined
|
|
63
|
+
nodeGroup = nodeData === null || nodeData === void 0 ? void 0 : nodeData.group;
|
|
64
|
+
nodeOrder = nodeData === null || nodeData === void 0 ? void 0 : nodeData.order;
|
|
65
|
+
nodeRank = nodeData === null || nodeData === void 0 ? void 0 : nodeData.rank;
|
|
66
|
+
}
|
|
67
|
+
return Object.assign(Object.assign({}, attributes), { group: nodeGroup, ord: nodeOrder, parentIds, rank: nodeRank });
|
|
42
68
|
});
|
|
43
|
-
|
|
69
|
+
const stratify = graphStratify();
|
|
70
|
+
return stratify(nodes);
|
|
44
71
|
}
|
|
45
72
|
/**
|
|
46
73
|
* Get graph edges in d3 expected format
|