@hpcc-js/graph 2.86.0 → 3.1.0

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 (158) hide show
  1. package/dist/index.js +191 -21537
  2. package/dist/index.js.map +7 -1
  3. package/package.json +41 -58
  4. package/src/AdjacencyGraph.ts +3 -3
  5. package/src/Graph.ts +22 -20
  6. package/src/GraphData.ts +6 -6
  7. package/src/GraphLayouts.ts +203 -162
  8. package/src/Sankey.ts +42 -29
  9. package/src/Vertex.ts +2 -2
  10. package/src/__package__.ts +2 -2
  11. package/src/graph2/dataGraph.ts +109 -69
  12. package/src/graph2/graph.ts +12 -12
  13. package/src/graph2/graphReactT.ts +4 -3
  14. package/src/graph2/graphT.ts +26 -23
  15. package/src/graph2/index.ts +7 -7
  16. package/src/graph2/layouts/circle.ts +1 -1
  17. package/src/graph2/layouts/dagre.ts +3 -3
  18. package/src/graph2/layouts/dagreWorker.ts +4 -3
  19. package/src/graph2/layouts/forceDirected.ts +2 -2
  20. package/src/graph2/layouts/forceDirectedWorker.ts +2 -2
  21. package/src/graph2/layouts/graphviz.ts +3 -3
  22. package/src/graph2/layouts/graphvizWorker.ts +1 -1
  23. package/src/graph2/layouts/index.ts +7 -7
  24. package/src/graph2/layouts/layout.ts +2 -2
  25. package/src/graph2/layouts/null.ts +5 -1
  26. package/src/graph2/layouts/tree.ts +3 -3
  27. package/src/graph2/liteMap.ts +1 -1
  28. package/src/graph2/sankeyGraph.ts +85 -56
  29. package/src/graph2/subgraph.tsx +3 -3
  30. package/src/graph2/vertex.tsx +4 -4
  31. package/src/index.ts +8 -8
  32. package/types/AdjacencyGraph.d.ts +2 -3
  33. package/types/Edge.d.ts +0 -1
  34. package/types/Graph.d.ts +10 -10
  35. package/types/GraphData.d.ts +2 -3
  36. package/types/GraphLayouts.d.ts +45 -6
  37. package/types/Sankey.d.ts +27 -46
  38. package/types/Subgraph.d.ts +0 -1
  39. package/types/Vertex.d.ts +0 -1
  40. package/types/__package__.d.ts +2 -3
  41. package/types/graph2/dataGraph.d.ts +68 -34
  42. package/types/graph2/graph.d.ts +10 -10
  43. package/types/graph2/graphReactT.d.ts +3 -3
  44. package/types/graph2/graphT.d.ts +5 -6
  45. package/types/graph2/index.d.ts +7 -8
  46. package/types/graph2/layouts/circle.d.ts +1 -2
  47. package/types/graph2/layouts/dagre.d.ts +3 -4
  48. package/types/graph2/layouts/dagreWorker.d.ts +0 -1
  49. package/types/graph2/layouts/forceDirected.d.ts +2 -3
  50. package/types/graph2/layouts/forceDirectedWorker.d.ts +0 -1
  51. package/types/graph2/layouts/geoForceDirected.d.ts +0 -1
  52. package/types/graph2/layouts/graphviz.d.ts +2 -3
  53. package/types/graph2/layouts/graphvizWorker.d.ts +0 -1
  54. package/types/graph2/layouts/index.d.ts +7 -8
  55. package/types/graph2/layouts/layout.d.ts +2 -3
  56. package/types/graph2/layouts/null.d.ts +2 -2
  57. package/types/graph2/layouts/placeholders.d.ts +0 -1
  58. package/types/graph2/layouts/tree.d.ts +3 -4
  59. package/types/graph2/sankeyGraph.d.ts +54 -50
  60. package/types/graph2/subgraph.d.ts +2 -3
  61. package/types/graph2/vertex.d.ts +2 -3
  62. package/types/index.d.ts +8 -9
  63. package/dist/index.es6.js +0 -21516
  64. package/dist/index.es6.js.map +0 -1
  65. package/dist/index.min.js +0 -2
  66. package/dist/index.min.js.map +0 -1
  67. package/types/AdjacencyGraph.d.ts.map +0 -1
  68. package/types/Edge.d.ts.map +0 -1
  69. package/types/Graph.d.ts.map +0 -1
  70. package/types/GraphData.d.ts.map +0 -1
  71. package/types/GraphLayouts.d.ts.map +0 -1
  72. package/types/Sankey.d.ts.map +0 -1
  73. package/types/Subgraph.d.ts.map +0 -1
  74. package/types/Vertex.d.ts.map +0 -1
  75. package/types/__package__.d.ts.map +0 -1
  76. package/types/__tests__/data.d.ts +0 -9
  77. package/types/__tests__/data.d.ts.map +0 -1
  78. package/types/__tests__/index.d.ts +0 -2
  79. package/types/__tests__/index.d.ts.map +0 -1
  80. package/types/__tests__/test1.d.ts +0 -5
  81. package/types/__tests__/test1.d.ts.map +0 -1
  82. package/types/__tests__/test2.d.ts +0 -5
  83. package/types/__tests__/test2.d.ts.map +0 -1
  84. package/types/__tests__/test3.d.ts +0 -5
  85. package/types/__tests__/test3.d.ts.map +0 -1
  86. package/types/__tests__/test4.d.ts +0 -5
  87. package/types/__tests__/test4.d.ts.map +0 -1
  88. package/types/__tests__/test5.d.ts +0 -30
  89. package/types/__tests__/test5.d.ts.map +0 -1
  90. package/types/graph2/dataGraph.d.ts.map +0 -1
  91. package/types/graph2/graph.d.ts.map +0 -1
  92. package/types/graph2/graphReactT.d.ts.map +0 -1
  93. package/types/graph2/graphT.d.ts.map +0 -1
  94. package/types/graph2/index.d.ts.map +0 -1
  95. package/types/graph2/layouts/circle.d.ts.map +0 -1
  96. package/types/graph2/layouts/dagre.d.ts.map +0 -1
  97. package/types/graph2/layouts/dagreWorker.d.ts.map +0 -1
  98. package/types/graph2/layouts/forceDirected.d.ts.map +0 -1
  99. package/types/graph2/layouts/forceDirectedWorker.d.ts.map +0 -1
  100. package/types/graph2/layouts/geoForceDirected.d.ts.map +0 -1
  101. package/types/graph2/layouts/graphviz.d.ts.map +0 -1
  102. package/types/graph2/layouts/graphvizWorker.d.ts.map +0 -1
  103. package/types/graph2/layouts/index.d.ts.map +0 -1
  104. package/types/graph2/layouts/layout.d.ts.map +0 -1
  105. package/types/graph2/layouts/null.d.ts.map +0 -1
  106. package/types/graph2/layouts/placeholders.d.ts.map +0 -1
  107. package/types/graph2/layouts/tree.d.ts.map +0 -1
  108. package/types/graph2/liteMap.d.ts +0 -13
  109. package/types/graph2/liteMap.d.ts.map +0 -1
  110. package/types/graph2/liteSVGZooom.d.ts +0 -16
  111. package/types/graph2/liteSVGZooom.d.ts.map +0 -1
  112. package/types/graph2/sankeyGraph.d.ts.map +0 -1
  113. package/types/graph2/subgraph.d.ts.map +0 -1
  114. package/types/graph2/vertex.d.ts.map +0 -1
  115. package/types/index.d.ts.map +0 -1
  116. package/types/test.d.ts +0 -17
  117. package/types/test.d.ts.map +0 -1
  118. package/types-3.4/AdjacencyGraph.d.ts +0 -69
  119. package/types-3.4/Edge.d.ts +0 -60
  120. package/types-3.4/Graph.d.ts +0 -159
  121. package/types-3.4/GraphData.d.ts +0 -33
  122. package/types-3.4/GraphLayouts.d.ts +0 -6
  123. package/types-3.4/Sankey.d.ts +0 -72
  124. package/types-3.4/Subgraph.d.ts +0 -45
  125. package/types-3.4/Vertex.d.ts +0 -83
  126. package/types-3.4/__package__.d.ts +0 -4
  127. package/types-3.4/__tests__/data.d.ts +0 -9
  128. package/types-3.4/__tests__/index.d.ts +0 -2
  129. package/types-3.4/__tests__/test1.d.ts +0 -5
  130. package/types-3.4/__tests__/test2.d.ts +0 -5
  131. package/types-3.4/__tests__/test3.d.ts +0 -5
  132. package/types-3.4/__tests__/test4.d.ts +0 -5
  133. package/types-3.4/__tests__/test5.d.ts +0 -30
  134. package/types-3.4/graph2/dataGraph.d.ts +0 -66
  135. package/types-3.4/graph2/graph.d.ts +0 -55
  136. package/types-3.4/graph2/graphReactT.d.ts +0 -15
  137. package/types-3.4/graph2/graphT.d.ts +0 -234
  138. package/types-3.4/graph2/index.d.ts +0 -8
  139. package/types-3.4/graph2/layouts/circle.d.ts +0 -7
  140. package/types-3.4/graph2/layouts/dagre.d.ts +0 -13
  141. package/types-3.4/graph2/layouts/dagreWorker.d.ts +0 -35
  142. package/types-3.4/graph2/layouts/forceDirected.d.ts +0 -19
  143. package/types-3.4/graph2/layouts/forceDirectedWorker.d.ts +0 -32
  144. package/types-3.4/graph2/layouts/geoForceDirected.d.ts +0 -2
  145. package/types-3.4/graph2/layouts/graphviz.d.ts +0 -15
  146. package/types-3.4/graph2/layouts/graphvizWorker.d.ts +0 -59
  147. package/types-3.4/graph2/layouts/index.d.ts +0 -8
  148. package/types-3.4/graph2/layouts/layout.d.ts +0 -43
  149. package/types-3.4/graph2/layouts/null.d.ts +0 -8
  150. package/types-3.4/graph2/layouts/placeholders.d.ts +0 -83
  151. package/types-3.4/graph2/layouts/tree.d.ts +0 -51
  152. package/types-3.4/graph2/liteMap.d.ts +0 -16
  153. package/types-3.4/graph2/liteSVGZooom.d.ts +0 -16
  154. package/types-3.4/graph2/sankeyGraph.d.ts +0 -73
  155. package/types-3.4/graph2/subgraph.d.ts +0 -12
  156. package/types-3.4/graph2/vertex.d.ts +0 -13
  157. package/types-3.4/index.d.ts +0 -9
  158. package/types-3.4/test.d.ts +0 -17
package/package.json CHANGED
@@ -1,81 +1,64 @@
1
1
  {
2
2
  "name": "@hpcc-js/graph",
3
- "version": "2.86.0",
3
+ "version": "3.1.0",
4
4
  "description": "hpcc-js - Viz Graph",
5
- "main": "dist/index.js",
6
- "module": "dist/index.es6",
7
- "unpkg": "dist/index.min.js",
8
- "jsdelivr": "dist/index.min.js",
9
- "types": "types/index.d.ts",
10
- "typesVersions": {
11
- "<3.8": {
12
- "*": [
13
- "types-3.4/index.d.ts"
14
- ]
15
- }
5
+ "type": "module",
6
+ "exports": {
7
+ ".": {
8
+ "types": "./types/index.d.ts",
9
+ "default": "./dist/index.js"
10
+ },
11
+ "./dist/*": "./dist/*"
16
12
  },
13
+ "module": "./dist/index.js",
14
+ "browser": "./dist/index.js",
15
+ "types": "./types/index.d.ts",
17
16
  "files": [
18
17
  "dist/*",
19
- "types/*",
20
- "types-3.4/*",
21
- "src/*"
18
+ "src/*",
19
+ "types/*"
22
20
  ],
23
21
  "scripts": {
24
- "clean": "rimraf --glob lib* types dist *.tsbuildinfo workers/lib-* workers/dist workers/types workers/*.tsbuildinfo",
25
- "compile-es6": "tsc --module es6 --outDir ./lib-es6",
26
- "compile-es6-watch": "npm run compile-es6 -- -w",
27
- "compile-umd": "tsc --module umd --outDir ./lib-umd",
28
- "compile-umd-watch": "npm run compile-umd -- -w",
29
- "compile-workers": "tsc --project ./workers/tsconfig.json",
30
- "bundle": "rollup -c",
31
- "bundle-workers": "rollup -c ./workers/rollup.config.js",
32
- "bundle-watch": "npm run bundle -- -w",
33
- "minimize": "terser dist/index.js -c -m --source-map \"content='dist/index.js.map',url='index.min.js.map'\" -o dist/index.min.js",
34
- "minimize-workers-forceDirected": "terser workers/dist/forceDirected.js -c -m -o workers/dist/forceDirected.min.js",
35
- "minimize-workers-dagre": "terser workers/dist/dagre.js -c -m -o workers/dist/dagre.min.js",
36
- "minimize-workers-graphviz": "terser workers/dist/graphviz.js -c -m -o workers/dist/graphviz.min.js",
37
- "minimize-workers": "run-p minimize-workers-forceDirected minimize-workers-dagre minimize-workers-graphviz",
38
- "wrap-workers-forceDirected": "node util/wrapWorker.js forceDirected",
39
- "wrap-workers-dagre": "node util/wrapWorker.js dagre",
40
- "wrap-workers-graphviz": "node util/wrapWorker.js graphviz",
41
- "wrap-workers": "run-p wrap-workers-forceDirected wrap-workers-dagre wrap-workers-graphviz",
42
- "build-workers": "run-s compile-workers bundle-workers minimize-workers wrap-workers",
43
- "build-package": "npm run compile-es6 && npm run bundle",
44
- "gen-legacy-types": "downlevel-dts ./types ./types-3.4",
45
- "build": "run-s build-workers build-package",
46
- "watch": "npm-run-all compile-es6 -p compile-es6-watch bundle-watch",
47
- "stamp": "node ../../node_modules/@hpcc-js/bundle/src/stamp.js",
22
+ "clean": "rimraf --glob lib* types dist *.tsbuildinfo .turbo",
23
+ "bundle": "node esbuild.js",
24
+ "bundle-watch": "npm run bundle -- --development --watch",
25
+ "gen-types": "tsc --project tsconfig.json",
26
+ "gen-types-watch": "npm run gen-types -- --watch",
27
+ "build": "run-p gen-types bundle",
48
28
  "lint": "eslint ./src",
29
+ "lint-fix": "eslint --fix src/**/*.ts",
49
30
  "docs": "typedoc --options tdoptions.json .",
50
- "ddd": "downlevel-dts . ts3.4",
51
- "update": "npx --yes npm-check-updates -u -t minor"
31
+ "test-browser": "vitest run --project browser",
32
+ "test": "vitest run",
33
+ "coverage": "vitest run --coverage",
34
+ "update": "npx --yes npm-check-updates -u -t minor",
35
+ "update-major": "npx --yes npm-check-updates -u"
52
36
  },
53
37
  "dependencies": {
54
- "@hpcc-js/api": "^2.13.0",
55
- "@hpcc-js/common": "^2.72.0",
56
- "@hpcc-js/html": "^2.43.0",
57
- "@hpcc-js/react": "^2.54.0",
58
- "@hpcc-js/util": "^2.52.0"
38
+ "@hpcc-js/api": "^3.2.0",
39
+ "@hpcc-js/common": "^3.2.0",
40
+ "@hpcc-js/html": "^3.1.0",
41
+ "@hpcc-js/react": "^3.1.0",
42
+ "@hpcc-js/util": "^3.2.0"
59
43
  },
60
44
  "devDependencies": {
61
- "@hpcc-js/bundle": "^2.12.0",
62
- "@hpcc-js/wasm": "2.17.1",
63
- "@types/d3-transition": "1.3.5",
64
- "@types/dagre": "0.7.52",
65
- "d3-array": "^1",
66
- "d3-drag": "^1",
45
+ "@dagrejs/dagre": "1.1.4",
46
+ "@hpcc-js/esbuild-plugins": "^1.3.0",
47
+ "@hpcc-js/wasm-graphviz": "1.6.1",
48
+ "@types/d3-transition": "1.3.6",
67
49
  "d3-force": "^1",
68
50
  "d3-geo": "^1",
69
51
  "d3-interpolate-path": "2.3.0",
70
52
  "d3-sankey": "^0",
71
- "d3-scale": "^1",
72
- "d3-selection": "^1",
73
53
  "d3-shape": "^1",
74
54
  "d3-tile": "^1",
75
55
  "d3-transition": "^1",
76
- "dagre": "0.8.5",
77
- "es6-promise": "4.2.8",
78
- "tslib": "2.6.3"
56
+ "react": "18.3.1",
57
+ "react-dom": "18.3.1"
58
+ },
59
+ "peerDependencies": {
60
+ "react": "^17.0.0 || ^18.0.0",
61
+ "react-dom": "^17.0.0 || ^18.0.0"
79
62
  },
80
63
  "repository": {
81
64
  "type": "git",
@@ -88,5 +71,5 @@
88
71
  "url": "https://github.com/hpcc-systems/Visualization/issues"
89
72
  },
90
73
  "homepage": "https://github.com/hpcc-systems/Visualization",
91
- "gitHead": "99332f074dd1fff0cbb8eae52c5b6c98d6ad5a7a"
74
+ "gitHead": "658c50fd965a7744ba8db675ba6878607c44d5e2"
92
75
  }
@@ -1,8 +1,8 @@
1
1
  import { PropertyExt } from "@hpcc-js/common";
2
2
  import { hashSum } from "@hpcc-js/util";
3
- import { Edge } from "./Edge";
4
- import { Graph, IGraphData } from "./Graph";
5
- import { IAnnotation, Vertex } from "./Vertex";
3
+ import { Edge } from "./Edge.ts";
4
+ import { Graph, IGraphData } from "./Graph.ts";
5
+ import { IAnnotation, Vertex } from "./Vertex.ts";
6
6
 
7
7
  interface IAnnotationIndexes {
8
8
  iconCol: number;
package/src/Graph.ts CHANGED
@@ -2,11 +2,11 @@
2
2
  import { d3Event, drag as d3Drag, ISize, Platform, select as d3Select, Spacer, SVGGlowFilter, SVGZoomWidget, ToggleButton, Utility, Widget } from "@hpcc-js/common";
3
3
 
4
4
  import "d3-transition";
5
- import { Edge } from "./Edge";
6
- import { GraphData } from "./GraphData";
7
- import * as GraphLayouts from "./GraphLayouts";
8
- import { Subgraph } from "./Subgraph";
9
- import { Vertex } from "./Vertex";
5
+ import { Edge } from "./Edge.ts";
6
+ import { GraphData } from "./GraphData.ts";
7
+ import * as GraphLayouts from "./GraphLayouts.ts";
8
+ import { Subgraph } from "./Subgraph.ts";
9
+ import { Vertex } from "./Vertex.ts";
10
10
 
11
11
  import "../src/Graph.css";
12
12
 
@@ -105,7 +105,7 @@ export class Graph extends SVGZoomWidget {
105
105
  size(): ISize;
106
106
  size(_): this;
107
107
  size(_?): ISize | this {
108
- const retVal = super.size.apply(this, arguments);
108
+ const retVal = super.size.apply(this, arguments as any);
109
109
  return retVal;
110
110
  }
111
111
 
@@ -117,7 +117,7 @@ export class Graph extends SVGZoomWidget {
117
117
  data(): IGraphData;
118
118
  data(_: IGraphData, merge?: boolean): this;
119
119
  data(_?: IGraphData, merge?: boolean): IGraphData | this {
120
- const retVal = super.data.apply(this, arguments);
120
+ const retVal = super.data.apply(this, arguments as any);
121
121
  if (arguments.length) {
122
122
  if (!merge) {
123
123
  this._graphData = new GraphData();
@@ -283,7 +283,7 @@ export class Graph extends SVGZoomWidget {
283
283
  this._neighborOffsets = [];
284
284
 
285
285
  if (Platform.svgMarkerGlitch) {
286
- this._graphData.nodeEdges(d.id()).forEach(function (id) {
286
+ this._graphData.nodeEdges(d.id()).forEach(function (this, id) {
287
287
  const edge = this._graphData.edge(id);
288
288
  this._popMarkers(edge.element());
289
289
  });
@@ -639,7 +639,7 @@ export class Graph extends SVGZoomWidget {
639
639
  }
640
640
 
641
641
  const context = this;
642
- const layoutEngine = this.getLayoutEngine();
642
+ const layoutEngine = this.getLayoutEngine() as GraphLayouts.ForceDirected;
643
643
  if (this.layout() === "ForceDirected2") {
644
644
  this.forceLayout = layoutEngine;
645
645
  this.forceLayout.force
@@ -964,15 +964,6 @@ export class Graph extends SVGZoomWidget {
964
964
  ;
965
965
  }
966
966
 
967
- // IGraph ---
968
- edge_click: (_row, _col, _sel, _more) => void;
969
- edge_dblclick: (_row, _col, _sel, _more) => void;
970
-
971
- // ITooltip ---
972
- tooltip;
973
- tooltipHTML: (_) => string;
974
- tooltipFormat: (_) => string;
975
-
976
967
  // Progess Events ---
977
968
  progress(what: "start" | "end" | "layout-start" | "layout-tick" | "layout-end") {
978
969
  }
@@ -988,7 +979,8 @@ export interface Graph {
988
979
  dragSingleNeighbors(_: boolean): this;
989
980
  layout(): GraphLayoutType;
990
981
  layout(_: GraphLayoutType): this;
991
- // scale: { (): string; (_: string): this; };
982
+ // scale(): string;
983
+ // scale(_: string): this;
992
984
  applyScaleOnLayout(): boolean;
993
985
  applyScaleOnLayout(_: boolean): this;
994
986
  highlightOnMouseOverVertex(): boolean;
@@ -1034,6 +1026,15 @@ export interface Graph {
1034
1026
  forceDirectedTheta(_: number): this;
1035
1027
  forceDirectedGravity(): number;
1036
1028
  forceDirectedGravity(_: number): this;
1029
+
1030
+ // IGraph ---
1031
+ edge_click(_row, _col, _sel, _more): void;
1032
+ edge_dblclick(_row, _col, _sel, _more): void;
1033
+
1034
+ // ITooltip ---
1035
+ tooltip;
1036
+ tooltipHTML(_): string;
1037
+ tooltipFormat(_): string;
1037
1038
  }
1038
1039
 
1039
1040
  Graph.prototype.publish("allowDragging", true, "boolean", "Allow Dragging of Vertices", null, { tags: ["Advanced"] });
@@ -1066,8 +1067,9 @@ Graph.prototype.publish("forceDirectedTheta", 0.8, "number", "Barnes–Hut appro
1066
1067
  Graph.prototype.publish("forceDirectedGravity", 0.1, "number", "Gravitational strength", null, { tags: ["Advanced"] });
1067
1068
 
1068
1069
  const _origScale = Graph.prototype.scale;
1070
+ //@ts-ignore
1069
1071
  Graph.prototype.scale = function (_?, transitionDuration?) {
1070
- const retVal = _origScale.apply(this, arguments);
1072
+ const retVal = _origScale.apply(this, arguments as any);
1071
1073
  if (arguments.length) {
1072
1074
  this.zoomTo(_, transitionDuration);
1073
1075
  }
package/src/GraphData.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { Edge as GLEdge, GraphEdge, graphlib, Node } from "dagre";
2
- import { Vertex } from "./Vertex";
1
+ import { Edge as GLEdge, GraphEdge, graphlib, Node } from "@dagrejs/dagre";
2
+ import { Vertex } from "./Vertex.ts";
3
3
 
4
4
  type GLNode = Node<Vertex>;
5
5
 
@@ -40,9 +40,9 @@ export class GraphData {
40
40
  }
41
41
 
42
42
  eachNode(callback) {
43
- this._g.nodes().forEach(function (item) {
43
+ this._g.nodes().forEach(item => {
44
44
  callback(item, this.node(item));
45
- }, this);
45
+ });
46
46
  }
47
47
 
48
48
  private filterEdges(pred): GLEdge[] {
@@ -56,9 +56,9 @@ export class GraphData {
56
56
  }
57
57
 
58
58
  eachEdge(callback) {
59
- this._g.edges().forEach(function (item) {
59
+ this._g.edges().forEach(item => {
60
60
  callback(item, item.v, item.w, this.edge(item));
61
- }, this);
61
+ });
62
62
  }
63
63
 
64
64
  setData(subgraphs, vertices, edges, hierarchy, merge) {
@@ -1,173 +1,214 @@
1
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
- });
2
+ import { GraphLabel, graphlib, layout } from "@dagrejs/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
+
26
47
  }
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
- });
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
+ }
46
74
  }
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
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;
80
103
  });
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();
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();
112
143
  }
113
- this.force.stop();
144
+ }
145
+
146
+ nodePos(u) {
147
+ return this.vertexMap[u];
148
+ }
149
+
150
+ edgePoints(_e) {
151
+ return [];
114
152
  }
115
153
  }
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
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
+ });
135
173
  });
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, {
174
+ graphData.eachEdge((e, s, t) => {
175
+ const value = graphData.edge(e);
176
+ this.digraph.setEdge(s, t, {
144
177
  weight: value.weight()
145
178
  }, 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;
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
+ }
167
214
  }
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
- };