@krainovsd/graph 0.14.0-beta.8 → 0.15.0-beta.1
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.
- package/lib/cjs/index.cjs +845 -375
- package/lib/cjs/index.cjs.map +1 -1
- package/lib/esm/constants/force-controls.js +6 -4
- package/lib/esm/constants/force-controls.js.map +1 -1
- package/lib/esm/constants/highlight-controls.js +6 -3
- package/lib/esm/constants/highlight-controls.js.map +1 -1
- package/lib/esm/constants/link-controls.js +6 -3
- package/lib/esm/constants/link-controls.js.map +1 -1
- package/lib/esm/constants/node-controls.js +6 -3
- package/lib/esm/constants/node-controls.js.map +1 -1
- package/lib/esm/index.js +8 -6
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/module/GraphCanvas/GraphCanvas.js +40 -17
- package/lib/esm/module/GraphCanvas/GraphCanvas.js.map +1 -1
- package/lib/esm/module/GraphCanvas/StaticGraphCanvas.js +127 -0
- package/lib/esm/module/GraphCanvas/StaticGraphCanvas.js.map +1 -0
- package/lib/esm/module/GraphCanvas/constants/graph-settings.js +6 -7
- package/lib/esm/module/GraphCanvas/constants/graph-settings.js.map +1 -1
- package/lib/esm/module/GraphCanvas/constants/highlight-settings.js +1 -4
- package/lib/esm/module/GraphCanvas/constants/highlight-settings.js.map +1 -1
- package/lib/esm/module/GraphCanvas/constants/index.js +6 -4
- package/lib/esm/module/GraphCanvas/constants/index.js.map +1 -1
- package/lib/esm/module/GraphCanvas/constants/link-settings.js +1 -9
- package/lib/esm/module/GraphCanvas/constants/link-settings.js.map +1 -1
- package/lib/esm/module/GraphCanvas/constants/node-settings.js +1 -10
- package/lib/esm/module/GraphCanvas/constants/node-settings.js.map +1 -1
- package/lib/esm/module/GraphCanvas/lib/settings/force-settings-getter.js +6 -4
- package/lib/esm/module/GraphCanvas/lib/settings/force-settings-getter.js.map +1 -1
- package/lib/esm/module/GraphCanvas/lib/settings/graph-settings-getter.js +0 -3
- package/lib/esm/module/GraphCanvas/lib/settings/graph-settings-getter.js.map +1 -1
- package/lib/esm/module/GraphCanvas/lib/settings/highlight-settings-getter.js +6 -3
- package/lib/esm/module/GraphCanvas/lib/settings/highlight-settings-getter.js.map +1 -1
- package/lib/esm/module/GraphCanvas/lib/settings/link-settings-getter.js +6 -3
- package/lib/esm/module/GraphCanvas/lib/settings/link-settings-getter.js.map +1 -1
- package/lib/esm/module/GraphCanvas/lib/settings/node-settings-getter.js +20 -6
- package/lib/esm/module/GraphCanvas/lib/settings/node-settings-getter.js.map +1 -1
- package/lib/esm/module/GraphCanvas/lib/utils/calculate-curve-link-position-by-node.js +6 -4
- package/lib/esm/module/GraphCanvas/lib/utils/calculate-curve-link-position-by-node.js.map +1 -1
- package/lib/esm/module/GraphCanvas/lib/utils/calculate-link-position-by-node.js +6 -4
- package/lib/esm/module/GraphCanvas/lib/utils/calculate-link-position-by-node.js.map +1 -1
- package/lib/esm/module/GraphCanvas/lib/utils/get-particle-position.js +1 -1
- package/lib/esm/module/GraphCanvas/lib/utils/get-particle-position.js.map +1 -1
- package/lib/esm/module/GraphCanvas/lib/utils/is-node-visible.js +25 -27
- package/lib/esm/module/GraphCanvas/lib/utils/is-node-visible.js.map +1 -1
- package/lib/esm/module/GraphCanvas/lib/utils/is-overlaps-node.js.map +1 -1
- package/lib/esm/module/GraphCanvas/lib/utils/node-by-pointer-getter.js +2 -1
- package/lib/esm/module/GraphCanvas/lib/utils/node-by-pointer-getter.js.map +1 -1
- package/lib/esm/module/GraphCanvas/lib/utils/node-highlight.js +7 -11
- package/lib/esm/module/GraphCanvas/lib/utils/node-highlight.js.map +1 -1
- package/lib/esm/module/GraphCanvas/lib/utils/node-iteration-extractor.js +3 -0
- package/lib/esm/module/GraphCanvas/lib/utils/node-iteration-extractor.js.map +1 -1
- package/lib/esm/module/GraphCanvas/lib/utils/precompute-graph.js +24 -0
- package/lib/esm/module/GraphCanvas/lib/utils/precompute-graph.js.map +1 -0
- package/lib/esm/module/GraphCanvas/lib/utils/prepare-graph-data.js +49 -0
- package/lib/esm/module/GraphCanvas/lib/utils/prepare-graph-data.js.map +1 -0
- package/lib/esm/module/GraphCanvas/lib/utils/svg-context.js +159 -0
- package/lib/esm/module/GraphCanvas/lib/utils/svg-context.js.map +1 -0
- package/lib/esm/module/GraphCanvas/slices/draw-links.js +24 -42
- package/lib/esm/module/GraphCanvas/slices/draw-links.js.map +1 -1
- package/lib/esm/module/GraphCanvas/slices/draw-nodes.js +80 -168
- package/lib/esm/module/GraphCanvas/slices/draw-nodes.js.map +1 -1
- package/lib/esm/module/GraphCanvas/slices/draw-text.js +1 -9
- package/lib/esm/module/GraphCanvas/slices/draw-text.js.map +1 -1
- package/lib/esm/module/GraphCanvas/slices/export-svg.js +62 -0
- package/lib/esm/module/GraphCanvas/slices/export-svg.js.map +1 -0
- package/lib/esm/module/GraphCanvas/slices/init-dnd.js +15 -3
- package/lib/esm/module/GraphCanvas/slices/init-dnd.js.map +1 -1
- package/lib/esm/module/GraphCanvas/slices/init-draw.js +212 -8
- package/lib/esm/module/GraphCanvas/slices/init-draw.js.map +1 -1
- package/lib/esm/module/GraphCanvas/slices/init-pointer.js +6 -8
- package/lib/esm/module/GraphCanvas/slices/init-pointer.js.map +1 -1
- package/lib/esm/module/GraphCanvas/slices/init-simulation.js +3 -4
- package/lib/esm/module/GraphCanvas/slices/init-simulation.js.map +1 -1
- package/lib/esm/module/GraphCanvas/slices/init-zoom.js +2 -4
- package/lib/esm/module/GraphCanvas/slices/init-zoom.js.map +1 -1
- package/lib/esm/module/GraphCanvas/slices/update-link-cache.js +5 -5
- package/lib/esm/module/GraphCanvas/slices/update-node-cache.js +17 -29
- package/lib/esm/module/GraphCanvas/slices/update-node-cache.js.map +1 -1
- package/lib/index.d.ts +95 -43
- package/package.json +1 -1
|
@@ -3,7 +3,33 @@ import { setDrawTime } from '../../../lib/draw-time.js';
|
|
|
3
3
|
import { getDrawLink } from './draw-links.js';
|
|
4
4
|
import { getDrawNode } from './draw-nodes.js';
|
|
5
5
|
|
|
6
|
+
const COS_PI_6 = 0.8660254037844386;
|
|
7
|
+
const SIN_PI_6 = 0.5;
|
|
8
|
+
function clearBatch(batch) {
|
|
9
|
+
// eslint-disable-next-line guard-for-in
|
|
10
|
+
for (const key in batch) {
|
|
11
|
+
batch[key].length = 0;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
function clearNestedBatch(batch) {
|
|
15
|
+
// eslint-disable-next-line guard-for-in
|
|
16
|
+
for (const outerKey in batch) {
|
|
17
|
+
const inner = batch[outerKey];
|
|
18
|
+
// eslint-disable-next-line guard-for-in
|
|
19
|
+
for (const innerKey in inner) {
|
|
20
|
+
inner[innerKey].length = 0;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
6
24
|
function initDraw() {
|
|
25
|
+
const nodeBatch = {};
|
|
26
|
+
const nodeImageBatch = {};
|
|
27
|
+
const textBatch = {};
|
|
28
|
+
const deferredNodeDraw = [];
|
|
29
|
+
const deferredTextDraw = [];
|
|
30
|
+
const linkBatch = {};
|
|
31
|
+
const particleBatch = {};
|
|
32
|
+
const arrowBatch = {};
|
|
7
33
|
function draw() {
|
|
8
34
|
if (!this.context)
|
|
9
35
|
return;
|
|
@@ -11,18 +37,196 @@ function initDraw() {
|
|
|
11
37
|
this.listeners.onDraw.call(this);
|
|
12
38
|
return;
|
|
13
39
|
}
|
|
40
|
+
clearBatch(nodeBatch);
|
|
41
|
+
clearBatch(nodeImageBatch);
|
|
42
|
+
clearNestedBatch(textBatch);
|
|
43
|
+
deferredNodeDraw.length = 0;
|
|
44
|
+
deferredTextDraw.length = 0;
|
|
45
|
+
clearBatch(linkBatch);
|
|
46
|
+
clearBatch(particleBatch);
|
|
47
|
+
clearBatch(arrowBatch);
|
|
48
|
+
const k = this.areaTransform.k;
|
|
49
|
+
const area = {
|
|
50
|
+
left: -this.areaTransform.x / k,
|
|
51
|
+
right: (this.width - this.areaTransform.x) / k,
|
|
52
|
+
top: -this.areaTransform.y / k,
|
|
53
|
+
bottom: (this.height - this.areaTransform.y) / k,
|
|
54
|
+
};
|
|
14
55
|
this.context.save();
|
|
15
56
|
this.context.clearRect(0, 0, this.width, this.height);
|
|
16
57
|
this.context.translate(this.areaTransform.x, this.areaTransform.y);
|
|
17
58
|
this.context.scale(this.areaTransform.k, this.areaTransform.k);
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
59
|
+
this.nodes.forEach(getDrawNode(nodeBatch, nodeImageBatch, textBatch, deferredNodeDraw, deferredTextDraw, area), this);
|
|
60
|
+
this.links.forEach(getDrawLink(linkBatch, particleBatch, arrowBatch, performance.now()), this);
|
|
61
|
+
const linkKeys = Object.keys(linkBatch);
|
|
62
|
+
for (let i = 0; i < linkKeys.length; i++) {
|
|
63
|
+
const key = linkKeys[i];
|
|
64
|
+
const group = linkBatch[key];
|
|
65
|
+
const [alpha, color, width] = key.split("|");
|
|
66
|
+
this.context.beginPath();
|
|
67
|
+
this.context.globalAlpha = +alpha;
|
|
68
|
+
this.context.strokeStyle = color;
|
|
69
|
+
this.context.lineWidth = +width;
|
|
70
|
+
this.context.setLineDash([]);
|
|
71
|
+
for (let j = 0; j < group.length; j++) {
|
|
72
|
+
const item = group[j];
|
|
73
|
+
if (!item.curve) {
|
|
74
|
+
this.context.moveTo(item.xStart, item.yStart);
|
|
75
|
+
this.context.lineTo(item.xEnd, item.yEnd);
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
this.context.moveTo(item.xStart, item.yStart);
|
|
79
|
+
this.context.quadraticCurveTo(item.xControl, item.yControl, item.xEnd, item.yEnd);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
this.context.stroke();
|
|
83
|
+
}
|
|
84
|
+
const particleKeys = Object.keys(particleBatch);
|
|
85
|
+
for (let i = 0; i < particleKeys.length; i++) {
|
|
86
|
+
const key = particleKeys[i];
|
|
87
|
+
const group = particleBatch[key];
|
|
88
|
+
const [bcolor, width, color] = key.split("|");
|
|
89
|
+
this.context.beginPath();
|
|
90
|
+
this.context.globalAlpha = 1;
|
|
91
|
+
this.context.strokeStyle = bcolor;
|
|
92
|
+
this.context.lineWidth = +width;
|
|
93
|
+
this.context.fillStyle = color;
|
|
94
|
+
for (let j = 0; j < group.length; j++) {
|
|
95
|
+
const item = group[j];
|
|
96
|
+
this.context.moveTo(item.x + item.r, item.y);
|
|
97
|
+
this.context.arc(item.x, item.y, item.r, 0, Math.PI * 2);
|
|
98
|
+
}
|
|
99
|
+
this.context.fill();
|
|
100
|
+
if (+width > 0) {
|
|
101
|
+
this.context.stroke();
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
const arrowKeys = Object.keys(arrowBatch);
|
|
105
|
+
for (let i = 0; i < arrowKeys.length; i++) {
|
|
106
|
+
const key = arrowKeys[i];
|
|
107
|
+
const group = arrowBatch[key];
|
|
108
|
+
const [alpha, bcolor, width, color] = key.split("|");
|
|
109
|
+
this.context.beginPath();
|
|
110
|
+
this.context.globalAlpha = +alpha;
|
|
111
|
+
this.context.strokeStyle = bcolor;
|
|
112
|
+
this.context.lineWidth = +width;
|
|
113
|
+
this.context.fillStyle = color;
|
|
114
|
+
for (let j = 0; j < group.length; j++) {
|
|
115
|
+
const item = group[j];
|
|
116
|
+
this.context.moveTo(item.x, item.y);
|
|
117
|
+
const cosA = Math.cos(item.angle);
|
|
118
|
+
const sinA = Math.sin(item.angle);
|
|
119
|
+
const cos1 = cosA * COS_PI_6 + sinA * SIN_PI_6;
|
|
120
|
+
const sin1 = sinA * COS_PI_6 - cosA * SIN_PI_6;
|
|
121
|
+
const cos2 = cosA * COS_PI_6 - sinA * SIN_PI_6;
|
|
122
|
+
const sin2 = sinA * COS_PI_6 + cosA * SIN_PI_6;
|
|
123
|
+
this.context.lineTo(item.x - item.size * cos1, item.y - item.size * sin1);
|
|
124
|
+
this.context.lineTo(item.x - item.size * cos2, item.y - item.size * sin2);
|
|
125
|
+
this.context.closePath();
|
|
126
|
+
}
|
|
127
|
+
this.context.fill();
|
|
128
|
+
if (+width > 0) {
|
|
129
|
+
this.context.stroke();
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
const nodeKeys = Object.keys(nodeBatch);
|
|
133
|
+
for (let i = 0; i < nodeKeys.length; i++) {
|
|
134
|
+
const key = nodeKeys[i];
|
|
135
|
+
const group = nodeBatch[key];
|
|
136
|
+
const [alpha, bcolor, width, color] = key.split("|");
|
|
137
|
+
this.context.beginPath();
|
|
138
|
+
this.context.globalAlpha = +alpha;
|
|
139
|
+
this.context.strokeStyle = bcolor;
|
|
140
|
+
this.context.lineWidth = +width;
|
|
141
|
+
this.context.fillStyle = color;
|
|
142
|
+
for (let j = 0; j < group.length; j++) {
|
|
143
|
+
const item = group[j];
|
|
144
|
+
switch (item.shape) {
|
|
145
|
+
case "circle": {
|
|
146
|
+
this.context.moveTo(item.x + item.radius, item.y);
|
|
147
|
+
this.context.arc(item.x, item.y, item.radius, 0, 2 * Math.PI);
|
|
148
|
+
break;
|
|
149
|
+
}
|
|
150
|
+
case "square": {
|
|
151
|
+
this.context.roundRect(item.x - item.width / 2, item.y - item.height / 2, item.width, item.height, item.radius);
|
|
152
|
+
break;
|
|
153
|
+
}
|
|
154
|
+
case "text": {
|
|
155
|
+
if (this.nodeSettings.textNodeDebug) {
|
|
156
|
+
this.context.rect(item.x - item.width / 2, item.y - item.height / 2, item.width, item.height);
|
|
157
|
+
}
|
|
158
|
+
break;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
this.context.fill();
|
|
163
|
+
if (+width > 0) {
|
|
164
|
+
this.context.stroke();
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
const nodeImageKeys = Object.keys(nodeImageBatch);
|
|
168
|
+
for (let i = 0; i < nodeImageKeys.length; i++) {
|
|
169
|
+
const key = nodeImageKeys[i];
|
|
170
|
+
const group = nodeImageBatch[key];
|
|
171
|
+
const [alpha, bcolor, width, color] = key.split("|");
|
|
172
|
+
this.context.globalAlpha = +alpha;
|
|
173
|
+
this.context.strokeStyle = bcolor;
|
|
174
|
+
this.context.lineWidth = +width;
|
|
175
|
+
this.context.fillStyle = color;
|
|
176
|
+
for (let j = 0; j < group.length; j++) {
|
|
177
|
+
const item = group[j];
|
|
178
|
+
if (!item.image)
|
|
179
|
+
continue;
|
|
180
|
+
this.context.beginPath();
|
|
181
|
+
switch (item.shape) {
|
|
182
|
+
case "circle": {
|
|
183
|
+
this.context.arc(item.x, item.y, item.radius, 0, 2 * Math.PI);
|
|
184
|
+
this.context.closePath();
|
|
185
|
+
this.context.save();
|
|
186
|
+
this.context.clip();
|
|
187
|
+
this.context.drawImage(item.image, item.x - item.radius, item.y - item.radius, item.radius * 2, item.radius * 2);
|
|
188
|
+
this.context.restore();
|
|
189
|
+
break;
|
|
190
|
+
}
|
|
191
|
+
case "square": {
|
|
192
|
+
this.context.roundRect(item.x - item.width / 2, item.y - item.height / 2, item.width, item.height, item.radius);
|
|
193
|
+
this.context.closePath();
|
|
194
|
+
this.context.save();
|
|
195
|
+
this.context.clip();
|
|
196
|
+
this.context.drawImage(item.image, item.x - item.width / 2, item.y - item.height / 2, item.width, item.height);
|
|
197
|
+
this.context.restore();
|
|
198
|
+
break;
|
|
199
|
+
}
|
|
200
|
+
default: {
|
|
201
|
+
continue;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
if (+width > 0) {
|
|
205
|
+
this.context.stroke();
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
const textKeys = Object.keys(textBatch);
|
|
210
|
+
for (let i = 0; i < textKeys.length; i++) {
|
|
211
|
+
const font = textKeys[i];
|
|
212
|
+
const fontGroup = textBatch[font];
|
|
213
|
+
const textInnerKeys = Object.keys(fontGroup);
|
|
214
|
+
this.context.font = font;
|
|
215
|
+
for (let j = 0; j < textInnerKeys.length; j++) {
|
|
216
|
+
const key = textInnerKeys[j];
|
|
217
|
+
const group = fontGroup[key];
|
|
218
|
+
const [alpha, align, color] = key.split("|");
|
|
219
|
+
this.context.globalAlpha = +alpha;
|
|
220
|
+
this.context.textAlign = align;
|
|
221
|
+
this.context.fillStyle = color;
|
|
222
|
+
for (let k = 0; k < group.length; k++) {
|
|
223
|
+
const item = group[k];
|
|
224
|
+
this.context.fillText(item.text, item.x, item.y);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
deferredNodeDraw.forEach((draw) => draw());
|
|
229
|
+
deferredTextDraw.forEach((draw) => draw());
|
|
26
230
|
this.context.restore();
|
|
27
231
|
/** selection rectangle */
|
|
28
232
|
if (this.isSelecting && this.selectionRect) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"init-draw.js","sources":["../../../../../src/module/GraphCanvas/slices/init-draw.ts"],"sourcesContent":["import { setDrawTime } from \"@/lib\";\nimport type { GraphCanvas } from \"../GraphCanvas\";\nimport { getDrawLink } from \"./draw-links\";\nimport { getDrawNode } from \"./draw-nodes\";\n\nexport function initDraw<\n NodeData extends Record<string, unknown>,\n LinkData extends Record<string, unknown>,\n>(this: GraphCanvas<NodeData, LinkData>) {\n function draw(this: GraphCanvas<NodeData, LinkData>) {\n if (!this.context) return;\n\n if (this.listeners.onDraw) {\n this.listeners.onDraw.call(this);\n\n return;\n }\n\n this.context.save();\n this.context.clearRect(0, 0, this.width, this.height);\n this.context.translate(this.areaTransform.x, this.areaTransform.y);\n this.context.scale(this.areaTransform.k, this.areaTransform.k);\n\n const textRenders: (() => void)[] = [];\n const nodeRenders: (() => void)[] = [];\n this.nodes.forEach(getDrawNode<NodeData, LinkData>(nodeRenders, textRenders).bind(this));\n\n /** links */\n this.links.forEach(getDrawLink<NodeData, LinkData>().bind(this));\n\n /** nodes */\n\n nodeRenders.forEach((render) => render());\n textRenders.forEach((render) => render());\n\n this.context.restore();\n\n /** selection rectangle */\n if (this.isSelecting && this.selectionRect) {\n const rect = this.selectionRect;\n const screenX = Math.min(rect.x1, rect.x2) * this.areaTransform.k + this.areaTransform.x;\n const screenY = Math.min(rect.y1, rect.y2) * this.areaTransform.k + this.areaTransform.y;\n const screenW = Math.abs(rect.x2 - rect.x1) * this.areaTransform.k;\n const screenH = Math.abs(rect.y2 - rect.y1) * this.areaTransform.k;\n\n this.context.fillStyle = \"rgba(66, 133, 244, 0.2)\";\n this.context.fillRect(screenX, screenY, screenW, screenH);\n this.context.strokeStyle = \"rgba(66, 133, 244, 0.8)\";\n this.context.lineWidth = 2;\n this.context.strokeRect(screenX, screenY, screenW, screenH);\n }\n this.listeners.onDrawFinished?.call?.(this);\n }\n\n if (this.graphSettings.showDrawTime) {\n return setDrawTime(draw.bind(this), this.graphSettings.showDrawTimeEveryTick);\n }\n\n return draw.bind(this);\n}\n"],"names":[],"mappings":";;;;;SAKgB,QAAQ,GAAA;AAItB,IAAA,SAAS,IAAI,GAAA;QACX,IAAI,CAAC,IAAI,CAAC,OAAO;YAAE;AAEnB,QAAA,IAAI,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE;YACzB,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC;YAEhC;;AAGF,QAAA,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE;AACnB,QAAA,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,EAAE,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC;AACrD,QAAA,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,EAAE,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC;AAClE,QAAA,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,EAAE,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC;QAE9D,MAAM,WAAW,GAAmB,EAAE;QACtC,MAAM,WAAW,GAAmB,EAAE;AACtC,Q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AAO,EAAE,OAAO,EAAE,OAAO,CAAC;AACzD,YAAA,IAAI,CAAC,OAAO,CAAC,WAAW,GAAG,yBAAyB;AACpD,YAAA,IAAI,CAAC,OAAO,CAAC,SAAS,GAAG,CAAC;AAC1B,YAAA,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC;;QAE7D,IAAI,CAAC,SAAS,CAAC,cAAc,EAAE,IAAI,GAAG,IAAI,CAAC;;AAG7C,IAAA,IAAI,IAAI,CAAC,aAAa,CAAC,YAAY,EAAE;AACnC,QAAA,OAAO,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,IAAI,CAAC,aAAa,CAAC,qBAAqB,CAAC;;AAG/E,IAAA,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC;AACxB;;;;"}
|
|
1
|
+
{"version":3,"file":"init-draw.js","sources":["../../../../../src/module/GraphCanvas/slices/init-draw.ts"],"sourcesContent":["import { setDrawTime } from \"@/lib\";\nimport type { GraphCanvas } from \"../GraphCanvas\";\nimport type {\n Area,\n DeferredDraw,\n LinkArrowDrawBatch,\n LinkDrawBatch,\n LinkParticleDrawBatch,\n NodeDrawBatch,\n NodeTextDrawBatch,\n} from \"../types\";\nimport { getDrawLink } from \"./draw-links\";\nimport { getDrawNode } from \"./draw-nodes\";\n\nconst COS_PI_6 = 0.8660254037844386;\nconst SIN_PI_6 = 0.5;\n\nfunction clearBatch<T>(batch: Record<string, T[]>) {\n // eslint-disable-next-line guard-for-in\n for (const key in batch) {\n batch[key].length = 0;\n }\n}\n\nfunction clearNestedBatch<T>(batch: Record<string, Record<string, T[]>>) {\n // eslint-disable-next-line guard-for-in\n for (const outerKey in batch) {\n const inner = batch[outerKey];\n // eslint-disable-next-line guard-for-in\n for (const innerKey in inner) {\n inner[innerKey].length = 0;\n }\n }\n}\n\nexport function initDraw<\n NodeData extends Record<string, unknown>,\n LinkData extends Record<string, unknown>,\n>(this: GraphCanvas<NodeData, LinkData>) {\n const nodeBatch: Record<string, NodeDrawBatch[]> = {};\n const nodeImageBatch: Record<string, NodeDrawBatch[]> = {};\n const textBatch: Record<string, Record<string, NodeTextDrawBatch[]>> = {};\n const deferredNodeDraw: DeferredDraw[] = [];\n const deferredTextDraw: DeferredDraw[] = [];\n const linkBatch: Record<string, LinkDrawBatch[]> = {};\n const particleBatch: Record<string, LinkParticleDrawBatch[]> = {};\n const arrowBatch: Record<string, LinkArrowDrawBatch[]> = {};\n\n function draw(this: GraphCanvas<NodeData, LinkData>) {\n if (!this.context) return;\n if (this.listeners.onDraw) {\n this.listeners.onDraw.call(this);\n return;\n }\n clearBatch(nodeBatch);\n clearBatch(nodeImageBatch);\n clearNestedBatch(textBatch);\n deferredNodeDraw.length = 0;\n deferredTextDraw.length = 0;\n clearBatch(linkBatch);\n clearBatch(particleBatch);\n clearBatch(arrowBatch);\n const k = this.areaTransform.k;\n const area: Area = {\n left: -this.areaTransform.x / k,\n right: (this.width - this.areaTransform.x) / k,\n top: -this.areaTransform.y / k,\n bottom: (this.height - this.areaTransform.y) / k,\n };\n this.context.save();\n this.context.clearRect(0, 0, this.width, this.height);\n this.context.translate(this.areaTransform.x, this.areaTransform.y);\n this.context.scale(this.areaTransform.k, this.areaTransform.k);\n this.nodes.forEach(\n getDrawNode<NodeData, LinkData>(\n nodeBatch,\n nodeImageBatch,\n textBatch,\n deferredNodeDraw,\n deferredTextDraw,\n area,\n ),\n this,\n );\n this.links.forEach(\n getDrawLink<NodeData, LinkData>(linkBatch, particleBatch, arrowBatch, performance.now()),\n this,\n );\n const linkKeys = Object.keys(linkBatch);\n for (let i = 0; i < linkKeys.length; i++) {\n const key = linkKeys[i];\n const group = linkBatch[key];\n const [alpha, color, width] = key.split(\"|\");\n this.context.beginPath();\n this.context.globalAlpha = +alpha;\n this.context.strokeStyle = color;\n this.context.lineWidth = +width;\n this.context.setLineDash([]);\n for (let j = 0; j < group.length; j++) {\n const item = group[j];\n if (!item.curve) {\n this.context.moveTo(item.xStart, item.yStart);\n this.context.lineTo(item.xEnd, item.yEnd);\n } else {\n this.context.moveTo(item.xStart, item.yStart);\n this.context.quadraticCurveTo(item.xControl, item.yControl, item.xEnd, item.yEnd);\n }\n }\n this.context.stroke();\n }\n const particleKeys = Object.keys(particleBatch);\n for (let i = 0; i < particleKeys.length; i++) {\n const key = particleKeys[i];\n const group = particleBatch[key];\n const [bcolor, width, color] = key.split(\"|\");\n this.context.beginPath();\n this.context.globalAlpha = 1;\n this.context.strokeStyle = bcolor;\n this.context.lineWidth = +width;\n this.context.fillStyle = color;\n for (let j = 0; j < group.length; j++) {\n const item = group[j];\n this.context.moveTo(item.x + item.r, item.y);\n this.context.arc(item.x, item.y, item.r, 0, Math.PI * 2);\n }\n this.context.fill();\n if (+width > 0) {\n this.context.stroke();\n }\n }\n const arrowKeys = Object.keys(arrowBatch);\n for (let i = 0; i < arrowKeys.length; i++) {\n const key = arrowKeys[i];\n const group = arrowBatch[key];\n const [alpha, bcolor, width, color] = key.split(\"|\");\n this.context.beginPath();\n this.context.globalAlpha = +alpha;\n this.context.strokeStyle = bcolor;\n this.context.lineWidth = +width;\n this.context.fillStyle = color;\n for (let j = 0; j < group.length; j++) {\n const item = group[j];\n this.context.moveTo(item.x, item.y);\n const cosA = Math.cos(item.angle);\n const sinA = Math.sin(item.angle);\n const cos1 = cosA * COS_PI_6 + sinA * SIN_PI_6;\n const sin1 = sinA * COS_PI_6 - cosA * SIN_PI_6;\n const cos2 = cosA * COS_PI_6 - sinA * SIN_PI_6;\n const sin2 = sinA * COS_PI_6 + cosA * SIN_PI_6;\n this.context.lineTo(item.x - item.size * cos1, item.y - item.size * sin1);\n this.context.lineTo(item.x - item.size * cos2, item.y - item.size * sin2);\n this.context.closePath();\n }\n this.context.fill();\n if (+width > 0) {\n this.context.stroke();\n }\n }\n const nodeKeys = Object.keys(nodeBatch);\n for (let i = 0; i < nodeKeys.length; i++) {\n const key = nodeKeys[i];\n const group = nodeBatch[key];\n const [alpha, bcolor, width, color] = key.split(\"|\");\n this.context.beginPath();\n this.context.globalAlpha = +alpha;\n this.context.strokeStyle = bcolor;\n this.context.lineWidth = +width;\n this.context.fillStyle = color;\n for (let j = 0; j < group.length; j++) {\n const item = group[j];\n switch (item.shape) {\n case \"circle\": {\n this.context.moveTo(item.x + item.radius, item.y);\n this.context.arc(item.x, item.y, item.radius, 0, 2 * Math.PI);\n break;\n }\n case \"square\": {\n this.context.roundRect(\n item.x - item.width / 2,\n item.y - item.height / 2,\n item.width,\n item.height,\n item.radius,\n );\n break;\n }\n case \"text\": {\n if (this.nodeSettings.textNodeDebug) {\n this.context.rect(\n item.x - item.width / 2,\n item.y - item.height / 2,\n item.width,\n item.height,\n );\n }\n break;\n }\n default: {\n }\n }\n }\n this.context.fill();\n if (+width > 0) {\n this.context.stroke();\n }\n }\n const nodeImageKeys = Object.keys(nodeImageBatch);\n for (let i = 0; i < nodeImageKeys.length; i++) {\n const key = nodeImageKeys[i];\n const group = nodeImageBatch[key];\n const [alpha, bcolor, width, color] = key.split(\"|\");\n this.context.globalAlpha = +alpha;\n this.context.strokeStyle = bcolor;\n this.context.lineWidth = +width;\n this.context.fillStyle = color;\n for (let j = 0; j < group.length; j++) {\n const item = group[j];\n if (!item.image) continue;\n this.context.beginPath();\n switch (item.shape) {\n case \"circle\": {\n this.context.arc(item.x, item.y, item.radius, 0, 2 * Math.PI);\n this.context.closePath();\n this.context.save();\n this.context.clip();\n this.context.drawImage(\n item.image,\n item.x - item.radius,\n item.y - item.radius,\n item.radius * 2,\n item.radius * 2,\n );\n this.context.restore();\n break;\n }\n case \"square\": {\n this.context.roundRect(\n item.x - item.width / 2,\n item.y - item.height / 2,\n item.width,\n item.height,\n item.radius,\n );\n this.context.closePath();\n this.context.save();\n this.context.clip();\n this.context.drawImage(\n item.image,\n item.x - item.width / 2,\n item.y - item.height / 2,\n item.width,\n item.height,\n );\n this.context.restore();\n break;\n }\n default: {\n continue;\n }\n }\n if (+width > 0) {\n this.context.stroke();\n }\n }\n }\n const textKeys = Object.keys(textBatch);\n for (let i = 0; i < textKeys.length; i++) {\n const font = textKeys[i];\n const fontGroup = textBatch[font];\n const textInnerKeys = Object.keys(fontGroup);\n this.context.font = font;\n for (let j = 0; j < textInnerKeys.length; j++) {\n const key = textInnerKeys[j];\n const group = fontGroup[key];\n const [alpha, align, color] = key.split(\"|\");\n this.context.globalAlpha = +alpha;\n this.context.textAlign = align as CanvasTextAlign;\n this.context.fillStyle = color;\n for (let k = 0; k < group.length; k++) {\n const item = group[k];\n this.context.fillText(item.text, item.x, item.y);\n }\n }\n }\n deferredNodeDraw.forEach((draw) => draw());\n deferredTextDraw.forEach((draw) => draw());\n this.context.restore();\n\n /** selection rectangle */\n if (this.isSelecting && this.selectionRect) {\n const rect = this.selectionRect;\n const screenX = Math.min(rect.x1, rect.x2) * this.areaTransform.k + this.areaTransform.x;\n const screenY = Math.min(rect.y1, rect.y2) * this.areaTransform.k + this.areaTransform.y;\n const screenW = Math.abs(rect.x2 - rect.x1) * this.areaTransform.k;\n const screenH = Math.abs(rect.y2 - rect.y1) * this.areaTransform.k;\n\n this.context.fillStyle = \"rgba(66, 133, 244, 0.2)\";\n this.context.fillRect(screenX, screenY, screenW, screenH);\n this.context.strokeStyle = \"rgba(66, 133, 244, 0.8)\";\n this.context.lineWidth = 2;\n this.context.strokeRect(screenX, screenY, screenW, screenH);\n }\n this.listeners.onDrawFinished?.call?.(this);\n }\n\n if (this.graphSettings.showDrawTime) {\n return setDrawTime(draw.bind(this), this.graphSettings.showDrawTimeEveryTick);\n }\n\n return draw.bind(this);\n}\n"],"names":[],"mappings":";;;;;AAcA,MAAM,QAAQ,GAAG,kBAAkB;AACnC,MAAM,QAAQ,GAAG,GAAG;AAEpB,SAAS,UAAU,CAAI,KAA0B,EAAA;;AAE/C,IAAA,KAAK,MAAM,GAAG,IAAI,KAAK,EAAE;AACvB,QAAA,KAAK,CAAC,GAAG,CAAC,CAAC,MAAM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AC,IAAI,CAAC,EAAE,IAAI,CAAC,aAAa,CAAC,qBAAqB,CAAC;;AAG/E,IAAA,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC;AACxB;;;;"}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import '../constants/force-settings.js';
|
|
2
|
-
import '../constants/graph-settings.js';
|
|
3
|
-
import '../constants/highlight-settings.js';
|
|
4
|
-
import '../constants/link-settings.js';
|
|
5
|
-
import '../constants/node-settings.js';
|
|
6
2
|
import '@krainovsd/js-helpers';
|
|
7
3
|
import { nodeByPointerGetter } from '../lib/utils/node-by-pointer-getter.js';
|
|
8
4
|
import { linkByPointerGetter } from '../lib/utils/link-by-pointer-getter.js';
|
|
5
|
+
import 'd3-force';
|
|
6
|
+
import 'd3-selection';
|
|
7
|
+
import 'd3-zoom';
|
|
8
|
+
import 'd3-array';
|
|
9
|
+
import 'd3-drag';
|
|
9
10
|
|
|
10
11
|
function initPointer() {
|
|
11
12
|
if (!this.area || !this.nodes)
|
|
@@ -13,6 +14,7 @@ function initPointer() {
|
|
|
13
14
|
function onHover(event) {
|
|
14
15
|
if (!this.area || this.isSelecting)
|
|
15
16
|
return;
|
|
17
|
+
const [pointerX, pointerY] = this.getPointerAreaPosition(event);
|
|
16
18
|
let currentNode;
|
|
17
19
|
let currentLink;
|
|
18
20
|
const checkHighlightNode = this.highlightSettings.highlightByHoverNode && !this.isDragging;
|
|
@@ -20,7 +22,6 @@ function initPointer() {
|
|
|
20
22
|
let highlightNode = true;
|
|
21
23
|
let highlightLink = true;
|
|
22
24
|
if (checkHighlightNode) {
|
|
23
|
-
const [pointerX, pointerY] = this.getPointerAreaPosition(event);
|
|
24
25
|
currentNode = nodeByPointerGetter({
|
|
25
26
|
pointerX,
|
|
26
27
|
pointerY,
|
|
@@ -33,7 +34,6 @@ function initPointer() {
|
|
|
33
34
|
this.area.style.cursor = "pointer";
|
|
34
35
|
}
|
|
35
36
|
else if (checkHighlightLink) {
|
|
36
|
-
const [pointerX, pointerY] = this.getPointerAreaPosition(event);
|
|
37
37
|
currentLink = linkByPointerGetter({
|
|
38
38
|
pointerX,
|
|
39
39
|
pointerY,
|
|
@@ -57,7 +57,6 @@ function initPointer() {
|
|
|
57
57
|
if (!this.listeners.onHover)
|
|
58
58
|
return;
|
|
59
59
|
if (!currentNode && !checkHighlightNode) {
|
|
60
|
-
const [pointerX, pointerY] = this.getPointerAreaPosition(event);
|
|
61
60
|
currentNode = nodeByPointerGetter({
|
|
62
61
|
pointerX,
|
|
63
62
|
pointerY,
|
|
@@ -65,7 +64,6 @@ function initPointer() {
|
|
|
65
64
|
});
|
|
66
65
|
}
|
|
67
66
|
if (!currentNode && (!checkHighlightNode || (!checkHighlightLink && !currentLink))) {
|
|
68
|
-
const [pointerX, pointerY] = this.getPointerAreaPosition(event);
|
|
69
67
|
currentLink = linkByPointerGetter({
|
|
70
68
|
pointerX,
|
|
71
69
|
pointerY,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"init-pointer.js","sources":["../../../../../src/module/GraphCanvas/slices/init-pointer.ts"],"sourcesContent":["import type { GraphCanvas } from \"../GraphCanvas\";\nimport { linkByPointerGetter, nodeByPointerGetter } from \"../lib\";\nimport type { LinkInterface, NodeInterface } from \"../types\";\n\nexport function initPointer<\n NodeData extends Record<string, unknown>,\n LinkData extends Record<string, unknown>,\n>(this: GraphCanvas<NodeData, LinkData>) {\n if (!this.area || !this.nodes) throw new Error(\"bad init data\");\n\n function onHover(this: GraphCanvas<NodeData, LinkData>, event: MouseEvent | TouchEvent) {\n if (!this.area || this.isSelecting) return;\n\n let currentNode: NodeInterface<NodeData> | undefined;\n let currentLink: LinkInterface<NodeData, LinkData> | undefined;\n const checkHighlightNode = this.highlightSettings.highlightByHoverNode && !this.isDragging;\n const checkHighlightLink = this.highlightSettings.highlightByHoverLink && !this.isDragging;\n let highlightNode = true;\n let highlightLink = true;\n\n if (checkHighlightNode) {\n const [pointerX, pointerY] = this.getPointerAreaPosition(event);\n currentNode = nodeByPointerGetter({\n pointerX,\n pointerY,\n nodes: this.nodes,\n });\n if (currentNode?.highlight != undefined) highlightNode = currentNode.highlight;\n }\n if (currentNode && highlightNode) {\n this.area.style.cursor = \"pointer\";\n } else if (checkHighlightLink) {\n const [pointerX, pointerY] = this.getPointerAreaPosition(event);\n currentLink = linkByPointerGetter({\n pointerX,\n pointerY,\n linkHoverExtraZone: this.highlightSettings.linkHoverExtraZone,\n links: this.links,\n curve: this.linkSettings.curve,\n });\n if (currentLink?.highlight != undefined) highlightLink = currentLink?.highlight;\n if (currentLink && highlightLink) {\n this.area.style.cursor = \"pointer\";\n } else {\n this.area.style.cursor = \"default\";\n }\n } else {\n this.area.style.cursor = \"default\";\n }\n this.animateHighlight(\n highlightNode ? currentNode : undefined,\n highlightLink ? currentLink : undefined,\n );\n\n if (!this.listeners.onHover) return;\n if (!currentNode && !checkHighlightNode) {\n const [pointerX, pointerY] = this.getPointerAreaPosition(event);\n currentNode = nodeByPointerGetter({\n pointerX,\n pointerY,\n nodes: this.nodes,\n });\n }\n if (!currentNode && (!checkHighlightNode || (!checkHighlightLink && !currentLink))) {\n const [pointerX, pointerY] = this.getPointerAreaPosition(event);\n currentLink = linkByPointerGetter({\n pointerX,\n pointerY,\n linkHoverExtraZone: this.highlightSettings.linkHoverExtraZone,\n links: this.links,\n curve: this.linkSettings.curve,\n });\n }\n this.listeners.onHover.call(this, event, currentNode, currentLink);\n }\n function onWheelClick(this: GraphCanvas<NodeData, LinkData>, event: MouseEvent | TouchEvent) {\n if (\n this.isDragging ||\n !this.listeners.onWheelClick ||\n !(\"button\" in event) ||\n event.button !== 1\n )\n return;\n\n const [pointerX, pointerY] = this.getPointerAreaPosition(event);\n const currentNode = nodeByPointerGetter({\n pointerX,\n pointerY,\n nodes: this.nodes,\n });\n\n if (!currentNode) {\n const [pointerX, pointerY] = this.getPointerAreaPosition(event);\n const currentLink = linkByPointerGetter({\n pointerX,\n pointerY,\n linkHoverExtraZone: this.highlightSettings.linkHoverExtraZone,\n links: this.links,\n curve: this.linkSettings.curve,\n });\n\n return void this.listeners.onWheelClick.call(this, event, undefined, currentLink);\n }\n\n return void this.listeners.onWheelClick.call(this, event, currentNode, undefined);\n }\n function onRightClick(this: GraphCanvas<NodeData, LinkData>, event: MouseEvent) {\n if (!this.listeners.onContextMenu) return;\n\n const [pointerX, pointerY] = this.getPointerAreaPosition(event);\n const currentNode = nodeByPointerGetter({\n pointerX,\n pointerY,\n nodes: this.nodes,\n });\n\n if (!currentNode) {\n const [pointerX, pointerY] = this.getPointerAreaPosition(event);\n const currentLink = linkByPointerGetter({\n pointerX,\n pointerY,\n linkHoverExtraZone: this.highlightSettings.linkHoverExtraZone,\n links: this.links,\n curve: this.linkSettings.curve,\n });\n\n return void this.listeners.onContextMenu.call(this, event, undefined, currentLink);\n }\n\n return void this.listeners.onContextMenu.call(this, event, currentNode, undefined);\n }\n function onDoubleClick(this: GraphCanvas<NodeData, LinkData>, event: MouseEvent | TouchEvent) {\n if (!this.listeners.onDoubleClick) return;\n\n const [pointerX, pointerY] = this.getPointerAreaPosition(event);\n const currentNode = nodeByPointerGetter({\n pointerX,\n pointerY,\n nodes: this.nodes,\n });\n if (!currentNode) {\n const [pointerX, pointerY] = this.getPointerAreaPosition(event);\n const currentLink = linkByPointerGetter({\n pointerX,\n pointerY,\n linkHoverExtraZone: this.highlightSettings.linkHoverExtraZone,\n links: this.links,\n curve: this.linkSettings.curve,\n });\n\n return void this.listeners.onDoubleClick.call(this, event, undefined, currentLink);\n }\n\n return void this.listeners.onDoubleClick.call(this, event, currentNode, undefined);\n }\n function onClick(this: GraphCanvas<NodeData, LinkData>, event: MouseEvent | TouchEvent) {\n if (this.isDragging || !this.listeners.onClick || (\"button\" in event && event.button !== 0))\n return;\n const [pointerX, pointerY] = this.getPointerAreaPosition(event);\n const currentNode = nodeByPointerGetter({\n pointerX,\n pointerY,\n nodes: this.nodes,\n });\n if (!currentNode) {\n const [pointerX, pointerY] = this.getPointerAreaPosition(event);\n const currentLink = linkByPointerGetter({\n pointerX,\n pointerY,\n linkHoverExtraZone: this.highlightSettings.linkHoverExtraZone,\n links: this.links,\n curve: this.linkSettings.curve,\n });\n\n return void this.listeners.onClick.call(this, event, undefined, currentLink);\n }\n\n return void this.listeners.onClick.call(this, event, currentNode, undefined);\n }\n\n /** hover */\n this.area.addEventListener(\"mousemove\", onHover.bind(this), {\n signal: this.eventAbortController.signal,\n });\n this.area.addEventListener(\"touchmove\", onHover.bind(this), {\n signal: this.eventAbortController.signal,\n });\n\n /** dblclick */\n this.area.addEventListener(\"dblclick\", onDoubleClick.bind(this), {\n signal: this.eventAbortController.signal,\n });\n\n /** wheel click */\n this.area.addEventListener(\"mousedown\", onWheelClick.bind(this), {\n signal: this.eventAbortController.signal,\n });\n\n /** click */\n this.area.addEventListener(\"click\", onClick.bind(this), {\n signal: this.eventAbortController.signal,\n });\n\n /** right click */\n this.area.addEventListener(\"contextmenu\", onRightClick.bind(this), {\n signal: this.eventAbortController.signal,\n });\n}\n"],"names":[],"mappings":";;;;;;;;;SAIgB,WAAW,GAAA;IAIzB,IAAI,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,KAAK;AAAE,QAAA,MAAM,IAAI,KAAK,CAAC,eAAe,CAAC;IAE/D,SAAS,OAAO,CAAwC,KAA8B,EAAA;AACpF,QAAA,IAAI,CAAC,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,WAAW;YAAE;AAEpC,QAAA,IAAI,WAAgD;AACpD,QAAA,IAAI,WAA0D;AAC9D,QAAA,MAAM,kBAAkB,GAAG,IAAI,CAAC,iBAAiB,CAAC,oBAAoB,IAAI,CAAC,IAAI,CAAC,UAAU;AAC1F,QAAA,MAAM,kBAAkB,GAAG,IAAI,CAAC,iBAAiB,CAAC,oBAAoB,IAAI,CAAC,IAAI,CAAC,UAAU;QAC1F,IAAI,aAAa,GAAG,IAAI;QACxB,IAAI,aAAa,GAAG,IAAI;QAExB,IAAI,k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,CAAC;AACF,IAAA,IAAI,CAAC,IAAI,CAAC,gBAAgB,CAAC,WAAW,EAAE,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;AAC1D,QAAA,MAAM,EAAE,IAAI,CAAC,oBAAoB,CAAC,MAAM;AACzC,KAAA,CAAC;;AAGF,IAAA,IAAI,CAAC,IAAI,CAAC,gBAAgB,CAAC,UAAU,EAAE,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;AAC/D,QAAA,MAAM,EAAE,IAAI,CAAC,oBAAoB,CAAC,MAAM;AACzC,KAAA,CAAC;;AAGF,IAAA,IAAI,CAAC,IAAI,CAAC,gBAAgB,CAAC,WAAW,EAAE,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;AAC/D,QAAA,MAAM,EAAE,IAAI,CAAC,oBAAoB,CAAC,MAAM;AACzC,KAAA,CAAC;;AAGF,IAAA,IAAI,CAAC,IAAI,CAAC,gBAAgB,CAAC,OAAO,EAAE,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;AACtD,QAAA,MAAM,EAAE,IAAI,CAAC,oBAAoB,CAAC,MAAM;AACzC,KAAA,CAAC;;AAGF,IAAA,IAAI,CAAC,IAAI,CAAC,gBAAgB,CAAC,aAAa,EAAE,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;AACjE,QAAA,MAAM,EAAE,IAAI,CAAC,oBAAoB,CAAC,MAAM;AACzC,KAAA,CAAC;AACJ;;;;"}
|
|
1
|
+
{"version":3,"file":"init-pointer.js","sources":["../../../../../src/module/GraphCanvas/slices/init-pointer.ts"],"sourcesContent":["import type { GraphCanvas } from \"../GraphCanvas\";\nimport { linkByPointerGetter, nodeByPointerGetter } from \"../lib\";\nimport type { LinkInterface, NodeInterface } from \"../types\";\n\nexport function initPointer<\n NodeData extends Record<string, unknown>,\n LinkData extends Record<string, unknown>,\n>(this: GraphCanvas<NodeData, LinkData>) {\n if (!this.area || !this.nodes) throw new Error(\"bad init data\");\n\n function onHover(this: GraphCanvas<NodeData, LinkData>, event: MouseEvent | TouchEvent) {\n if (!this.area || this.isSelecting) return;\n\n const [pointerX, pointerY] = this.getPointerAreaPosition(event);\n\n let currentNode: NodeInterface<NodeData> | undefined;\n let currentLink: LinkInterface<NodeData, LinkData> | undefined;\n const checkHighlightNode = this.highlightSettings.highlightByHoverNode && !this.isDragging;\n const checkHighlightLink = this.highlightSettings.highlightByHoverLink && !this.isDragging;\n let highlightNode = true;\n let highlightLink = true;\n\n if (checkHighlightNode) {\n currentNode = nodeByPointerGetter({\n pointerX,\n pointerY,\n nodes: this.nodes,\n });\n if (currentNode?.highlight != undefined) highlightNode = currentNode.highlight;\n }\n if (currentNode && highlightNode) {\n this.area.style.cursor = \"pointer\";\n } else if (checkHighlightLink) {\n currentLink = linkByPointerGetter({\n pointerX,\n pointerY,\n linkHoverExtraZone: this.highlightSettings.linkHoverExtraZone,\n links: this.links,\n curve: this.linkSettings.curve,\n });\n if (currentLink?.highlight != undefined) highlightLink = currentLink?.highlight;\n if (currentLink && highlightLink) {\n this.area.style.cursor = \"pointer\";\n } else {\n this.area.style.cursor = \"default\";\n }\n } else {\n this.area.style.cursor = \"default\";\n }\n this.animateHighlight(\n highlightNode ? currentNode : undefined,\n highlightLink ? currentLink : undefined,\n );\n\n if (!this.listeners.onHover) return;\n if (!currentNode && !checkHighlightNode) {\n currentNode = nodeByPointerGetter({\n pointerX,\n pointerY,\n nodes: this.nodes,\n });\n }\n if (!currentNode && (!checkHighlightNode || (!checkHighlightLink && !currentLink))) {\n currentLink = linkByPointerGetter({\n pointerX,\n pointerY,\n linkHoverExtraZone: this.highlightSettings.linkHoverExtraZone,\n links: this.links,\n curve: this.linkSettings.curve,\n });\n }\n this.listeners.onHover.call(this, event, currentNode, currentLink);\n }\n function onWheelClick(this: GraphCanvas<NodeData, LinkData>, event: MouseEvent | TouchEvent) {\n if (\n this.isDragging ||\n !this.listeners.onWheelClick ||\n !(\"button\" in event) ||\n event.button !== 1\n )\n return;\n\n const [pointerX, pointerY] = this.getPointerAreaPosition(event);\n const currentNode = nodeByPointerGetter({\n pointerX,\n pointerY,\n nodes: this.nodes,\n });\n\n if (!currentNode) {\n const [pointerX, pointerY] = this.getPointerAreaPosition(event);\n const currentLink = linkByPointerGetter({\n pointerX,\n pointerY,\n linkHoverExtraZone: this.highlightSettings.linkHoverExtraZone,\n links: this.links,\n curve: this.linkSettings.curve,\n });\n\n return void this.listeners.onWheelClick.call(this, event, undefined, currentLink);\n }\n\n return void this.listeners.onWheelClick.call(this, event, currentNode, undefined);\n }\n function onRightClick(this: GraphCanvas<NodeData, LinkData>, event: MouseEvent) {\n if (!this.listeners.onContextMenu) return;\n\n const [pointerX, pointerY] = this.getPointerAreaPosition(event);\n const currentNode = nodeByPointerGetter({\n pointerX,\n pointerY,\n nodes: this.nodes,\n });\n\n if (!currentNode) {\n const [pointerX, pointerY] = this.getPointerAreaPosition(event);\n const currentLink = linkByPointerGetter({\n pointerX,\n pointerY,\n linkHoverExtraZone: this.highlightSettings.linkHoverExtraZone,\n links: this.links,\n curve: this.linkSettings.curve,\n });\n\n return void this.listeners.onContextMenu.call(this, event, undefined, currentLink);\n }\n\n return void this.listeners.onContextMenu.call(this, event, currentNode, undefined);\n }\n function onDoubleClick(this: GraphCanvas<NodeData, LinkData>, event: MouseEvent | TouchEvent) {\n if (!this.listeners.onDoubleClick) return;\n\n const [pointerX, pointerY] = this.getPointerAreaPosition(event);\n const currentNode = nodeByPointerGetter({\n pointerX,\n pointerY,\n nodes: this.nodes,\n });\n if (!currentNode) {\n const [pointerX, pointerY] = this.getPointerAreaPosition(event);\n const currentLink = linkByPointerGetter({\n pointerX,\n pointerY,\n linkHoverExtraZone: this.highlightSettings.linkHoverExtraZone,\n links: this.links,\n curve: this.linkSettings.curve,\n });\n\n return void this.listeners.onDoubleClick.call(this, event, undefined, currentLink);\n }\n\n return void this.listeners.onDoubleClick.call(this, event, currentNode, undefined);\n }\n function onClick(this: GraphCanvas<NodeData, LinkData>, event: MouseEvent | TouchEvent) {\n if (this.isDragging || !this.listeners.onClick || (\"button\" in event && event.button !== 0))\n return;\n const [pointerX, pointerY] = this.getPointerAreaPosition(event);\n const currentNode = nodeByPointerGetter({\n pointerX,\n pointerY,\n nodes: this.nodes,\n });\n if (!currentNode) {\n const [pointerX, pointerY] = this.getPointerAreaPosition(event);\n const currentLink = linkByPointerGetter({\n pointerX,\n pointerY,\n linkHoverExtraZone: this.highlightSettings.linkHoverExtraZone,\n links: this.links,\n curve: this.linkSettings.curve,\n });\n\n return void this.listeners.onClick.call(this, event, undefined, currentLink);\n }\n\n return void this.listeners.onClick.call(this, event, currentNode, undefined);\n }\n\n /** hover */\n this.area.addEventListener(\"mousemove\", onHover.bind(this), {\n signal: this.eventAbortController.signal,\n });\n this.area.addEventListener(\"touchmove\", onHover.bind(this), {\n signal: this.eventAbortController.signal,\n });\n\n /** dblclick */\n this.area.addEventListener(\"dblclick\", onDoubleClick.bind(this), {\n signal: this.eventAbortController.signal,\n });\n\n /** wheel click */\n this.area.addEventListener(\"mousedown\", onWheelClick.bind(this), {\n signal: this.eventAbortController.signal,\n });\n\n /** click */\n this.area.addEventListener(\"click\", onClick.bind(this), {\n signal: this.eventAbortController.signal,\n });\n\n /** right click */\n this.area.addEventListener(\"contextmenu\", onRightClick.bind(this), {\n signal: this.eventAbortController.signal,\n });\n}\n"],"names":[],"mappings":";;;;;;;;;;SAIgB,WAAW,GAAA;IAIzB,IAAI,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,KAAK;AAAE,QAAA,MAAM,IAAI,KAAK,CAAC,eAAe,CAAC;IAE/D,SAAS,OAAO,CAAwC,KAA8B,EAAA;AACpF,QAAA,IAAI,CAAC,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,WAAW;YAAE;AAEpC,QAAA,MAAM,CAAC,QAAQ,EAAE,QAAQ,CAAC,GAAG,IAAI,CAAC,sBAAsB,CAAC,KAAK,CAAC;AAE/D,QA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AO,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;AAC1D,QAAA,MAAM,EAAE,IAAI,CAAC,oBAAoB,CAAC,MAAM;AACzC,KAAA,CAAC;;AAGF,IAAA,IAAI,CAAC,IAAI,CAAC,gBAAgB,CAAC,UAAU,EAAE,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;AAC/D,QAAA,MAAM,EAAE,IAAI,CAAC,oBAAoB,CAAC,MAAM;AACzC,KAAA,CAAC;;AAGF,IAAA,IAAI,CAAC,IAAI,CAAC,gBAAgB,CAAC,WAAW,EAAE,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;AAC/D,QAAA,MAAM,EAAE,IAAI,CAAC,oBAAoB,CAAC,MAAM;AACzC,KAAA,CAAC;;AAGF,IAAA,IAAI,CAAC,IAAI,CAAC,gBAAgB,CAAC,OAAO,EAAE,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;AACtD,QAAA,MAAM,EAAE,IAAI,CAAC,oBAAoB,CAAC,MAAM;AACzC,KAAA,CAAC;;AAGF,IAAA,IAAI,CAAC,IAAI,CAAC,gBAAgB,CAAC,aAAa,EAAE,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;AACjE,QAAA,MAAM,EAAE,IAAI,CAAC,oBAAoB,CAAC,MAAM;AACzC,KAAA,CAAC;AACJ;;;;"}
|
|
@@ -2,12 +2,11 @@ import { forceCollide, forceX, forceY, forceManyBody, forceCenter, forceSimulati
|
|
|
2
2
|
import '@krainovsd/js-helpers';
|
|
3
3
|
import { getDrawTime, resetDrawTime } from '../../../lib/draw-time.js';
|
|
4
4
|
import '../constants/force-settings.js';
|
|
5
|
-
import '../constants/graph-settings.js';
|
|
6
|
-
import '../constants/highlight-settings.js';
|
|
7
|
-
import '../constants/link-settings.js';
|
|
8
|
-
import '../constants/node-settings.js';
|
|
9
5
|
import 'd3-array';
|
|
10
6
|
import { nodeIterationExtractor } from '../lib/utils/node-iteration-extractor.js';
|
|
7
|
+
import 'd3-selection';
|
|
8
|
+
import 'd3-zoom';
|
|
9
|
+
import 'd3-drag';
|
|
11
10
|
import { initZoom } from './init-zoom.js';
|
|
12
11
|
|
|
13
12
|
function initSimulation() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"init-simulation.js","sources":["../../../../../src/module/GraphCanvas/slices/init-simulation.ts"],"sourcesContent":["import {\n type ForceLink,\n forceCenter,\n forceCollide,\n forceLink,\n forceManyBody,\n forceSimulation,\n forceX,\n forceY,\n} from \"d3-force\";\nimport { getDrawTime, resetDrawTime } from \"@/lib\";\nimport type { GraphCanvas } from \"../GraphCanvas\";\nimport { nodeIterationExtractor } from \"../lib\";\nimport type { LinkInterface, NodeInterface } from \"../types\";\nimport { initZoom } from \"./init-zoom\";\n\nexport function initSimulation<\n NodeData extends Record<string, unknown>,\n LinkData extends Record<string, unknown>,\n>(this: GraphCanvas<NodeData, LinkData>) {\n if (!this.simulation) {\n this.simulation = forceSimulation<NodeInterface<NodeData>, LinkInterface<NodeData, LinkData>>()\n .nodes(this.nodes)\n .force(\n \"link\",\n forceLink<NodeInterface<NodeData>, LinkInterface<NodeData, LinkData>>(this.links).id(\n this.nodeSettings.idGetter.bind(this),\n ),\n )\n .on(\"tick\", () => {\n this.draw();\n })\n .on(\"end\", () => {\n this.listeners.onSimulationEnd?.call?.(this);\n if (this.area) {\n initZoom.call<\n GraphCanvas<NodeData, LinkData>,\n Parameters<typeof initZoom>,\n ReturnType<typeof initZoom>\n >(this, this.areaTransform);\n }\n if (this.graphSettings.showDrawTime) {\n getDrawTime();\n // eslint-disable-next-line no-console\n console.log(`nodes: ${this.nodes.length} | links: ${this.links.length}`);\n resetDrawTime();\n }\n })\n .stop();\n initSimulationForces.call<\n GraphCanvas<NodeData, LinkData>,\n Parameters<typeof initSimulationForces>,\n ReturnType<typeof initSimulationForces>\n >(this);\n }\n}\n\nexport function initSimulationForces<\n NodeData extends Record<string, unknown>,\n LinkData extends Record<string, unknown>,\n>(this: GraphCanvas<NodeData, LinkData>) {\n if (!this.simulation) return;\n\n const linkForce = this.simulation.force(\"link\") as\n | ForceLink<NodeInterface<NodeData>, LinkInterface<NodeData, LinkData>>\n | undefined;\n\n if (!linkForce) return;\n\n if ((!this.forceSettings.forces || !this.forceSettings.xForce) && this.simulation.force(\"x\")) {\n this.simulation.force(\"x\", null);\n }\n if ((!this.forceSettings.forces || !this.forceSettings.yForce) && this.simulation.force(\"y\")) {\n this.simulation.force(\"y\", null);\n }\n if (\n (!this.forceSettings.forces || !this.forceSettings.chargeForce) &&\n this.simulation.force(\"charge\")\n ) {\n this.simulation.force(\"charge\", null);\n }\n if (\n (!this.forceSettings.forces || !this.forceSettings.centerForce) &&\n this.simulation.force(\"center\")\n ) {\n this.simulation.force(\"center\", null);\n }\n if (!this.forceSettings.forces || !this.forceSettings.linkForce) {\n linkForce.distance(0).strength(0).iterations(0);\n }\n\n if (this.forceSettings.forces && this.forceSettings.linkForce) {\n linkForce\n .distance(this.forceSettings.linkDistance)\n .strength(this.forceSettings.linkStrength)\n .iterations(this.forceSettings.linkIterations);\n }\n if (this.forceSettings.forces && this.forceSettings.xForce) {\n this.simulation.force(\n \"x\",\n forceX<NodeInterface<NodeData>>(this.forceSettings.xPosition).strength(\n this.forceSettings.xStrength,\n ),\n );\n }\n if (this.forceSettings.forces && this.forceSettings.yForce) {\n this.simulation.force(\n \"y\",\n forceY<NodeInterface<NodeData>>(this.forceSettings.yPosition).strength(\n this.forceSettings.yStrength,\n ),\n );\n }\n if (this.forceSettings.forces && this.forceSettings.chargeForce) {\n this.simulation.force(\n \"charge\",\n forceManyBody<NodeInterface<NodeData>>()\n .strength(this.forceSettings.chargeStrength)\n .distanceMax(Infinity)\n .distanceMin(this.forceSettings.chargeDistanceMin),\n );\n }\n if (this.forceSettings.forces && this.forceSettings.centerForce) {\n this.simulation.force(\n \"center\",\n forceCenter<NodeInterface<NodeData>>(\n this.forceSettings.centerPosition.x ?? 0,\n this.forceSettings.centerPosition.y ?? 0,\n ).strength(this.forceSettings.centerStrength),\n );\n }\n\n initCollideForce.call<\n GraphCanvas<NodeData, LinkData>,\n Parameters<typeof initCollideForce>,\n ReturnType<typeof initCollideForce>\n >(this, true);\n}\n\nexport function initCollideForce<\n NodeData extends Record<string, unknown>,\n LinkData extends Record<string, unknown>,\n>(this: GraphCanvas<NodeData, LinkData>, forceUpdate: boolean) {\n if (!this.simulation) return;\n\n if (\n (!this.forceSettings.collideForce || !this.forceSettings.forces) &&\n this.simulation.force(\"collide\")\n ) {\n this.simulation.force(\"collide\", null);\n }\n\n if (this.forceSettings.forces && this.forceSettings.collideForce) {\n const isHasMax =\n this.forceSettings.collideOffMax.links != 0 && this.forceSettings.collideOffMax.nodes != 0;\n const isMaxCollideNodes =\n isHasMax && this.forceSettings.collideOffMax.nodes < this.nodes.length;\n const isMaxCollideLinks =\n isHasMax && this.forceSettings.collideOffMax.links < this.links.length;\n if (isMaxCollideNodes && isMaxCollideLinks) {\n this.simulation.force(\"collide\", null);\n } else if (!this.simulation.force(\"collide\") || forceUpdate) {\n this.simulation.force(\n \"collide\",\n forceCollide<NodeInterface<NodeData>>()\n .radius((node, index) => {\n const nodeOptions = this.nodeOptionsCache[index];\n if (!nodeOptions) return 0;\n\n switch (nodeOptions.shape) {\n case \"circle\": {\n if (this.forceSettings.collideRadius) {\n return nodeIterationExtractor(\n node,\n index,\n this.nodes,\n this,\n this.forceSettings.collideRadius,\n undefined,\n );\n }\n\n return nodeOptions.radius + this.forceSettings.collideAdditionalRadius;\n }\n case \"square\": {\n return (\n Math.sqrt(nodeOptions.width ** 2 + nodeOptions.height ** 2) / 2 +\n this.forceSettings.collideAdditionalRadius\n );\n }\n case \"text\": {\n return (\n Math.sqrt(nodeOptions.width ** 2 + nodeOptions.height ** 2) / 2 +\n this.forceSettings.collideAdditionalRadius\n );\n }\n default: {\n if (this.forceSettings.collideRadius) {\n return nodeIterationExtractor(\n node,\n index,\n this.nodes,\n this,\n this.forceSettings.collideRadius,\n undefined,\n );\n }\n\n return nodeOptions.radius + this.forceSettings.collideAdditionalRadius;\n }\n }\n })\n .strength(this.forceSettings.collideStrength)\n .iterations(this.forceSettings.collideIterations),\n );\n }\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;;;SAgBgB,cAAc,GAAA;AAI5B,IAAA,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE;AACpB,QAAA,IAAI,CAAC,UAAU,GAAG,eAAe;AAC9B,aAAA,KAAK,CAAC,IAAI,CAAC,KAAK;aAChB,KAAK,CACJ,MAAM,EACN,SAAS,CAA6D,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAClF,IAAI,CAAC,YAAY,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CACtC;AAEF,aAAA,EAAE,CAAC,MAAM,EAAE,MAAK;YACf,IAAI,CAAC,IAAI,EAAE;AACb,SAAC;AACA,aAAA,EAAE,CAAC,KAAK,EAAE,MAAK;YACd,IAAI,CAAC,SAAS,CAAC,eAAe,EAAE,IAAI,GAAG,IAAI,CAAC;AAC5C,YAAA,IAAI,IAAI,CAAC,IAAI,EAAE;gBACb,QAAQ,CAAC,IAAI,CAIX,IAAI,EAAE,IAAI,CAAC,aAAa,CAAC;;AAE7B,YAAA,IAAI,IAAI,CAAC,aAAa,CAAC,YAAY,EAAE;AACnC,gBAAA,WAAW,EAAE;;AAEb,gBAAA,OAAO,CAAC,GAAG,CAAC,CAAU,OAAA,EAAA,IAAI,CAAC,KAAK,CAAC,MAAM,CAAA,UAAA,EAAa,IAAI,CAAC,KAAK,CAAC,MAAM,CAAA,CAAE,CAAC;AACxE,gBAAA,aAAa,EAAE;;AAEnB,SAAC;AACA,aAAA,IAAI,EAAE;AACT,QAAA,oBAAoB,CAAC,IAAI,CAIvB,IAAI,CAAC;;AAEX;SAEgB,oBAAoB,GAAA;IAIlC,IAAI,CAAC,IAAI,CAAC,UAAU;QAAE;IAEtB,MAAM,SAAS,GAAG,IAAI,CAAC,UAAU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AAG5E,aAAC;AACA,iBAAA,QAAQ,CAAC,IAAI,CAAC,aAAa,CAAC,eAAe;iBAC3C,UAAU,CAAC,IAAI,CAAC,aAAa,CAAC,iBAAiB,CAAC,CACpD;;;AAGP;;;;"}
|
|
1
|
+
{"version":3,"file":"init-simulation.js","sources":["../../../../../src/module/GraphCanvas/slices/init-simulation.ts"],"sourcesContent":["import {\n type ForceLink,\n forceCenter,\n forceCollide,\n forceLink,\n forceManyBody,\n forceSimulation,\n forceX,\n forceY,\n} from \"d3-force\";\nimport { getDrawTime, resetDrawTime } from \"@/lib\";\nimport type { GraphCanvas } from \"../GraphCanvas\";\nimport { nodeIterationExtractor } from \"../lib\";\nimport type { LinkInterface, NodeInterface } from \"../types\";\nimport { initZoom } from \"./init-zoom\";\n\nexport function initSimulation<\n NodeData extends Record<string, unknown>,\n LinkData extends Record<string, unknown>,\n>(this: GraphCanvas<NodeData, LinkData>) {\n if (!this.simulation) {\n this.simulation = forceSimulation<NodeInterface<NodeData>, LinkInterface<NodeData, LinkData>>()\n .nodes(this.nodes)\n .force(\n \"link\",\n forceLink<NodeInterface<NodeData>, LinkInterface<NodeData, LinkData>>(this.links).id(\n this.nodeSettings.idGetter.bind(this),\n ),\n )\n .on(\"tick\", () => {\n this.draw();\n })\n .on(\"end\", () => {\n this.listeners.onSimulationEnd?.call?.(this);\n if (this.area) {\n initZoom.call<\n GraphCanvas<NodeData, LinkData>,\n Parameters<typeof initZoom>,\n ReturnType<typeof initZoom>\n >(this, this.areaTransform);\n }\n if (this.graphSettings.showDrawTime) {\n getDrawTime();\n // eslint-disable-next-line no-console\n console.log(`nodes: ${this.nodes.length} | links: ${this.links.length}`);\n resetDrawTime();\n }\n })\n .stop();\n initSimulationForces.call<\n GraphCanvas<NodeData, LinkData>,\n Parameters<typeof initSimulationForces>,\n ReturnType<typeof initSimulationForces>\n >(this);\n }\n}\n\nexport function initSimulationForces<\n NodeData extends Record<string, unknown>,\n LinkData extends Record<string, unknown>,\n>(this: GraphCanvas<NodeData, LinkData>) {\n if (!this.simulation) return;\n\n const linkForce = this.simulation.force(\"link\") as\n | ForceLink<NodeInterface<NodeData>, LinkInterface<NodeData, LinkData>>\n | undefined;\n\n if (!linkForce) return;\n\n if ((!this.forceSettings.forces || !this.forceSettings.xForce) && this.simulation.force(\"x\")) {\n this.simulation.force(\"x\", null);\n }\n if ((!this.forceSettings.forces || !this.forceSettings.yForce) && this.simulation.force(\"y\")) {\n this.simulation.force(\"y\", null);\n }\n if (\n (!this.forceSettings.forces || !this.forceSettings.chargeForce) &&\n this.simulation.force(\"charge\")\n ) {\n this.simulation.force(\"charge\", null);\n }\n if (\n (!this.forceSettings.forces || !this.forceSettings.centerForce) &&\n this.simulation.force(\"center\")\n ) {\n this.simulation.force(\"center\", null);\n }\n if (!this.forceSettings.forces || !this.forceSettings.linkForce) {\n linkForce.distance(0).strength(0).iterations(0);\n }\n\n if (this.forceSettings.forces && this.forceSettings.linkForce) {\n linkForce\n .distance(this.forceSettings.linkDistance)\n .strength(this.forceSettings.linkStrength)\n .iterations(this.forceSettings.linkIterations);\n }\n if (this.forceSettings.forces && this.forceSettings.xForce) {\n this.simulation.force(\n \"x\",\n forceX<NodeInterface<NodeData>>(this.forceSettings.xPosition).strength(\n this.forceSettings.xStrength,\n ),\n );\n }\n if (this.forceSettings.forces && this.forceSettings.yForce) {\n this.simulation.force(\n \"y\",\n forceY<NodeInterface<NodeData>>(this.forceSettings.yPosition).strength(\n this.forceSettings.yStrength,\n ),\n );\n }\n if (this.forceSettings.forces && this.forceSettings.chargeForce) {\n this.simulation.force(\n \"charge\",\n forceManyBody<NodeInterface<NodeData>>()\n .strength(this.forceSettings.chargeStrength)\n .distanceMax(Infinity)\n .distanceMin(this.forceSettings.chargeDistanceMin),\n );\n }\n if (this.forceSettings.forces && this.forceSettings.centerForce) {\n this.simulation.force(\n \"center\",\n forceCenter<NodeInterface<NodeData>>(\n this.forceSettings.centerPosition.x ?? 0,\n this.forceSettings.centerPosition.y ?? 0,\n ).strength(this.forceSettings.centerStrength),\n );\n }\n\n initCollideForce.call<\n GraphCanvas<NodeData, LinkData>,\n Parameters<typeof initCollideForce>,\n ReturnType<typeof initCollideForce>\n >(this, true);\n}\n\nexport function initCollideForce<\n NodeData extends Record<string, unknown>,\n LinkData extends Record<string, unknown>,\n>(this: GraphCanvas<NodeData, LinkData>, forceUpdate: boolean) {\n if (!this.simulation) return;\n\n if (\n (!this.forceSettings.collideForce || !this.forceSettings.forces) &&\n this.simulation.force(\"collide\")\n ) {\n this.simulation.force(\"collide\", null);\n }\n\n if (this.forceSettings.forces && this.forceSettings.collideForce) {\n const isHasMax =\n this.forceSettings.collideOffMax.links != 0 && this.forceSettings.collideOffMax.nodes != 0;\n const isMaxCollideNodes =\n isHasMax && this.forceSettings.collideOffMax.nodes < this.nodes.length;\n const isMaxCollideLinks =\n isHasMax && this.forceSettings.collideOffMax.links < this.links.length;\n if (isMaxCollideNodes && isMaxCollideLinks) {\n this.simulation.force(\"collide\", null);\n } else if (!this.simulation.force(\"collide\") || forceUpdate) {\n this.simulation.force(\n \"collide\",\n forceCollide<NodeInterface<NodeData>>()\n .radius((node, index) => {\n const nodeOptions = this.nodeOptionsCache[index];\n if (!nodeOptions) return 0;\n\n switch (nodeOptions.shape) {\n case \"circle\": {\n if (this.forceSettings.collideRadius) {\n return nodeIterationExtractor(\n node,\n index,\n this.nodes,\n this,\n this.forceSettings.collideRadius,\n undefined,\n );\n }\n\n return nodeOptions.radius + this.forceSettings.collideAdditionalRadius;\n }\n case \"square\": {\n return (\n Math.sqrt(nodeOptions.width ** 2 + nodeOptions.height ** 2) / 2 +\n this.forceSettings.collideAdditionalRadius\n );\n }\n case \"text\": {\n return (\n Math.sqrt(nodeOptions.width ** 2 + nodeOptions.height ** 2) / 2 +\n this.forceSettings.collideAdditionalRadius\n );\n }\n default: {\n if (this.forceSettings.collideRadius) {\n return nodeIterationExtractor(\n node,\n index,\n this.nodes,\n this,\n this.forceSettings.collideRadius,\n undefined,\n );\n }\n\n return nodeOptions.radius + this.forceSettings.collideAdditionalRadius;\n }\n }\n })\n .strength(this.forceSettings.collideStrength)\n .iterations(this.forceSettings.collideIterations),\n );\n }\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;;SAgBgB,cAAc,GAAA;AAI5B,IAAA,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE;AACpB,QAAA,IAAI,CAAC,UAAU,GAAG,eAAe;AAC9B,aAAA,KAAK,CAAC,IAAI,CAAC,KAAK;aAChB,KAAK,CACJ,MAAM,EACN,SAAS,CAA6D,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAClF,IAAI,CAAC,YAAY,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CACtC;AAEF,aAAA,EAAE,CAAC,MAAM,EAAE,MAAK;YACf,IAAI,CAAC,IAAI,EAAE;AACb,SAAC;AACA,aAAA,EAAE,CAAC,KAAK,EAAE,MAAK;YACd,IAAI,CAAC,SAAS,CAAC,eAAe,EAAE,IAAI,GAAG,IAAI,CAAC;AAC5C,YAAA,IAAI,IAAI,CAAC,IAAI,EAAE;gBACb,QAAQ,CAAC,IAAI,CAIX,IAAI,EAAE,IAAI,CAAC,aAAa,CAAC;;AAE7B,YAAA,IAAI,IAAI,CAAC,aAAa,CAAC,YAAY,EAAE;AACnC,gBAAA,WAAW,EAAE;;AAEb,gBAAA,OAAO,CAAC,GAAG,CAAC,CAAU,OAAA,EAAA,IAAI,CAAC,KAAK,CAAC,MAAM,CAAA,UAAA,EAAa,IAAI,CAAC,KAAK,CAAC,MAAM,CAAA,CAAE,CAAC;AACxE,gBAAA,aAAa,EAAE;;AAEnB,SAAC;AACA,aAAA,IAAI,EAAE;AACT,QAAA,oBAAoB,CAAC,IAAI,CAIvB,IAAI,CAAC;;AAEX;SAEgB,oBAAoB,GAAA;IAIlC,IAAI,CAAC,IAAI,CAAC,UAAU;QAAE;IAEtB,MAAM,SAAS,GAAG,IAAI,CAAC,UAAU,CAAC,KAAK,C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ACA,iBAAA,QAAQ,CAAC,IAAI,CAAC,aAAa,CAAC,eAAe;iBAC3C,UAAU,CAAC,IAAI,CAAC,aAAa,CAAC,iBAAiB,CAAC,CACpD;;;AAGP;;;;"}
|
|
@@ -2,12 +2,10 @@ import { isArray } from '@krainovsd/js-helpers';
|
|
|
2
2
|
import { select } from 'd3-selection';
|
|
3
3
|
import { zoom, ZoomTransform } from 'd3-zoom';
|
|
4
4
|
import '../constants/force-settings.js';
|
|
5
|
-
import '../constants/graph-settings.js';
|
|
6
|
-
import '../constants/highlight-settings.js';
|
|
7
|
-
import '../constants/link-settings.js';
|
|
8
|
-
import '../constants/node-settings.js';
|
|
9
5
|
import { computeGraphBounds } from '../lib/utils/compute-graph-bounds.js';
|
|
10
6
|
import 'd3-array';
|
|
7
|
+
import 'd3-force';
|
|
8
|
+
import 'd3-drag';
|
|
11
9
|
import { updateLinkCache } from './update-link-cache.js';
|
|
12
10
|
import { updateNodeCache } from './update-node-cache.js';
|
|
13
11
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"init-zoom.js","sources":["../../../../../src/module/GraphCanvas/slices/init-zoom.ts"],"sourcesContent":["import { isArray } from \"@krainovsd/js-helpers\";\nimport { select as d3Select } from \"d3-selection\";\nimport { ZoomTransform, zoom } from \"d3-zoom\";\nimport type { GraphCanvas } from \"../GraphCanvas\";\nimport { computeGraphBounds } from \"../lib\";\nimport type { ZoomEventInterface } from \"../types\";\nimport { updateLinkCache } from \"./update-link-cache\";\nimport { updateNodeCache } from \"./update-node-cache\";\n\nconst DEFAULT_ZOOM_EXTENT: [number, number] = [0.3, 10];\nconst DEFAULT_TRANSLATE_EXTENT_COEFFICIENT = 8;\nconst DEFAULT_MARGIN = 0.25;\n\nexport function initZoom<\n NodeData extends Record<string, unknown>,\n LinkData extends Record<string, unknown>,\n>(this: GraphCanvas<NodeData, LinkData>, currentZoom?: ZoomTransform) {\n if (!this.area) throw new Error(\"bad init data\");\n\n const bounds = computeGraphBounds(this.nodes);\n const zoomExtent = resolveZoomExtent(\n this.graphSettings.zoomExtent,\n this.width,\n this.height,\n this.graphSettings.zoomExtentMargin ?? DEFAULT_MARGIN,\n bounds,\n );\n const translateExtent = resolveTranslateExtent(\n this.graphSettings.translateExtent,\n this.graphSettings.translateExtentCoefficient,\n this.graphSettings.translateExtentOverlap,\n this.width,\n this.height,\n zoomExtent,\n bounds,\n );\n this._translateExtent = translateExtent;\n\n const zoomInstance = zoom<HTMLCanvasElement, unknown>()\n .scaleExtent(zoomExtent)\n .filter((event) => {\n return !(event instanceof MouseEvent && event.shiftKey);\n })\n .on(\"zoom\", (event: ZoomEventInterface) => {\n if (this._zoomAnimating) return;\n this.listeners.onZoom?.call?.(this, event);\n const oldTransform = this.areaTransform;\n this.areaTransform = event.transform;\n if (this.areaTransform.k !== oldTransform.k) {\n updateLinkCache.call<\n GraphCanvas<NodeData, LinkData>,\n Parameters<typeof updateLinkCache>,\n ReturnType<typeof updateLinkCache>\n >(this);\n updateNodeCache.call<\n GraphCanvas<NodeData, LinkData>,\n Parameters<typeof updateNodeCache>,\n ReturnType<typeof updateNodeCache>\n >(this);\n }\n this.tick();\n });\n\n zoomInstance.translateExtent(translateExtent);\n d3Select(this.area).call(zoomInstance).on(\"dblclick.zoom\", null);\n\n const zoomInitial = currentZoom ?? this.graphSettings.zoomInitial;\n this.areaTransform = new ZoomTransform(\n Math.max(zoomInitial?.k ?? 1, zoomExtent[0]),\n zoomInitial?.x ?? this.width / 2,\n zoomInitial?.y ?? this.height / 2,\n );\n zoom<HTMLCanvasElement, unknown>().transform(d3Select(this.area), this.areaTransform);\n}\n\nfunction resolveZoomExtent(\n userExtent: [number, number] | null,\n viewWidth: number,\n viewHeight: number,\n margin: number,\n bounds: ReturnType<typeof computeGraphBounds>,\n): [number, number] {\n if (\n userExtent &&\n userExtent.length === 2 &&\n userExtent[0] != undefined &&\n userExtent[1] != undefined\n ) {\n return userExtent;\n }\n if (!bounds) return DEFAULT_ZOOM_EXTENT;\n const graphWidth = bounds.maxX - bounds.minX;\n const graphHeight = bounds.maxY - bounds.minY;\n if (graphWidth === 0 || graphHeight === 0) return DEFAULT_ZOOM_EXTENT;\n const scaleToFit = (1 - margin) / Math.max(graphWidth / viewWidth, graphHeight / viewHeight);\n return [scaleToFit, DEFAULT_ZOOM_EXTENT[1]];\n}\n\nfunction resolveTranslateExtent(\n userExtent: [[number?, number?], [number?, number?]] | null,\n userCoefficient: number | [number, number] | null,\n overlap: number,\n viewWidth: number,\n viewHeight: number,\n zoomExtent: [number, number],\n bounds: ReturnType<typeof computeGraphBounds>,\n): [[number, number], [number, number]] {\n if (userExtent && userExtent.length >= 2 && isArray(userExtent[0]) && isArray(userExtent[1])) {\n return [\n [\n userExtent[0][0] ?? -viewWidth * DEFAULT_TRANSLATE_EXTENT_COEFFICIENT,\n userExtent[0][1] ?? -viewHeight * DEFAULT_TRANSLATE_EXTENT_COEFFICIENT,\n ],\n [\n userExtent[1][0] ?? viewWidth * DEFAULT_TRANSLATE_EXTENT_COEFFICIENT,\n userExtent[1][1] ?? viewHeight * DEFAULT_TRANSLATE_EXTENT_COEFFICIENT,\n ],\n ];\n }\n if (userCoefficient) {\n const [cx, cy] = isArray(userCoefficient)\n ? userCoefficient\n : [userCoefficient, userCoefficient];\n return [\n [-viewWidth * cx, -viewHeight * cy],\n [viewWidth * cx, viewHeight * cy],\n ];\n }\n if (!bounds) {\n return [\n [\n -viewWidth * DEFAULT_TRANSLATE_EXTENT_COEFFICIENT,\n -viewHeight * DEFAULT_TRANSLATE_EXTENT_COEFFICIENT,\n ],\n [\n viewWidth * DEFAULT_TRANSLATE_EXTENT_COEFFICIENT,\n viewHeight * DEFAULT_TRANSLATE_EXTENT_COEFFICIENT,\n ],\n ];\n }\n\n const minZoom = zoomExtent[0];\n const zoomViewWidth = viewWidth / minZoom;\n const zoomViewHeight = viewHeight / minZoom;\n const graphWidth = bounds.maxX - bounds.minX;\n const graphHeight = bounds.maxY - bounds.minY;\n\n const minX = bounds.minX + overlap * graphWidth - zoomViewWidth;\n const maxX = bounds.maxX - overlap * graphWidth + zoomViewWidth;\n const minY = bounds.minY + overlap * graphHeight - zoomViewHeight;\n const maxY = bounds.maxY - overlap * graphHeight + zoomViewHeight;\n\n return [\n [minX, minY],\n [maxX, maxY],\n ];\n}\n"],"names":["d3Select"],"mappings":"
|
|
1
|
+
{"version":3,"file":"init-zoom.js","sources":["../../../../../src/module/GraphCanvas/slices/init-zoom.ts"],"sourcesContent":["import { isArray } from \"@krainovsd/js-helpers\";\nimport { select as d3Select } from \"d3-selection\";\nimport { ZoomTransform, zoom } from \"d3-zoom\";\nimport type { GraphCanvas } from \"../GraphCanvas\";\nimport { computeGraphBounds } from \"../lib\";\nimport type { ZoomEventInterface } from \"../types\";\nimport { updateLinkCache } from \"./update-link-cache\";\nimport { updateNodeCache } from \"./update-node-cache\";\n\nconst DEFAULT_ZOOM_EXTENT: [number, number] = [0.3, 10];\nconst DEFAULT_TRANSLATE_EXTENT_COEFFICIENT = 8;\nconst DEFAULT_MARGIN = 0.25;\n\nexport function initZoom<\n NodeData extends Record<string, unknown>,\n LinkData extends Record<string, unknown>,\n>(this: GraphCanvas<NodeData, LinkData>, currentZoom?: ZoomTransform) {\n if (!this.area) throw new Error(\"bad init data\");\n\n const bounds = computeGraphBounds(this.nodes);\n const zoomExtent = resolveZoomExtent(\n this.graphSettings.zoomExtent,\n this.width,\n this.height,\n this.graphSettings.zoomExtentMargin ?? DEFAULT_MARGIN,\n bounds,\n );\n const translateExtent = resolveTranslateExtent(\n this.graphSettings.translateExtent,\n this.graphSettings.translateExtentCoefficient,\n this.graphSettings.translateExtentOverlap,\n this.width,\n this.height,\n zoomExtent,\n bounds,\n );\n this._translateExtent = translateExtent;\n\n const zoomInstance = zoom<HTMLCanvasElement, unknown>()\n .scaleExtent(zoomExtent)\n .filter((event) => {\n return !(event instanceof MouseEvent && event.shiftKey);\n })\n .on(\"zoom\", (event: ZoomEventInterface) => {\n if (this._zoomAnimating) return;\n this.listeners.onZoom?.call?.(this, event);\n const oldTransform = this.areaTransform;\n this.areaTransform = event.transform;\n if (this.areaTransform.k !== oldTransform.k) {\n updateLinkCache.call<\n GraphCanvas<NodeData, LinkData>,\n Parameters<typeof updateLinkCache>,\n ReturnType<typeof updateLinkCache>\n >(this);\n updateNodeCache.call<\n GraphCanvas<NodeData, LinkData>,\n Parameters<typeof updateNodeCache>,\n ReturnType<typeof updateNodeCache>\n >(this);\n }\n this.tick();\n });\n\n zoomInstance.translateExtent(translateExtent);\n d3Select(this.area).call(zoomInstance).on(\"dblclick.zoom\", null);\n\n const zoomInitial = currentZoom ?? this.graphSettings.zoomInitial;\n this.areaTransform = new ZoomTransform(\n Math.max(zoomInitial?.k ?? 1, zoomExtent[0]),\n zoomInitial?.x ?? this.width / 2,\n zoomInitial?.y ?? this.height / 2,\n );\n zoom<HTMLCanvasElement, unknown>().transform(d3Select(this.area), this.areaTransform);\n}\n\nfunction resolveZoomExtent(\n userExtent: [number, number] | null,\n viewWidth: number,\n viewHeight: number,\n margin: number,\n bounds: ReturnType<typeof computeGraphBounds>,\n): [number, number] {\n if (\n userExtent &&\n userExtent.length === 2 &&\n userExtent[0] != undefined &&\n userExtent[1] != undefined\n ) {\n return userExtent;\n }\n if (!bounds) return DEFAULT_ZOOM_EXTENT;\n const graphWidth = bounds.maxX - bounds.minX;\n const graphHeight = bounds.maxY - bounds.minY;\n if (graphWidth === 0 || graphHeight === 0) return DEFAULT_ZOOM_EXTENT;\n const scaleToFit = (1 - margin) / Math.max(graphWidth / viewWidth, graphHeight / viewHeight);\n return [scaleToFit, DEFAULT_ZOOM_EXTENT[1]];\n}\n\nfunction resolveTranslateExtent(\n userExtent: [[number?, number?], [number?, number?]] | null,\n userCoefficient: number | [number, number] | null,\n overlap: number,\n viewWidth: number,\n viewHeight: number,\n zoomExtent: [number, number],\n bounds: ReturnType<typeof computeGraphBounds>,\n): [[number, number], [number, number]] {\n if (userExtent && userExtent.length >= 2 && isArray(userExtent[0]) && isArray(userExtent[1])) {\n return [\n [\n userExtent[0][0] ?? -viewWidth * DEFAULT_TRANSLATE_EXTENT_COEFFICIENT,\n userExtent[0][1] ?? -viewHeight * DEFAULT_TRANSLATE_EXTENT_COEFFICIENT,\n ],\n [\n userExtent[1][0] ?? viewWidth * DEFAULT_TRANSLATE_EXTENT_COEFFICIENT,\n userExtent[1][1] ?? viewHeight * DEFAULT_TRANSLATE_EXTENT_COEFFICIENT,\n ],\n ];\n }\n if (userCoefficient) {\n const [cx, cy] = isArray(userCoefficient)\n ? userCoefficient\n : [userCoefficient, userCoefficient];\n return [\n [-viewWidth * cx, -viewHeight * cy],\n [viewWidth * cx, viewHeight * cy],\n ];\n }\n if (!bounds) {\n return [\n [\n -viewWidth * DEFAULT_TRANSLATE_EXTENT_COEFFICIENT,\n -viewHeight * DEFAULT_TRANSLATE_EXTENT_COEFFICIENT,\n ],\n [\n viewWidth * DEFAULT_TRANSLATE_EXTENT_COEFFICIENT,\n viewHeight * DEFAULT_TRANSLATE_EXTENT_COEFFICIENT,\n ],\n ];\n }\n\n const minZoom = zoomExtent[0];\n const zoomViewWidth = viewWidth / minZoom;\n const zoomViewHeight = viewHeight / minZoom;\n const graphWidth = bounds.maxX - bounds.minX;\n const graphHeight = bounds.maxY - bounds.minY;\n\n const minX = bounds.minX + overlap * graphWidth - zoomViewWidth;\n const maxX = bounds.maxX - overlap * graphWidth + zoomViewWidth;\n const minY = bounds.minY + overlap * graphHeight - zoomViewHeight;\n const maxY = bounds.maxY - overlap * graphHeight + zoomViewHeight;\n\n return [\n [minX, minY],\n [maxX, maxY],\n ];\n}\n"],"names":["d3Select"],"mappings":";;;;;;;;;;;AASA,MAAM,mBAAmB,GAAqB,CAAC,GAAG,EAAE,EAAE,CAAC;AACvD,MAAM,oCAAoC,GAAG,CAAC;AAC9C,MAAM,cAAc,GAAG,IAAI;AAErB,SAAU,QAAQ,CAGiB,WAA2B,EAAA;IAClE,IAAI,CAAC,IAAI,CAAC,IAAI;AAA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AACnD,aAAA;AACD,YAAA;AACE,gBAAA,SAAS,GAAG,oCAAoC;AAChD,gBAAA,UAAU,GAAG,oCAAoC;AAClD,aAAA;SACF;;AAGH,IAAA,MAAM,OAAO,GAAG,UAAU,CAAC,CAAC,CAAC;AAC7B,IAAA,MAAM,aAAa,GAAG,SAAS,GAAG,OAAO;AACzC,IAAA,MAAM,cAAc,GAAG,UAAU,GAAG,OAAO;IAC3C,MAAM,UAAU,GAAG,MAAM,CAAC,IAAI,GAAG,MAAM,CAAC,IAAI;IAC5C,MAAM,WAAW,GAAG,MAAM,CAAC,IAAI,GAAG,MAAM,CAAC,IAAI;IAE7C,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,GAAG,OAAO,GAAG,UAAU,GAAG,aAAa;IAC/D,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,GAAG,OAAO,GAAG,UAAU,GAAG,aAAa;IAC/D,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,GAAG,OAAO,GAAG,WAAW,GAAG,cAAc;IACjE,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,GAAG,OAAO,GAAG,WAAW,GAAG,cAAc;IAEjE,OAAO;QACL,CAAC,IAAI,EAAE,IAAI,CAAC;QACZ,CAAC,IAAI,EAAE,IAAI,CAAC;KACb;AACH;;;;"}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import '../constants/force-settings.js';
|
|
2
|
-
import '../constants/graph-settings.js';
|
|
3
|
-
import '../constants/highlight-settings.js';
|
|
4
|
-
import '../constants/link-settings.js';
|
|
5
|
-
import '../constants/node-settings.js';
|
|
6
2
|
import { linkOptionsGetter } from '../lib/settings/link-settings-getter.js';
|
|
7
3
|
import '@krainovsd/js-helpers';
|
|
4
|
+
import { extractLinkPointIds } from '../lib/utils/extract-link-point-ids.js';
|
|
8
5
|
import { linkIterationExtractor } from '../lib/utils/link-iteration-extractor.js';
|
|
9
6
|
import 'd3-array';
|
|
10
|
-
import
|
|
7
|
+
import 'd3-force';
|
|
8
|
+
import 'd3-selection';
|
|
9
|
+
import 'd3-zoom';
|
|
10
|
+
import 'd3-drag';
|
|
11
11
|
|
|
12
12
|
function updateLinkCache() {
|
|
13
13
|
if (!this.context)
|