@hpcc-js/graph 3.6.3 → 3.6.5

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-CjmNyQgU.js.map → graphviz-DQ0E8zfY.js.map} +1 -1
  5. package/dist/index.js +2 -2
  6. package/dist/index.js.map +1 -1
  7. package/dist/index.umd.cjs +2 -2
  8. package/dist/index.umd.cjs.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 +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
@@ -1,214 +1,214 @@
1
- import { forceCenter as d3ForceCenter, forceLink as d3ForceLink, forceManyBody as d3ForceManyBody, forceSimulation as d3ForceSimulation } from "d3-force";
2
- import { GraphLabel, graphlib, layout } from "dagre";
3
- import { GraphData } from "./GraphData.ts";
4
-
5
- interface Pos {
6
- x?: number;
7
- y?: number;
8
- width?: number;
9
- height?: number;
10
- }
11
-
12
- export class Circle {
13
-
14
- protected pos: { [id: string]: Pos } = {};
15
-
16
- constructor(graphData: GraphData, width?, height?, radius?) {
17
- const context = this;
18
- this.pos = {};
19
-
20
- // Initial Positions ---
21
- const padding = 0;
22
- radius = radius || (width < height ? width - padding : height - padding) / 2;
23
- const order = graphData.nodeCount();
24
- let currStep = -Math.PI / 2;
25
- const step = 2 * Math.PI / order;
26
- graphData.eachNode(function (u, value) {
27
- const size = value.getBBox();
28
- const maxSize = 0; // Math.max(size.width, size.height);
29
- context.pos[u] = {
30
- x: value.fixed ? value.x : width / 2 + Math.cos(currStep) * (radius - maxSize),
31
- y: value.fixed ? value.y : height / 2 + Math.sin(currStep) * (radius - maxSize),
32
- width: size.width,
33
- height: size.height
34
- };
35
- currStep += step;
36
- });
37
- }
38
-
39
- nodePos(u) {
40
- return this.pos[u];
41
- }
42
-
43
- edgePoints(_e) {
44
- return [];
45
- }
46
-
47
- }
48
-
49
- export class None {
50
-
51
- protected pos: { [id: string]: Pos } = {};
52
-
53
- constructor(graphData: GraphData, _width, _height, _radius) {
54
- const context = this;
55
- this.pos = {};
56
-
57
- graphData.eachNode(function (u, value) {
58
- context.pos[u] = {
59
- x: value.x,
60
- y: value.y,
61
- width: value.width,
62
- height: value.height
63
- };
64
- });
65
- }
66
-
67
- nodePos(u) {
68
- return this.pos[u];
69
- }
70
-
71
- edgePoints(_e) {
72
- return [];
73
- }
74
- }
75
-
76
- export class ForceDirected {
77
-
78
- protected pos: { [id: string]: Pos } = {};
79
- vertices: any[] = [];
80
- protected vertexMap: { [id: string]: any } = {};
81
- protected edges: any[] = [];
82
- protected force: any;
83
-
84
- constructor(graphData: GraphData, width, height, options) {
85
- options = options || {};
86
- this.pos = {};
87
- this.vertices = [];
88
- this.vertexMap = {};
89
-
90
- graphData.eachNode(u => {
91
- const vertex = graphData.node(u);
92
- const size = vertex.getBBox();
93
- const newItem = {
94
- id: u,
95
- x: vertex.pos().x,
96
- y: vertex.pos().y,
97
- width: size.width,
98
- height: size.height,
99
- value: vertex
100
- };
101
- this.vertices.push(newItem);
102
- this.vertexMap[u] = newItem;
103
- });
104
- this.edges = [];
105
- graphData.eachEdge((_e, s, t) => {
106
- this.edges.push({
107
- source: s,
108
- target: t
109
- });
110
- });
111
- const forceLink = d3ForceLink()
112
- .id(function (d: any) {
113
- return d.id;
114
- })
115
- .distance(options.linkDistance)
116
- .strength(options.linkStrength)
117
- ;
118
- const forceManyBody = d3ForceManyBody()
119
- .strength(function (d: any) {
120
- const cs = d.value.getBBox();
121
- return options.charge * Math.max(cs.width, cs.height);
122
- })
123
- ;
124
- this.force = d3ForceSimulation()
125
- .force("link", forceLink)
126
- .force("charge", forceManyBody)
127
- .force("center", d3ForceCenter(width / 2, height / 2))
128
- .velocityDecay(options.oneShot ? 0.1 : options.friction)
129
- .nodes(this.vertices)
130
- ;
131
- forceLink
132
- .links(this.edges)
133
- ;
134
-
135
- if (options.oneShot) {
136
- this.force.restart();
137
- let total = graphData.nodeCount();
138
- total = Math.min(total * total, 500);
139
- for (let i = 0; i < total; ++i) {
140
- this.force.tick();
141
- }
142
- this.force.stop();
143
- }
144
- }
145
-
146
- nodePos(u) {
147
- return this.vertexMap[u];
148
- }
149
-
150
- edgePoints(_e) {
151
- return [];
152
- }
153
- }
154
-
155
- export class Hierarchy {
156
-
157
- protected digraph: any;
158
- protected dagreLayout: any;
159
-
160
- constructor(graphData: GraphData, _width, _height, options) {
161
- this.digraph = new graphlib.Graph({ multigraph: true, compound: true })
162
- .setGraph(options)
163
- .setDefaultNodeLabel(function () { return {}; })
164
- .setDefaultEdgeLabel(function () { return {}; })
165
- ;
166
- graphData.eachNode(u => {
167
- const value = graphData.node(u);
168
- const clientSize = value.getBBox();
169
- this.digraph.setNode(u, {
170
- width: clientSize.width,
171
- height: clientSize.height
172
- });
173
- });
174
- graphData.eachEdge((e, s, t) => {
175
- const value = graphData.edge(e);
176
- this.digraph.setEdge(s, t, {
177
- weight: value.weight()
178
- }, value._id);
179
- if (!options.digraph) {
180
- this.digraph.setEdge(t, s, {
181
- weight: value.weight()
182
- }, value._id);
183
- }
184
- });
185
- graphData.eachNode(u => {
186
- this.digraph.setParent(u, graphData.parent(u));
187
- });
188
-
189
- this.dagreLayout = layout(this.digraph, { debugTiming: false } as GraphLabel);
190
- const deltaX = -this.digraph.graph().width / 2;
191
- const deltaY = -this.digraph.graph().height / 2;
192
- this.digraph.nodes().forEach(u => {
193
- const value = this.digraph.node(u);
194
- value.x += deltaX + _width / 2;
195
- value.y += deltaY + _height / 2;
196
- });
197
- this.digraph.edges().forEach(e => {
198
- const value = this.digraph.edge(e);
199
- for (let i = 0; i < value.points.length; ++i) {
200
- value.points[i].x += deltaX + _width / 2;
201
- value.points[i].y += deltaY + _height / 2;
202
- }
203
- });
204
- this.digraph = this.digraph;
205
- }
206
-
207
- nodePos(u) {
208
- return this.digraph.node(u);
209
- }
210
-
211
- edgePoints(edge) {
212
- return this.digraph.edge(edge._sourceVertex.id(), edge._targetVertex.id(), edge._id).points;
213
- }
214
- }
1
+ import { forceCenter as d3ForceCenter, forceLink as d3ForceLink, forceManyBody as d3ForceManyBody, forceSimulation as d3ForceSimulation } from "d3-force";
2
+ import { GraphLabel, graphlib, layout } from "dagre";
3
+ import { GraphData } from "./GraphData.ts";
4
+
5
+ interface Pos {
6
+ x?: number;
7
+ y?: number;
8
+ width?: number;
9
+ height?: number;
10
+ }
11
+
12
+ export class Circle {
13
+
14
+ protected pos: { [id: string]: Pos } = {};
15
+
16
+ constructor(graphData: GraphData, width?, height?, radius?) {
17
+ const context = this;
18
+ this.pos = {};
19
+
20
+ // Initial Positions ---
21
+ const padding = 0;
22
+ radius = radius || (width < height ? width - padding : height - padding) / 2;
23
+ const order = graphData.nodeCount();
24
+ let currStep = -Math.PI / 2;
25
+ const step = 2 * Math.PI / order;
26
+ graphData.eachNode(function (u, value) {
27
+ const size = value.getBBox();
28
+ const maxSize = 0; // Math.max(size.width, size.height);
29
+ context.pos[u] = {
30
+ x: value.fixed ? value.x : width / 2 + Math.cos(currStep) * (radius - maxSize),
31
+ y: value.fixed ? value.y : height / 2 + Math.sin(currStep) * (radius - maxSize),
32
+ width: size.width,
33
+ height: size.height
34
+ };
35
+ currStep += step;
36
+ });
37
+ }
38
+
39
+ nodePos(u) {
40
+ return this.pos[u];
41
+ }
42
+
43
+ edgePoints(_e) {
44
+ return [];
45
+ }
46
+
47
+ }
48
+
49
+ export class None {
50
+
51
+ protected pos: { [id: string]: Pos } = {};
52
+
53
+ constructor(graphData: GraphData, _width, _height, _radius) {
54
+ const context = this;
55
+ this.pos = {};
56
+
57
+ graphData.eachNode(function (u, value) {
58
+ context.pos[u] = {
59
+ x: value.x,
60
+ y: value.y,
61
+ width: value.width,
62
+ height: value.height
63
+ };
64
+ });
65
+ }
66
+
67
+ nodePos(u) {
68
+ return this.pos[u];
69
+ }
70
+
71
+ edgePoints(_e) {
72
+ return [];
73
+ }
74
+ }
75
+
76
+ export class ForceDirected {
77
+
78
+ protected pos: { [id: string]: Pos } = {};
79
+ vertices: any[] = [];
80
+ protected vertexMap: { [id: string]: any } = {};
81
+ protected edges: any[] = [];
82
+ protected force: any;
83
+
84
+ constructor(graphData: GraphData, width, height, options) {
85
+ options = options || {};
86
+ this.pos = {};
87
+ this.vertices = [];
88
+ this.vertexMap = {};
89
+
90
+ graphData.eachNode(u => {
91
+ const vertex = graphData.node(u);
92
+ const size = vertex.getBBox();
93
+ const newItem = {
94
+ id: u,
95
+ x: vertex.pos().x,
96
+ y: vertex.pos().y,
97
+ width: size.width,
98
+ height: size.height,
99
+ value: vertex
100
+ };
101
+ this.vertices.push(newItem);
102
+ this.vertexMap[u] = newItem;
103
+ });
104
+ this.edges = [];
105
+ graphData.eachEdge((_e, s, t) => {
106
+ this.edges.push({
107
+ source: s,
108
+ target: t
109
+ });
110
+ });
111
+ const forceLink = d3ForceLink()
112
+ .id(function (d: any) {
113
+ return d.id;
114
+ })
115
+ .distance(options.linkDistance)
116
+ .strength(options.linkStrength)
117
+ ;
118
+ const forceManyBody = d3ForceManyBody()
119
+ .strength(function (d: any) {
120
+ const cs = d.value.getBBox();
121
+ return options.charge * Math.max(cs.width, cs.height);
122
+ })
123
+ ;
124
+ this.force = d3ForceSimulation()
125
+ .force("link", forceLink)
126
+ .force("charge", forceManyBody)
127
+ .force("center", d3ForceCenter(width / 2, height / 2))
128
+ .velocityDecay(options.oneShot ? 0.1 : options.friction)
129
+ .nodes(this.vertices)
130
+ ;
131
+ forceLink
132
+ .links(this.edges)
133
+ ;
134
+
135
+ if (options.oneShot) {
136
+ this.force.restart();
137
+ let total = graphData.nodeCount();
138
+ total = Math.min(total * total, 500);
139
+ for (let i = 0; i < total; ++i) {
140
+ this.force.tick();
141
+ }
142
+ this.force.stop();
143
+ }
144
+ }
145
+
146
+ nodePos(u) {
147
+ return this.vertexMap[u];
148
+ }
149
+
150
+ edgePoints(_e) {
151
+ return [];
152
+ }
153
+ }
154
+
155
+ export class Hierarchy {
156
+
157
+ protected digraph: any;
158
+ protected dagreLayout: any;
159
+
160
+ constructor(graphData: GraphData, _width, _height, options) {
161
+ this.digraph = new graphlib.Graph({ multigraph: true, compound: true })
162
+ .setGraph(options)
163
+ .setDefaultNodeLabel(function () { return {}; })
164
+ .setDefaultEdgeLabel(function () { return {}; })
165
+ ;
166
+ graphData.eachNode(u => {
167
+ const value = graphData.node(u);
168
+ const clientSize = value.getBBox();
169
+ this.digraph.setNode(u, {
170
+ width: clientSize.width,
171
+ height: clientSize.height
172
+ });
173
+ });
174
+ graphData.eachEdge((e, s, t) => {
175
+ const value = graphData.edge(e);
176
+ this.digraph.setEdge(s, t, {
177
+ weight: value.weight()
178
+ }, value._id);
179
+ if (!options.digraph) {
180
+ this.digraph.setEdge(t, s, {
181
+ weight: value.weight()
182
+ }, value._id);
183
+ }
184
+ });
185
+ graphData.eachNode(u => {
186
+ this.digraph.setParent(u, graphData.parent(u));
187
+ });
188
+
189
+ this.dagreLayout = layout(this.digraph, { debugTiming: false } as GraphLabel);
190
+ const deltaX = -this.digraph.graph().width / 2;
191
+ const deltaY = -this.digraph.graph().height / 2;
192
+ this.digraph.nodes().forEach(u => {
193
+ const value = this.digraph.node(u);
194
+ value.x += deltaX + _width / 2;
195
+ value.y += deltaY + _height / 2;
196
+ });
197
+ this.digraph.edges().forEach(e => {
198
+ const value = this.digraph.edge(e);
199
+ for (let i = 0; i < value.points.length; ++i) {
200
+ value.points[i].x += deltaX + _width / 2;
201
+ value.points[i].y += deltaY + _height / 2;
202
+ }
203
+ });
204
+ this.digraph = this.digraph;
205
+ }
206
+
207
+ nodePos(u) {
208
+ return this.digraph.node(u);
209
+ }
210
+
211
+ edgePoints(edge) {
212
+ return this.digraph.edge(edge._sourceVertex.id(), edge._targetVertex.id(), edge._id).points;
213
+ }
214
+ }
package/src/Sankey.css CHANGED
@@ -1,46 +1,46 @@
1
- .graph_Sankey .node rect {
2
- cursor: move;
3
- fill-opacity: .9;
4
- shape-rendering: crispEdges;
5
- stroke: darkgray;
6
- }
7
-
8
- .graph_Sankey .node.selected rect {
9
- stroke: red;
10
- }
11
-
12
- .graph_Sankey .node.over rect {
13
- stroke: orange;
14
- }
15
-
16
- .graph_Sankey .node.selected.over rect {
17
- stroke: red;
18
- }
19
-
20
- .graph_Sankey .node text {
21
- pointer-events: none;
22
- text-shadow: 0 1px 0 #fff;
23
- }
24
-
25
- .graph_Sankey .node.selected text {
26
- fill: red;
27
- }
28
-
29
- .graph_Sankey .node.over text {
30
- fill: orange;
31
- }
32
-
33
- .graph_Sankey .node.selected.over text {
34
- fill: red;
35
- }
36
-
37
- .graph_Sankey .link {
38
- fill: none;
39
- stroke: #000;
40
- stroke-opacity: .2;
41
- }
42
-
43
- .graph_Sankey .link:hover {
44
- stroke-opacity: .5;
45
- }
46
-
1
+ .graph_Sankey .node rect {
2
+ cursor: move;
3
+ fill-opacity: .9;
4
+ shape-rendering: crispEdges;
5
+ stroke: darkgray;
6
+ }
7
+
8
+ .graph_Sankey .node.selected rect {
9
+ stroke: red;
10
+ }
11
+
12
+ .graph_Sankey .node.over rect {
13
+ stroke: orange;
14
+ }
15
+
16
+ .graph_Sankey .node.selected.over rect {
17
+ stroke: red;
18
+ }
19
+
20
+ .graph_Sankey .node text {
21
+ pointer-events: none;
22
+ text-shadow: 0 1px 0 #fff;
23
+ }
24
+
25
+ .graph_Sankey .node.selected text {
26
+ fill: red;
27
+ }
28
+
29
+ .graph_Sankey .node.over text {
30
+ fill: orange;
31
+ }
32
+
33
+ .graph_Sankey .node.selected.over text {
34
+ fill: red;
35
+ }
36
+
37
+ .graph_Sankey .link {
38
+ fill: none;
39
+ stroke: #000;
40
+ stroke-opacity: .2;
41
+ }
42
+
43
+ .graph_Sankey .link:hover {
44
+ stroke-opacity: .5;
45
+ }
46
+