@hpcc-js/graph 3.6.5 → 3.6.6

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 (77) hide show
  1. package/LICENSE +43 -43
  2. package/README.md +256 -256
  3. package/dist/assets/dagre-B-z4SP0u.js.map +1 -1
  4. package/dist/assets/graphviz-DQ0E8zfY.js.map +1 -1
  5. package/dist/index.js +1 -1
  6. package/dist/index.js.map +1 -1
  7. package/dist/index.umd.cjs +1 -1
  8. package/dist/index.umd.cjs.map +1 -1
  9. package/package.json +6 -6
  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 +1077 -1077
  15. package/src/GraphData.ts +187 -187
  16. package/src/GraphLayouts.ts +214 -214
  17. package/src/Sankey.css +46 -46
  18. package/src/Sankey.ts +304 -304
  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/common/graphT.css +38 -38
  32. package/src/common/graphT.ts +1363 -1363
  33. package/src/common/index.ts +3 -3
  34. package/src/common/layouts/circle.ts +37 -37
  35. package/src/common/layouts/dagre.ts +145 -145
  36. package/src/common/layouts/dagreWorker.ts +24 -24
  37. package/src/common/layouts/forceDirected.ts +117 -117
  38. package/src/common/layouts/forceDirectedWorker.ts +22 -22
  39. package/src/common/layouts/geoForceDirected.ts +112 -112
  40. package/src/common/layouts/graphviz.ts +137 -137
  41. package/src/common/layouts/graphvizWorker.ts +27 -27
  42. package/src/common/layouts/index.ts +7 -7
  43. package/src/common/layouts/layout.ts +147 -147
  44. package/src/common/layouts/null.ts +39 -39
  45. package/src/common/layouts/placeholders.ts +113 -113
  46. package/src/common/layouts/tree.ts +326 -326
  47. package/src/common/layouts/workers/dagre.ts +46 -46
  48. package/src/common/layouts/workers/dagreOptions.ts +35 -35
  49. package/src/common/layouts/workers/forceDirected.ts +38 -38
  50. package/src/common/layouts/workers/forceDirectedOptions.ts +30 -30
  51. package/src/common/layouts/workers/graphviz.ts +225 -225
  52. package/src/common/layouts/workers/graphvizOptions.ts +70 -70
  53. package/src/common/liteMap.ts +72 -72
  54. package/src/common/liteSVGZooom.ts +61 -61
  55. package/src/common/sankeyGraph.css +45 -45
  56. package/src/common/sankeyGraph.ts +345 -345
  57. package/src/html/annotation.ts +71 -71
  58. package/src/html/component.ts +18 -18
  59. package/src/html/edge.ts +15 -15
  60. package/src/html/graphHtml.ts +11 -11
  61. package/src/html/graphHtmlT.ts +117 -117
  62. package/src/html/icon.ts +64 -64
  63. package/src/html/image.ts +26 -26
  64. package/src/html/imageChar.ts +18 -18
  65. package/src/html/index.ts +8 -8
  66. package/src/html/intersection.ts +110 -110
  67. package/src/html/shape.ts +141 -141
  68. package/src/html/text.ts +59 -59
  69. package/src/html/textBox.ts +45 -45
  70. package/src/html/vertex.ts +67 -67
  71. package/src/index.ts +10 -10
  72. package/src/react/dataGraph.ts +345 -345
  73. package/src/react/graphReact.ts +177 -177
  74. package/src/react/graphReactT.ts +44 -44
  75. package/src/react/index.ts +4 -4
  76. package/src/react/subgraph.tsx +30 -30
  77. package/src/react/vertex.tsx +31 -31
package/src/GraphData.ts CHANGED
@@ -1,187 +1,187 @@
1
- import { Edge as GLEdge, GraphEdge, graphlib, Node } from "dagre";
2
- import { Vertex } from "./Vertex.ts";
3
-
4
- type GLNode = Node<Vertex>;
5
-
6
- class GraphlibGraph extends graphlib.Graph<Vertex> {
7
- }
8
-
9
- interface GraphlibGraph {
10
- nodeEdges(outNodeName: string, inNodeName?: string): GLEdge[] | undefined;
11
- }
12
-
13
- export interface GraphLabel {
14
- debugTiming?: boolean;
15
- }
16
-
17
- export class GraphData {
18
-
19
- private _g: GraphlibGraph;
20
-
21
- constructor() {
22
- this._g = new GraphlibGraph({ multigraph: true, compound: true });
23
- this._g.setGraph({});
24
- this._g.setDefaultNodeLabel(function () { return { debug: "error" }; });
25
- this._g.setDefaultEdgeLabel(function () { return { debug: "error" }; });
26
- }
27
-
28
- parent(cn: string): string {
29
- return this._g.parent(cn);
30
- }
31
-
32
- private filterNodes(pred) {
33
- const filtered = [];
34
- this.eachNode(function (e) {
35
- if (pred(e)) {
36
- filtered.push(e);
37
- }
38
- });
39
- return filtered;
40
- }
41
-
42
- eachNode(callback) {
43
- this._g.nodes().forEach(item => {
44
- callback(item, this.node(item));
45
- });
46
- }
47
-
48
- private filterEdges(pred): GLEdge[] {
49
- const filtered = [];
50
- this.eachEdge(function (e) {
51
- if (pred(e)) {
52
- filtered.push(e);
53
- }
54
- });
55
- return filtered;
56
- }
57
-
58
- eachEdge(callback) {
59
- this._g.edges().forEach(item => {
60
- callback(item, item.v, item.w, this.edge(item));
61
- });
62
- }
63
-
64
- setData(subgraphs, vertices, edges, hierarchy, merge) {
65
- const retVal = {
66
- addedVertices: [],
67
- addedEdges: []
68
- };
69
-
70
- const allVertices = subgraphs.concat(vertices);
71
-
72
- // Add new items ---
73
- for (let i = 0; i < allVertices.length; ++i) {
74
- const entity = allVertices[i];
75
- if (!merge || !this._g.hasNode(entity._id)) {
76
- this._g.setNode(entity._id, entity);
77
- retVal.addedVertices.push(entity);
78
- }
79
- }
80
- for (let i = 0; i < edges.length; ++i) {
81
- const edge = edges[i];
82
- if (!merge || !this._g.hasEdge(edge._id)) {
83
- if (edge._sourceVertex && edge._targetVertex) {
84
- this._g.setEdge(edge._sourceVertex._id, edge._targetVertex._id, edge, edge._id);
85
- retVal.addedEdges.push(edge);
86
- } else {
87
- console.warn("Bad edge definition");
88
- }
89
- }
90
- }
91
- if (hierarchy) {
92
- for (let i = 0; i < hierarchy.length; ++i) {
93
- this._g.setParent(hierarchy[i].child._id, hierarchy[i].parent._id);
94
- }
95
- }
96
-
97
- // Remove old items ---
98
- if (merge) {
99
- const edgeIDs = edges.map(function (item) {
100
- return item._id;
101
- });
102
- this
103
- .filterEdges(item => edgeIDs.indexOf(item.name) < 0)
104
- .forEach(item => this._g.removeEdge(item.v, item.w))
105
- ;
106
-
107
- const vertexIDs = allVertices.map(function (item) {
108
- return item._id;
109
- });
110
- this
111
- .filterNodes(item => vertexIDs.indexOf(item) < 0)
112
- .forEach(item => this._g.removeNode(item))
113
- ;
114
- }
115
- return retVal;
116
- }
117
-
118
- node(id: string): GLNode {
119
- return this._g.node(id);
120
- }
121
-
122
- nodeCount(): number {
123
- return this._g.nodeCount();
124
- }
125
-
126
- nodes(): GLNode[] {
127
- return this._g.nodes().map(n => this._g.node(n));
128
- }
129
-
130
- nodeEdges(id: string): GLEdge[] {
131
- return this._g.nodeEdges(id);
132
- }
133
-
134
- edge(glEdge: GLEdge): GraphEdge {
135
- return this._g.edge(glEdge);
136
- }
137
-
138
- edges(): GraphEdge[] {
139
- return this._g.edges().map(e => this._g.edge(e));
140
- }
141
-
142
- neighbors(id: string) {
143
- return this._g.neighbors(id).map(n => this._g.node(n));
144
- }
145
-
146
- singleNeighbors(id: string) {
147
- return this._g.neighbors(id)
148
- .filter((n: any) => this._g.neighbors(n).length === 1)
149
- .map(item => this._g.node(item as any));
150
- }
151
-
152
- gatherShortestPath(pathObj, targetID) {
153
- const retVal = [];
154
- let walkID = targetID;
155
- let pathItem = pathObj[walkID];
156
- while (pathItem) {
157
- if (pathItem.distance < Infinity && pathItem.predecessor) {
158
- const anEdge = this._g.nodeEdges(walkID, pathItem.predecessor)[0];
159
- retVal.push(this._g.edge(anEdge as any));
160
- }
161
- walkID = pathItem.predecessor;
162
- pathItem = pathObj[walkID];
163
- }
164
- return retVal;
165
- }
166
-
167
- shortestPath(sourceID: string, targetID: string) {
168
- return this.gatherShortestPath(graphlib.alg.dijkstra(this._g, sourceID), targetID);
169
- }
170
-
171
- undirectedShortestPath(sourceID: string, targetID: string) {
172
- return this.gatherShortestPath(graphlib.alg.dijkstra(this._g, sourceID, null, v => this._g.nodeEdges(v) as any), targetID);
173
- }
174
-
175
- getJSON() {
176
- const graphObj = graphlib.json.write(this._g);
177
- return JSON.stringify(graphObj, function (key, value) {
178
- if (key === "value") {
179
- if (value._text && value._text._text) {
180
- return value._text._text;
181
- }
182
- return value._id;
183
- }
184
- return value;
185
- }, " ");
186
- }
187
- }
1
+ import { Edge as GLEdge, GraphEdge, graphlib, Node } from "dagre";
2
+ import { Vertex } from "./Vertex.ts";
3
+
4
+ type GLNode = Node<Vertex>;
5
+
6
+ class GraphlibGraph extends graphlib.Graph<Vertex> {
7
+ }
8
+
9
+ interface GraphlibGraph {
10
+ nodeEdges(outNodeName: string, inNodeName?: string): GLEdge[] | undefined;
11
+ }
12
+
13
+ export interface GraphLabel {
14
+ debugTiming?: boolean;
15
+ }
16
+
17
+ export class GraphData {
18
+
19
+ private _g: GraphlibGraph;
20
+
21
+ constructor() {
22
+ this._g = new GraphlibGraph({ multigraph: true, compound: true });
23
+ this._g.setGraph({});
24
+ this._g.setDefaultNodeLabel(function () { return { debug: "error" }; });
25
+ this._g.setDefaultEdgeLabel(function () { return { debug: "error" }; });
26
+ }
27
+
28
+ parent(cn: string): string {
29
+ return this._g.parent(cn);
30
+ }
31
+
32
+ private filterNodes(pred) {
33
+ const filtered = [];
34
+ this.eachNode(function (e) {
35
+ if (pred(e)) {
36
+ filtered.push(e);
37
+ }
38
+ });
39
+ return filtered;
40
+ }
41
+
42
+ eachNode(callback) {
43
+ this._g.nodes().forEach(item => {
44
+ callback(item, this.node(item));
45
+ });
46
+ }
47
+
48
+ private filterEdges(pred): GLEdge[] {
49
+ const filtered = [];
50
+ this.eachEdge(function (e) {
51
+ if (pred(e)) {
52
+ filtered.push(e);
53
+ }
54
+ });
55
+ return filtered;
56
+ }
57
+
58
+ eachEdge(callback) {
59
+ this._g.edges().forEach(item => {
60
+ callback(item, item.v, item.w, this.edge(item));
61
+ });
62
+ }
63
+
64
+ setData(subgraphs, vertices, edges, hierarchy, merge) {
65
+ const retVal = {
66
+ addedVertices: [],
67
+ addedEdges: []
68
+ };
69
+
70
+ const allVertices = subgraphs.concat(vertices);
71
+
72
+ // Add new items ---
73
+ for (let i = 0; i < allVertices.length; ++i) {
74
+ const entity = allVertices[i];
75
+ if (!merge || !this._g.hasNode(entity._id)) {
76
+ this._g.setNode(entity._id, entity);
77
+ retVal.addedVertices.push(entity);
78
+ }
79
+ }
80
+ for (let i = 0; i < edges.length; ++i) {
81
+ const edge = edges[i];
82
+ if (!merge || !this._g.hasEdge(edge._id)) {
83
+ if (edge._sourceVertex && edge._targetVertex) {
84
+ this._g.setEdge(edge._sourceVertex._id, edge._targetVertex._id, edge, edge._id);
85
+ retVal.addedEdges.push(edge);
86
+ } else {
87
+ console.warn("Bad edge definition");
88
+ }
89
+ }
90
+ }
91
+ if (hierarchy) {
92
+ for (let i = 0; i < hierarchy.length; ++i) {
93
+ this._g.setParent(hierarchy[i].child._id, hierarchy[i].parent._id);
94
+ }
95
+ }
96
+
97
+ // Remove old items ---
98
+ if (merge) {
99
+ const edgeIDs = edges.map(function (item) {
100
+ return item._id;
101
+ });
102
+ this
103
+ .filterEdges(item => edgeIDs.indexOf(item.name) < 0)
104
+ .forEach(item => this._g.removeEdge(item.v, item.w))
105
+ ;
106
+
107
+ const vertexIDs = allVertices.map(function (item) {
108
+ return item._id;
109
+ });
110
+ this
111
+ .filterNodes(item => vertexIDs.indexOf(item) < 0)
112
+ .forEach(item => this._g.removeNode(item))
113
+ ;
114
+ }
115
+ return retVal;
116
+ }
117
+
118
+ node(id: string): GLNode {
119
+ return this._g.node(id);
120
+ }
121
+
122
+ nodeCount(): number {
123
+ return this._g.nodeCount();
124
+ }
125
+
126
+ nodes(): GLNode[] {
127
+ return this._g.nodes().map(n => this._g.node(n));
128
+ }
129
+
130
+ nodeEdges(id: string): GLEdge[] {
131
+ return this._g.nodeEdges(id);
132
+ }
133
+
134
+ edge(glEdge: GLEdge): GraphEdge {
135
+ return this._g.edge(glEdge);
136
+ }
137
+
138
+ edges(): GraphEdge[] {
139
+ return this._g.edges().map(e => this._g.edge(e));
140
+ }
141
+
142
+ neighbors(id: string) {
143
+ return this._g.neighbors(id).map(n => this._g.node(n));
144
+ }
145
+
146
+ singleNeighbors(id: string) {
147
+ return this._g.neighbors(id)
148
+ .filter((n: any) => this._g.neighbors(n).length === 1)
149
+ .map(item => this._g.node(item as any));
150
+ }
151
+
152
+ gatherShortestPath(pathObj, targetID) {
153
+ const retVal = [];
154
+ let walkID = targetID;
155
+ let pathItem = pathObj[walkID];
156
+ while (pathItem) {
157
+ if (pathItem.distance < Infinity && pathItem.predecessor) {
158
+ const anEdge = this._g.nodeEdges(walkID, pathItem.predecessor)[0];
159
+ retVal.push(this._g.edge(anEdge as any));
160
+ }
161
+ walkID = pathItem.predecessor;
162
+ pathItem = pathObj[walkID];
163
+ }
164
+ return retVal;
165
+ }
166
+
167
+ shortestPath(sourceID: string, targetID: string) {
168
+ return this.gatherShortestPath(graphlib.alg.dijkstra(this._g, sourceID), targetID);
169
+ }
170
+
171
+ undirectedShortestPath(sourceID: string, targetID: string) {
172
+ return this.gatherShortestPath(graphlib.alg.dijkstra(this._g, sourceID, null, v => this._g.nodeEdges(v) as any), targetID);
173
+ }
174
+
175
+ getJSON() {
176
+ const graphObj = graphlib.json.write(this._g);
177
+ return JSON.stringify(graphObj, function (key, value) {
178
+ if (key === "value") {
179
+ if (value._text && value._text._text) {
180
+ return value._text._text;
181
+ }
182
+ return value._id;
183
+ }
184
+ return value;
185
+ }, " ");
186
+ }
187
+ }