@hpcc-js/graph 2.87.1 → 2.87.3
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/LICENSE +43 -43
- package/README.md +256 -256
- package/dist/index.es6.js +11 -11
- package/dist/index.es6.js.map +1 -1
- package/dist/index.js +11 -11
- package/dist/index.js.map +1 -1
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +1 -1
- package/package.json +9 -9
- package/src/AdjacencyGraph.ts +224 -224
- package/src/Edge.css +23 -23
- package/src/Edge.ts +257 -257
- package/src/Graph.css +18 -18
- package/src/Graph.ts +1075 -1075
- package/src/GraphData.ts +187 -187
- package/src/GraphLayouts.ts +173 -173
- package/src/Sankey.css +46 -46
- package/src/Sankey.ts +291 -291
- package/src/Subgraph.css +10 -10
- package/src/Subgraph.ts +165 -165
- package/src/Vertex.css +3 -3
- package/src/Vertex.ts +282 -282
- package/src/__package__.ts +3 -3
- package/src/__tests__/data.ts +444 -444
- package/src/__tests__/index.ts +1 -1
- package/src/__tests__/test1.ts +18 -18
- package/src/__tests__/test2.ts +80 -80
- package/src/__tests__/test3.ts +46 -46
- package/src/__tests__/test4.ts +66 -66
- package/src/__tests__/test5.ts +85 -85
- package/src/graph2/dataGraph.ts +305 -305
- package/src/graph2/graph.css +34 -34
- package/src/graph2/graph.ts +135 -135
- package/src/graph2/graphReactT.ts +44 -44
- package/src/graph2/graphT.ts +1330 -1330
- package/src/graph2/index.ts +7 -7
- package/src/graph2/layouts/circle.ts +37 -37
- package/src/graph2/layouts/dagre.ts +132 -132
- package/src/graph2/layouts/dagreWorker.ts +36 -36
- package/src/graph2/layouts/forceDirected.ts +117 -117
- package/src/graph2/layouts/forceDirectedWorker.ts +32 -32
- package/src/graph2/layouts/geoForceDirected.ts +112 -112
- package/src/graph2/layouts/graphviz.ts +124 -124
- package/src/graph2/layouts/graphvizWorker.ts +71 -71
- package/src/graph2/layouts/index.ts +7 -7
- package/src/graph2/layouts/layout.ts +105 -105
- package/src/graph2/layouts/null.ts +35 -35
- package/src/graph2/layouts/placeholders.ts +103 -103
- package/src/graph2/layouts/tree.ts +328 -328
- package/src/graph2/liteMap.ts +72 -72
- package/src/graph2/liteSVGZooom.ts +61 -61
- package/src/graph2/sankeyGraph.css +45 -45
- package/src/graph2/sankeyGraph.ts +316 -316
- package/src/graph2/subgraph.tsx +30 -30
- package/src/graph2/vertex.tsx +31 -31
- package/src/index.ts +8 -8
- package/src/test.ts +649 -649
- package/types/__package__.d.ts +2 -2
- package/types-3.4/__package__.d.ts +2 -2
|
@@ -1,124 +1,124 @@
|
|
|
1
|
-
import { curveBasis as d3CurveBasis, line as d3Line } from "d3-shape";
|
|
2
|
-
import { Cluster, graphviz as gvWorker, Node, isLayoutSuccess, LayoutError } from "./graphvizWorker";
|
|
3
|
-
import { Layout, Point } from "./layout";
|
|
4
|
-
import { EdgePlaceholder } from "./placeholders";
|
|
5
|
-
|
|
6
|
-
type Engine = "circo" | "dot" | "fdp" | "neato" | "osage" | "patchwork" | "twopi";
|
|
7
|
-
|
|
8
|
-
const lineBasis = d3Line<Point>()
|
|
9
|
-
.x(d => d[0])
|
|
10
|
-
.y(d => d[1])
|
|
11
|
-
.curve(d3CurveBasis)
|
|
12
|
-
;
|
|
13
|
-
|
|
14
|
-
export class Graphviz extends Layout {
|
|
15
|
-
|
|
16
|
-
_engine: Engine;
|
|
17
|
-
_wasmFolder: string;
|
|
18
|
-
|
|
19
|
-
constructor(graph, engine: Engine, wasmFolder: string) {
|
|
20
|
-
super(graph);
|
|
21
|
-
this._engine = engine;
|
|
22
|
-
this._wasmFolder = wasmFolder;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
start() {
|
|
26
|
-
super.start();
|
|
27
|
-
const size = this._graph.size();
|
|
28
|
-
const data = this._graph.graphData();
|
|
29
|
-
const nodeIdx = {};
|
|
30
|
-
const hierarchy: Array<Cluster | Node> = data.hierarchy((type, item, children) => {
|
|
31
|
-
switch (type) {
|
|
32
|
-
case "subgraph":
|
|
33
|
-
return {
|
|
34
|
-
id: item.id,
|
|
35
|
-
text: item.props.text,
|
|
36
|
-
children
|
|
37
|
-
};
|
|
38
|
-
case "vertex":
|
|
39
|
-
delete item["fx"];
|
|
40
|
-
delete item["fy"];
|
|
41
|
-
const bbox = item.element.node().getBBox();
|
|
42
|
-
const retVal = {
|
|
43
|
-
id: item.id,
|
|
44
|
-
text: item.props.text,
|
|
45
|
-
width: bbox.width,
|
|
46
|
-
height: bbox.height
|
|
47
|
-
};
|
|
48
|
-
nodeIdx[retVal.id] = retVal;
|
|
49
|
-
return retVal;
|
|
50
|
-
}
|
|
51
|
-
}) as Array<Cluster | Node>;
|
|
52
|
-
return gvWorker({
|
|
53
|
-
items: hierarchy,
|
|
54
|
-
links: data.allEdges().map(e => ({
|
|
55
|
-
id: String(e.props.id),
|
|
56
|
-
source: nodeIdx[e.source.id],
|
|
57
|
-
target: nodeIdx[e.target.id],
|
|
58
|
-
text: e.props.label || ""
|
|
59
|
-
})),
|
|
60
|
-
raw: ""
|
|
61
|
-
}, {
|
|
62
|
-
engine: this._engine
|
|
63
|
-
}).response.then(response => {
|
|
64
|
-
if (this.running()) {
|
|
65
|
-
if (isLayoutSuccess(response)) {
|
|
66
|
-
response.clusters.forEach(n => {
|
|
67
|
-
const sg = data.subgraph(n.id);
|
|
68
|
-
sg.x = n.x + size.width / 2 - n.width;
|
|
69
|
-
sg.y = n.y + size.height / 2 - n.height;
|
|
70
|
-
sg.props.width = n.width;
|
|
71
|
-
sg.props.height = n.height;
|
|
72
|
-
});
|
|
73
|
-
response.nodes.forEach(n => {
|
|
74
|
-
const v = data.vertex(n.id);
|
|
75
|
-
v.x = n.x + size.width / 2;
|
|
76
|
-
v.y = n.y + size.height / 2;
|
|
77
|
-
});
|
|
78
|
-
response.links.forEach(l => {
|
|
79
|
-
const e = data.edge(l.id);
|
|
80
|
-
const start: [number, number] = [e.source.x, e.source.y];
|
|
81
|
-
const mid: [number, number][] = l.points !== undefined ? l.points.map(p => [p[0] + size.width / 2, p[1] + size.height / 2]) : [];
|
|
82
|
-
const end: [number, number] = [e.target.x, e.target.y];
|
|
83
|
-
e.points = [start, ...mid, end];
|
|
84
|
-
// e.points = l.points.map(p => [p[0] + size.width / 2, p[1] + size.height / 2]);
|
|
85
|
-
});
|
|
86
|
-
this._graph
|
|
87
|
-
.moveSubgraphs(true)
|
|
88
|
-
.moveVertices(true)
|
|
89
|
-
.moveEdges(true)
|
|
90
|
-
;
|
|
91
|
-
this.stop();
|
|
92
|
-
} else {
|
|
93
|
-
const err = response as LayoutError;
|
|
94
|
-
console.error(`Graphviz layout fail: ${err.error}`, err.errorDot);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
return this;
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
edgePath(ep: EdgePlaceholder, curveDepth: number): { path: string, labelPos: Point } {
|
|
102
|
-
let points = [];
|
|
103
|
-
let hasNaN = false;
|
|
104
|
-
if (ep.points) {
|
|
105
|
-
points = ep.points.map(p => {
|
|
106
|
-
const x = this._graph.project(p[0], false);
|
|
107
|
-
const y = this._graph.project(p[1], false);
|
|
108
|
-
if (isNaN(x) || isNaN(y)) {
|
|
109
|
-
hasNaN = true;
|
|
110
|
-
}
|
|
111
|
-
return [x, y];
|
|
112
|
-
});
|
|
113
|
-
}
|
|
114
|
-
if (hasNaN || points.length < 2) {
|
|
115
|
-
return super.edgePath(ep, curveDepth);
|
|
116
|
-
}
|
|
117
|
-
return {
|
|
118
|
-
path: lineBasis(points),
|
|
119
|
-
labelPos: this.center(points)
|
|
120
|
-
};
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
}
|
|
124
|
-
|
|
1
|
+
import { curveBasis as d3CurveBasis, line as d3Line } from "d3-shape";
|
|
2
|
+
import { Cluster, graphviz as gvWorker, Node, isLayoutSuccess, LayoutError } from "./graphvizWorker";
|
|
3
|
+
import { Layout, Point } from "./layout";
|
|
4
|
+
import { EdgePlaceholder } from "./placeholders";
|
|
5
|
+
|
|
6
|
+
type Engine = "circo" | "dot" | "fdp" | "neato" | "osage" | "patchwork" | "twopi";
|
|
7
|
+
|
|
8
|
+
const lineBasis = d3Line<Point>()
|
|
9
|
+
.x(d => d[0])
|
|
10
|
+
.y(d => d[1])
|
|
11
|
+
.curve(d3CurveBasis)
|
|
12
|
+
;
|
|
13
|
+
|
|
14
|
+
export class Graphviz extends Layout {
|
|
15
|
+
|
|
16
|
+
_engine: Engine;
|
|
17
|
+
_wasmFolder: string;
|
|
18
|
+
|
|
19
|
+
constructor(graph, engine: Engine, wasmFolder: string) {
|
|
20
|
+
super(graph);
|
|
21
|
+
this._engine = engine;
|
|
22
|
+
this._wasmFolder = wasmFolder;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
start() {
|
|
26
|
+
super.start();
|
|
27
|
+
const size = this._graph.size();
|
|
28
|
+
const data = this._graph.graphData();
|
|
29
|
+
const nodeIdx = {};
|
|
30
|
+
const hierarchy: Array<Cluster | Node> = data.hierarchy((type, item, children) => {
|
|
31
|
+
switch (type) {
|
|
32
|
+
case "subgraph":
|
|
33
|
+
return {
|
|
34
|
+
id: item.id,
|
|
35
|
+
text: item.props.text,
|
|
36
|
+
children
|
|
37
|
+
};
|
|
38
|
+
case "vertex":
|
|
39
|
+
delete item["fx"];
|
|
40
|
+
delete item["fy"];
|
|
41
|
+
const bbox = item.element.node().getBBox();
|
|
42
|
+
const retVal = {
|
|
43
|
+
id: item.id,
|
|
44
|
+
text: item.props.text,
|
|
45
|
+
width: bbox.width,
|
|
46
|
+
height: bbox.height
|
|
47
|
+
};
|
|
48
|
+
nodeIdx[retVal.id] = retVal;
|
|
49
|
+
return retVal;
|
|
50
|
+
}
|
|
51
|
+
}) as Array<Cluster | Node>;
|
|
52
|
+
return gvWorker({
|
|
53
|
+
items: hierarchy,
|
|
54
|
+
links: data.allEdges().map(e => ({
|
|
55
|
+
id: String(e.props.id),
|
|
56
|
+
source: nodeIdx[e.source.id],
|
|
57
|
+
target: nodeIdx[e.target.id],
|
|
58
|
+
text: e.props.label || ""
|
|
59
|
+
})),
|
|
60
|
+
raw: ""
|
|
61
|
+
}, {
|
|
62
|
+
engine: this._engine
|
|
63
|
+
}).response.then(response => {
|
|
64
|
+
if (this.running()) {
|
|
65
|
+
if (isLayoutSuccess(response)) {
|
|
66
|
+
response.clusters.forEach(n => {
|
|
67
|
+
const sg = data.subgraph(n.id);
|
|
68
|
+
sg.x = n.x + size.width / 2 - n.width;
|
|
69
|
+
sg.y = n.y + size.height / 2 - n.height;
|
|
70
|
+
sg.props.width = n.width;
|
|
71
|
+
sg.props.height = n.height;
|
|
72
|
+
});
|
|
73
|
+
response.nodes.forEach(n => {
|
|
74
|
+
const v = data.vertex(n.id);
|
|
75
|
+
v.x = n.x + size.width / 2;
|
|
76
|
+
v.y = n.y + size.height / 2;
|
|
77
|
+
});
|
|
78
|
+
response.links.forEach(l => {
|
|
79
|
+
const e = data.edge(l.id);
|
|
80
|
+
const start: [number, number] = [e.source.x, e.source.y];
|
|
81
|
+
const mid: [number, number][] = l.points !== undefined ? l.points.map(p => [p[0] + size.width / 2, p[1] + size.height / 2]) : [];
|
|
82
|
+
const end: [number, number] = [e.target.x, e.target.y];
|
|
83
|
+
e.points = [start, ...mid, end];
|
|
84
|
+
// e.points = l.points.map(p => [p[0] + size.width / 2, p[1] + size.height / 2]);
|
|
85
|
+
});
|
|
86
|
+
this._graph
|
|
87
|
+
.moveSubgraphs(true)
|
|
88
|
+
.moveVertices(true)
|
|
89
|
+
.moveEdges(true)
|
|
90
|
+
;
|
|
91
|
+
this.stop();
|
|
92
|
+
} else {
|
|
93
|
+
const err = response as LayoutError;
|
|
94
|
+
console.error(`Graphviz layout fail: ${err.error}`, err.errorDot);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return this;
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
edgePath(ep: EdgePlaceholder, curveDepth: number): { path: string, labelPos: Point } {
|
|
102
|
+
let points = [];
|
|
103
|
+
let hasNaN = false;
|
|
104
|
+
if (ep.points) {
|
|
105
|
+
points = ep.points.map(p => {
|
|
106
|
+
const x = this._graph.project(p[0], false);
|
|
107
|
+
const y = this._graph.project(p[1], false);
|
|
108
|
+
if (isNaN(x) || isNaN(y)) {
|
|
109
|
+
hasNaN = true;
|
|
110
|
+
}
|
|
111
|
+
return [x, y];
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
if (hasNaN || points.length < 2) {
|
|
115
|
+
return super.edgePath(ep, curveDepth);
|
|
116
|
+
}
|
|
117
|
+
return {
|
|
118
|
+
path: lineBasis(points),
|
|
119
|
+
labelPos: this.center(points)
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
}
|
|
124
|
+
|