@hpcc-js/graph 2.87.2 → 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.
Files changed (57) hide show
  1. package/LICENSE +43 -43
  2. package/README.md +256 -256
  3. package/dist/index.es6.js +7 -7
  4. package/dist/index.es6.js.map +1 -1
  5. package/dist/index.js +7 -7
  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
@@ -1,173 +1,173 @@
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";
4
-
5
- export function Circle(graphData: GraphData, width?, height?, radius?) {
6
- const context = this;
7
- this.pos = {};
8
-
9
- // Initial Positions ---
10
- const padding = 0;
11
- radius = radius || (width < height ? width - padding : height - padding) / 2;
12
- const order = graphData.nodeCount();
13
- let currStep = -Math.PI / 2;
14
- const step = 2 * Math.PI / order;
15
- graphData.eachNode(function (u, value) {
16
- const size = value.getBBox();
17
- const maxSize = 0; // Math.max(size.width, size.height);
18
- context.pos[u] = {
19
- x: value.fixed ? value.x : width / 2 + Math.cos(currStep) * (radius - maxSize),
20
- y: value.fixed ? value.y : height / 2 + Math.sin(currStep) * (radius - maxSize),
21
- width: size.width,
22
- height: size.height
23
- };
24
- currStep += step;
25
- });
26
- }
27
- Circle.prototype.nodePos = function (u) {
28
- return this.pos[u];
29
- };
30
- Circle.prototype.edgePoints = function (_e) {
31
- return [];
32
- };
33
-
34
- export function None(graphData: GraphData, _width, _height, _radius) {
35
- const context = this;
36
- this.pos = {};
37
-
38
- graphData.eachNode(function (u, value) {
39
- context.pos[u] = {
40
- x: value.x,
41
- y: value.y,
42
- width: value.width,
43
- height: value.height
44
- };
45
- });
46
- }
47
- None.prototype.nodePos = function (u) {
48
- return this.pos[u];
49
- };
50
- None.prototype.edgePoints = function (_e) {
51
- return [];
52
- };
53
-
54
- export function ForceDirected(graphData: GraphData, width, height, options) {
55
- options = options || {};
56
- const context = this;
57
- this.pos = {};
58
-
59
- this.vertices = [];
60
- this.vertexMap = {};
61
- graphData.eachNode(function (u) {
62
- const vertex = graphData.node(u);
63
- const size = vertex.getBBox();
64
- const newItem = {
65
- id: u,
66
- x: vertex.pos().x,
67
- y: vertex.pos().y,
68
- width: size.width,
69
- height: size.height,
70
- value: vertex
71
- };
72
- context.vertices.push(newItem);
73
- context.vertexMap[u] = newItem;
74
- });
75
- this.edges = [];
76
- graphData.eachEdge(function (_e, s, t) {
77
- context.edges.push({
78
- source: s,
79
- target: t
80
- });
81
- });
82
- const forceLink = d3ForceLink()
83
- .id(function (d: any) {
84
- return d.id;
85
- })
86
- .distance(options.linkDistance)
87
- .strength(options.linkStrength)
88
- ;
89
- const forceManyBody = d3ForceManyBody()
90
- .strength(function (d: any) {
91
- const cs = d.value.getBBox();
92
- return options.charge * Math.max(cs.width, cs.height);
93
- })
94
- ;
95
- this.force = d3ForceSimulation()
96
- .force("link", forceLink)
97
- .force("charge", forceManyBody)
98
- .force("center", d3ForceCenter(width / 2, height / 2))
99
- .velocityDecay(options.oneShot ? 0.1 : options.friction)
100
- .nodes(this.vertices)
101
- ;
102
- forceLink
103
- .links(this.edges)
104
- ;
105
-
106
- if (options.oneShot) {
107
- this.force.restart();
108
- let total = graphData.nodeCount();
109
- total = Math.min(total * total, 500);
110
- for (let i = 0; i < total; ++i) {
111
- this.force.tick();
112
- }
113
- this.force.stop();
114
- }
115
- }
116
- ForceDirected.prototype.nodePos = function (u) {
117
- return this.vertexMap[u];
118
- };
119
- ForceDirected.prototype.edgePoints = function (_e) {
120
- return [];
121
- };
122
-
123
- export function Hierarchy(graphData: GraphData, _width, _height, options) {
124
- const digraph = new graphlib.Graph({ multigraph: true, compound: true })
125
- .setGraph(options)
126
- .setDefaultNodeLabel(function () { return {}; })
127
- .setDefaultEdgeLabel(function () { return {}; })
128
- ;
129
- graphData.eachNode(function (u) {
130
- const value = graphData.node(u);
131
- const clientSize = value.getBBox();
132
- digraph.setNode(u, {
133
- width: clientSize.width,
134
- height: clientSize.height
135
- });
136
- });
137
- graphData.eachEdge(function (e, s, t) {
138
- const value = graphData.edge(e);
139
- digraph.setEdge(s, t, {
140
- weight: value.weight()
141
- }, value._id);
142
- if (!options.digraph) {
143
- digraph.setEdge(t, s, {
144
- weight: value.weight()
145
- }, value._id);
146
- }
147
- });
148
- graphData.eachNode(function (u) {
149
- digraph.setParent(u, graphData.parent(u));
150
- });
151
- this.dagreLayout = layout(digraph, { debugTiming: false } as GraphLabel);
152
- const deltaX = -digraph.graph().width / 2;
153
- const deltaY = -digraph.graph().height / 2;
154
- digraph.nodes().forEach(function (u) {
155
- const value = digraph.node(u);
156
- value.x += deltaX + _width / 2;
157
- value.y += deltaY + _height / 2;
158
- });
159
- digraph.edges().forEach(function (e) {
160
- const value = digraph.edge(e);
161
- for (let i = 0; i < value.points.length; ++i) {
162
- value.points[i].x += deltaX + _width / 2;
163
- value.points[i].y += deltaY + _height / 2;
164
- }
165
- });
166
- this.digraph = digraph;
167
- }
168
- Hierarchy.prototype.nodePos = function (u) {
169
- return this.digraph.node(u);
170
- };
171
- Hierarchy.prototype.edgePoints = function (edge) {
172
- return this.digraph.edge(edge._sourceVertex.id(), edge._targetVertex.id(), edge._id).points;
173
- };
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";
4
+
5
+ export function Circle(graphData: GraphData, width?, height?, radius?) {
6
+ const context = this;
7
+ this.pos = {};
8
+
9
+ // Initial Positions ---
10
+ const padding = 0;
11
+ radius = radius || (width < height ? width - padding : height - padding) / 2;
12
+ const order = graphData.nodeCount();
13
+ let currStep = -Math.PI / 2;
14
+ const step = 2 * Math.PI / order;
15
+ graphData.eachNode(function (u, value) {
16
+ const size = value.getBBox();
17
+ const maxSize = 0; // Math.max(size.width, size.height);
18
+ context.pos[u] = {
19
+ x: value.fixed ? value.x : width / 2 + Math.cos(currStep) * (radius - maxSize),
20
+ y: value.fixed ? value.y : height / 2 + Math.sin(currStep) * (radius - maxSize),
21
+ width: size.width,
22
+ height: size.height
23
+ };
24
+ currStep += step;
25
+ });
26
+ }
27
+ Circle.prototype.nodePos = function (u) {
28
+ return this.pos[u];
29
+ };
30
+ Circle.prototype.edgePoints = function (_e) {
31
+ return [];
32
+ };
33
+
34
+ export function None(graphData: GraphData, _width, _height, _radius) {
35
+ const context = this;
36
+ this.pos = {};
37
+
38
+ graphData.eachNode(function (u, value) {
39
+ context.pos[u] = {
40
+ x: value.x,
41
+ y: value.y,
42
+ width: value.width,
43
+ height: value.height
44
+ };
45
+ });
46
+ }
47
+ None.prototype.nodePos = function (u) {
48
+ return this.pos[u];
49
+ };
50
+ None.prototype.edgePoints = function (_e) {
51
+ return [];
52
+ };
53
+
54
+ export function ForceDirected(graphData: GraphData, width, height, options) {
55
+ options = options || {};
56
+ const context = this;
57
+ this.pos = {};
58
+
59
+ this.vertices = [];
60
+ this.vertexMap = {};
61
+ graphData.eachNode(function (u) {
62
+ const vertex = graphData.node(u);
63
+ const size = vertex.getBBox();
64
+ const newItem = {
65
+ id: u,
66
+ x: vertex.pos().x,
67
+ y: vertex.pos().y,
68
+ width: size.width,
69
+ height: size.height,
70
+ value: vertex
71
+ };
72
+ context.vertices.push(newItem);
73
+ context.vertexMap[u] = newItem;
74
+ });
75
+ this.edges = [];
76
+ graphData.eachEdge(function (_e, s, t) {
77
+ context.edges.push({
78
+ source: s,
79
+ target: t
80
+ });
81
+ });
82
+ const forceLink = d3ForceLink()
83
+ .id(function (d: any) {
84
+ return d.id;
85
+ })
86
+ .distance(options.linkDistance)
87
+ .strength(options.linkStrength)
88
+ ;
89
+ const forceManyBody = d3ForceManyBody()
90
+ .strength(function (d: any) {
91
+ const cs = d.value.getBBox();
92
+ return options.charge * Math.max(cs.width, cs.height);
93
+ })
94
+ ;
95
+ this.force = d3ForceSimulation()
96
+ .force("link", forceLink)
97
+ .force("charge", forceManyBody)
98
+ .force("center", d3ForceCenter(width / 2, height / 2))
99
+ .velocityDecay(options.oneShot ? 0.1 : options.friction)
100
+ .nodes(this.vertices)
101
+ ;
102
+ forceLink
103
+ .links(this.edges)
104
+ ;
105
+
106
+ if (options.oneShot) {
107
+ this.force.restart();
108
+ let total = graphData.nodeCount();
109
+ total = Math.min(total * total, 500);
110
+ for (let i = 0; i < total; ++i) {
111
+ this.force.tick();
112
+ }
113
+ this.force.stop();
114
+ }
115
+ }
116
+ ForceDirected.prototype.nodePos = function (u) {
117
+ return this.vertexMap[u];
118
+ };
119
+ ForceDirected.prototype.edgePoints = function (_e) {
120
+ return [];
121
+ };
122
+
123
+ export function Hierarchy(graphData: GraphData, _width, _height, options) {
124
+ const digraph = new graphlib.Graph({ multigraph: true, compound: true })
125
+ .setGraph(options)
126
+ .setDefaultNodeLabel(function () { return {}; })
127
+ .setDefaultEdgeLabel(function () { return {}; })
128
+ ;
129
+ graphData.eachNode(function (u) {
130
+ const value = graphData.node(u);
131
+ const clientSize = value.getBBox();
132
+ digraph.setNode(u, {
133
+ width: clientSize.width,
134
+ height: clientSize.height
135
+ });
136
+ });
137
+ graphData.eachEdge(function (e, s, t) {
138
+ const value = graphData.edge(e);
139
+ digraph.setEdge(s, t, {
140
+ weight: value.weight()
141
+ }, value._id);
142
+ if (!options.digraph) {
143
+ digraph.setEdge(t, s, {
144
+ weight: value.weight()
145
+ }, value._id);
146
+ }
147
+ });
148
+ graphData.eachNode(function (u) {
149
+ digraph.setParent(u, graphData.parent(u));
150
+ });
151
+ this.dagreLayout = layout(digraph, { debugTiming: false } as GraphLabel);
152
+ const deltaX = -digraph.graph().width / 2;
153
+ const deltaY = -digraph.graph().height / 2;
154
+ digraph.nodes().forEach(function (u) {
155
+ const value = digraph.node(u);
156
+ value.x += deltaX + _width / 2;
157
+ value.y += deltaY + _height / 2;
158
+ });
159
+ digraph.edges().forEach(function (e) {
160
+ const value = digraph.edge(e);
161
+ for (let i = 0; i < value.points.length; ++i) {
162
+ value.points[i].x += deltaX + _width / 2;
163
+ value.points[i].y += deltaY + _height / 2;
164
+ }
165
+ });
166
+ this.digraph = digraph;
167
+ }
168
+ Hierarchy.prototype.nodePos = function (u) {
169
+ return this.digraph.node(u);
170
+ };
171
+ Hierarchy.prototype.edgePoints = function (edge) {
172
+ return this.digraph.edge(edge._sourceVertex.id(), edge._targetVertex.id(), edge._id).points;
173
+ };
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
+