@deck.gl-community/graph-layers 9.0.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 (210) hide show
  1. package/LICENSE +20 -0
  2. package/README.md +7 -0
  3. package/dist/core/base-layout.d.ts +71 -0
  4. package/dist/core/base-layout.js +133 -0
  5. package/dist/core/cache.d.ts +14 -0
  6. package/dist/core/cache.js +26 -0
  7. package/dist/core/constants.d.ts +101 -0
  8. package/dist/core/constants.js +48 -0
  9. package/dist/core/edge.d.ts +86 -0
  10. package/dist/core/edge.js +121 -0
  11. package/dist/core/graph-engine.d.ts +54 -0
  12. package/dist/core/graph-engine.js +128 -0
  13. package/dist/core/graph.d.ts +155 -0
  14. package/dist/core/graph.js +301 -0
  15. package/dist/core/interaction-manager.d.ts +40 -0
  16. package/dist/core/interaction-manager.js +169 -0
  17. package/dist/core/node.d.ts +103 -0
  18. package/dist/core/node.js +177 -0
  19. package/dist/index.cjs +3540 -0
  20. package/dist/index.cjs.map +7 -0
  21. package/dist/index.d.ts +19 -0
  22. package/dist/index.js +28 -0
  23. package/dist/layers/common-layers/flow-path-layer/flow-path-layer-fragment.glsl.d.ts +1 -0
  24. package/dist/layers/common-layers/flow-path-layer/flow-path-layer-fragment.glsl.js +49 -0
  25. package/dist/layers/common-layers/flow-path-layer/flow-path-layer-vertex-tf.glsl.d.ts +1 -0
  26. package/dist/layers/common-layers/flow-path-layer/flow-path-layer-vertex-tf.glsl.js +14 -0
  27. package/dist/layers/common-layers/flow-path-layer/flow-path-layer-vertex.glsl.d.ts +1 -0
  28. package/dist/layers/common-layers/flow-path-layer/flow-path-layer-vertex.glsl.js +73 -0
  29. package/dist/layers/common-layers/flow-path-layer/flow-path-layer.d.ts +20 -0
  30. package/dist/layers/common-layers/flow-path-layer/flow-path-layer.js +133 -0
  31. package/dist/layers/common-layers/marker-layer/atlas-data-url.d.ts +3 -0
  32. package/dist/layers/common-layers/marker-layer/atlas-data-url.js +8 -0
  33. package/dist/layers/common-layers/marker-layer/marker-layer.d.ts +13 -0
  34. package/dist/layers/common-layers/marker-layer/marker-layer.js +29 -0
  35. package/dist/layers/common-layers/marker-layer/marker-list.d.ts +62 -0
  36. package/dist/layers/common-layers/marker-layer/marker-list.js +67 -0
  37. package/dist/layers/common-layers/marker-layer/marker-mapping.d.ts +422 -0
  38. package/dist/layers/common-layers/marker-layer/marker-mapping.js +427 -0
  39. package/dist/layers/common-layers/spline-layer/spline-layer.d.ts +24 -0
  40. package/dist/layers/common-layers/spline-layer/spline-layer.js +68 -0
  41. package/dist/layers/common-layers/zoomable-text-layer/zoomable-text-layer.d.ts +16 -0
  42. package/dist/layers/common-layers/zoomable-text-layer/zoomable-text-layer.js +65 -0
  43. package/dist/layers/edge-layer.d.ts +25 -0
  44. package/dist/layers/edge-layer.js +75 -0
  45. package/dist/layers/edge-layers/curved-edge-layer.d.ts +6 -0
  46. package/dist/layers/edge-layers/curved-edge-layer.js +69 -0
  47. package/dist/layers/edge-layers/edge-label-layer.d.ts +6 -0
  48. package/dist/layers/edge-layers/edge-label-layer.js +42 -0
  49. package/dist/layers/edge-layers/flow-layer.d.ts +6 -0
  50. package/dist/layers/edge-layers/flow-layer.js +28 -0
  51. package/dist/layers/edge-layers/path-edge-layer.d.ts +6 -0
  52. package/dist/layers/edge-layers/path-edge-layer.js +27 -0
  53. package/dist/layers/edge-layers/straight-line-edge-layer.d.ts +6 -0
  54. package/dist/layers/edge-layers/straight-line-edge-layer.js +26 -0
  55. package/dist/layers/graph-layer.d.ts +32 -0
  56. package/dist/layers/graph-layer.js +193 -0
  57. package/dist/layers/node-layers/circle-layer.d.ts +6 -0
  58. package/dist/layers/node-layers/circle-layer.js +23 -0
  59. package/dist/layers/node-layers/image-layer.d.ts +6 -0
  60. package/dist/layers/node-layers/image-layer.js +23 -0
  61. package/dist/layers/node-layers/label-layer.d.ts +6 -0
  62. package/dist/layers/node-layers/label-layer.js +23 -0
  63. package/dist/layers/node-layers/path-rounded-rectange-layer.d.ts +6 -0
  64. package/dist/layers/node-layers/path-rounded-rectange-layer.js +46 -0
  65. package/dist/layers/node-layers/rectangle-layer.d.ts +6 -0
  66. package/dist/layers/node-layers/rectangle-layer.js +49 -0
  67. package/dist/layers/node-layers/rounded-rectangle-layer-fragment.d.ts +1 -0
  68. package/dist/layers/node-layers/rounded-rectangle-layer-fragment.js +30 -0
  69. package/dist/layers/node-layers/rounded-rectangle-layer.d.ts +8 -0
  70. package/dist/layers/node-layers/rounded-rectangle-layer.js +28 -0
  71. package/dist/layers/node-layers/zoomable-marker-layer.d.ts +10 -0
  72. package/dist/layers/node-layers/zoomable-marker-layer.js +40 -0
  73. package/dist/layouts/d3-force/d3-force-layout.d.ts +24 -0
  74. package/dist/layouts/d3-force/d3-force-layout.js +116 -0
  75. package/dist/layouts/d3-force/worker.d.ts +0 -0
  76. package/dist/layouts/d3-force/worker.js +46 -0
  77. package/dist/layouts/gpu-force/gpu-force-layout.d.ts +30 -0
  78. package/dist/layouts/gpu-force/gpu-force-layout.js +232 -0
  79. package/dist/layouts/gpu-force/worker.d.ts +0 -0
  80. package/dist/layouts/gpu-force/worker.js +116 -0
  81. package/dist/layouts/simple-layout/simple-layout.d.ts +22 -0
  82. package/dist/layouts/simple-layout/simple-layout.js +64 -0
  83. package/dist/loaders/edge-parsers.d.ts +6 -0
  84. package/dist/loaders/edge-parsers.js +17 -0
  85. package/dist/loaders/json-loader.d.ts +7 -0
  86. package/dist/loaders/json-loader.js +16 -0
  87. package/dist/loaders/node-parsers.d.ts +3 -0
  88. package/dist/loaders/node-parsers.js +11 -0
  89. package/dist/style/style-property.d.ts +14 -0
  90. package/dist/style/style-property.js +195 -0
  91. package/dist/style/style-sheet.d.ts +10 -0
  92. package/dist/style/style-sheet.js +252 -0
  93. package/dist/utils/create-graph.d.ts +8 -0
  94. package/dist/utils/create-graph.js +33 -0
  95. package/dist/utils/layer-utils.d.ts +1 -0
  96. package/dist/utils/layer-utils.js +20 -0
  97. package/dist/utils/log.d.ts +2 -0
  98. package/dist/utils/log.js +6 -0
  99. package/dist/utils/polygon-calculations.d.ts +1 -0
  100. package/dist/utils/polygon-calculations.js +102 -0
  101. package/package.json +55 -0
  102. package/src/core/base-layout.ts +154 -0
  103. package/src/core/cache.ts +31 -0
  104. package/src/core/constants.ts +58 -0
  105. package/src/core/edge.ts +145 -0
  106. package/src/core/graph-engine.ts +170 -0
  107. package/src/core/graph.ts +342 -0
  108. package/src/core/interaction-manager.ts +225 -0
  109. package/src/core/node.ts +205 -0
  110. package/src/index.ts +42 -0
  111. package/src/layers/common-layers/flow-path-layer/flow-path-layer-fragment.glsl.ts +50 -0
  112. package/src/layers/common-layers/flow-path-layer/flow-path-layer-vertex-tf.glsl.ts +15 -0
  113. package/src/layers/common-layers/flow-path-layer/flow-path-layer-vertex.glsl.ts +74 -0
  114. package/src/layers/common-layers/flow-path-layer/flow-path-layer.ts +154 -0
  115. package/src/layers/common-layers/marker-layer/atlas-data-url.ts +10 -0
  116. package/src/layers/common-layers/marker-layer/marker-atlas.png +0 -0
  117. package/src/layers/common-layers/marker-layer/marker-layer.ts +36 -0
  118. package/src/layers/common-layers/marker-layer/marker-list.ts +68 -0
  119. package/src/layers/common-layers/marker-layer/marker-mapping.ts +428 -0
  120. package/src/layers/common-layers/marker-layer/markers/bell-filled.png +0 -0
  121. package/src/layers/common-layers/marker-layer/markers/bell.png +0 -0
  122. package/src/layers/common-layers/marker-layer/markers/bookmark-filled.png +0 -0
  123. package/src/layers/common-layers/marker-layer/markers/bookmark.png +0 -0
  124. package/src/layers/common-layers/marker-layer/markers/cd-filled.png +0 -0
  125. package/src/layers/common-layers/marker-layer/markers/cd.png +0 -0
  126. package/src/layers/common-layers/marker-layer/markers/checkmark.png +0 -0
  127. package/src/layers/common-layers/marker-layer/markers/circle-check-filled.png +0 -0
  128. package/src/layers/common-layers/marker-layer/markers/circle-check.png +0 -0
  129. package/src/layers/common-layers/marker-layer/markers/circle-filled.png +0 -0
  130. package/src/layers/common-layers/marker-layer/markers/circle-i-filled.png +0 -0
  131. package/src/layers/common-layers/marker-layer/markers/circle-i.png +0 -0
  132. package/src/layers/common-layers/marker-layer/markers/circle-minus-filled.png +0 -0
  133. package/src/layers/common-layers/marker-layer/markers/circle-minus.png +0 -0
  134. package/src/layers/common-layers/marker-layer/markers/circle-plus-filled.png +0 -0
  135. package/src/layers/common-layers/marker-layer/markers/circle-plus.png +0 -0
  136. package/src/layers/common-layers/marker-layer/markers/circle-questionmark-filled.png +0 -0
  137. package/src/layers/common-layers/marker-layer/markers/circle-questionmark.png +0 -0
  138. package/src/layers/common-layers/marker-layer/markers/circle-slash-filled.png +0 -0
  139. package/src/layers/common-layers/marker-layer/markers/circle-slash.png +0 -0
  140. package/src/layers/common-layers/marker-layer/markers/circle-x-filled.png +0 -0
  141. package/src/layers/common-layers/marker-layer/markers/circle-x.png +0 -0
  142. package/src/layers/common-layers/marker-layer/markers/circle.png +0 -0
  143. package/src/layers/common-layers/marker-layer/markers/diamond-filled.png +0 -0
  144. package/src/layers/common-layers/marker-layer/markers/diamond.png +0 -0
  145. package/src/layers/common-layers/marker-layer/markers/flag-filled.png +0 -0
  146. package/src/layers/common-layers/marker-layer/markers/flag.png +0 -0
  147. package/src/layers/common-layers/marker-layer/markers/gear.png +0 -0
  148. package/src/layers/common-layers/marker-layer/markers/heart-filled.png +0 -0
  149. package/src/layers/common-layers/marker-layer/markers/heart.png +0 -0
  150. package/src/layers/common-layers/marker-layer/markers/location-marker-filled.png +0 -0
  151. package/src/layers/common-layers/marker-layer/markers/location-marker.png +0 -0
  152. package/src/layers/common-layers/marker-layer/markers/octagonal-star-filled.png +0 -0
  153. package/src/layers/common-layers/marker-layer/markers/octagonal-star.png +0 -0
  154. package/src/layers/common-layers/marker-layer/markers/person-filled.png +0 -0
  155. package/src/layers/common-layers/marker-layer/markers/person.png +0 -0
  156. package/src/layers/common-layers/marker-layer/markers/pin-filled.png +0 -0
  157. package/src/layers/common-layers/marker-layer/markers/pin.png +0 -0
  158. package/src/layers/common-layers/marker-layer/markers/plus-small.png +0 -0
  159. package/src/layers/common-layers/marker-layer/markers/plus.png +0 -0
  160. package/src/layers/common-layers/marker-layer/markers/rectangle-filled.png +0 -0
  161. package/src/layers/common-layers/marker-layer/markers/rectangle.png +0 -0
  162. package/src/layers/common-layers/marker-layer/markers/star-filled.png +0 -0
  163. package/src/layers/common-layers/marker-layer/markers/star.png +0 -0
  164. package/src/layers/common-layers/marker-layer/markers/tag-filled.png +0 -0
  165. package/src/layers/common-layers/marker-layer/markers/tag.png +0 -0
  166. package/src/layers/common-layers/marker-layer/markers/thumb-down-filled.png +0 -0
  167. package/src/layers/common-layers/marker-layer/markers/thumb-down.png +0 -0
  168. package/src/layers/common-layers/marker-layer/markers/thumb-up.png +0 -0
  169. package/src/layers/common-layers/marker-layer/markers/thumb_up-filled.png +0 -0
  170. package/src/layers/common-layers/marker-layer/markers/triangle-down-filled.png +0 -0
  171. package/src/layers/common-layers/marker-layer/markers/triangle-down.png +0 -0
  172. package/src/layers/common-layers/marker-layer/markers/triangle-left-filled.png +0 -0
  173. package/src/layers/common-layers/marker-layer/markers/triangle-left.png +0 -0
  174. package/src/layers/common-layers/marker-layer/markers/triangle-right-filled.png +0 -0
  175. package/src/layers/common-layers/marker-layer/markers/triangle-right.png +0 -0
  176. package/src/layers/common-layers/marker-layer/markers/triangle-up-filled.png +0 -0
  177. package/src/layers/common-layers/marker-layer/markers/triangle-up.png +0 -0
  178. package/src/layers/common-layers/marker-layer/markers/x-small.png +0 -0
  179. package/src/layers/common-layers/marker-layer/markers/x.png +0 -0
  180. package/src/layers/common-layers/spline-layer/spline-layer.ts +83 -0
  181. package/src/layers/common-layers/zoomable-text-layer/zoomable-text-layer.ts +90 -0
  182. package/src/layers/edge-layer.ts +88 -0
  183. package/src/layers/edge-layers/curved-edge-layer.ts +88 -0
  184. package/src/layers/edge-layers/edge-label-layer.ts +48 -0
  185. package/src/layers/edge-layers/flow-layer.ts +34 -0
  186. package/src/layers/edge-layers/path-edge-layer.ts +39 -0
  187. package/src/layers/edge-layers/straight-line-edge-layer.ts +38 -0
  188. package/src/layers/graph-layer.ts +225 -0
  189. package/src/layers/node-layers/circle-layer.ts +29 -0
  190. package/src/layers/node-layers/image-layer.ts +29 -0
  191. package/src/layers/node-layers/label-layer.ts +29 -0
  192. package/src/layers/node-layers/path-rounded-rectange-layer.ts +56 -0
  193. package/src/layers/node-layers/rectangle-layer.ts +58 -0
  194. package/src/layers/node-layers/rounded-rectangle-layer-fragment.ts +31 -0
  195. package/src/layers/node-layers/rounded-rectangle-layer.ts +32 -0
  196. package/src/layers/node-layers/zoomable-marker-layer.ts +49 -0
  197. package/src/layouts/d3-force/d3-force-layout.ts +145 -0
  198. package/src/layouts/d3-force/worker.ts +61 -0
  199. package/src/layouts/gpu-force/gpu-force-layout.ts +249 -0
  200. package/src/layouts/gpu-force/worker.ts +137 -0
  201. package/src/layouts/simple-layout/simple-layout.ts +87 -0
  202. package/src/loaders/edge-parsers.ts +21 -0
  203. package/src/loaders/json-loader.ts +19 -0
  204. package/src/loaders/node-parsers.ts +13 -0
  205. package/src/style/style-property.ts +229 -0
  206. package/src/style/style-sheet.ts +277 -0
  207. package/src/utils/create-graph.ts +38 -0
  208. package/src/utils/layer-utils.ts +23 -0
  209. package/src/utils/log.ts +9 -0
  210. package/src/utils/polygon-calculations.ts +154 -0
package/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2015 - 2021 Uber Technologies, Inc.
2
+ Copyright (c) 2022 - 2023 react-graph-layers contributors
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ of this software and associated documentation files (the "Software"), to deal
6
+ in the Software without restriction, including without limitation the rights
7
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the Software is
9
+ furnished to do so, subject to the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be included in
12
+ all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
+ THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,7 @@
1
+ # graph-layers
2
+
3
+ TBD
4
+
5
+ <p align="center">
6
+ <img src="https://i.imgur.com/BF9aOEu.png" height="400" />
7
+ </p>
@@ -0,0 +1,71 @@
1
+ export interface BaseLayoutOptions {
2
+ }
3
+ /**
4
+ * All the layout classes are extended from this base layout class.
5
+ */
6
+ export declare class BaseLayout extends EventTarget {
7
+ /** Name of the layout. */
8
+ protected readonly _name: string;
9
+ /** Extra configuration options of the layout. */
10
+ protected _options: BaseLayoutOptions;
11
+ version: number;
12
+ state: string;
13
+ /**
14
+ * Constructor of BaseLayout
15
+ * @param {Object} options extra configuration options of the layout
16
+ */
17
+ constructor(options?: BaseLayoutOptions);
18
+ /**
19
+ * @fires BaseLayout#onLayoutStart
20
+ * @protected
21
+ */
22
+ _onLayoutStart(): void;
23
+ /**
24
+ * @fires BaseLayout#onLayoutChange
25
+ * @protected
26
+ */
27
+ _onLayoutChange(): void;
28
+ /**
29
+ * @fires BaseLayout#onLayoutDone
30
+ * @protected
31
+ */
32
+ _onLayoutDone(): void;
33
+ /**
34
+ * @fires BaseLayout#onLayoutError
35
+ * @protected
36
+ */
37
+ _onLayoutError(): void;
38
+ /**
39
+ * Check the equality of two layouts
40
+ * @param {Object} layout The layout to be compared.
41
+ * @return {Bool} True if the layout is the same as itself.
42
+ */
43
+ equals(layout: BaseLayout): boolean;
44
+ /** virtual functions: will be implemented in the child class */
45
+ initializeGraph(graph: any): void;
46
+ updateGraph(graph: any): void;
47
+ start(): void;
48
+ update(): void;
49
+ resume(): void;
50
+ stop(): void;
51
+ getNodePosition(node: Node): [number, number];
52
+ getEdgePosition(edge: any): {
53
+ type: string;
54
+ sourcePosition: number[];
55
+ targetPosition: number[];
56
+ controlPoints: any[];
57
+ };
58
+ /**
59
+ * Pin the node to a designated position, and the node won't move anymore
60
+ * @param {Object} node Node to be locked
61
+ * @param {Number} x x coordinate
62
+ * @param {Number} y y coordinate
63
+ */
64
+ lockNodePosition(node: any, x: any, y: any): void;
65
+ /**
66
+ * Unlock the node, the node will be able to move freely.
67
+ * @param {Object} node Node to be unlocked
68
+ */
69
+ unlockNodePosition(node: any): void;
70
+ _updateState(state: any): void;
71
+ }
@@ -0,0 +1,133 @@
1
+ // deck.gl-community
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+ import isEqual from 'lodash.isequal';
5
+ import { EDGE_TYPE, LAYOUT_STATE } from './constants';
6
+ /**
7
+ * All the layout classes are extended from this base layout class.
8
+ */
9
+ export class BaseLayout extends EventTarget {
10
+ /** Name of the layout. */
11
+ _name = 'BaseLayout';
12
+ /** Extra configuration options of the layout. */
13
+ _options;
14
+ version = 0;
15
+ state = LAYOUT_STATE.INIT;
16
+ /**
17
+ * Constructor of BaseLayout
18
+ * @param {Object} options extra configuration options of the layout
19
+ */
20
+ constructor(options = {}) {
21
+ super();
22
+ this._options = options;
23
+ }
24
+ /**
25
+ * @fires BaseLayout#onLayoutStart
26
+ * @protected
27
+ */
28
+ _onLayoutStart() {
29
+ this._updateState(LAYOUT_STATE.CALCULATING);
30
+ /**
31
+ * Layout calculation start.
32
+ *
33
+ * @event BaseLayout#onLayoutChange
34
+ * @type {CustomEvent}
35
+ */
36
+ this.dispatchEvent(new CustomEvent('onLayoutStart'));
37
+ }
38
+ /**
39
+ * @fires BaseLayout#onLayoutChange
40
+ * @protected
41
+ */
42
+ _onLayoutChange() {
43
+ this._updateState(LAYOUT_STATE.CALCULATING);
44
+ /**
45
+ * Layout calculation iteration.
46
+ *
47
+ * @event BaseLayout#onLayoutChange
48
+ * @type {CustomEvent}
49
+ */
50
+ this.dispatchEvent(new CustomEvent('onLayoutChange'));
51
+ }
52
+ /**
53
+ * @fires BaseLayout#onLayoutDone
54
+ * @protected
55
+ */
56
+ _onLayoutDone() {
57
+ this._updateState(LAYOUT_STATE.DONE);
58
+ /**
59
+ * Layout calculation is done.
60
+ *
61
+ * @event BaseLayout#onLayoutDone
62
+ * @type {CustomEvent}
63
+ */
64
+ this.dispatchEvent(new CustomEvent('onLayoutDone'));
65
+ }
66
+ /**
67
+ * @fires BaseLayout#onLayoutError
68
+ * @protected
69
+ */
70
+ _onLayoutError() {
71
+ this._updateState(LAYOUT_STATE.ERROR);
72
+ /**
73
+ * Layout calculation went wrong.
74
+ *
75
+ * @event BaseLayout#onLayoutError
76
+ * @type {CustomEvent}
77
+ */
78
+ this.dispatchEvent(new CustomEvent('onLayoutError'));
79
+ }
80
+ /**
81
+ * Check the equality of two layouts
82
+ * @param {Object} layout The layout to be compared.
83
+ * @return {Bool} True if the layout is the same as itself.
84
+ */
85
+ equals(layout) {
86
+ if (!layout || !(layout instanceof BaseLayout)) {
87
+ return false;
88
+ }
89
+ return this._name === layout._name && isEqual(this._options, layout._options);
90
+ }
91
+ /** virtual functions: will be implemented in the child class */
92
+ // first time to pass the graph data into this layout
93
+ initializeGraph(graph) { }
94
+ // update the existing graph
95
+ updateGraph(graph) { }
96
+ // start the layout calculation
97
+ start() { }
98
+ // update the layout calculation
99
+ update() { }
100
+ // resume the layout calculation
101
+ resume() { }
102
+ // stop the layout calculation
103
+ stop() { }
104
+ // access the position of the node in the layout
105
+ getNodePosition(node) {
106
+ return [0, 0];
107
+ }
108
+ // access the layout information of the edge
109
+ getEdgePosition(edge) {
110
+ return {
111
+ type: EDGE_TYPE.LINE,
112
+ sourcePosition: [0, 0],
113
+ targetPosition: [0, 0],
114
+ controlPoints: []
115
+ };
116
+ }
117
+ /**
118
+ * Pin the node to a designated position, and the node won't move anymore
119
+ * @param {Object} node Node to be locked
120
+ * @param {Number} x x coordinate
121
+ * @param {Number} y y coordinate
122
+ */
123
+ lockNodePosition(node, x, y) { }
124
+ /**
125
+ * Unlock the node, the node will be able to move freely.
126
+ * @param {Object} node Node to be unlocked
127
+ */
128
+ unlockNodePosition(node) { }
129
+ _updateState(state) {
130
+ this.state = state;
131
+ this.version += 1;
132
+ }
133
+ }
@@ -0,0 +1,14 @@
1
+ export declare class Cache<K, V> {
2
+ private readonly _keys;
3
+ /**
4
+ * @param key The key of the cache
5
+ * @returns {*} The value of the cache as set by the `set` method.
6
+ */
7
+ get(key: K): V | undefined;
8
+ /**
9
+ * @param key The key of the cache
10
+ * @param createValue A callback to create the value of the cache if it is needed.
11
+ * @param version The version of the cache. If the version is smaller than the current version, the cache will not be updated.
12
+ */
13
+ set(key: K, createValue: (...args: unknown[]) => V, version: number): void;
14
+ }
@@ -0,0 +1,26 @@
1
+ // deck.gl-community
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+ export class Cache {
5
+ _keys = new Map();
6
+ /**
7
+ * @param key The key of the cache
8
+ * @returns {*} The value of the cache as set by the `set` method.
9
+ */
10
+ get(key) {
11
+ return this._keys.get(key)?.value;
12
+ }
13
+ /**
14
+ * @param key The key of the cache
15
+ * @param createValue A callback to create the value of the cache if it is needed.
16
+ * @param version The version of the cache. If the version is smaller than the current version, the cache will not be updated.
17
+ */
18
+ set(key, createValue, version) {
19
+ const cached = this._keys.get(key);
20
+ const keyUpdated = cached === undefined || version > cached.version;
21
+ if (!keyUpdated) {
22
+ return;
23
+ }
24
+ this._keys.set(key, { version, value: createValue() });
25
+ }
26
+ }
@@ -0,0 +1,101 @@
1
+ /** All the markers supported by node type MARKER */
2
+ export declare const MARKER_TYPE: {
3
+ 'bell-filled': string;
4
+ bell: string;
5
+ 'bookmark-filled': string;
6
+ bookmark: string;
7
+ 'cd-filled': string;
8
+ cd: string;
9
+ checkmark: string;
10
+ 'circle-check-filled': string;
11
+ 'circle-check': string;
12
+ 'circle-filled': string;
13
+ 'circle-i-filled': string;
14
+ 'circle-i': string;
15
+ 'circle-minus-filled': string;
16
+ 'circle-minus': string;
17
+ 'circle-plus-filled': string;
18
+ 'circle-plus': string;
19
+ 'circle-questionmark-filled': string;
20
+ 'circle-questionmark': string;
21
+ 'circle-slash-filled': string;
22
+ 'circle-slash': string;
23
+ 'circle-x-filled': string;
24
+ 'circle-x': string;
25
+ circle: string;
26
+ 'diamond-filled': string;
27
+ diamond: string;
28
+ 'flag-filled': string;
29
+ flag: string;
30
+ gear: string;
31
+ 'heart-filled': string;
32
+ heart: string;
33
+ 'location-marker-filled': string;
34
+ 'location-marker': string;
35
+ 'octagonal-star-filled': string;
36
+ 'octagonal-star': string;
37
+ 'person-filled': string;
38
+ person: string;
39
+ 'pin-filled': string;
40
+ pin: string;
41
+ 'plus-small': string;
42
+ plus: string;
43
+ 'rectangle-filled': string;
44
+ rectangle: string;
45
+ 'star-filled': string;
46
+ star: string;
47
+ 'tag-filled': string;
48
+ tag: string;
49
+ 'thumb-down-filled': string;
50
+ 'thumb-down': string;
51
+ 'thumb-up': string;
52
+ 'thumb_up-filled': string;
53
+ 'triangle-down-filled': string;
54
+ 'triangle-down': string;
55
+ 'triangle-left-filled': string;
56
+ 'triangle-left': string;
57
+ 'triangle-right-filled': string;
58
+ 'triangle-right': string;
59
+ 'triangle-up-filled': string;
60
+ 'triangle-up': string;
61
+ 'x-small': string;
62
+ x: string;
63
+ };
64
+ export type ValueOf<T> = T[keyof T];
65
+ export declare const NODE_STATE: {
66
+ DEFAULT: string;
67
+ HOVER: string;
68
+ DRAGGING: string;
69
+ SELECTED: string;
70
+ };
71
+ export declare const EDGE_STATE: {
72
+ DEFAULT: string;
73
+ HOVER: string;
74
+ DRAGGING: string;
75
+ SELECTED: string;
76
+ };
77
+ export declare const NODE_TYPE: {
78
+ CIRCLE: string;
79
+ RECTANGLE: string;
80
+ ROUNDED_RECTANGLE: string;
81
+ PATH_ROUNDED_RECTANGLE: string;
82
+ ICON: string;
83
+ LABEL: string;
84
+ MARKER: string;
85
+ };
86
+ export declare const EDGE_TYPE: {
87
+ SPLINE_CURVE: string;
88
+ LINE: string;
89
+ PATH: string;
90
+ };
91
+ export declare const EDGE_DECORATOR_TYPE: {
92
+ LABEL: string;
93
+ FLOW: string;
94
+ };
95
+ export declare const LAYOUT_STATE: {
96
+ INIT: string;
97
+ START: string;
98
+ CALCULATING: string;
99
+ DONE: string;
100
+ ERROR: string;
101
+ };
@@ -0,0 +1,48 @@
1
+ // deck.gl-community
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+ import { MarkerList } from '../layers/common-layers/marker-layer/marker-list';
5
+ /** All the markers supported by node type MARKER */
6
+ export const MARKER_TYPE = MarkerList;
7
+ // the interaction state of a node.
8
+ export const NODE_STATE = {
9
+ DEFAULT: 'default',
10
+ HOVER: 'hover',
11
+ DRAGGING: 'dragging',
12
+ SELECTED: 'selected'
13
+ };
14
+ export const EDGE_STATE = {
15
+ DEFAULT: 'default',
16
+ HOVER: 'hover',
17
+ DRAGGING: 'dragging',
18
+ SELECTED: 'selected'
19
+ };
20
+ // node visual marker type
21
+ export const NODE_TYPE = {
22
+ CIRCLE: 'CIRCLE',
23
+ RECTANGLE: 'RECTANGLE',
24
+ ROUNDED_RECTANGLE: 'ROUNDED_RECTANGLE',
25
+ PATH_ROUNDED_RECTANGLE: 'PATH_ROUNDED_RECTANGLE',
26
+ ICON: 'ICON',
27
+ LABEL: 'LABEL',
28
+ MARKER: 'MARKER'
29
+ };
30
+ // edge shape
31
+ export const EDGE_TYPE = {
32
+ SPLINE_CURVE: 'SPLINE_CURVE',
33
+ LINE: 'LINE',
34
+ PATH: 'PATH'
35
+ };
36
+ // decorators on edges
37
+ export const EDGE_DECORATOR_TYPE = {
38
+ LABEL: 'EDGE_LABEL',
39
+ FLOW: 'FLOW'
40
+ };
41
+ // the status of the layout
42
+ export const LAYOUT_STATE = {
43
+ INIT: 'INIT',
44
+ START: 'START',
45
+ CALCULATING: 'CALCULATING',
46
+ DONE: 'DONE',
47
+ ERROR: 'ERROR'
48
+ };
@@ -0,0 +1,86 @@
1
+ import { Node } from './node';
2
+ interface EdgeOptions {
3
+ id: string | number;
4
+ sourceId: string | number;
5
+ targetId: string | number;
6
+ directed?: boolean;
7
+ data: Record<string, unknown>;
8
+ }
9
+ export declare class Edge {
10
+ /** Unique uuid of the edge. */
11
+ id: string | number;
12
+ /** ID of the source node. */
13
+ private _sourceId;
14
+ /** ID of the target node. */
15
+ private _targetId;
16
+ /** Whether the edge is directed or not. */
17
+ private _directed;
18
+ /** Origin data reference of the edge. */
19
+ private _data;
20
+ /** Check the type of the object when picking engine gets it. */
21
+ readonly isEdge = true;
22
+ /** Nodes at either end of this edge. */
23
+ private readonly _connectedNodes;
24
+ /** Edge state. */
25
+ state: string;
26
+ /**
27
+ * The constructor
28
+ * @param {String|Number} options.id - the unique ID of the edge
29
+ * @param {String|Number} options.sourceId - the ID of the source node
30
+ * @param {String|Number} options.targetId - the ID of the target node
31
+ * @param {Boolean} options.directed - whether the edge is directed or not
32
+ * @param {Record<string, unknown>} options.data - origin data reference
33
+ */
34
+ constructor({ id, sourceId, targetId, data, directed }: EdgeOptions);
35
+ /**
36
+ * Return the ID of the edge
37
+ * @return {String|Number} - the ID of the edge.
38
+ */
39
+ getId(): string | number;
40
+ /**
41
+ * Return whether the edge is directed or not.
42
+ * @return {Boolean} true if the edge is directed.
43
+ */
44
+ isDirected(): boolean;
45
+ /**
46
+ * Get the ID of the source node.
47
+ * @return {String|Number} the ID of the source node.
48
+ */
49
+ getSourceNodeId(): string | number;
50
+ /**
51
+ * Get the ID of the target node.
52
+ * @return {String|Number} the ID of the target node.
53
+ */
54
+ getTargetNodeId(): string | number;
55
+ /**
56
+ * Return of the value of the selected property key.
57
+ * @param {String} key - property key.
58
+ * @return {Any} - the value of the property.
59
+ */
60
+ getPropertyValue(key: string): unknown;
61
+ /**
62
+ * Set the origin data as a reference.
63
+ * @param {Object} data - the origin data.
64
+ */
65
+ setData(data: Record<string, unknown>): void;
66
+ /**
67
+ * Update a data property.
68
+ * @param {String} key - the key of the property
69
+ * @param {Any} value - the value of the property.
70
+ */
71
+ setDataProperty(key: string, value: unknown): void;
72
+ /**
73
+ * Set edge state
74
+ * @param {String} state - one of EDGE_STATE
75
+ */
76
+ setState(state: string): void;
77
+ /**
78
+ * Get edge state
79
+ * @returns {string} state - one of EDGE_STATE
80
+ */
81
+ getState(): string;
82
+ addNode(node: Node): void;
83
+ removeNode(node: Node): void;
84
+ getConnectedNodes(): Node[];
85
+ }
86
+ export {};
@@ -0,0 +1,121 @@
1
+ // deck.gl-community
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+ // Basic data structure of an edge
5
+ import { EDGE_STATE } from './constants';
6
+ export class Edge {
7
+ /** Unique uuid of the edge. */
8
+ id;
9
+ /** ID of the source node. */
10
+ _sourceId;
11
+ /** ID of the target node. */
12
+ _targetId;
13
+ /** Whether the edge is directed or not. */
14
+ _directed;
15
+ /** Origin data reference of the edge. */
16
+ _data;
17
+ /** Check the type of the object when picking engine gets it. */
18
+ isEdge = true;
19
+ /** Nodes at either end of this edge. */
20
+ _connectedNodes = {};
21
+ /** Edge state. */
22
+ state = EDGE_STATE.DEFAULT;
23
+ /**
24
+ * The constructor
25
+ * @param {String|Number} options.id - the unique ID of the edge
26
+ * @param {String|Number} options.sourceId - the ID of the source node
27
+ * @param {String|Number} options.targetId - the ID of the target node
28
+ * @param {Boolean} options.directed - whether the edge is directed or not
29
+ * @param {Record<string, unknown>} options.data - origin data reference
30
+ */
31
+ constructor({ id, sourceId, targetId, data, directed = false }) {
32
+ this.id = id;
33
+ this._sourceId = sourceId;
34
+ this._targetId = targetId;
35
+ this._directed = directed;
36
+ this._data = data;
37
+ }
38
+ /**
39
+ * Return the ID of the edge
40
+ * @return {String|Number} - the ID of the edge.
41
+ */
42
+ getId() {
43
+ return this.id;
44
+ }
45
+ /**
46
+ * Return whether the edge is directed or not.
47
+ * @return {Boolean} true if the edge is directed.
48
+ */
49
+ isDirected() {
50
+ return this._directed;
51
+ }
52
+ /**
53
+ * Get the ID of the source node.
54
+ * @return {String|Number} the ID of the source node.
55
+ */
56
+ getSourceNodeId() {
57
+ return this._sourceId;
58
+ }
59
+ /**
60
+ * Get the ID of the target node.
61
+ * @return {String|Number} the ID of the target node.
62
+ */
63
+ getTargetNodeId() {
64
+ return this._targetId;
65
+ }
66
+ /**
67
+ * Return of the value of the selected property key.
68
+ * @param {String} key - property key.
69
+ * @return {Any} - the value of the property.
70
+ */
71
+ getPropertyValue(key) {
72
+ // try to search the key within this object
73
+ if (this.hasOwnProperty(key)) {
74
+ return this[key];
75
+ }
76
+ // try to search the key in the original data reference
77
+ else if (this._data.hasOwnProperty(key)) {
78
+ return this._data[key];
79
+ }
80
+ // otherwise, not found
81
+ return undefined;
82
+ }
83
+ /**
84
+ * Set the origin data as a reference.
85
+ * @param {Object} data - the origin data.
86
+ */
87
+ setData(data) {
88
+ this._data = data;
89
+ }
90
+ /**
91
+ * Update a data property.
92
+ * @param {String} key - the key of the property
93
+ * @param {Any} value - the value of the property.
94
+ */
95
+ setDataProperty(key, value) {
96
+ this._data[key] = value;
97
+ }
98
+ /**
99
+ * Set edge state
100
+ * @param {String} state - one of EDGE_STATE
101
+ */
102
+ setState(state) {
103
+ this.state = state;
104
+ }
105
+ /**
106
+ * Get edge state
107
+ * @returns {string} state - one of EDGE_STATE
108
+ */
109
+ getState() {
110
+ return this.state;
111
+ }
112
+ addNode(node) {
113
+ this._connectedNodes[node.getId()] = node;
114
+ }
115
+ removeNode(node) {
116
+ delete this._connectedNodes[node.getId()];
117
+ }
118
+ getConnectedNodes() {
119
+ return Object.values(this._connectedNodes);
120
+ }
121
+ }
@@ -0,0 +1,54 @@
1
+ import { BaseLayout } from './base-layout';
2
+ import { Edge } from './edge';
3
+ import { Graph } from './graph';
4
+ export declare class GraphEngine extends EventTarget {
5
+ private readonly _graph;
6
+ private readonly _layout;
7
+ private readonly _cache;
8
+ private _layoutDirty;
9
+ private _transactionInProgress;
10
+ constructor(graph: Graph, layout: BaseLayout);
11
+ /** Getters */
12
+ getNodes: () => Node[];
13
+ getEdges: () => Edge[];
14
+ getNodePosition: (node: any) => [number, number];
15
+ getEdgePosition: (edge: any) => {
16
+ type: string;
17
+ sourcePosition: number[];
18
+ targetPosition: number[];
19
+ controlPoints: any[];
20
+ };
21
+ getGraphVersion: () => number;
22
+ getLayoutLastUpdate: () => number;
23
+ getLayoutState: () => string;
24
+ /** Operations on the graph */
25
+ lockNodePosition: (node: any, x: any, y: any) => void;
26
+ unlockNodePosition: (node: any) => void;
27
+ /**
28
+ * @fires GraphEngine#onLayoutStart
29
+ */
30
+ _onLayoutStart: () => void;
31
+ /**
32
+ * @fires GraphEngine#onLayoutChange
33
+ */
34
+ _onLayoutChange: () => void;
35
+ /**
36
+ * @fires GraphEngine#onLayoutDone
37
+ */
38
+ _onLayoutDone: () => void;
39
+ /**
40
+ * @fires GraphEngine#onLayoutError
41
+ */
42
+ _onLayoutError: () => void;
43
+ _onGraphStructureChanged: (entity: any) => void;
44
+ _onTransactionStart: () => void;
45
+ _onTransactionEnd: () => void;
46
+ /** Layout calculations */
47
+ run: () => void;
48
+ clear: () => void;
49
+ resume: () => void;
50
+ stop: () => void;
51
+ _graphChanged: () => void;
52
+ _updateLayout: () => void;
53
+ _updateCache(key: any, updateValue: any): void;
54
+ }