@hpcc-js/graph 2.87.3 → 2.87.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 (60) hide show
  1. package/LICENSE +43 -43
  2. package/README.md +256 -256
  3. package/dist/index.es6.js +5 -5
  4. package/dist/index.es6.js.map +1 -1
  5. package/dist/index.js +5 -5
  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 +9 -9
  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
  58. package/types/__package__.d.ts +2 -2
  59. package/types/__package__.d.ts.map +1 -1
  60. package/types-3.4/__package__.d.ts +2 -2
@@ -1,7 +1,7 @@
1
- export * from "./circle";
2
- export * from "./dagre";
3
- export * from "./forceDirected";
4
- export * from "./geoForceDirected";
5
- export * from "./graphviz";
6
- export type { ILayout } from "./layout";
7
- export * from "./null";
1
+ export * from "./circle";
2
+ export * from "./dagre";
3
+ export * from "./forceDirected";
4
+ export * from "./geoForceDirected";
5
+ export * from "./graphviz";
6
+ export type { ILayout } from "./layout";
7
+ export * from "./null";
@@ -1,105 +1,105 @@
1
- import { Graph2 as GraphCollection } from "@hpcc-js/util";
2
- import { curveBasis as d3CurveBasis, curveCardinal as d3CurveCardinal, line as d3Line } from "d3-shape";
3
- import { EdgePlaceholder, SubgraphPlaceholder, VertexPlaceholder } from "./placeholders";
4
- import { EdgeLayout } from "./tree";
5
-
6
- export type Point = [number, number];
7
-
8
- const lineBasis = d3Line<Point>()
9
- .x(d => d[0])
10
- .y(d => d[1])
11
- .curve(d3CurveBasis)
12
- ;
13
-
14
- const lineCardinal = d3Line<Point>()
15
- .x(d => d[0])
16
- .y(d => d[1])
17
- .curve(d3CurveCardinal)
18
- ;
19
-
20
- export interface ILayout {
21
- start(): Promise<this>;
22
- stop(): this;
23
- running(): boolean;
24
-
25
- edgePath(e: EdgePlaceholder, curveDepth: number): EdgeLayout;
26
- }
27
-
28
- export type Size = { width: number, height: number };
29
- export interface IGraph {
30
- size(): Size;
31
- graphData(): GraphCollection<VertexPlaceholder, EdgePlaceholder, SubgraphPlaceholder>;
32
-
33
- project(pos: number, clip: boolean);
34
- projectPlacholder(vp: VertexPlaceholder);
35
-
36
- moveSubgraphs(transition: boolean): this;
37
-
38
- moveVertexPlaceholder(vp: VertexPlaceholder, transition: boolean, moveEdges: boolean): this;
39
- moveVertices(transition: boolean): this;
40
-
41
- moveEdgePlaceholder(ep: EdgePlaceholder, transition: boolean): this;
42
- moveEdges(transition: boolean): this;
43
-
44
- progress(what: "start" | "stop" | "layout-start" | "layout-tick" | "layout-stop");
45
- }
46
-
47
- export class Layout implements ILayout {
48
-
49
- protected _graph: IGraph;
50
- protected _running = false;
51
-
52
- constructor(graph: IGraph) {
53
- this._graph = graph;
54
- }
55
-
56
- start(): Promise<this> {
57
- this._running = true;
58
- this._graph.progress("layout-start");
59
- return Promise.resolve(this);
60
- }
61
-
62
- stop() {
63
- this._running = false;
64
- this._graph.progress("layout-stop");
65
- return this;
66
- }
67
-
68
- running(): boolean {
69
- return this._running;
70
- }
71
-
72
- protected center(points: Point[]): Point {
73
- if (points.length % 2 === 1) {
74
- return points[Math.floor(points.length / 2)];
75
- }
76
- const p1 = points[points.length / 2 - 1];
77
- const p2 = points[points.length / 2];
78
- return [(p1[0] + p2[0]) / 2, (p1[1] + p2[1]) / 2];
79
- }
80
-
81
- edgePath(ep: EdgePlaceholder, curveDepth: number): { path: string, labelPos: Point } {
82
- const sPos = this._graph.projectPlacholder(ep.source);
83
- const tPos = this._graph.projectPlacholder(ep.target);
84
- const points: Point[] = [[sPos.x, sPos.y], [tPos.x, tPos.y]];
85
-
86
- if (curveDepth) {
87
- const dx = points[0][0] - points[1][0];
88
- const dy = points[0][1] - points[1][1];
89
- const dist = Math.sqrt(dx * dx + dy * dy);
90
- if (dist) {
91
- const midX = (points[0][0] + points[1][0]) / 2 - dy * curveDepth / 100;
92
- const midY = (points[0][1] + points[1][1]) / 2 + dx * curveDepth / 100;
93
- return {
94
- path: lineCardinal([points[0], [midX, midY], points[1]]),
95
- labelPos: [midX, midY]
96
- };
97
- }
98
- }
99
-
100
- return {
101
- path: lineBasis(points),
102
- labelPos: this.center(points)
103
- };
104
- }
105
- }
1
+ import { Graph2 as GraphCollection } from "@hpcc-js/util";
2
+ import { curveBasis as d3CurveBasis, curveCardinal as d3CurveCardinal, line as d3Line } from "d3-shape";
3
+ import { EdgePlaceholder, SubgraphPlaceholder, VertexPlaceholder } from "./placeholders";
4
+ import { EdgeLayout } from "./tree";
5
+
6
+ export type Point = [number, number];
7
+
8
+ const lineBasis = d3Line<Point>()
9
+ .x(d => d[0])
10
+ .y(d => d[1])
11
+ .curve(d3CurveBasis)
12
+ ;
13
+
14
+ const lineCardinal = d3Line<Point>()
15
+ .x(d => d[0])
16
+ .y(d => d[1])
17
+ .curve(d3CurveCardinal)
18
+ ;
19
+
20
+ export interface ILayout {
21
+ start(): Promise<this>;
22
+ stop(): this;
23
+ running(): boolean;
24
+
25
+ edgePath(e: EdgePlaceholder, curveDepth: number): EdgeLayout;
26
+ }
27
+
28
+ export type Size = { width: number, height: number };
29
+ export interface IGraph {
30
+ size(): Size;
31
+ graphData(): GraphCollection<VertexPlaceholder, EdgePlaceholder, SubgraphPlaceholder>;
32
+
33
+ project(pos: number, clip: boolean);
34
+ projectPlacholder(vp: VertexPlaceholder);
35
+
36
+ moveSubgraphs(transition: boolean): this;
37
+
38
+ moveVertexPlaceholder(vp: VertexPlaceholder, transition: boolean, moveEdges: boolean): this;
39
+ moveVertices(transition: boolean): this;
40
+
41
+ moveEdgePlaceholder(ep: EdgePlaceholder, transition: boolean): this;
42
+ moveEdges(transition: boolean): this;
43
+
44
+ progress(what: "start" | "stop" | "layout-start" | "layout-tick" | "layout-stop");
45
+ }
46
+
47
+ export class Layout implements ILayout {
48
+
49
+ protected _graph: IGraph;
50
+ protected _running = false;
51
+
52
+ constructor(graph: IGraph) {
53
+ this._graph = graph;
54
+ }
55
+
56
+ start(): Promise<this> {
57
+ this._running = true;
58
+ this._graph.progress("layout-start");
59
+ return Promise.resolve(this);
60
+ }
61
+
62
+ stop() {
63
+ this._running = false;
64
+ this._graph.progress("layout-stop");
65
+ return this;
66
+ }
67
+
68
+ running(): boolean {
69
+ return this._running;
70
+ }
71
+
72
+ protected center(points: Point[]): Point {
73
+ if (points.length % 2 === 1) {
74
+ return points[Math.floor(points.length / 2)];
75
+ }
76
+ const p1 = points[points.length / 2 - 1];
77
+ const p2 = points[points.length / 2];
78
+ return [(p1[0] + p2[0]) / 2, (p1[1] + p2[1]) / 2];
79
+ }
80
+
81
+ edgePath(ep: EdgePlaceholder, curveDepth: number): { path: string, labelPos: Point } {
82
+ const sPos = this._graph.projectPlacholder(ep.source);
83
+ const tPos = this._graph.projectPlacholder(ep.target);
84
+ const points: Point[] = [[sPos.x, sPos.y], [tPos.x, tPos.y]];
85
+
86
+ if (curveDepth) {
87
+ const dx = points[0][0] - points[1][0];
88
+ const dy = points[0][1] - points[1][1];
89
+ const dist = Math.sqrt(dx * dx + dy * dy);
90
+ if (dist) {
91
+ const midX = (points[0][0] + points[1][0]) / 2 - dy * curveDepth / 100;
92
+ const midY = (points[0][1] + points[1][1]) / 2 + dx * curveDepth / 100;
93
+ return {
94
+ path: lineCardinal([points[0], [midX, midY], points[1]]),
95
+ labelPos: [midX, midY]
96
+ };
97
+ }
98
+ }
99
+
100
+ return {
101
+ path: lineBasis(points),
102
+ labelPos: this.center(points)
103
+ };
104
+ }
105
+ }
@@ -1,35 +1,35 @@
1
- import { Layout } from "./layout";
2
-
3
- export class Null extends Layout {
4
-
5
- start(): Promise<this> {
6
- return super.start().then(() => {
7
- this.stop();
8
- return this;
9
- });
10
- }
11
- }
12
-
13
- export class Initial extends Layout {
14
-
15
- start(): Promise<this> {
16
- return super.start().then(() => {
17
- const size = this._graph.size();
18
- const data = this._graph.graphData();
19
- data.allEdges().forEach(e => delete e.points);
20
- // Avoid edges of 0 length ---
21
- data.allVertices().forEach(v => {
22
- delete v.fx;
23
- delete v.fy;
24
- v.x = size.width / 2 + Math.random() * 5 - 2.5;
25
- v.y = size.height / 2 + Math.random() * 5 - 2.5;
26
- });
27
- this._graph
28
- .moveVertices(true)
29
- .moveEdges(true)
30
- ;
31
- this.stop();
32
- return this;
33
- });
34
- }
35
- }
1
+ import { Layout } from "./layout";
2
+
3
+ export class Null extends Layout {
4
+
5
+ start(): Promise<this> {
6
+ return super.start().then(() => {
7
+ this.stop();
8
+ return this;
9
+ });
10
+ }
11
+ }
12
+
13
+ export class Initial extends Layout {
14
+
15
+ start(): Promise<this> {
16
+ return super.start().then(() => {
17
+ const size = this._graph.size();
18
+ const data = this._graph.graphData();
19
+ data.allEdges().forEach(e => delete e.points);
20
+ // Avoid edges of 0 length ---
21
+ data.allVertices().forEach(v => {
22
+ delete v.fx;
23
+ delete v.fy;
24
+ v.x = size.width / 2 + Math.random() * 5 - 2.5;
25
+ v.y = size.height / 2 + Math.random() * 5 - 2.5;
26
+ });
27
+ this._graph
28
+ .moveVertices(true)
29
+ .moveEdges(true)
30
+ ;
31
+ this.stop();
32
+ return this;
33
+ });
34
+ }
35
+ }
@@ -1,103 +1,103 @@
1
- import { Selection } from "@hpcc-js/common";
2
-
3
- export interface BaseProps {
4
- id: string | number;
5
- origData?: any;
6
- }
7
-
8
- export interface VertexBaseProps extends BaseProps {
9
- text: string;
10
- categoryID?: string;
11
- centroid?: boolean;
12
- hidden?: boolean;
13
- tooltip?: string;
14
- annotationIDs?: string[];
15
- }
16
-
17
- export interface SubgraphBaseProps extends BaseProps {
18
- text: string;
19
- width?: number;
20
- height?: number;
21
- }
22
-
23
- export type Point = [number, number];
24
-
25
- export interface EdgeBaseProps<V extends VertexBaseProps = VertexBaseProps> extends BaseProps {
26
- source: V;
27
- target: V;
28
- label?: string;
29
- labelPos?: Point;
30
- weight?: number;
31
- strokeDasharray?: string;
32
- strokeWidth?: number;
33
- stroke?: string;
34
- fontFamily?: string;
35
- }
36
-
37
- export interface HierarchyBase<SG extends SubgraphBaseProps, V extends VertexBaseProps> {
38
- id: string | number;
39
- parent: SG;
40
- child: SG | V;
41
- }
42
-
43
- export interface GraphDataProps<SG extends SubgraphBaseProps, V extends VertexBaseProps, E extends EdgeBaseProps<V>> {
44
- subgraphs?: SG[];
45
- vertices: V[];
46
- edges: E[];
47
- hierarchy?: HierarchyBase<SG, V>[];
48
- }
49
-
50
- export interface SubgraphPlaceholder<SG extends SubgraphBaseProps = SubgraphBaseProps> {
51
- id: string | number;
52
- element?: Selection<SVGGElement, SubgraphPlaceholder<SG>, SVGGElement, any>;
53
- props: SG;
54
-
55
- // Dagre / Graphviz Properties ---
56
- x?: number; // The node’s current x-position
57
- y?: number; // The node’s current y-position
58
- }
59
-
60
- export interface VertexPlaceholder<V extends VertexBaseProps = VertexBaseProps> {
61
- id: string | number;
62
- element?: Selection<SVGGElement, VertexPlaceholder<V>, SVGGElement, any>;
63
- props: V;
64
-
65
- // D3 Assigned Properties ---
66
- index?: number; // The node’s zero-based index into nodes
67
- x?: number; // The node’s current x-position
68
- y?: number; // The node’s current y-position
69
- fx?: number; // The node’s fixed x-position
70
- fy?: number; // The node’s fixed y-position
71
- vx?: number; // The node’s current x-velocity
72
- vy?: number; // The node’s current y-velocity
73
-
74
- // HPCC Drag /Drop Assigned Properties ---
75
- sx?: number; // The node’s drag start x
76
- sy?: number; // The node’s drag start y
77
-
78
- // Dagre / Graphviz Properties ---
79
-
80
- // Geo Locations ---
81
- lat?: number;
82
- lng?: number;
83
- }
84
-
85
- export interface EdgePlaceholder<V extends VertexBaseProps = VertexBaseProps, E extends EdgeBaseProps<V> = EdgeBaseProps<V>> {
86
- id: string | number;
87
- element?: Selection<SVGGElement, EdgePlaceholder<V, E>, SVGGElement, any>;
88
- elementPath?: Selection<SVGPathElement, EdgePlaceholder<V, E>, SVGGElement, any>;
89
- elementText?: Selection<SVGTextElement, EdgePlaceholder<V, E>, SVGGElement, any>;
90
- props: E;
91
- source: VertexPlaceholder<V>; // The link’s source node
92
- target: VertexPlaceholder<V>; // The link’s target node
93
-
94
- // D3 Assigned Properties ---
95
- index?: number; // The zero-based index into links, assigned by this method
96
-
97
- // Dagre Assigned Properties ---
98
- points?: Array<[number, number]>;
99
- }
100
-
101
- export function isEdgePlaceholder<V extends VertexBaseProps = VertexBaseProps, E extends EdgeBaseProps<V> = EdgeBaseProps<V>>(item): item is EdgePlaceholder<V, E> {
102
- return item.id !== undefined && item.props !== undefined && item.source !== undefined && item.target !== undefined;
103
- }
1
+ import { Selection } from "@hpcc-js/common";
2
+
3
+ export interface BaseProps {
4
+ id: string | number;
5
+ origData?: any;
6
+ }
7
+
8
+ export interface VertexBaseProps extends BaseProps {
9
+ text: string;
10
+ categoryID?: string;
11
+ centroid?: boolean;
12
+ hidden?: boolean;
13
+ tooltip?: string;
14
+ annotationIDs?: string[];
15
+ }
16
+
17
+ export interface SubgraphBaseProps extends BaseProps {
18
+ text: string;
19
+ width?: number;
20
+ height?: number;
21
+ }
22
+
23
+ export type Point = [number, number];
24
+
25
+ export interface EdgeBaseProps<V extends VertexBaseProps = VertexBaseProps> extends BaseProps {
26
+ source: V;
27
+ target: V;
28
+ label?: string;
29
+ labelPos?: Point;
30
+ weight?: number;
31
+ strokeDasharray?: string;
32
+ strokeWidth?: number;
33
+ stroke?: string;
34
+ fontFamily?: string;
35
+ }
36
+
37
+ export interface HierarchyBase<SG extends SubgraphBaseProps, V extends VertexBaseProps> {
38
+ id: string | number;
39
+ parent: SG;
40
+ child: SG | V;
41
+ }
42
+
43
+ export interface GraphDataProps<SG extends SubgraphBaseProps, V extends VertexBaseProps, E extends EdgeBaseProps<V>> {
44
+ subgraphs?: SG[];
45
+ vertices: V[];
46
+ edges: E[];
47
+ hierarchy?: HierarchyBase<SG, V>[];
48
+ }
49
+
50
+ export interface SubgraphPlaceholder<SG extends SubgraphBaseProps = SubgraphBaseProps> {
51
+ id: string | number;
52
+ element?: Selection<SVGGElement, SubgraphPlaceholder<SG>, SVGGElement, any>;
53
+ props: SG;
54
+
55
+ // Dagre / Graphviz Properties ---
56
+ x?: number; // The node’s current x-position
57
+ y?: number; // The node’s current y-position
58
+ }
59
+
60
+ export interface VertexPlaceholder<V extends VertexBaseProps = VertexBaseProps> {
61
+ id: string | number;
62
+ element?: Selection<SVGGElement, VertexPlaceholder<V>, SVGGElement, any>;
63
+ props: V;
64
+
65
+ // D3 Assigned Properties ---
66
+ index?: number; // The node’s zero-based index into nodes
67
+ x?: number; // The node’s current x-position
68
+ y?: number; // The node’s current y-position
69
+ fx?: number; // The node’s fixed x-position
70
+ fy?: number; // The node’s fixed y-position
71
+ vx?: number; // The node’s current x-velocity
72
+ vy?: number; // The node’s current y-velocity
73
+
74
+ // HPCC Drag /Drop Assigned Properties ---
75
+ sx?: number; // The node’s drag start x
76
+ sy?: number; // The node’s drag start y
77
+
78
+ // Dagre / Graphviz Properties ---
79
+
80
+ // Geo Locations ---
81
+ lat?: number;
82
+ lng?: number;
83
+ }
84
+
85
+ export interface EdgePlaceholder<V extends VertexBaseProps = VertexBaseProps, E extends EdgeBaseProps<V> = EdgeBaseProps<V>> {
86
+ id: string | number;
87
+ element?: Selection<SVGGElement, EdgePlaceholder<V, E>, SVGGElement, any>;
88
+ elementPath?: Selection<SVGPathElement, EdgePlaceholder<V, E>, SVGGElement, any>;
89
+ elementText?: Selection<SVGTextElement, EdgePlaceholder<V, E>, SVGGElement, any>;
90
+ props: E;
91
+ source: VertexPlaceholder<V>; // The link’s source node
92
+ target: VertexPlaceholder<V>; // The link’s target node
93
+
94
+ // D3 Assigned Properties ---
95
+ index?: number; // The zero-based index into links, assigned by this method
96
+
97
+ // Dagre Assigned Properties ---
98
+ points?: Array<[number, number]>;
99
+ }
100
+
101
+ export function isEdgePlaceholder<V extends VertexBaseProps = VertexBaseProps, E extends EdgeBaseProps<V> = EdgeBaseProps<V>>(item): item is EdgePlaceholder<V, E> {
102
+ return item.id !== undefined && item.props !== undefined && item.source !== undefined && item.target !== undefined;
103
+ }