@hpcc-js/graph 2.87.3 → 2.87.4

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 (60) hide show
  1. package/LICENSE +43 -43
  2. package/README.md +256 -256
  3. package/dist/index.es6.js +3 -3
  4. package/dist/index.es6.js.map +1 -1
  5. package/dist/index.js +3 -3
  6. package/dist/index.js.map +1 -1
  7. package/dist/index.min.js +1 -1
  8. package/dist/index.min.js.map +1 -1
  9. package/package.json +8 -8
  10. package/src/AdjacencyGraph.ts +224 -224
  11. package/src/Edge.css +23 -23
  12. package/src/Edge.ts +257 -257
  13. package/src/Graph.css +18 -18
  14. package/src/Graph.ts +1075 -1075
  15. package/src/GraphData.ts +187 -187
  16. package/src/GraphLayouts.ts +173 -173
  17. package/src/Sankey.css +46 -46
  18. package/src/Sankey.ts +291 -291
  19. package/src/Subgraph.css +10 -10
  20. package/src/Subgraph.ts +165 -165
  21. package/src/Vertex.css +3 -3
  22. package/src/Vertex.ts +282 -282
  23. package/src/__package__.ts +3 -3
  24. package/src/__tests__/data.ts +444 -444
  25. package/src/__tests__/index.ts +1 -1
  26. package/src/__tests__/test1.ts +18 -18
  27. package/src/__tests__/test2.ts +80 -80
  28. package/src/__tests__/test3.ts +46 -46
  29. package/src/__tests__/test4.ts +66 -66
  30. package/src/__tests__/test5.ts +85 -85
  31. package/src/graph2/dataGraph.ts +305 -305
  32. package/src/graph2/graph.css +34 -34
  33. package/src/graph2/graph.ts +135 -135
  34. package/src/graph2/graphReactT.ts +44 -44
  35. package/src/graph2/graphT.ts +1330 -1330
  36. package/src/graph2/index.ts +7 -7
  37. package/src/graph2/layouts/circle.ts +37 -37
  38. package/src/graph2/layouts/dagre.ts +132 -132
  39. package/src/graph2/layouts/dagreWorker.ts +35 -35
  40. package/src/graph2/layouts/forceDirected.ts +117 -117
  41. package/src/graph2/layouts/forceDirectedWorker.ts +30 -30
  42. package/src/graph2/layouts/geoForceDirected.ts +112 -112
  43. package/src/graph2/layouts/graphviz.ts +124 -124
  44. package/src/graph2/layouts/graphvizWorker.ts +71 -71
  45. package/src/graph2/layouts/index.ts +7 -7
  46. package/src/graph2/layouts/layout.ts +105 -105
  47. package/src/graph2/layouts/null.ts +35 -35
  48. package/src/graph2/layouts/placeholders.ts +103 -103
  49. package/src/graph2/layouts/tree.ts +328 -328
  50. package/src/graph2/liteMap.ts +72 -72
  51. package/src/graph2/liteSVGZooom.ts +61 -61
  52. package/src/graph2/sankeyGraph.css +45 -45
  53. package/src/graph2/sankeyGraph.ts +316 -316
  54. package/src/graph2/subgraph.tsx +30 -30
  55. package/src/graph2/vertex.tsx +31 -31
  56. package/src/index.ts +8 -8
  57. package/src/test.ts +649 -649
  58. package/types/__package__.d.ts +2 -2
  59. package/types/__package__.d.ts.map +1 -1
  60. package/types-3.4/__package__.d.ts +2 -2
@@ -1,33 +1,33 @@
1
- export interface Node {
2
- id: string;
3
- text: string;
4
- }
5
-
6
- export interface Link {
7
- id: string;
8
- source: Node;
9
- target: Node;
10
- }
11
-
12
- export interface Data {
13
- nodes: Node[];
14
- links: Link[];
15
- }
16
-
17
- export interface Options {
18
- alpha: number;
19
- alphaMin: number;
20
- alphaDecay: number;
21
- velocityDecay: number;
22
- repulsionStrength: number;
23
- linkDistance: number;
24
- linkStrength: number;
25
- iterations: number;
26
- pinCentroid: boolean;
27
- forceStrength: number;
28
- distanceMin: number;
29
- distanceMax: number;
30
- }
1
+ export interface Node {
2
+ id: string;
3
+ text: string;
4
+ }
5
+
6
+ export interface Link {
7
+ id: string;
8
+ source: Node;
9
+ target: Node;
10
+ }
11
+
12
+ export interface Data {
13
+ nodes: Node[];
14
+ links: Link[];
15
+ }
16
+
17
+ export interface Options {
18
+ alpha: number;
19
+ alphaMin: number;
20
+ alphaDecay: number;
21
+ velocityDecay: number;
22
+ repulsionStrength: number;
23
+ linkDistance: number;
24
+ linkStrength: number;
25
+ iterations: number;
26
+ pinCentroid: boolean;
27
+ forceStrength: number;
28
+ distanceMin: number;
29
+ distanceMax: number;
30
+ }
31
31
 
32
32
  export function forceDirected(data: Data, options: Options) {
33
33
  // eslint-disable-next-line quotes
@@ -1,112 +1,112 @@
1
- export const tmp = 42;
2
- /*
3
- import { forceLink as d3ForceLink, forceManyBody as d3ForceManyBody, forceSimulation as d3ForceSimulation } from "d3-force";
4
- import { Layout } from "./layout";
5
-
6
- export class GeoForceDirectedBase extends Layout {
7
-
8
- protected _links;
9
- protected _charge;
10
- protected _simulation;
11
-
12
- constructor(graph, readonly _options = defaultOptions) {
13
- super(graph);
14
- }
15
-
16
- start() {
17
- return super.start().then(() => {
18
- const data = this._graph.graphData();
19
- this._links = d3ForceLink(data.edges())
20
- .id(d => d.id)
21
- .distance(this._options.linkDistance)
22
- .strength(this._options.linkStrength)
23
- ;
24
- this._charge = d3ForceManyBody()
25
- .strength(d => this._options.charge * Math.max(d.width, d.height))
26
- ;
27
- this._simulation = d3ForceSimulation()
28
- .force("link", this._links)
29
- .force("charge", this._charge)
30
- .nodes(data.vertices().map(v => {
31
- // const { width, height } = v.widget.getBBox();
32
- // v["width"] = width;
33
- // v["height"] = height;
34
- return v;
35
- }))
36
- .stop()
37
- ;
38
-
39
- return this;
40
- });
41
- }
42
-
43
- stop() {
44
- this._simulation.stop();
45
- return super.stop();
46
- }
47
- }
48
-
49
- export class GeoForceDirected extends GeoForceDirectedBase {
50
-
51
- start() {
52
- return super.start().then(() => {
53
- const vertices = this._graph.graphData().vertices();
54
- vertices.forEach(vp => {
55
- if (vp.lat && vp.lng) {
56
- // const [x, y] = this._graph.project(vp.lat, vp.lng);
57
- // vp.fx = x;
58
- // vp.fy = y;
59
- }
60
- });
61
-
62
- this._simulation
63
- // .velocityDecay(0.1)
64
- .restart()
65
- ;
66
- let total = vertices.length;
67
- total = Math.min(total * total, 500);
68
- for (let i = 0; i < total; ++i) {
69
- this._simulation.tick();
70
- }
71
- this._simulation.stop();
72
- vertices.forEach(vp => {
73
- if (vp.lat && vp.lng) {
74
- delete vp.fx;
75
- delete vp.fy;
76
- }
77
- });
78
-
79
- this._graph
80
- .moveVertices(true)
81
- .moveEdges(true)
82
- ;
83
- this.stop();
84
-
85
- return this;
86
- });
87
- }
88
- }
89
-
90
- export class GeoForceDirectedAnimated extends GeoForceDirectedBase {
91
-
92
- start() {
93
- super.start();
94
- return new Promise<this>(resolve => {
95
- this._simulation
96
- .velocityDecay(this._options.velocityDecay)
97
- .on("tick", () => {
98
- this._graph
99
- .moveVertices(false)
100
- .moveEdges(false)
101
- ;
102
- })
103
- .on("end", () => {
104
- this._running = false;
105
- resolve(this);
106
- })
107
- .restart()
108
- ;
109
- });
110
- }
111
- }
112
- */
1
+ export const tmp = 42;
2
+ /*
3
+ import { forceLink as d3ForceLink, forceManyBody as d3ForceManyBody, forceSimulation as d3ForceSimulation } from "d3-force";
4
+ import { Layout } from "./layout";
5
+
6
+ export class GeoForceDirectedBase extends Layout {
7
+
8
+ protected _links;
9
+ protected _charge;
10
+ protected _simulation;
11
+
12
+ constructor(graph, readonly _options = defaultOptions) {
13
+ super(graph);
14
+ }
15
+
16
+ start() {
17
+ return super.start().then(() => {
18
+ const data = this._graph.graphData();
19
+ this._links = d3ForceLink(data.edges())
20
+ .id(d => d.id)
21
+ .distance(this._options.linkDistance)
22
+ .strength(this._options.linkStrength)
23
+ ;
24
+ this._charge = d3ForceManyBody()
25
+ .strength(d => this._options.charge * Math.max(d.width, d.height))
26
+ ;
27
+ this._simulation = d3ForceSimulation()
28
+ .force("link", this._links)
29
+ .force("charge", this._charge)
30
+ .nodes(data.vertices().map(v => {
31
+ // const { width, height } = v.widget.getBBox();
32
+ // v["width"] = width;
33
+ // v["height"] = height;
34
+ return v;
35
+ }))
36
+ .stop()
37
+ ;
38
+
39
+ return this;
40
+ });
41
+ }
42
+
43
+ stop() {
44
+ this._simulation.stop();
45
+ return super.stop();
46
+ }
47
+ }
48
+
49
+ export class GeoForceDirected extends GeoForceDirectedBase {
50
+
51
+ start() {
52
+ return super.start().then(() => {
53
+ const vertices = this._graph.graphData().vertices();
54
+ vertices.forEach(vp => {
55
+ if (vp.lat && vp.lng) {
56
+ // const [x, y] = this._graph.project(vp.lat, vp.lng);
57
+ // vp.fx = x;
58
+ // vp.fy = y;
59
+ }
60
+ });
61
+
62
+ this._simulation
63
+ // .velocityDecay(0.1)
64
+ .restart()
65
+ ;
66
+ let total = vertices.length;
67
+ total = Math.min(total * total, 500);
68
+ for (let i = 0; i < total; ++i) {
69
+ this._simulation.tick();
70
+ }
71
+ this._simulation.stop();
72
+ vertices.forEach(vp => {
73
+ if (vp.lat && vp.lng) {
74
+ delete vp.fx;
75
+ delete vp.fy;
76
+ }
77
+ });
78
+
79
+ this._graph
80
+ .moveVertices(true)
81
+ .moveEdges(true)
82
+ ;
83
+ this.stop();
84
+
85
+ return this;
86
+ });
87
+ }
88
+ }
89
+
90
+ export class GeoForceDirectedAnimated extends GeoForceDirectedBase {
91
+
92
+ start() {
93
+ super.start();
94
+ return new Promise<this>(resolve => {
95
+ this._simulation
96
+ .velocityDecay(this._options.velocityDecay)
97
+ .on("tick", () => {
98
+ this._graph
99
+ .moveVertices(false)
100
+ .moveEdges(false)
101
+ ;
102
+ })
103
+ .on("end", () => {
104
+ this._running = false;
105
+ resolve(this);
106
+ })
107
+ .restart()
108
+ ;
109
+ });
110
+ }
111
+ }
112
+ */
@@ -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
+