@hpcc-js/graph 2.84.1 → 2.84.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 (54) hide show
  1. package/dist/index.es6.js +28 -9
  2. package/dist/index.es6.js.map +1 -1
  3. package/dist/index.js +28 -9
  4. package/dist/index.js.map +1 -1
  5. package/dist/index.min.js +1 -1
  6. package/dist/index.min.js.map +1 -1
  7. package/package.json +9 -10
  8. package/src/__package__.ts +2 -2
  9. package/src/__tests__/data.ts +444 -0
  10. package/src/__tests__/index.ts +1 -0
  11. package/src/__tests__/test1.ts +18 -0
  12. package/src/__tests__/test2.ts +79 -0
  13. package/src/__tests__/test3.ts +46 -0
  14. package/src/__tests__/test4.ts +66 -0
  15. package/src/__tests__/test5.ts +86 -0
  16. package/src/graph2/graphT.ts +21 -6
  17. package/src/graph2/layouts/graphviz.ts +1 -2
  18. package/src/graph2/layouts/graphvizWorker.ts +1 -9
  19. package/src/graph2/layouts/placeholders.ts +4 -0
  20. package/types/__package__.d.ts +2 -2
  21. package/types/__package__.d.ts.map +1 -1
  22. package/types/__tests__/data.d.ts +9 -0
  23. package/types/__tests__/data.d.ts.map +1 -0
  24. package/types/__tests__/index.d.ts +2 -0
  25. package/types/__tests__/index.d.ts.map +1 -0
  26. package/types/__tests__/test1.d.ts +5 -0
  27. package/types/__tests__/test1.d.ts.map +1 -0
  28. package/types/__tests__/test2.d.ts +5 -0
  29. package/types/__tests__/test2.d.ts.map +1 -0
  30. package/types/__tests__/test3.d.ts +5 -0
  31. package/types/__tests__/test3.d.ts.map +1 -0
  32. package/types/__tests__/test4.d.ts +5 -0
  33. package/types/__tests__/test4.d.ts.map +1 -0
  34. package/types/__tests__/test5.d.ts +30 -0
  35. package/types/__tests__/test5.d.ts.map +1 -0
  36. package/types/graph2/graphT.d.ts +1 -0
  37. package/types/graph2/graphT.d.ts.map +1 -1
  38. package/types/graph2/layouts/graphviz.d.ts.map +1 -1
  39. package/types/graph2/layouts/graphvizWorker.d.ts +0 -1
  40. package/types/graph2/layouts/graphvizWorker.d.ts.map +1 -1
  41. package/types/graph2/layouts/placeholders.d.ts +1 -0
  42. package/types/graph2/layouts/placeholders.d.ts.map +1 -1
  43. package/types-3.4/__package__.d.ts +2 -2
  44. package/types-3.4/__tests__/data.d.ts +9 -0
  45. package/types-3.4/__tests__/index.d.ts +2 -0
  46. package/types-3.4/__tests__/test1.d.ts +5 -0
  47. package/types-3.4/__tests__/test2.d.ts +5 -0
  48. package/types-3.4/__tests__/test3.d.ts +5 -0
  49. package/types-3.4/__tests__/test4.d.ts +5 -0
  50. package/types-3.4/__tests__/test5.d.ts +30 -0
  51. package/types-3.4/graph2/graphT.d.ts +1 -0
  52. package/types-3.4/graph2/layouts/graphvizWorker.d.ts +0 -1
  53. package/types-3.4/graph2/layouts/placeholders.d.ts +1 -0
  54. package/dist/graphvizlib.wasm +0 -0
@@ -0,0 +1,66 @@
1
+ import { Vertex4, CentroidVertex4 } from "@hpcc-js/react";
2
+ import { Test2 } from "./test2";
3
+
4
+ export class Test4 extends Test2 {
5
+ constructor() {
6
+ super();
7
+ this
8
+ .vertexRenderer(Vertex4)
9
+ .centroidRenderer(CentroidVertex4)
10
+ ;
11
+ }
12
+ }
13
+
14
+ // 8
15
+ let seed = 8;
16
+ function random() {
17
+ const x = Math.sin(seed++) * 10000;
18
+ return x - Math.floor(x);
19
+ }
20
+ function rand() {
21
+ return Math.round(random() * 32767);
22
+ }
23
+
24
+ function make_pair<T>(a: T, b: T): [T, T] {
25
+ return [a, b];
26
+ }
27
+
28
+ // @ts-ignore
29
+ function genData(MAX_VERTICES = 200, MAX_EDGES = 200) {
30
+ const edges: [number, number][] = [];
31
+ function edges_has(p: [number, number]): boolean {
32
+ return edges.some(row => row[0] === p[0] && row[1] === p[1]);
33
+ }
34
+
35
+ const NUM = 1 + rand() % MAX_VERTICES;
36
+ let NUMEDGE = 1 + rand() % MAX_EDGES;
37
+
38
+ while (NUMEDGE > NUM * (NUM - 1) / 2) {
39
+ NUMEDGE = 1 + rand() % MAX_EDGES;
40
+ }
41
+
42
+ for (let j = 1; j <= NUMEDGE; j++) {
43
+ let a = 1 + rand() % NUM;
44
+ let b = 1 + rand() % NUM;
45
+ let p = make_pair(a, b);
46
+
47
+ while (edges_has(p) || a == b) {
48
+ a = 1 + rand() % NUM;
49
+ b = 1 + rand() % NUM;
50
+ p = make_pair(a, b);
51
+ }
52
+ edges.push(p);
53
+ }
54
+
55
+ const vertices: { [id: number]: boolean } = {};
56
+ for (const it of edges) {
57
+ vertices[it[0]] = true;
58
+ vertices[it[1]] = true;
59
+ }
60
+
61
+ const icons = ["fa-at", "fa-user-o", "fa-address-card-o", "fa-globe", "fa-phone"];
62
+ return {
63
+ vertices: Object.keys(vertices).map(v => [v, `Node-${v}`, icons[Math.floor(Math.random() * icons.length)]]),
64
+ edges: edges.map(e => [e[0], e[1], "", 1])
65
+ };
66
+ }
@@ -0,0 +1,86 @@
1
+ import { Vertex4, CentroidVertex4 } from "@hpcc-js/react";
2
+ import { Graph2 } from "../graph2/graph";
3
+
4
+ const VERTEX_ARR = [{
5
+ id: 0,
6
+ centroid: true,
7
+ text: "Vertex One",
8
+ iconFontFamily: "'Font Awesome 5 Free'",
9
+ }, {
10
+ id: 1,
11
+ centroid: false,
12
+ text: "Vertex Two",
13
+
14
+ }, {
15
+ id: 2,
16
+ centroid: false,
17
+ text: "Vertex Three",
18
+ }];
19
+
20
+ const EDGE_ARR = [{
21
+ id: 0,
22
+ source: VERTEX_ARR[0],
23
+ target: VERTEX_ARR[1]
24
+ }, {
25
+ id: 1,
26
+ source: VERTEX_ARR[0],
27
+ target: VERTEX_ARR[2]
28
+ }];
29
+
30
+ const VERTEX_ARR_UPDATED = [{
31
+ id: 0,
32
+ text: "Vertex One",
33
+ iconFontFamily: "'Font Awesome 5 Free'",
34
+ }, {
35
+ centroid: true,
36
+ id: 1,
37
+ text: "Vertex Two",
38
+
39
+ }, {
40
+ id: 2,
41
+ centroid: false,
42
+ text: "Vertex Three",
43
+ }];
44
+
45
+ export const EDGE_ARR_UPDATE = [{
46
+ id: 0,
47
+ source: VERTEX_ARR_UPDATED[1],
48
+ target: VERTEX_ARR_UPDATED[2]
49
+ }];
50
+
51
+ export class Test5 extends Graph2 {
52
+
53
+ constructor() {
54
+ super();
55
+ this
56
+ .minScale(0.1)
57
+ .layout("ForceDirected")
58
+ .centroidRenderer(CentroidVertex4)
59
+ .vertexRenderer(Vertex4)
60
+ .data({
61
+ vertices: VERTEX_ARR,
62
+ edges: EDGE_ARR
63
+ })
64
+ .transitionDuration(200)
65
+ .forceDirectedIterations(800)
66
+ .forceDirectedLinkDistance(100)
67
+ .forceDirectedAlphaDecay(0.014)
68
+ .applyScaleOnLayout(true)
69
+ .centroidColor("#ffffff")
70
+ .edgeStrokeWidth(2)
71
+ .edgeColor("#227AC2")
72
+ .minScale(0.1)
73
+ .edgeArcDepth(0)
74
+ .layout("ForceDirected")
75
+ .on("vertex_click", (vertex, col, sel, anno) => {
76
+ console.info("vertex_click", vertex);
77
+ })
78
+ .on("vertex_dblclick", (vertex, col, sel, anno) => {
79
+ console.info("vertex_dblclick", vertex);
80
+ })
81
+ .on("vertex_contextmenu", (vertex, col, sel, anno) => {
82
+ console.info("vertex_contextmenu", vertex);
83
+ })
84
+ ;
85
+ }
86
+ }
@@ -8,7 +8,7 @@ import { interpolatePath as d3InterpolatePath } from "d3-interpolate-path";
8
8
  import { Circle, Dagre, ForceDirected, ForceDirectedAnimated, Graphviz, ILayout, Null } from "./layouts/index";
9
9
  import { Options as FDOptions } from "./layouts/forceDirectedWorker";
10
10
  import type { VertexProps, EdgeProps, IGraphData2, HierarchyBase, SubgraphProps } from "./layouts/placeholders";
11
- import { EdgePlaceholder, SubgraphPlaceholder, VertexPlaceholder } from "./layouts/placeholders";
11
+ import { EdgePlaceholder, SubgraphPlaceholder, VertexPlaceholder, isEdgePlaceholder } from "./layouts/placeholders";
12
12
  import { Engine, graphviz as gvWorker } from "./layouts/graphvizWorker";
13
13
  import { Tree, RadialTree, Dendrogram, RadialDendrogram } from "./layouts/tree";
14
14
 
@@ -67,8 +67,12 @@ export class GraphT<SG extends SubgraphProps, V extends VertexProps, E extends E
67
67
  .idFunc(d => d.id)
68
68
  .sourceFunc(e => e.source.id)
69
69
  .targetFunc(e => e.target.id)
70
- .updateFunc((b: any, a: any) => {
70
+ .updateFunc((b: VertexPlaceholder<V> | EdgePlaceholder<E, V> | SubgraphPlaceholder<SG>, a: VertexPlaceholder<V> | EdgePlaceholder<E, V> | SubgraphPlaceholder<SG>) => {
71
71
  b.props = a.props;
72
+ if (isEdgePlaceholder(a) && isEdgePlaceholder(b)) {
73
+ b.source = a.source;
74
+ b.target = a.target;
75
+ }
72
76
  return b;
73
77
  })
74
78
  ;
@@ -188,14 +192,19 @@ export class GraphT<SG extends SubgraphProps, V extends VertexProps, E extends E
188
192
  d3Select(this).classed("grabbed", false);
189
193
  }
190
194
  if (doClick) {
195
+ const event = d3Event();
191
196
  context._selection.click({
192
197
  _id: String(d.id),
193
198
  element: () => d.element
194
- }, d3Event().sourceEvent);
199
+ }, event.sourceEvent);
195
200
  context.selectionChanged();
196
201
  const selected = d.element.classed("selected");
197
202
  const eventOrigin = context.resolveEventOrigin();
198
- context.vertex_click(d.props.origData || d.props, "", selected, eventOrigin);
203
+ if (event?.sourceEvent?.button === 2) {
204
+ context.vertex_contextmenu(d.props.origData || d.props, "", selected, eventOrigin);
205
+ } else {
206
+ context.vertex_click(d.props.origData || d.props, "", selected, eventOrigin);
207
+ }
199
208
  const doClickTime = Date.now();
200
209
  if (doClickTime - context._prevDoClickTime < context.doubleClickMaxDelay()) {
201
210
  context.vertex_dblclick(d.props.origData || d.props, "", selected, eventOrigin);
@@ -759,6 +768,9 @@ export class GraphT<SG extends SubgraphProps, V extends VertexProps, E extends E
759
768
  .on("dblclick", function (this: SVGElement, d) {
760
769
  d3Event().stopPropagation();
761
770
  })
771
+ .on("contextmenu", function (this: SVGElement, d) {
772
+ d3Event().preventDefault();
773
+ })
762
774
  .on("mousein", function (d) {
763
775
  Utility.safeRaise(this);
764
776
  context.highlightVertex(d3Select(this), d);
@@ -1029,6 +1041,7 @@ export class GraphT<SG extends SubgraphProps, V extends VertexProps, E extends E
1029
1041
  this.updateSubgraphs();
1030
1042
  this.updateVertices();
1031
1043
  this.updateEdges();
1044
+ this.moveEdges(false);
1032
1045
 
1033
1046
  this.updateLayout();
1034
1047
 
@@ -1127,6 +1140,9 @@ export class GraphT<SG extends SubgraphProps, V extends VertexProps, E extends E
1127
1140
  vertex_dblclick(row, _col, sel, data) {
1128
1141
  }
1129
1142
 
1143
+ vertex_contextmenu(row, _col, sel, data) {
1144
+ }
1145
+
1130
1146
  vertex_mousein(row, _col, sel, data) {
1131
1147
  }
1132
1148
 
@@ -1309,7 +1325,6 @@ export function graphviz(dot: string, engine: Engine = "dot", _scriptDir: string
1309
1325
  links: [],
1310
1326
  raw: dot
1311
1327
  }, {
1312
- engine: engine,
1313
- wasmFolder: new URL(scriptDir, document.baseURI).href
1328
+ engine: engine
1314
1329
  });
1315
1330
  }
@@ -59,8 +59,7 @@ export class Graphviz extends Layout {
59
59
  })),
60
60
  raw: ""
61
61
  }, {
62
- engine: this._engine,
63
- wasmFolder: this._wasmFolder
62
+ engine: this._engine
64
63
  }).response.then((response: any) => {
65
64
  if (this.running()) {
66
65
  response.clusters.forEach(n => {