@hpcc-js/graph 3.7.4 → 3.7.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-BK7FEJlA.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 +7 -7
  10. package/src/AdjacencyGraph.ts +224 -224
  11. package/src/Edge.css +22 -22
  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 +44 -44
  18. package/src/Sankey.ts +304 -304
  19. package/src/Subgraph.css +9 -9
  20. package/src/Subgraph.ts +165 -165
  21. package/src/Vertex.css +2 -2
  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 +44 -44
  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,345 +1,345 @@
1
- import { PropertyExt, Widget } from "@hpcc-js/common";
2
- import { Vertex3, CentroidVertex3, Vertex3Props, EdgeProps, SubgraphProps } from "@hpcc-js/react";
3
- import { compare2 } from "@hpcc-js/util";
4
- import { GraphReact } from "./graphReact.ts";
5
- import { HierarchyBase } from "../common/layouts/placeholders.ts";
6
-
7
- // Backward compatibility layer ---
8
- export type IVertex3 = Vertex3Props;
9
-
10
- export function toJsonObj<T>(row, columns): T {
11
- const retVal: T = {} as T;
12
- columns.forEach((c, i) => retVal[c] = row[i]);
13
- return retVal;
14
- }
15
-
16
- export class AnnotationColumn extends PropertyExt {
17
-
18
- protected _owner: DataGraph;
19
- owner(): DataGraph;
20
- owner(_: DataGraph): this;
21
- owner(_?: DataGraph): DataGraph | this {
22
- if (!arguments.length) return this._owner;
23
- this._owner = _!;
24
- return this;
25
- }
26
-
27
- valid(): boolean {
28
- return !!this.columnID();
29
- }
30
- }
31
- AnnotationColumn.prototype._class += " graph_AnnotationColumn";
32
-
33
- export interface AnnotationColumn {
34
- columnID(): string;
35
- columnID(_: string): this;
36
- annotationID(): string;
37
- annotationID(_: string): this;
38
- }
39
-
40
- AnnotationColumn.prototype.publish("columnID", "", "set", "Annotation column (boolean)", function (this: AnnotationColumn) { return this._owner.vertexColumns(); });
41
- AnnotationColumn.prototype.publish("annotationID", "", "string", "Annotation ID");
42
-
43
- export class DataGraph extends GraphReact {
44
-
45
- constructor() {
46
- super();
47
- this
48
- .vertexRenderer(Vertex3)
49
- .centroidRenderer(CentroidVertex3)
50
- .edgeColor("#287EC4")
51
- .edgeStrokeWidth(2)
52
- .edgeArcDepth(0)
53
- ;
54
- }
55
-
56
- clear() {
57
- this._prevSubgraphs = [];
58
- this._masterSubgraphs = [];
59
- this._masterSubgraphsMap = {};
60
-
61
- this._prevVertices = [];
62
- this._masterVertices = [];
63
- this._masterVerticesMap = {};
64
-
65
- this._prevEdges = [];
66
- this._masterEdges = [];
67
-
68
- this._prevHierarchy = [];
69
- this._masterHierarchy = [];
70
- this._masterHierarchyMap = {};
71
-
72
- this._graphData.clear();
73
- this.resetLayout();
74
- }
75
-
76
- indexOf(columns: readonly string[], column: string, defColumn: string = ""): number {
77
- const retVal = columns.indexOf(column);
78
- return retVal >= 0 ? retVal : columns.indexOf(defColumn);
79
- }
80
-
81
- private _prevSubgraphs: readonly SubgraphProps[] = [];
82
- private _masterSubgraphs: SubgraphProps[] = [];
83
- private _masterSubgraphsMap: { [key: string]: SubgraphProps } = {};
84
- mergeSubgraphs() {
85
- const columns = this.subgraphColumns();
86
- const idIdx = this.indexOf(columns, this.subgraphIDColumn(), "id");
87
- const labelIdx = this.indexOf(columns, this.subgraphLabelColumn(), "label");
88
- const subgraphs = this.subgraphs().map((sg): SubgraphProps => {
89
- return {
90
- id: "" + sg[idIdx],
91
- text: "" + sg[labelIdx],
92
- origData: toJsonObj<SubgraphProps>(sg, columns)
93
- };
94
- });
95
- const diff = compare2(this._prevSubgraphs, subgraphs, d => d.id);
96
- diff.exit.forEach(item => {
97
- this._masterSubgraphs = this._masterSubgraphs.filter(i => i.id !== item.id);
98
- delete this._masterSubgraphsMap[item.id];
99
- });
100
- diff.enter.forEach(item => {
101
- this._masterSubgraphs.push(item);
102
- this._masterSubgraphsMap[item.id] = item;
103
- });
104
- diff.update.forEach(item => {
105
- this._masterSubgraphsMap[item.id].origData = item.origData;
106
- });
107
- this._prevSubgraphs = subgraphs;
108
- }
109
-
110
- private _prevVertices: readonly IVertex3[] = [];
111
- private _masterVertices: IVertex3[] = [];
112
- private _masterVerticesMap: { [key: string]: IVertex3 } = {};
113
- mergeVertices() {
114
- const columns = this.vertexColumns();
115
- const annotationColumns = this.vertexAnnotationColumns();
116
- const catIdx = this.indexOf(columns, this.vertexCategoryColumn(), "category");
117
- const idIdx = this.indexOf(columns, this.vertexIDColumn(), "id");
118
- const labelIdx = this.indexOf(columns, this.vertexLabelColumn(), "label");
119
- const centroidIdx = this.indexOf(columns, this.vertexCentroidColumn(), "centroid");
120
- const imageUrlIdx = this.indexOf(columns, this.vertexImageUrlColumn(), "faChar");
121
- const faCharIdx = this.indexOf(columns, this.vertexFACharColumn(), "faChar");
122
- const vertexTooltipIdx = this.indexOf(columns, this.vertexTooltipColumn(), "tooltip");
123
- const annotationIdxs = annotationColumns.map(ac => this.indexOf(columns, ac.columnID(), ""));
124
- const expansionFACharIdx = this.indexOf(columns, this.vertexExpansionFACharColumn(), "expansionFAChar");
125
- const vertices: IVertex3[] = this.vertices().map((v): IVertex3 => {
126
- const annotationIDs = annotationIdxs.map((ai, i) => !!v[ai] ? annotationColumns[i].annotationID() : undefined).filter(a => !!a);
127
- return {
128
- categoryID: "" + v[catIdx],
129
- id: "" + v[idIdx],
130
- text: "" + v[labelIdx],
131
- tooltip: "" + v[vertexTooltipIdx],
132
- origData: toJsonObj(v, columns),
133
- centroid: !!v[centroidIdx],
134
- icon: {
135
- imageUrl: "" + (v[imageUrlIdx] || this.vertexImageUrl()),
136
- imageChar: "" + (v[faCharIdx] || this.vertexFAChar())
137
- },
138
- annotationIDs,
139
- annotations: this.annotations().filter(ann => annotationIDs.indexOf(ann.id) >= 0),
140
- expansionIcon: v[expansionFACharIdx] ? {
141
- imageChar: "" + v[expansionFACharIdx]
142
- } : undefined
143
- } as IVertex3;
144
- });
145
- const diff = compare2(this._prevVertices, vertices, d => d.id);
146
- diff.exit.forEach(item => {
147
- this._masterVertices = this._masterVertices.filter(i => i.id !== item.id);
148
- delete this._masterVerticesMap[item.id];
149
- });
150
- diff.enter.forEach(item => {
151
- this._masterVertices.push(item);
152
- this._masterVerticesMap[item.id] = item;
153
- });
154
- diff.update.forEach(item => {
155
- this._masterVerticesMap[item.id].origData = item.origData;
156
- });
157
- this._prevVertices = vertices;
158
- }
159
-
160
- protected _prevEdges: readonly EdgeProps<IVertex3>[] = [];
161
- protected _masterEdges: EdgeProps<IVertex3>[] = [];
162
- private _masterEdgesMap: { [key: string]: EdgeProps<IVertex3> } = {};
163
- mergeEdges() {
164
- const columns = this.edgeColumns();
165
- const idIdx = this.indexOf(columns, this.edgeIDColumn(), "id");
166
- const sourceIdx = this.indexOf(columns, this.edgeSourceColumn(), "source");
167
- const targetIdx = this.indexOf(columns, this.edgeTargetColumn(), "target");
168
- const labelIdx = this.indexOf(columns, this.edgeLabelColumn(), "label");
169
- const weightIdx = this.indexOf(columns, this.edgeWeightColumn(), "weight");
170
- const colorIdx = this.indexOf(columns, this.edgeColorColumn(), "color");
171
- const edges: EdgeProps<IVertex3>[] = this.edges().map((e): EdgeProps<IVertex3> => {
172
- const source = this._masterVerticesMap["" + e[sourceIdx]];
173
- if (!source) console.error(`Invalid edge source entity "${e[sourceIdx]}" does not exist.`);
174
- const target = this._masterVerticesMap["" + e[targetIdx]];
175
- if (!target) console.error(`Invalid edge target entity "${e[targetIdx]}" does not exist.`);
176
- return {
177
- id: idIdx >= 0 ? "" + e[idIdx] : "" + e[sourceIdx] + "->" + e[targetIdx],
178
- source,
179
- target,
180
- weight: +e[weightIdx] || 1,
181
- stroke: e[colorIdx] as string,
182
- label: labelIdx >= 0 ? ("" + e[labelIdx]) : "",
183
- origData: toJsonObj(e, columns),
184
- labelPos: [0, 0],
185
- path: ""
186
- };
187
- }).filter(e => e.source && e.target);
188
- const diff = compare2(this._masterEdges, edges, d => d.id);
189
- diff.exit.forEach(item => {
190
- this._masterEdges = this._masterEdges.filter(i => i.id !== item.id);
191
- delete this._masterEdgesMap[item.id];
192
- });
193
- diff.enter.forEach(item => {
194
- this._masterEdges.push(item);
195
- this._masterEdgesMap[item.id] = item;
196
-
197
- });
198
- diff.update.forEach(item => {
199
- this._masterEdgesMap[item.id].origData = item.origData;
200
- });
201
- this._prevEdges = edges;
202
- }
203
-
204
- private _prevHierarchy: readonly HierarchyBase<SubgraphProps, IVertex3>[] = [];
205
- private _masterHierarchy: HierarchyBase<SubgraphProps, IVertex3>[] = [];
206
- private _masterHierarchyMap: { [key: string]: HierarchyBase<SubgraphProps, IVertex3> } = {};
207
- mergeHierarchy() {
208
- const columns = this.hierarchyColumns();
209
- const parentIDIdx = this.indexOf(columns, this.hierarchyParentIDColumn(), "parentID");
210
- const childIDIdx = this.indexOf(columns, this.hierarchyChildIDColumn(), "childID");
211
- const hierarchy: HierarchyBase<SubgraphProps, IVertex3>[] = this.hierarchy().map((h): HierarchyBase<SubgraphProps, IVertex3> => {
212
- return {
213
- id: "" + h[parentIDIdx] + "=>" + h[childIDIdx],
214
- parent: this._masterSubgraphsMap["" + h[parentIDIdx]] as SubgraphProps,
215
- child: this._masterSubgraphsMap["" + h[childIDIdx]] || this._masterVerticesMap["" + h[childIDIdx]]
216
- };
217
- });
218
- const diff = compare2(this._prevHierarchy, hierarchy, d => d.id);
219
- diff.exit.forEach(item => {
220
- this._masterHierarchy = this._masterHierarchy.filter(i => i.id !== item.id);
221
- delete this._masterHierarchyMap[item.id];
222
- });
223
- diff.enter.forEach(item => {
224
- this._masterHierarchy.push(item);
225
- this._masterHierarchyMap[item.id] = item;
226
- });
227
- this._prevHierarchy = hierarchy;
228
- }
229
-
230
- update(domNode, element) {
231
- this.mergeSubgraphs();
232
- this.mergeVertices();
233
- this.mergeEdges();
234
- this.mergeHierarchy();
235
- this.data({ subgraphs: this._masterSubgraphs, vertices: this._masterVertices, edges: this._masterEdges, hierarchy: this._masterHierarchy });
236
- super.update(domNode, element);
237
- }
238
-
239
- render(callback?: (w: Widget) => void): this {
240
- super.render(w => {
241
- if (callback) {
242
- callback(w);
243
- }
244
- });
245
- return this;
246
- }
247
- }
248
- DataGraph.prototype._class += " graph_DataGraph";
249
-
250
- export interface DataGraph {
251
- subgraphColumns(): string[];
252
- subgraphColumns(_: string[]): this;
253
- subgraphs(): Array<Array<string | number | boolean>>;
254
- subgraphs(_: Array<Array<string | number | boolean>>): this;
255
- subgraphIDColumn(): string;
256
- subgraphIDColumn(_: string): this;
257
- subgraphLabelColumn(): string;
258
- subgraphLabelColumn(_: string): this;
259
-
260
- vertexColumns(): string[];
261
- vertexColumns(_: string[]): this;
262
- vertices(): Array<Array<string | number | boolean>>;
263
- vertices(_: Array<Array<string | number | boolean>>): this;
264
- vertexCategoryColumn(): string;
265
- vertexCategoryColumn(_: string): this;
266
- vertexIDColumn(): string;
267
- vertexIDColumn(_: string): this;
268
- vertexLabelColumn(): string;
269
- vertexLabelColumn(_: string): this;
270
- vertexCentroidColumn(): string;
271
- vertexCentroidColumn(_: string): this;
272
- vertexImageUrl(): string;
273
- vertexImageUrl(_: string): this;
274
- vertexImageUrlColumn(): string;
275
- vertexImageUrlColumn(_: string): this;
276
- vertexFAChar(): string;
277
- vertexFAChar(_: string): this;
278
- vertexFACharColumn(): string;
279
- vertexFACharColumn(_: string): this;
280
- vertexTooltipColumn(): string;
281
- vertexTooltipColumn(_: string): this;
282
- vertexAnnotationColumns(): AnnotationColumn[];
283
- vertexAnnotationColumns(_: AnnotationColumn[]): this;
284
- vertexExpansionFACharColumn(): string;
285
- vertexExpansionFACharColumn(_: string): this;
286
-
287
- edgeColumns(): string[];
288
- edgeColumns(_: string[]): this;
289
- edges(): Array<Array<string | number | boolean>>;
290
- edges(_: Array<Array<string | number | boolean>>): this;
291
- edgeIDColumn(): string;
292
- edgeIDColumn(_: string): this;
293
- edgeLabelColumn(): string;
294
- edgeLabelColumn(_: string): this;
295
- edgeSourceColumn(): string;
296
- edgeSourceColumn(_: string): this;
297
- edgeTargetColumn(): string;
298
- edgeTargetColumn(_: string): this;
299
- edgeWeightColumn(): string;
300
- edgeWeightColumn(_: string): this;
301
- edgeColorColumn(): string;
302
- edgeColorColumn(_: string): this;
303
-
304
- hierarchyColumns(): string[];
305
- hierarchyColumns(_: string[]): this;
306
- hierarchy(): Array<Array<string | number | boolean>>;
307
- hierarchy(_: Array<Array<string | number | boolean>>): this;
308
- hierarchyParentIDColumn(): string;
309
- hierarchyParentIDColumn(_: string): this;
310
- hierarchyChildIDColumn(): string;
311
- hierarchyChildIDColumn(_: string): this;
312
- }
313
-
314
- DataGraph.prototype.publish("subgraphColumns", [], "any", "Subgraph Columns", undefined, { internal: true });
315
- DataGraph.prototype.publish("subgraphs", [], "any", "Subgraphs", undefined, { internal: true });
316
- DataGraph.prototype.publish("subgraphIDColumn", "", "string", "Subgraph ID column");
317
- DataGraph.prototype.publish("subgraphLabelColumn", "", "string", "Subgraph Label column");
318
-
319
- DataGraph.prototype.publish("vertexColumns", [], "any", "Vertex Columns", undefined, { internal: true });
320
- DataGraph.prototype.publish("vertices", [], "any", "Vertices (Nodes)", undefined, { internal: true });
321
- DataGraph.prototype.publish("vertexCategoryColumn", "", "set", "Vertex Category ID column", function (this: DataGraph) { return this.vertexColumns(); }, { optional: true });
322
- DataGraph.prototype.publish("vertexIDColumn", "", "set", "Vertex ID column", function (this: DataGraph) { return this.vertexColumns(); }, { optional: true });
323
- DataGraph.prototype.publish("vertexLabelColumn", "", "set", "Vertex label column", function (this: DataGraph) { return this.vertexColumns(); }, { optional: true });
324
- DataGraph.prototype.publish("vertexCentroidColumn", "", "set", "Vertex centroid column (boolean)", function (this: DataGraph) { return this.vertexColumns(); }, { optional: true });
325
- DataGraph.prototype.publish("vertexImageUrl", "", "string", "Vertex default image url");
326
- DataGraph.prototype.publish("vertexImageUrlColumn", "", "set", "Vertex image url column", function (this: DataGraph) { return this.vertexColumns(); }, { optional: true });
327
- DataGraph.prototype.publish("vertexFAChar", "?", "string", "Vertex default FAChar");
328
- DataGraph.prototype.publish("vertexFACharColumn", "", "set", "Vertex FAChar column", function (this: DataGraph) { return this.vertexColumns(); }, { optional: true });
329
- DataGraph.prototype.publish("vertexTooltipColumn", "", "set", "Vertex tooltip column", function (this: DataGraph) { return this.vertexColumns(); }, { optional: true });
330
- DataGraph.prototype.publish("vertexAnnotationColumns", [], "propertyArray", "Annotations", undefined, { autoExpand: AnnotationColumn });
331
- DataGraph.prototype.publish("vertexExpansionFACharColumn", "", "set", "Vertex expansion FAChar column", function (this: DataGraph) { return this.vertexColumns(); }, { optional: true });
332
-
333
- DataGraph.prototype.publish("edgeColumns", [], "any", "Edge columns", undefined, { internal: true });
334
- DataGraph.prototype.publish("edges", [], "any", "Edges (Edges)", undefined, { internal: true });
335
- DataGraph.prototype.publish("edgeIDColumn", "", "set", "Edge ID column", function (this: DataGraph) { return this.edgeColumns(); }, { optional: true });
336
- DataGraph.prototype.publish("edgeLabelColumn", "", "set", "Edge label column", function (this: DataGraph) { return this.edgeColumns(); }, { optional: true });
337
- DataGraph.prototype.publish("edgeSourceColumn", "", "set", "Edge source ID column", function (this: DataGraph) { return this.edgeColumns(); }, { optional: true });
338
- DataGraph.prototype.publish("edgeTargetColumn", "", "set", "Edge target ID column", function (this: DataGraph) { return this.edgeColumns(); }, { optional: true });
339
- DataGraph.prototype.publish("edgeWeightColumn", "", "set", "Edge weight column", function (this: DataGraph) { return this.edgeColumns(); }, { optional: true });
340
- DataGraph.prototype.publish("edgeColorColumn", "", "set", "Edge color column", function (this: DataGraph) { return this.edgeColumns(); }, { optional: true });
341
-
342
- DataGraph.prototype.publish("hierarchyColumns", [], "any", "Subgraph Columns");
343
- DataGraph.prototype.publish("hierarchy", [], "any", "Subgraphs");
344
- DataGraph.prototype.publish("hierarchyParentIDColumn", "", "string", "Subgraph ID column");
345
- DataGraph.prototype.publish("hierarchyChildIDColumn", "", "string", "Subgraph Label column");
1
+ import { PropertyExt, Widget } from "@hpcc-js/common";
2
+ import { Vertex3, CentroidVertex3, Vertex3Props, EdgeProps, SubgraphProps } from "@hpcc-js/react";
3
+ import { compare2 } from "@hpcc-js/util";
4
+ import { GraphReact } from "./graphReact.ts";
5
+ import { HierarchyBase } from "../common/layouts/placeholders.ts";
6
+
7
+ // Backward compatibility layer ---
8
+ export type IVertex3 = Vertex3Props;
9
+
10
+ export function toJsonObj<T>(row, columns): T {
11
+ const retVal: T = {} as T;
12
+ columns.forEach((c, i) => retVal[c] = row[i]);
13
+ return retVal;
14
+ }
15
+
16
+ export class AnnotationColumn extends PropertyExt {
17
+
18
+ protected _owner: DataGraph;
19
+ owner(): DataGraph;
20
+ owner(_: DataGraph): this;
21
+ owner(_?: DataGraph): DataGraph | this {
22
+ if (!arguments.length) return this._owner;
23
+ this._owner = _!;
24
+ return this;
25
+ }
26
+
27
+ valid(): boolean {
28
+ return !!this.columnID();
29
+ }
30
+ }
31
+ AnnotationColumn.prototype._class += " graph_AnnotationColumn";
32
+
33
+ export interface AnnotationColumn {
34
+ columnID(): string;
35
+ columnID(_: string): this;
36
+ annotationID(): string;
37
+ annotationID(_: string): this;
38
+ }
39
+
40
+ AnnotationColumn.prototype.publish("columnID", "", "set", "Annotation column (boolean)", function (this: AnnotationColumn) { return this._owner.vertexColumns(); });
41
+ AnnotationColumn.prototype.publish("annotationID", "", "string", "Annotation ID");
42
+
43
+ export class DataGraph extends GraphReact {
44
+
45
+ constructor() {
46
+ super();
47
+ this
48
+ .vertexRenderer(Vertex3)
49
+ .centroidRenderer(CentroidVertex3)
50
+ .edgeColor("#287EC4")
51
+ .edgeStrokeWidth(2)
52
+ .edgeArcDepth(0)
53
+ ;
54
+ }
55
+
56
+ clear() {
57
+ this._prevSubgraphs = [];
58
+ this._masterSubgraphs = [];
59
+ this._masterSubgraphsMap = {};
60
+
61
+ this._prevVertices = [];
62
+ this._masterVertices = [];
63
+ this._masterVerticesMap = {};
64
+
65
+ this._prevEdges = [];
66
+ this._masterEdges = [];
67
+
68
+ this._prevHierarchy = [];
69
+ this._masterHierarchy = [];
70
+ this._masterHierarchyMap = {};
71
+
72
+ this._graphData.clear();
73
+ this.resetLayout();
74
+ }
75
+
76
+ indexOf(columns: readonly string[], column: string, defColumn: string = ""): number {
77
+ const retVal = columns.indexOf(column);
78
+ return retVal >= 0 ? retVal : columns.indexOf(defColumn);
79
+ }
80
+
81
+ private _prevSubgraphs: readonly SubgraphProps[] = [];
82
+ private _masterSubgraphs: SubgraphProps[] = [];
83
+ private _masterSubgraphsMap: { [key: string]: SubgraphProps } = {};
84
+ mergeSubgraphs() {
85
+ const columns = this.subgraphColumns();
86
+ const idIdx = this.indexOf(columns, this.subgraphIDColumn(), "id");
87
+ const labelIdx = this.indexOf(columns, this.subgraphLabelColumn(), "label");
88
+ const subgraphs = this.subgraphs().map((sg): SubgraphProps => {
89
+ return {
90
+ id: "" + sg[idIdx],
91
+ text: "" + sg[labelIdx],
92
+ origData: toJsonObj<SubgraphProps>(sg, columns)
93
+ };
94
+ });
95
+ const diff = compare2(this._prevSubgraphs, subgraphs, d => d.id);
96
+ diff.exit.forEach(item => {
97
+ this._masterSubgraphs = this._masterSubgraphs.filter(i => i.id !== item.id);
98
+ delete this._masterSubgraphsMap[item.id];
99
+ });
100
+ diff.enter.forEach(item => {
101
+ this._masterSubgraphs.push(item);
102
+ this._masterSubgraphsMap[item.id] = item;
103
+ });
104
+ diff.update.forEach(item => {
105
+ this._masterSubgraphsMap[item.id].origData = item.origData;
106
+ });
107
+ this._prevSubgraphs = subgraphs;
108
+ }
109
+
110
+ private _prevVertices: readonly IVertex3[] = [];
111
+ private _masterVertices: IVertex3[] = [];
112
+ private _masterVerticesMap: { [key: string]: IVertex3 } = {};
113
+ mergeVertices() {
114
+ const columns = this.vertexColumns();
115
+ const annotationColumns = this.vertexAnnotationColumns();
116
+ const catIdx = this.indexOf(columns, this.vertexCategoryColumn(), "category");
117
+ const idIdx = this.indexOf(columns, this.vertexIDColumn(), "id");
118
+ const labelIdx = this.indexOf(columns, this.vertexLabelColumn(), "label");
119
+ const centroidIdx = this.indexOf(columns, this.vertexCentroidColumn(), "centroid");
120
+ const imageUrlIdx = this.indexOf(columns, this.vertexImageUrlColumn(), "faChar");
121
+ const faCharIdx = this.indexOf(columns, this.vertexFACharColumn(), "faChar");
122
+ const vertexTooltipIdx = this.indexOf(columns, this.vertexTooltipColumn(), "tooltip");
123
+ const annotationIdxs = annotationColumns.map(ac => this.indexOf(columns, ac.columnID(), ""));
124
+ const expansionFACharIdx = this.indexOf(columns, this.vertexExpansionFACharColumn(), "expansionFAChar");
125
+ const vertices: IVertex3[] = this.vertices().map((v): IVertex3 => {
126
+ const annotationIDs = annotationIdxs.map((ai, i) => !!v[ai] ? annotationColumns[i].annotationID() : undefined).filter(a => !!a);
127
+ return {
128
+ categoryID: "" + v[catIdx],
129
+ id: "" + v[idIdx],
130
+ text: "" + v[labelIdx],
131
+ tooltip: "" + v[vertexTooltipIdx],
132
+ origData: toJsonObj(v, columns),
133
+ centroid: !!v[centroidIdx],
134
+ icon: {
135
+ imageUrl: "" + (v[imageUrlIdx] || this.vertexImageUrl()),
136
+ imageChar: "" + (v[faCharIdx] || this.vertexFAChar())
137
+ },
138
+ annotationIDs,
139
+ annotations: this.annotations().filter(ann => annotationIDs.indexOf(ann.id) >= 0),
140
+ expansionIcon: v[expansionFACharIdx] ? {
141
+ imageChar: "" + v[expansionFACharIdx]
142
+ } : undefined
143
+ } as IVertex3;
144
+ });
145
+ const diff = compare2(this._prevVertices, vertices, d => d.id);
146
+ diff.exit.forEach(item => {
147
+ this._masterVertices = this._masterVertices.filter(i => i.id !== item.id);
148
+ delete this._masterVerticesMap[item.id];
149
+ });
150
+ diff.enter.forEach(item => {
151
+ this._masterVertices.push(item);
152
+ this._masterVerticesMap[item.id] = item;
153
+ });
154
+ diff.update.forEach(item => {
155
+ this._masterVerticesMap[item.id].origData = item.origData;
156
+ });
157
+ this._prevVertices = vertices;
158
+ }
159
+
160
+ protected _prevEdges: readonly EdgeProps<IVertex3>[] = [];
161
+ protected _masterEdges: EdgeProps<IVertex3>[] = [];
162
+ private _masterEdgesMap: { [key: string]: EdgeProps<IVertex3> } = {};
163
+ mergeEdges() {
164
+ const columns = this.edgeColumns();
165
+ const idIdx = this.indexOf(columns, this.edgeIDColumn(), "id");
166
+ const sourceIdx = this.indexOf(columns, this.edgeSourceColumn(), "source");
167
+ const targetIdx = this.indexOf(columns, this.edgeTargetColumn(), "target");
168
+ const labelIdx = this.indexOf(columns, this.edgeLabelColumn(), "label");
169
+ const weightIdx = this.indexOf(columns, this.edgeWeightColumn(), "weight");
170
+ const colorIdx = this.indexOf(columns, this.edgeColorColumn(), "color");
171
+ const edges: EdgeProps<IVertex3>[] = this.edges().map((e): EdgeProps<IVertex3> => {
172
+ const source = this._masterVerticesMap["" + e[sourceIdx]];
173
+ if (!source) console.error(`Invalid edge source entity "${e[sourceIdx]}" does not exist.`);
174
+ const target = this._masterVerticesMap["" + e[targetIdx]];
175
+ if (!target) console.error(`Invalid edge target entity "${e[targetIdx]}" does not exist.`);
176
+ return {
177
+ id: idIdx >= 0 ? "" + e[idIdx] : "" + e[sourceIdx] + "->" + e[targetIdx],
178
+ source,
179
+ target,
180
+ weight: +e[weightIdx] || 1,
181
+ stroke: e[colorIdx] as string,
182
+ label: labelIdx >= 0 ? ("" + e[labelIdx]) : "",
183
+ origData: toJsonObj(e, columns),
184
+ labelPos: [0, 0],
185
+ path: ""
186
+ };
187
+ }).filter(e => e.source && e.target);
188
+ const diff = compare2(this._masterEdges, edges, d => d.id);
189
+ diff.exit.forEach(item => {
190
+ this._masterEdges = this._masterEdges.filter(i => i.id !== item.id);
191
+ delete this._masterEdgesMap[item.id];
192
+ });
193
+ diff.enter.forEach(item => {
194
+ this._masterEdges.push(item);
195
+ this._masterEdgesMap[item.id] = item;
196
+
197
+ });
198
+ diff.update.forEach(item => {
199
+ this._masterEdgesMap[item.id].origData = item.origData;
200
+ });
201
+ this._prevEdges = edges;
202
+ }
203
+
204
+ private _prevHierarchy: readonly HierarchyBase<SubgraphProps, IVertex3>[] = [];
205
+ private _masterHierarchy: HierarchyBase<SubgraphProps, IVertex3>[] = [];
206
+ private _masterHierarchyMap: { [key: string]: HierarchyBase<SubgraphProps, IVertex3> } = {};
207
+ mergeHierarchy() {
208
+ const columns = this.hierarchyColumns();
209
+ const parentIDIdx = this.indexOf(columns, this.hierarchyParentIDColumn(), "parentID");
210
+ const childIDIdx = this.indexOf(columns, this.hierarchyChildIDColumn(), "childID");
211
+ const hierarchy: HierarchyBase<SubgraphProps, IVertex3>[] = this.hierarchy().map((h): HierarchyBase<SubgraphProps, IVertex3> => {
212
+ return {
213
+ id: "" + h[parentIDIdx] + "=>" + h[childIDIdx],
214
+ parent: this._masterSubgraphsMap["" + h[parentIDIdx]] as SubgraphProps,
215
+ child: this._masterSubgraphsMap["" + h[childIDIdx]] || this._masterVerticesMap["" + h[childIDIdx]]
216
+ };
217
+ });
218
+ const diff = compare2(this._prevHierarchy, hierarchy, d => d.id);
219
+ diff.exit.forEach(item => {
220
+ this._masterHierarchy = this._masterHierarchy.filter(i => i.id !== item.id);
221
+ delete this._masterHierarchyMap[item.id];
222
+ });
223
+ diff.enter.forEach(item => {
224
+ this._masterHierarchy.push(item);
225
+ this._masterHierarchyMap[item.id] = item;
226
+ });
227
+ this._prevHierarchy = hierarchy;
228
+ }
229
+
230
+ update(domNode, element) {
231
+ this.mergeSubgraphs();
232
+ this.mergeVertices();
233
+ this.mergeEdges();
234
+ this.mergeHierarchy();
235
+ this.data({ subgraphs: this._masterSubgraphs, vertices: this._masterVertices, edges: this._masterEdges, hierarchy: this._masterHierarchy });
236
+ super.update(domNode, element);
237
+ }
238
+
239
+ render(callback?: (w: Widget) => void): this {
240
+ super.render(w => {
241
+ if (callback) {
242
+ callback(w);
243
+ }
244
+ });
245
+ return this;
246
+ }
247
+ }
248
+ DataGraph.prototype._class += " graph_DataGraph";
249
+
250
+ export interface DataGraph {
251
+ subgraphColumns(): string[];
252
+ subgraphColumns(_: string[]): this;
253
+ subgraphs(): Array<Array<string | number | boolean>>;
254
+ subgraphs(_: Array<Array<string | number | boolean>>): this;
255
+ subgraphIDColumn(): string;
256
+ subgraphIDColumn(_: string): this;
257
+ subgraphLabelColumn(): string;
258
+ subgraphLabelColumn(_: string): this;
259
+
260
+ vertexColumns(): string[];
261
+ vertexColumns(_: string[]): this;
262
+ vertices(): Array<Array<string | number | boolean>>;
263
+ vertices(_: Array<Array<string | number | boolean>>): this;
264
+ vertexCategoryColumn(): string;
265
+ vertexCategoryColumn(_: string): this;
266
+ vertexIDColumn(): string;
267
+ vertexIDColumn(_: string): this;
268
+ vertexLabelColumn(): string;
269
+ vertexLabelColumn(_: string): this;
270
+ vertexCentroidColumn(): string;
271
+ vertexCentroidColumn(_: string): this;
272
+ vertexImageUrl(): string;
273
+ vertexImageUrl(_: string): this;
274
+ vertexImageUrlColumn(): string;
275
+ vertexImageUrlColumn(_: string): this;
276
+ vertexFAChar(): string;
277
+ vertexFAChar(_: string): this;
278
+ vertexFACharColumn(): string;
279
+ vertexFACharColumn(_: string): this;
280
+ vertexTooltipColumn(): string;
281
+ vertexTooltipColumn(_: string): this;
282
+ vertexAnnotationColumns(): AnnotationColumn[];
283
+ vertexAnnotationColumns(_: AnnotationColumn[]): this;
284
+ vertexExpansionFACharColumn(): string;
285
+ vertexExpansionFACharColumn(_: string): this;
286
+
287
+ edgeColumns(): string[];
288
+ edgeColumns(_: string[]): this;
289
+ edges(): Array<Array<string | number | boolean>>;
290
+ edges(_: Array<Array<string | number | boolean>>): this;
291
+ edgeIDColumn(): string;
292
+ edgeIDColumn(_: string): this;
293
+ edgeLabelColumn(): string;
294
+ edgeLabelColumn(_: string): this;
295
+ edgeSourceColumn(): string;
296
+ edgeSourceColumn(_: string): this;
297
+ edgeTargetColumn(): string;
298
+ edgeTargetColumn(_: string): this;
299
+ edgeWeightColumn(): string;
300
+ edgeWeightColumn(_: string): this;
301
+ edgeColorColumn(): string;
302
+ edgeColorColumn(_: string): this;
303
+
304
+ hierarchyColumns(): string[];
305
+ hierarchyColumns(_: string[]): this;
306
+ hierarchy(): Array<Array<string | number | boolean>>;
307
+ hierarchy(_: Array<Array<string | number | boolean>>): this;
308
+ hierarchyParentIDColumn(): string;
309
+ hierarchyParentIDColumn(_: string): this;
310
+ hierarchyChildIDColumn(): string;
311
+ hierarchyChildIDColumn(_: string): this;
312
+ }
313
+
314
+ DataGraph.prototype.publish("subgraphColumns", [], "any", "Subgraph Columns", undefined, { internal: true });
315
+ DataGraph.prototype.publish("subgraphs", [], "any", "Subgraphs", undefined, { internal: true });
316
+ DataGraph.prototype.publish("subgraphIDColumn", "", "string", "Subgraph ID column");
317
+ DataGraph.prototype.publish("subgraphLabelColumn", "", "string", "Subgraph Label column");
318
+
319
+ DataGraph.prototype.publish("vertexColumns", [], "any", "Vertex Columns", undefined, { internal: true });
320
+ DataGraph.prototype.publish("vertices", [], "any", "Vertices (Nodes)", undefined, { internal: true });
321
+ DataGraph.prototype.publish("vertexCategoryColumn", "", "set", "Vertex Category ID column", function (this: DataGraph) { return this.vertexColumns(); }, { optional: true });
322
+ DataGraph.prototype.publish("vertexIDColumn", "", "set", "Vertex ID column", function (this: DataGraph) { return this.vertexColumns(); }, { optional: true });
323
+ DataGraph.prototype.publish("vertexLabelColumn", "", "set", "Vertex label column", function (this: DataGraph) { return this.vertexColumns(); }, { optional: true });
324
+ DataGraph.prototype.publish("vertexCentroidColumn", "", "set", "Vertex centroid column (boolean)", function (this: DataGraph) { return this.vertexColumns(); }, { optional: true });
325
+ DataGraph.prototype.publish("vertexImageUrl", "", "string", "Vertex default image url");
326
+ DataGraph.prototype.publish("vertexImageUrlColumn", "", "set", "Vertex image url column", function (this: DataGraph) { return this.vertexColumns(); }, { optional: true });
327
+ DataGraph.prototype.publish("vertexFAChar", "?", "string", "Vertex default FAChar");
328
+ DataGraph.prototype.publish("vertexFACharColumn", "", "set", "Vertex FAChar column", function (this: DataGraph) { return this.vertexColumns(); }, { optional: true });
329
+ DataGraph.prototype.publish("vertexTooltipColumn", "", "set", "Vertex tooltip column", function (this: DataGraph) { return this.vertexColumns(); }, { optional: true });
330
+ DataGraph.prototype.publish("vertexAnnotationColumns", [], "propertyArray", "Annotations", undefined, { autoExpand: AnnotationColumn });
331
+ DataGraph.prototype.publish("vertexExpansionFACharColumn", "", "set", "Vertex expansion FAChar column", function (this: DataGraph) { return this.vertexColumns(); }, { optional: true });
332
+
333
+ DataGraph.prototype.publish("edgeColumns", [], "any", "Edge columns", undefined, { internal: true });
334
+ DataGraph.prototype.publish("edges", [], "any", "Edges (Edges)", undefined, { internal: true });
335
+ DataGraph.prototype.publish("edgeIDColumn", "", "set", "Edge ID column", function (this: DataGraph) { return this.edgeColumns(); }, { optional: true });
336
+ DataGraph.prototype.publish("edgeLabelColumn", "", "set", "Edge label column", function (this: DataGraph) { return this.edgeColumns(); }, { optional: true });
337
+ DataGraph.prototype.publish("edgeSourceColumn", "", "set", "Edge source ID column", function (this: DataGraph) { return this.edgeColumns(); }, { optional: true });
338
+ DataGraph.prototype.publish("edgeTargetColumn", "", "set", "Edge target ID column", function (this: DataGraph) { return this.edgeColumns(); }, { optional: true });
339
+ DataGraph.prototype.publish("edgeWeightColumn", "", "set", "Edge weight column", function (this: DataGraph) { return this.edgeColumns(); }, { optional: true });
340
+ DataGraph.prototype.publish("edgeColorColumn", "", "set", "Edge color column", function (this: DataGraph) { return this.edgeColumns(); }, { optional: true });
341
+
342
+ DataGraph.prototype.publish("hierarchyColumns", [], "any", "Subgraph Columns");
343
+ DataGraph.prototype.publish("hierarchy", [], "any", "Subgraphs");
344
+ DataGraph.prototype.publish("hierarchyParentIDColumn", "", "string", "Subgraph ID column");
345
+ DataGraph.prototype.publish("hierarchyChildIDColumn", "", "string", "Subgraph Label column");