@krainovsd/graph 0.14.0-beta.9 → 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 +636 -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 +36 -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/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 +4 -5
- package/lib/esm/module/GraphCanvas/slices/export-svg.js.map +1 -1
- 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 +94 -43
- package/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"precompute-graph.js","sources":["../../../../../../src/module/GraphCanvas/lib/utils/precompute-graph.ts"],"sourcesContent":["import { GraphCanvas } from \"../../GraphCanvas\";\nimport type {\n ForceSettingsInterface,\n LinkInterface,\n LinkSettingsInterface,\n NodeInterface,\n NodeSettingsInterface,\n} from \"../../types\";\n\ntype PrecomputeGraphOptions<\n NodeData extends Record<string, unknown>,\n LinkData extends Record<string, unknown>,\n> = {\n nodes: NodeInterface<NodeData>[];\n links: LinkInterface<NodeData, LinkData>[];\n forceSettings?: ForceSettingsInterface<NodeData, LinkData>;\n nodeSettings?: NodeSettingsInterface<NodeData, LinkData>;\n linkSettings?: LinkSettingsInterface<NodeData, LinkData>;\n maxMs?: number;\n};\nexport function precomputeGraph<\n NodeData extends Record<string, unknown>,\n LinkData extends Record<string, unknown>,\n>(opts: PrecomputeGraphOptions<NodeData, LinkData>) {\n const div = document.createElement(\"div\");\n const graph = new GraphCanvas({\n root: div,\n nodes: opts.nodes,\n links: opts.links,\n nodeSettings: opts.nodeSettings,\n linkSettings: opts.linkSettings,\n forceSettings: {\n ...opts.forceSettings,\n precompute: true,\n precomputeDisableForcesAfter: true,\n precomputeMaxTicks: Infinity,\n precomputeMaxTimeMs: opts.maxMs ?? Infinity,\n },\n });\n graph.precompute();\n graph.destroy();\n}\n"],"names":[],"mappings":";;AAoBM,SAAU,eAAe,CAG7B,IAAgD,EAAA;IAChD,MAAM,GAAG,GAAG,QAAQ,CAAC,aAAa,CAAC,KAAK,CAAC;AACzC,IAAA,MAAM,KAAK,GAAG,IAAI,WAAW,CAAC;AAC5B,QAAA,IAAI,EAAE,GAAG;QACT,KAAK,EAAE,IAAI,CAAC,KAAK;QACjB,KAAK,EAAE,IAAI,CAAC,KAAK;QACjB,YAAY,EAAE,IAAI,CAAC,YAAY;QAC/B,YAAY,EAAE,IAAI,CAAC,YAAY;AAC/B,QAAA,aAAa,EAAE;YACb,GAAG,IAAI,CAAC,aAAa;AACrB,YAAA,UAAU,EAAE,IAAI;AAChB,YAAA,4BAA4B,EAAE,IAAI;AAClC,YAAA,kBAAkB,EAAE,QAAQ;AAC5B,YAAA,mBAAmB,EAAE,IAAI,CAAC,KAAK,IAAI,QAAQ;AAC5C,SAAA;AACF,KAAA,CAAC;IACF,KAAK,CAAC,UAAU,EAAE;IAClB,KAAK,CAAC,OAAO,EAAE;AACjB;;;;"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { extractLinkPointIds } from './extract-link-point-ids.js';
|
|
2
|
+
|
|
3
|
+
function prepareGraph(opts) {
|
|
4
|
+
const nodes = opts.nodes;
|
|
5
|
+
const links = opts.links;
|
|
6
|
+
const map = new Map();
|
|
7
|
+
const neighbors = new Map();
|
|
8
|
+
for (let i = 0; i < links.length; i++) {
|
|
9
|
+
const link = links[i];
|
|
10
|
+
const { sourceId, targetId } = extractLinkPointIds(link);
|
|
11
|
+
const sources = neighbors.get(sourceId);
|
|
12
|
+
if (sources) {
|
|
13
|
+
sources.push(targetId);
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
neighbors.set(sourceId, [targetId]);
|
|
17
|
+
}
|
|
18
|
+
const targets = neighbors.get(targetId);
|
|
19
|
+
if (targets) {
|
|
20
|
+
targets.push(sourceId);
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
neighbors.set(targetId, [sourceId]);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
for (let i = 0; i < nodes.length; i++) {
|
|
27
|
+
const node = nodes[i];
|
|
28
|
+
map.set(node.id, node);
|
|
29
|
+
node.index = i;
|
|
30
|
+
node.x ??= 0;
|
|
31
|
+
node.y ??= 0;
|
|
32
|
+
if (opts.neighbors) {
|
|
33
|
+
const n = neighbors.get(node.id);
|
|
34
|
+
if (n) {
|
|
35
|
+
node.neighbors = [...new Set(n)];
|
|
36
|
+
node.linkCount = node.neighbors.length;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
for (let i = 0; i < links.length; i++) {
|
|
41
|
+
const link = links[i];
|
|
42
|
+
const { sourceId, targetId } = extractLinkPointIds(link);
|
|
43
|
+
link.source = map.get(sourceId) ?? link.source;
|
|
44
|
+
link.target = map.get(targetId) ?? link.target;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export { prepareGraph };
|
|
49
|
+
//# sourceMappingURL=prepare-graph-data.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prepare-graph-data.js","sources":["../../../../../../src/module/GraphCanvas/lib/utils/prepare-graph-data.ts"],"sourcesContent":["import type { LinkInterface, NodeInterface } from \"../../types\";\nimport { extractLinkPointIds } from \"./extract-link-point-ids\";\n\ntype PrepareGraphOptions<\n NodeData extends Record<string, unknown>,\n LinkData extends Record<string, unknown>,\n> = {\n nodes: NodeInterface<NodeData>[];\n links: LinkInterface<NodeData, LinkData>[];\n neighbors?: boolean;\n};\nexport function prepareGraph<\n NodeData extends Record<string, unknown>,\n LinkData extends Record<string, unknown>,\n>(opts: PrepareGraphOptions<NodeData, LinkData>) {\n const nodes = opts.nodes;\n const links = opts.links;\n const map = new Map<string | number, NodeInterface<NodeData>>();\n const neighbors = new Map<string | number, (string | number)[]>();\n\n for (let i = 0; i < links.length; i++) {\n const link = links[i];\n const { sourceId, targetId } = extractLinkPointIds(link);\n const sources = neighbors.get(sourceId);\n if (sources) {\n sources.push(targetId);\n } else {\n neighbors.set(sourceId, [targetId]);\n }\n const targets = neighbors.get(targetId);\n if (targets) {\n targets.push(sourceId);\n } else {\n neighbors.set(targetId, [sourceId]);\n }\n }\n\n for (let i = 0; i < nodes.length; i++) {\n const node = nodes[i];\n map.set(node.id, node);\n node.index = i;\n node.x ??= 0;\n node.y ??= 0;\n if (opts.neighbors) {\n const n = neighbors.get(node.id);\n if (n) {\n node.neighbors = [...new Set(n)];\n node.linkCount = node.neighbors.length;\n }\n }\n }\n\n for (let i = 0; i < links.length; i++) {\n const link = links[i];\n const { sourceId, targetId } = extractLinkPointIds(link);\n link.source = map.get(sourceId) ?? link.source;\n link.target = map.get(targetId) ?? link.target;\n }\n}\n"],"names":[],"mappings":";;AAWM,SAAU,YAAY,CAG1B,IAA6C,EAAA;AAC7C,IAAA,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK;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AG,CAAC,IAAI,CAAC,EAAE,CAAC;YAChC,IAAI,CAAC,EAAE;gBACL,IAAI,CAAC,SAAS,GAAG,CAAC,GAAG,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC;gBAChC,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC,MAAM;;;;AAK5C,IAAA,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;AACrC,QAAA,MAAM,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC;QACrB,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,GAAG,mBAAmB,CAAC,IAAI,CAAC;AACxD,QAAA,IAAI,CAAC,MAAM,GAAG,GAAG,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,IAAI,CAAC,MAAM;AAC9C,QAAA,IAAI,CAAC,MAAM,GAAG,GAAG,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,IAAI,CAAC,MAAM;;AAElD;;;;"}
|
|
@@ -1,16 +1,16 @@
|
|
|
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 'd3-array';
|
|
8
4
|
import { calculateLinkPositionByNode } from '../lib/utils/calculate-link-position-by-node.js';
|
|
9
5
|
import { getParticlePosition, approximateQuadraticBezierLength } from '../lib/utils/get-particle-position.js';
|
|
10
6
|
import { linkFade, linkHighlight } from '../lib/utils/link-highlight.js';
|
|
7
|
+
import 'd3-force';
|
|
8
|
+
import 'd3-selection';
|
|
9
|
+
import 'd3-zoom';
|
|
10
|
+
import 'd3-drag';
|
|
11
11
|
import { calculateCurveLinkPositionByNode } from '../lib/utils/calculate-curve-link-position-by-node.js';
|
|
12
12
|
|
|
13
|
-
function getDrawLink() {
|
|
13
|
+
function getDrawLink(linkBatch, particleBatch, arrowBatch, now) {
|
|
14
14
|
return function drawLink(link, index) {
|
|
15
15
|
if (!this.context ||
|
|
16
16
|
typeof link.source !== "object" ||
|
|
@@ -119,10 +119,9 @@ function getDrawLink() {
|
|
|
119
119
|
}
|
|
120
120
|
}
|
|
121
121
|
/** Link */
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
this.context.lineWidth = width;
|
|
122
|
+
const linkBatchKey = `${alpha}|${color}|${width}`;
|
|
123
|
+
linkBatch[linkBatchKey] ??= [];
|
|
124
|
+
const linkGroup = linkBatch[linkBatchKey];
|
|
126
125
|
let xStart = link.source.x;
|
|
127
126
|
let yStart = link.source.y;
|
|
128
127
|
let xEnd = link.target.x;
|
|
@@ -152,9 +151,7 @@ function getDrawLink() {
|
|
|
152
151
|
link._y2 = yEnd;
|
|
153
152
|
link._ax = xEndArrow;
|
|
154
153
|
link._ay = yEndArrow;
|
|
155
|
-
|
|
156
|
-
this.context.lineTo(xEnd, yEnd);
|
|
157
|
-
this.context.stroke();
|
|
154
|
+
linkGroup.push({ curve: false, xStart, yStart, xEnd, yEnd, xControl, yControl });
|
|
158
155
|
}
|
|
159
156
|
else {
|
|
160
157
|
const position = calculateCurveLinkPositionByNode(xStart, yStart, xEnd, yEnd, link.source, link.target, link._groupIndex ?? 0, isHasArrow ? arrowSize : 0);
|
|
@@ -175,14 +172,7 @@ function getDrawLink() {
|
|
|
175
172
|
link._ax = position.xEndArrow;
|
|
176
173
|
link._ay = position.yEndArrow;
|
|
177
174
|
linkDistance = approximateQuadraticBezierLength(position.xStart, position.yStart, position.xControl, position.yControl, position.xEnd, position.yEnd);
|
|
178
|
-
|
|
179
|
-
this.context.moveTo(position.xStart, position.yStart);
|
|
180
|
-
this.context.quadraticCurveTo(position.xControl, position.yControl, position.xEnd, position.yEnd);
|
|
181
|
-
this.context.setLineDash([]);
|
|
182
|
-
// if (isDashed) {
|
|
183
|
-
// this.context.setLineDash([10, 5]);
|
|
184
|
-
// }
|
|
185
|
-
this.context.stroke();
|
|
175
|
+
linkGroup.push({ curve: true, xStart, yStart, xEnd, yEnd, xControl, yControl });
|
|
186
176
|
}
|
|
187
177
|
/** Particle */
|
|
188
178
|
if (this.linkSettings.particles && (currentLinkHighlighted || currentNodeHighlighted)) {
|
|
@@ -198,6 +188,9 @@ function getDrawLink() {
|
|
|
198
188
|
}
|
|
199
189
|
this.particles[index] = particles;
|
|
200
190
|
}
|
|
191
|
+
const particleBatchKey = `${linkOptions.particleBorderColor}|${linkOptions.particleBorderWidth}|${linkOptions.particleColor}`;
|
|
192
|
+
particleBatch[particleBatchKey] ??= [];
|
|
193
|
+
const particleGroup = particleBatch[particleBatchKey];
|
|
201
194
|
this.particles[index].forEach((particle, _, particles) => {
|
|
202
195
|
if (!this.context)
|
|
203
196
|
return;
|
|
@@ -212,17 +205,10 @@ function getDrawLink() {
|
|
|
212
205
|
xControl,
|
|
213
206
|
yControl,
|
|
214
207
|
speed,
|
|
208
|
+
now,
|
|
215
209
|
});
|
|
216
210
|
if (particle.x != undefined && particle.y != undefined) {
|
|
217
|
-
|
|
218
|
-
this.context.strokeStyle = linkOptions.particleBorderColor;
|
|
219
|
-
this.context.lineWidth = linkOptions.particleBorderWidth;
|
|
220
|
-
this.context.arc(particle.x, particle.y, linkOptions.particleRadius, 0, Math.PI * 2);
|
|
221
|
-
this.context.fillStyle = linkOptions.particleColor;
|
|
222
|
-
this.context.fill();
|
|
223
|
-
if (linkOptions.particleBorderWidth > 0) {
|
|
224
|
-
this.context.stroke();
|
|
225
|
-
}
|
|
211
|
+
particleGroup.push({ x: particle.x, y: particle.y, r: linkOptions.particleRadius });
|
|
226
212
|
}
|
|
227
213
|
});
|
|
228
214
|
}
|
|
@@ -242,19 +228,15 @@ function getDrawLink() {
|
|
|
242
228
|
angle = Math.atan2(tangentY, tangentX);
|
|
243
229
|
}
|
|
244
230
|
}
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
this.context.fill();
|
|
255
|
-
if (arrowBorderWidth > 0) {
|
|
256
|
-
this.context.stroke();
|
|
257
|
-
}
|
|
231
|
+
const arrowBatchKey = `${arrowAlpha}|${arrowBorderColor}|${arrowBorderWidth}|${arrowColor}`;
|
|
232
|
+
arrowBatch[arrowBatchKey] ??= [];
|
|
233
|
+
const arrowGroup = arrowBatch[arrowBatchKey];
|
|
234
|
+
arrowGroup.push({
|
|
235
|
+
x: xEndArrow,
|
|
236
|
+
y: yEndArrow,
|
|
237
|
+
size: arrowSize,
|
|
238
|
+
angle,
|
|
239
|
+
});
|
|
258
240
|
}
|
|
259
241
|
if (linkOptions.drawExtraLink) {
|
|
260
242
|
linkOptions.drawExtraLink.call(this, link, { ...linkOptions, alpha });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"draw-links.js","sources":["../../../../../src/module/GraphCanvas/slices/draw-links.ts"],"sourcesContent":["import type { GraphCanvas } from \"../GraphCanvas\";\nimport { calculateLinkPositionByNode, getParticlePosition, linkFade, linkHighlight } from \"../lib\";\nimport { calculateCurveLinkPositionByNode } from \"../lib/utils/calculate-curve-link-position-by-node\";\nimport { approximateQuadraticBezierLength } from \"../lib/utils/get-particle-position\";\nimport type { LinkInterface, LinkParticle } from \"../types\";\n\nexport function getDrawLink<\n NodeData extends Record<string, unknown>,\n LinkData extends Record<string, unknown>,\n>() {\n return function drawLink(\n this: GraphCanvas<NodeData, LinkData>,\n link: LinkInterface<NodeData, LinkData>,\n index: number,\n ) {\n if (\n !this.context ||\n typeof link.source !== \"object\" ||\n typeof link.target !== \"object\" ||\n !link.source.x ||\n !link.source.y ||\n !link.target.x ||\n !link.target.y\n )\n return;\n\n if (\n (link.visible != undefined && !link.visible) ||\n (link.source.visible != undefined && !link.source.visible) ||\n (link.target.visible != undefined && !link.target.visible)\n )\n return;\n\n if (!link.source._visible && !link.target._visible) return;\n\n const linkOptions = this.linkOptionsCache[index];\n if (!linkOptions) return;\n\n if (linkOptions.drawLink) {\n linkOptions.drawLink.call(this, link, linkOptions);\n\n return;\n }\n\n let alpha = linkOptions.alpha;\n let color = linkOptions.color;\n let width = linkOptions.width;\n let arrowAlpha = this.linkSettings.arrowByHighlight ? 0 : linkOptions.arrowAlpha;\n let arrowColor = linkOptions.arrowColor;\n let arrowSize = linkOptions.arrowSize;\n let arrowBorderWidth = linkOptions.arrowBorderWidth;\n let arrowBorderColor = linkOptions.arrowBorderColor;\n\n const currentNodeHighlighted =\n this.highlightedNode &&\n (this.highlightedNode.id == link.source.id || this.highlightedNode.id == link.target.id);\n /** Highlight */\n if (this.highlightedNeighbors && this.highlightedNode) {\n /** By Node Not Highlight */\n if (!currentNodeHighlighted) {\n const fadeOptions = linkFade({\n arrow: this.linkSettings.arrow,\n arrowByHighlight: this.linkSettings.arrowByHighlight,\n linkOptions,\n highlightProgress: this.highlightProgress,\n highlightForArrowFadingMin: this.highlightSettings.highlightByNodeForArrowFadingMin,\n highlightForLinkFadingMin: this.highlightSettings.highlightByNodeForLinkFadingMin,\n });\n alpha = fadeOptions.alpha;\n arrowAlpha = fadeOptions.arrowAlpha;\n } else {\n const highlightOptions = linkHighlight({\n arrow: this.linkSettings.arrow,\n arrowByHighlight: this.linkSettings.arrowByHighlight,\n linkOptions,\n highlightProgress: this.highlightProgress,\n highlightForArrowBorderColor: this.highlightSettings.highlightByNodeForArrowBorderColor,\n highlightForArrowBorderSizingAdditional:\n this.highlightSettings.highlightByNodeForArrowBorderSizingAdditional,\n highlightForArrowColor: this.highlightSettings.highlightByNodeForArrowColor,\n highlightForArrowSizeAdditional:\n this.highlightSettings.highlightByNodeForArrowSizeAdditional,\n highlightForLinkColor: this.highlightSettings.highlightByNodeForLinkColor,\n highlightForLinkSizeAdditional:\n this.highlightSettings.highlightByNodeForLinkSizeAdditional,\n });\n arrowAlpha = highlightOptions.arrowAlpha;\n color = highlightOptions.color;\n width = highlightOptions.width;\n arrowColor = highlightOptions.arrowColor;\n arrowSize = highlightOptions.arrowSize;\n arrowBorderWidth = highlightOptions.arrowBorderWidth;\n arrowBorderColor = highlightOptions.arrowBorderColor;\n }\n }\n\n const currentLinkHighlighted = this.highlightedLink === link;\n if (this.highlightedNeighbors && this.highlightedLink) {\n /** By Link Not Highlight */\n if (!currentLinkHighlighted) {\n const fadeOptions = linkFade({\n arrow: this.linkSettings.arrow,\n arrowByHighlight: this.linkSettings.arrowByHighlight,\n linkOptions,\n highlightProgress: this.highlightProgress,\n highlightForArrowFadingMin: this.highlightSettings.highlightByLinkForArrowFadingMin,\n highlightForLinkFadingMin: this.highlightSettings.highlightByLinkForLinkFadingMin,\n });\n alpha = fadeOptions.alpha;\n arrowAlpha = fadeOptions.arrowAlpha;\n } else {\n /** By Link Highlight */\n const highlightOptions = linkHighlight({\n arrow: this.linkSettings.arrow,\n arrowByHighlight: this.linkSettings.arrowByHighlight,\n linkOptions,\n highlightProgress: this.highlightProgress,\n highlightForArrowBorderColor: this.highlightSettings.highlightByLinkForArrowBorderColor,\n highlightForArrowBorderSizingAdditional:\n this.highlightSettings.highlightByLinkForArrowBorderSizingAdditional,\n highlightForArrowColor: this.highlightSettings.highlightByLinkForArrowColor,\n highlightForArrowSizeAdditional:\n this.highlightSettings.highlightByLinkForArrowSizeAdditional,\n highlightForLinkColor: this.highlightSettings.highlightByLinkForLinkColor,\n highlightForLinkSizeAdditional:\n this.highlightSettings.highlightByLinkForLinkSizeAdditional,\n });\n arrowAlpha = highlightOptions.arrowAlpha;\n color = highlightOptions.color;\n width = highlightOptions.width;\n arrowColor = highlightOptions.arrowColor;\n arrowSize = highlightOptions.arrowSize;\n arrowBorderWidth = highlightOptions.arrowBorderWidth;\n arrowBorderColor = highlightOptions.arrowBorderColor;\n }\n }\n\n /** Link */\n this.context.beginPath();\n this.context.globalAlpha = alpha;\n this.context.strokeStyle = color;\n this.context.lineWidth = width;\n let xStart = link.source.x;\n let yStart = link.source.y;\n let xEnd = link.target.x;\n let yEnd = link.target.y;\n let xControl = 0;\n let yControl = 0;\n let xEndArrow = xEnd;\n let yEndArrow = yEnd;\n let linkDistance = 0;\n const isHasArrow = this.linkSettings.arrow && arrowAlpha > 0;\n if (!this.linkSettings.curve) {\n if (\n this.linkSettings.prettyDraw ||\n (this.linkSettings.arrow && arrowAlpha > 0) ||\n (this.particles && (currentNodeHighlighted || currentLinkHighlighted))\n ) {\n const position = calculateLinkPositionByNode(\n xStart,\n yStart,\n xEnd,\n yEnd,\n link.source,\n link.target,\n isHasArrow ? arrowSize : 0,\n );\n\n xStart = position.xStart;\n xEnd = position.xEnd;\n yStart = position.yStart;\n yEnd = position.yEnd;\n xEndArrow = position.xEndArrow;\n yEndArrow = position.yEndArrow;\n linkDistance = position.distance;\n }\n link._x1 = xStart;\n link._y1 = yStart;\n link._x2 = xEnd;\n link._y2 = yEnd;\n link._ax = xEndArrow;\n link._ay = yEndArrow;\n this.context.moveTo(xStart, yStart);\n this.context.lineTo(xEnd, yEnd);\n this.context.stroke();\n } else {\n const position = calculateCurveLinkPositionByNode(\n xStart,\n yStart,\n xEnd,\n yEnd,\n link.source,\n link.target,\n link._groupIndex ?? 0,\n isHasArrow ? arrowSize : 0,\n );\n xStart = position.xStart;\n yStart = position.yStart;\n xEnd = position.xEnd;\n yEnd = position.yEnd;\n xControl = position.xControl;\n yControl = position.yControl;\n xEndArrow = position.xEndArrow;\n yEndArrow = position.yEndArrow;\n link._x1 = position.xStart;\n link._y1 = position.yStart;\n link._x2 = position.xEnd;\n link._y2 = position.yEnd;\n link._cx = position.xControl;\n link._cy = position.yControl;\n link._ax = position.xEndArrow;\n link._ay = position.yEndArrow;\n linkDistance = approximateQuadraticBezierLength(\n position.xStart,\n position.yStart,\n position.xControl,\n position.yControl,\n position.xEnd,\n position.yEnd,\n );\n this.context.beginPath();\n this.context.moveTo(position.xStart, position.yStart);\n this.context.quadraticCurveTo(\n position.xControl,\n position.yControl,\n position.xEnd,\n position.yEnd,\n );\n this.context.setLineDash([]);\n // if (isDashed) {\n // this.context.setLineDash([10, 5]);\n // }\n this.context.stroke();\n }\n\n /** Particle */\n if (this.linkSettings.particles && (currentLinkHighlighted || currentNodeHighlighted)) {\n const speed = (1 / this.linkSettings.particleSpeedByDistance) * (1 + 0.5);\n if (!this.particles[index]) {\n const particleCount = Math.max(\n 1,\n Math.floor(linkDistance / this.linkSettings.particleCountByDistance),\n );\n const particles: LinkParticle[] = [];\n for (let i = 0; i < particleCount; i++) {\n const particle: LinkParticle = {\n index: i,\n };\n particles.push(particle);\n }\n this.particles[index] = particles;\n }\n this.particles[index].forEach((particle, _, particles) => {\n if (!this.context) return;\n getParticlePosition({\n distance: linkDistance,\n particle,\n totalCount: particles.length,\n xEnd,\n xStart,\n yEnd,\n yStart,\n xControl,\n yControl,\n speed,\n });\n if (particle.x != undefined && particle.y != undefined) {\n this.context.beginPath();\n this.context.strokeStyle = linkOptions.particleBorderColor;\n this.context.lineWidth = linkOptions.particleBorderWidth;\n this.context.arc(particle.x, particle.y, linkOptions.particleRadius, 0, Math.PI * 2);\n this.context.fillStyle = linkOptions.particleColor;\n this.context.fill();\n if (linkOptions.particleBorderWidth > 0) {\n this.context.stroke();\n }\n }\n });\n }\n\n /** Arrow */\n if (this.linkSettings.arrow && arrowAlpha > 0) {\n let angle = 0;\n if (!this.linkSettings.curve) {\n angle = Math.atan2(yEndArrow - yStart, xEndArrow - xStart);\n } else {\n const tangentX = 2 * (xEndArrow - xControl);\n const tangentY = 2 * (yEndArrow - yControl);\n if (Math.abs(tangentX) < 0.001 && Math.abs(tangentY) < 0.001) {\n angle = Math.atan2(yEndArrow - yControl, xEndArrow - xControl);\n } else {\n angle = Math.atan2(tangentY, tangentX);\n }\n }\n this.context.beginPath();\n this.context.globalAlpha = arrowAlpha;\n this.context.strokeStyle = arrowBorderColor;\n this.context.lineWidth = arrowBorderWidth;\n this.context.fillStyle = arrowColor;\n this.context.moveTo(xEndArrow, yEndArrow);\n this.context.lineTo(\n xEndArrow - arrowSize * Math.cos(angle - Math.PI / 6),\n yEndArrow - arrowSize * Math.sin(angle - Math.PI / 6),\n );\n this.context.lineTo(\n xEndArrow - arrowSize * Math.cos(angle + Math.PI / 6),\n yEndArrow - arrowSize * Math.sin(angle + Math.PI / 6),\n );\n this.context.closePath();\n this.context.fill();\n if (arrowBorderWidth > 0) {\n this.context.stroke();\n }\n }\n\n if (linkOptions.drawExtraLink) {\n linkOptions.drawExtraLink.call(this, link, { ...linkOptions, alpha });\n }\n };\n}\n"],"names":[],"mappings":";;;;;;;;;;;;SAMgB,WAAW,GAAA;AAIzB,IAAA,OAAO,SAAS,QAAQ,CAEtB,IAAuC,EACvC,KAAa,EAAA;QAEb,IACE,CAAC,IAAI,CAAC,OAAO;AACb,YAAA,OAAO,IAAI,CAAC,MAAM,KAAK,QAAQ;AAC/B,YAAA,OAAO,IAAI,CAAC,MAAM,KAAK,QAAQ;AAC/B,YAAA,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;AACd,YAAA,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;AACd,YAAA,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;AACd,YAAA,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;YAEd;QAEF,IACE,CAAC,IAAI,CAAC,OAAO,IAAI,SAAS,IAAI,CAAC,IAAI,CAAC,OAAO;AAC3C,aAAC,IAAI,CAAC,MAAM,CAAC,OAAO,IAAI,SAAS,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC;AAC1D,aAAC,IAAI,CAAC,MAAM,CAAC,OAAO,IAAI,SAAS,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC;YAE1D;AAEF,QAAA,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ;YAAE;QAEpD,MAAM,WAAW,GAAG,IAAI,CAAC,gBA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"draw-links.js","sources":["../../../../../src/module/GraphCanvas/slices/draw-links.ts"],"sourcesContent":["import type { GraphCanvas } from \"../GraphCanvas\";\nimport { calculateLinkPositionByNode, getParticlePosition, linkFade, linkHighlight } from \"../lib\";\nimport { calculateCurveLinkPositionByNode } from \"../lib/utils/calculate-curve-link-position-by-node\";\nimport { approximateQuadraticBezierLength } from \"../lib/utils/get-particle-position\";\nimport type {\n LinkArrowDrawBatch,\n LinkDrawBatch,\n LinkInterface,\n LinkParticle,\n LinkParticleDrawBatch,\n} from \"../types\";\n\nexport function getDrawLink<\n NodeData extends Record<string, unknown>,\n LinkData extends Record<string, unknown>,\n>(\n linkBatch: Record<string, LinkDrawBatch[]>,\n particleBatch: Record<string, LinkParticleDrawBatch[]>,\n arrowBatch: Record<string, LinkArrowDrawBatch[]>,\n now: number,\n) {\n return function drawLink(\n this: GraphCanvas<NodeData, LinkData>,\n link: LinkInterface<NodeData, LinkData>,\n index: number,\n ) {\n if (\n !this.context ||\n typeof link.source !== \"object\" ||\n typeof link.target !== \"object\" ||\n !link.source.x ||\n !link.source.y ||\n !link.target.x ||\n !link.target.y\n )\n return;\n\n if (\n (link.visible != undefined && !link.visible) ||\n (link.source.visible != undefined && !link.source.visible) ||\n (link.target.visible != undefined && !link.target.visible)\n )\n return;\n\n if (!link.source._visible && !link.target._visible) return;\n\n const linkOptions = this.linkOptionsCache[index];\n if (!linkOptions) return;\n\n if (linkOptions.drawLink) {\n linkOptions.drawLink.call(this, link, linkOptions);\n\n return;\n }\n\n let alpha = linkOptions.alpha;\n let color = linkOptions.color;\n let width = linkOptions.width;\n let arrowAlpha = this.linkSettings.arrowByHighlight ? 0 : linkOptions.arrowAlpha;\n let arrowColor = linkOptions.arrowColor;\n let arrowSize = linkOptions.arrowSize;\n let arrowBorderWidth = linkOptions.arrowBorderWidth;\n let arrowBorderColor = linkOptions.arrowBorderColor;\n\n const currentNodeHighlighted =\n this.highlightedNode &&\n (this.highlightedNode.id == link.source.id || this.highlightedNode.id == link.target.id);\n /** Highlight */\n if (this.highlightedNeighbors && this.highlightedNode) {\n /** By Node Not Highlight */\n if (!currentNodeHighlighted) {\n const fadeOptions = linkFade({\n arrow: this.linkSettings.arrow,\n arrowByHighlight: this.linkSettings.arrowByHighlight,\n linkOptions,\n highlightProgress: this.highlightProgress,\n highlightForArrowFadingMin: this.highlightSettings.highlightByNodeForArrowFadingMin,\n highlightForLinkFadingMin: this.highlightSettings.highlightByNodeForLinkFadingMin,\n });\n alpha = fadeOptions.alpha;\n arrowAlpha = fadeOptions.arrowAlpha;\n } else {\n const highlightOptions = linkHighlight({\n arrow: this.linkSettings.arrow,\n arrowByHighlight: this.linkSettings.arrowByHighlight,\n linkOptions,\n highlightProgress: this.highlightProgress,\n highlightForArrowBorderColor: this.highlightSettings.highlightByNodeForArrowBorderColor,\n highlightForArrowBorderSizingAdditional:\n this.highlightSettings.highlightByNodeForArrowBorderSizingAdditional,\n highlightForArrowColor: this.highlightSettings.highlightByNodeForArrowColor,\n highlightForArrowSizeAdditional:\n this.highlightSettings.highlightByNodeForArrowSizeAdditional,\n highlightForLinkColor: this.highlightSettings.highlightByNodeForLinkColor,\n highlightForLinkSizeAdditional:\n this.highlightSettings.highlightByNodeForLinkSizeAdditional,\n });\n arrowAlpha = highlightOptions.arrowAlpha;\n color = highlightOptions.color;\n width = highlightOptions.width;\n arrowColor = highlightOptions.arrowColor;\n arrowSize = highlightOptions.arrowSize;\n arrowBorderWidth = highlightOptions.arrowBorderWidth;\n arrowBorderColor = highlightOptions.arrowBorderColor;\n }\n }\n\n const currentLinkHighlighted = this.highlightedLink === link;\n if (this.highlightedNeighbors && this.highlightedLink) {\n /** By Link Not Highlight */\n if (!currentLinkHighlighted) {\n const fadeOptions = linkFade({\n arrow: this.linkSettings.arrow,\n arrowByHighlight: this.linkSettings.arrowByHighlight,\n linkOptions,\n highlightProgress: this.highlightProgress,\n highlightForArrowFadingMin: this.highlightSettings.highlightByLinkForArrowFadingMin,\n highlightForLinkFadingMin: this.highlightSettings.highlightByLinkForLinkFadingMin,\n });\n alpha = fadeOptions.alpha;\n arrowAlpha = fadeOptions.arrowAlpha;\n } else {\n /** By Link Highlight */\n const highlightOptions = linkHighlight({\n arrow: this.linkSettings.arrow,\n arrowByHighlight: this.linkSettings.arrowByHighlight,\n linkOptions,\n highlightProgress: this.highlightProgress,\n highlightForArrowBorderColor: this.highlightSettings.highlightByLinkForArrowBorderColor,\n highlightForArrowBorderSizingAdditional:\n this.highlightSettings.highlightByLinkForArrowBorderSizingAdditional,\n highlightForArrowColor: this.highlightSettings.highlightByLinkForArrowColor,\n highlightForArrowSizeAdditional:\n this.highlightSettings.highlightByLinkForArrowSizeAdditional,\n highlightForLinkColor: this.highlightSettings.highlightByLinkForLinkColor,\n highlightForLinkSizeAdditional:\n this.highlightSettings.highlightByLinkForLinkSizeAdditional,\n });\n arrowAlpha = highlightOptions.arrowAlpha;\n color = highlightOptions.color;\n width = highlightOptions.width;\n arrowColor = highlightOptions.arrowColor;\n arrowSize = highlightOptions.arrowSize;\n arrowBorderWidth = highlightOptions.arrowBorderWidth;\n arrowBorderColor = highlightOptions.arrowBorderColor;\n }\n }\n\n /** Link */\n const linkBatchKey = `${alpha}|${color}|${width}`;\n linkBatch[linkBatchKey] ??= [];\n const linkGroup = linkBatch[linkBatchKey];\n let xStart = link.source.x;\n let yStart = link.source.y;\n let xEnd = link.target.x;\n let yEnd = link.target.y;\n let xControl = 0;\n let yControl = 0;\n let xEndArrow = xEnd;\n let yEndArrow = yEnd;\n let linkDistance = 0;\n const isHasArrow = this.linkSettings.arrow && arrowAlpha > 0;\n if (!this.linkSettings.curve) {\n if (\n this.linkSettings.prettyDraw ||\n (this.linkSettings.arrow && arrowAlpha > 0) ||\n (this.particles && (currentNodeHighlighted || currentLinkHighlighted))\n ) {\n const position = calculateLinkPositionByNode(\n xStart,\n yStart,\n xEnd,\n yEnd,\n link.source,\n link.target,\n isHasArrow ? arrowSize : 0,\n );\n\n xStart = position.xStart;\n xEnd = position.xEnd;\n yStart = position.yStart;\n yEnd = position.yEnd;\n xEndArrow = position.xEndArrow;\n yEndArrow = position.yEndArrow;\n linkDistance = position.distance;\n }\n link._x1 = xStart;\n link._y1 = yStart;\n link._x2 = xEnd;\n link._y2 = yEnd;\n link._ax = xEndArrow;\n link._ay = yEndArrow;\n linkGroup.push({ curve: false, xStart, yStart, xEnd, yEnd, xControl, yControl });\n } else {\n const position = calculateCurveLinkPositionByNode(\n xStart,\n yStart,\n xEnd,\n yEnd,\n link.source,\n link.target,\n link._groupIndex ?? 0,\n isHasArrow ? arrowSize : 0,\n );\n xStart = position.xStart;\n yStart = position.yStart;\n xEnd = position.xEnd;\n yEnd = position.yEnd;\n xControl = position.xControl;\n yControl = position.yControl;\n xEndArrow = position.xEndArrow;\n yEndArrow = position.yEndArrow;\n link._x1 = position.xStart;\n link._y1 = position.yStart;\n link._x2 = position.xEnd;\n link._y2 = position.yEnd;\n link._cx = position.xControl;\n link._cy = position.yControl;\n link._ax = position.xEndArrow;\n link._ay = position.yEndArrow;\n linkDistance = approximateQuadraticBezierLength(\n position.xStart,\n position.yStart,\n position.xControl,\n position.yControl,\n position.xEnd,\n position.yEnd,\n );\n linkGroup.push({ curve: true, xStart, yStart, xEnd, yEnd, xControl, yControl });\n }\n\n /** Particle */\n if (this.linkSettings.particles && (currentLinkHighlighted || currentNodeHighlighted)) {\n const speed = (1 / this.linkSettings.particleSpeedByDistance) * (1 + 0.5);\n if (!this.particles[index]) {\n const particleCount = Math.max(\n 1,\n Math.floor(linkDistance / this.linkSettings.particleCountByDistance),\n );\n const particles: LinkParticle[] = [];\n for (let i = 0; i < particleCount; i++) {\n const particle: LinkParticle = {\n index: i,\n };\n particles.push(particle);\n }\n this.particles[index] = particles;\n }\n const particleBatchKey = `${linkOptions.particleBorderColor}|${linkOptions.particleBorderWidth}|${linkOptions.particleColor}`;\n particleBatch[particleBatchKey] ??= [];\n const particleGroup = particleBatch[particleBatchKey];\n this.particles[index].forEach((particle, _, particles) => {\n if (!this.context) return;\n getParticlePosition({\n distance: linkDistance,\n particle,\n totalCount: particles.length,\n xEnd,\n xStart,\n yEnd,\n yStart,\n xControl,\n yControl,\n speed,\n now,\n });\n if (particle.x != undefined && particle.y != undefined) {\n particleGroup.push({ x: particle.x, y: particle.y, r: linkOptions.particleRadius });\n }\n });\n }\n\n /** Arrow */\n if (this.linkSettings.arrow && arrowAlpha > 0) {\n let angle = 0;\n if (!this.linkSettings.curve) {\n angle = Math.atan2(yEndArrow - yStart, xEndArrow - xStart);\n } else {\n const tangentX = 2 * (xEndArrow - xControl);\n const tangentY = 2 * (yEndArrow - yControl);\n if (Math.abs(tangentX) < 0.001 && Math.abs(tangentY) < 0.001) {\n angle = Math.atan2(yEndArrow - yControl, xEndArrow - xControl);\n } else {\n angle = Math.atan2(tangentY, tangentX);\n }\n }\n const arrowBatchKey = `${arrowAlpha}|${arrowBorderColor}|${arrowBorderWidth}|${arrowColor}`;\n arrowBatch[arrowBatchKey] ??= [];\n const arrowGroup = arrowBatch[arrowBatchKey];\n arrowGroup.push({\n x: xEndArrow,\n y: yEndArrow,\n size: arrowSize,\n angle,\n });\n }\n if (linkOptions.drawExtraLink) {\n linkOptions.drawExtraLink.call(this, link, { ...linkOptions, alpha });\n }\n };\n}\n"],"names":[],"mappings":";;;;;;;;;;;;AAYM,SAAU,WAAW,CAIzB,SAA0C,EAC1C,aAAsD,EACtD,UAAgD,EAChD,GAAW,EAAA;AAEX,IAAA,OAAO,SAAS,QAAQ,CAEtB,IAAuC,EACvC,KAAa,EAAA;QAEb,IACE,CAAC,IAAI,CAAC,OAAO;AACb,YAAA,OAAO,IAAI,CAAC,MAAM,KAAK,QAAQ;AAC/B,YAAA,OAAO,IAAI,CAAC,MAAM,KAAK,QAAQ;AAC/B,YAAA,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;AACd,YAAA,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;AACd,YAAA,CAAC,IAAI,CAAC,MAAM,CAAC,CAA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E,QAAQ,CAAC;;;YAG1C,MAAM,aAAa,GAAG,CAAA,EAAG,UAAU,CAAA,CAAA,EAAI,gBAAgB,CAAA,CAAA,EAAI,gBAAgB,CAAA,CAAA,EAAI,UAAU,CAAA,CAAE;AAC3F,YAAA,UAAU,CAAC,aAAa,CAAC,KAAK,EAAE;AAChC,YAAA,MAAM,UAAU,GAAG,UAAU,CAAC,aAAa,CAAC;YAC5C,UAAU,CAAC,IAAI,CAAC;AACd,gBAAA,CAAC,EAAE,SAAS;AACZ,gBAAA,CAAC,EAAE,SAAS;AACZ,gBAAA,IAAI,EAAE,SAAS;gBACf,KAAK;AACN,aAAA,CAAC;;AAEJ,QAAA,IAAI,WAAW,CAAC,aAAa,EAAE;AAC7B,YAAA,WAAW,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE,GAAG,WAAW,EAAE,KAAK,EAAE,CAAC;;AAEzE,KAAC;AACH;;;;"}
|
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
import { isNumber } from '@krainovsd/js-helpers';
|
|
2
2
|
import '../constants/force-settings.js';
|
|
3
|
-
import '../constants/graph-settings.js';
|
|
4
|
-
import '../constants/highlight-settings.js';
|
|
5
|
-
import '../constants/link-settings.js';
|
|
6
|
-
import '../constants/node-settings.js';
|
|
7
3
|
import 'd3-array';
|
|
8
4
|
import { isNodeVisible } from '../lib/utils/is-node-visible.js';
|
|
9
5
|
import { nodeFade, nodeHighlight } from '../lib/utils/node-highlight.js';
|
|
10
|
-
import
|
|
6
|
+
import 'd3-force';
|
|
7
|
+
import 'd3-selection';
|
|
8
|
+
import 'd3-zoom';
|
|
9
|
+
import 'd3-drag';
|
|
11
10
|
|
|
12
|
-
function getDrawNode(
|
|
11
|
+
function getDrawNode(nodeBatch, nodeImageBatch, textBatch, deferredNodeRender, deferredTextRender, area) {
|
|
13
12
|
return function drawNode(node, index) {
|
|
14
13
|
if (!this.context || !node.x || !node.y)
|
|
15
14
|
return;
|
|
@@ -23,12 +22,12 @@ function getDrawNode(nodeRenders, textRenders) {
|
|
|
23
22
|
if (!nodeOptions)
|
|
24
23
|
return;
|
|
25
24
|
if (nodeOptions.nodeDraw && nodeOptions.textDraw) {
|
|
26
|
-
|
|
25
|
+
deferredNodeRender.push(() => {
|
|
27
26
|
if (nodeOptions.nodeDraw) {
|
|
28
27
|
nodeOptions.nodeDraw.bind(this)(node, nodeOptions);
|
|
29
28
|
}
|
|
30
29
|
});
|
|
31
|
-
|
|
30
|
+
deferredTextRender.push(() => {
|
|
32
31
|
if (nodeOptions.textDraw) {
|
|
33
32
|
nodeOptions.textDraw.bind(this)(node, nodeOptions);
|
|
34
33
|
}
|
|
@@ -148,7 +147,6 @@ function getDrawNode(nodeRenders, textRenders) {
|
|
|
148
147
|
labelWeight = highlightOptions.labelWeight;
|
|
149
148
|
}
|
|
150
149
|
}
|
|
151
|
-
/** Node parameters */
|
|
152
150
|
node._radius = radius;
|
|
153
151
|
node._borderWidth = borderWidth;
|
|
154
152
|
node._width = width;
|
|
@@ -158,138 +156,55 @@ function getDrawNode(nodeRenders, textRenders) {
|
|
|
158
156
|
? Math.min(nodeOptions.borderRadius, nodeOptions.width / 2, nodeOptions.height / 2)
|
|
159
157
|
: 0;
|
|
160
158
|
node._shape = nodeOptions.shape ?? "circle";
|
|
161
|
-
|
|
162
|
-
if (!isNodeVisible({
|
|
163
|
-
height: this.height,
|
|
164
|
-
width: this.width,
|
|
165
|
-
transform: this.areaTransform,
|
|
166
|
-
node,
|
|
167
|
-
})) {
|
|
159
|
+
if (!isNodeVisible(node, area)) {
|
|
168
160
|
node._visible = false;
|
|
169
161
|
return;
|
|
170
162
|
}
|
|
171
163
|
node._visible = true;
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
}
|
|
191
|
-
else {
|
|
192
|
-
this.context.arc(node.x, node.y, radius, 0, 2 * Math.PI);
|
|
193
|
-
this.context.closePath();
|
|
194
|
-
this.context.save();
|
|
195
|
-
this.context.clip();
|
|
196
|
-
this.context.drawImage(node.image, node.x - radius, node.y - radius, radius * 2, radius * 2);
|
|
197
|
-
this.context.restore();
|
|
198
|
-
if (borderWidth > 0) {
|
|
199
|
-
this.context.stroke();
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
if (node.label && labelLines) {
|
|
203
|
-
this.context.globalAlpha = labelAlpha;
|
|
204
|
-
drawText({
|
|
205
|
-
context: this.context,
|
|
206
|
-
lines: labelLines,
|
|
207
|
-
textAlign: nodeOptions.labelAlign,
|
|
208
|
-
textColor: nodeOptions.labelColor,
|
|
209
|
-
textFont: nodeOptions.labelFont,
|
|
210
|
-
textGap: nodeOptions.labelGap,
|
|
211
|
-
textSize: labelSize,
|
|
212
|
-
textStyle: nodeOptions.labelStyle,
|
|
213
|
-
textWeight: labelWeight,
|
|
214
|
-
x: node.x,
|
|
215
|
-
y: node.y + labelSize / 3,
|
|
216
|
-
});
|
|
217
|
-
}
|
|
218
|
-
break;
|
|
219
|
-
}
|
|
220
|
-
case "square": {
|
|
221
|
-
if (!node.image) {
|
|
222
|
-
this.context.roundRect(node.x - width / 2, node.y - height / 2, width, height, node._borderRadius);
|
|
223
|
-
this.context.fill();
|
|
224
|
-
if (borderWidth > 0) {
|
|
225
|
-
this.context.stroke();
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
else {
|
|
229
|
-
this.context.roundRect(node.x - width / 2, node.y - height / 2, width, height, node._borderRadius);
|
|
230
|
-
this.context.closePath();
|
|
231
|
-
this.context.save();
|
|
232
|
-
this.context.clip();
|
|
233
|
-
this.context.drawImage(node.image, node.x - width / 2, node.y - height / 2, width, height);
|
|
234
|
-
this.context.restore();
|
|
235
|
-
if (borderWidth > 0) {
|
|
236
|
-
this.context.stroke();
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
if (node.label && labelLines) {
|
|
240
|
-
this.context.globalAlpha = labelAlpha;
|
|
241
|
-
drawText({
|
|
242
|
-
context: this.context,
|
|
243
|
-
lines: labelLines,
|
|
244
|
-
textAlign: nodeOptions.labelAlign,
|
|
245
|
-
textColor: nodeOptions.labelColor,
|
|
246
|
-
textFont: nodeOptions.labelFont,
|
|
247
|
-
textGap: nodeOptions.labelGap,
|
|
248
|
-
textSize: labelSize,
|
|
249
|
-
textStyle: nodeOptions.labelStyle,
|
|
250
|
-
textWeight: labelWeight,
|
|
251
|
-
x: node.x,
|
|
252
|
-
y: node.y + labelSize / 3,
|
|
253
|
-
});
|
|
254
|
-
}
|
|
255
|
-
break;
|
|
256
|
-
}
|
|
257
|
-
case "text": {
|
|
258
|
-
if (this.nodeSettings.textNodeDebug) {
|
|
259
|
-
this.context.strokeRect(node.x - width / 2, node.y - height / 2, width, height);
|
|
260
|
-
}
|
|
261
|
-
if (nodeOptions.label && labelLines)
|
|
262
|
-
drawText({
|
|
263
|
-
lines: labelLines,
|
|
264
|
-
context: this.context,
|
|
265
|
-
textAlign: nodeOptions.labelAlign,
|
|
266
|
-
textColor: nodeOptions.labelColor,
|
|
267
|
-
textFont: nodeOptions.labelFont,
|
|
268
|
-
textSize: labelSize,
|
|
269
|
-
x: node.x,
|
|
270
|
-
y: node.y + textSize / 4 - (labelLines.length - 1) * (textSize / 2),
|
|
271
|
-
textStyle: nodeOptions.labelStyle,
|
|
272
|
-
textWeight,
|
|
273
|
-
textGap: nodeOptions.labelGap,
|
|
274
|
-
});
|
|
275
|
-
this.context.fill();
|
|
276
|
-
if (borderWidth > 0) {
|
|
277
|
-
this.context.stroke();
|
|
278
|
-
}
|
|
279
|
-
break;
|
|
280
|
-
}
|
|
281
|
-
default: {
|
|
282
|
-
this.context.arc(node.x, node.y, radius, 0, 2 * Math.PI);
|
|
283
|
-
this.context.fill();
|
|
284
|
-
if (borderWidth > 0) {
|
|
285
|
-
this.context.stroke();
|
|
286
|
-
}
|
|
287
|
-
break;
|
|
288
|
-
}
|
|
289
|
-
}
|
|
164
|
+
const nodeBatchKey = `${alpha}|${borderColor}|${borderWidth}|${color}`;
|
|
165
|
+
let nodeGroup;
|
|
166
|
+
if (!node.image) {
|
|
167
|
+
nodeBatch[nodeBatchKey] ??= [];
|
|
168
|
+
nodeGroup = nodeBatch[nodeBatchKey];
|
|
169
|
+
}
|
|
170
|
+
else {
|
|
171
|
+
nodeImageBatch[nodeBatchKey] ??= [];
|
|
172
|
+
nodeGroup = nodeImageBatch[nodeBatchKey];
|
|
173
|
+
}
|
|
174
|
+
nodeGroup.push({
|
|
175
|
+
shape: nodeOptions.shape,
|
|
176
|
+
x: node.x,
|
|
177
|
+
y: node.y,
|
|
178
|
+
radius,
|
|
179
|
+
width,
|
|
180
|
+
height,
|
|
181
|
+
image: node.image,
|
|
290
182
|
});
|
|
183
|
+
const labelLines = this.cachedNodeLabel[index];
|
|
184
|
+
if (labelLines && labelLines.length > 0) {
|
|
185
|
+
let y = node.y + labelSize / 3;
|
|
186
|
+
let weight = labelWeight;
|
|
187
|
+
if (nodeOptions.shape == "text") {
|
|
188
|
+
y = node.y + textSize / 4 - (labelLines.length - 1) * (textSize / 2);
|
|
189
|
+
weight = textWeight;
|
|
190
|
+
}
|
|
191
|
+
const font = `${nodeOptions.labelStyle} normal ${weight} ${labelSize}px ${nodeOptions.labelFont}`;
|
|
192
|
+
textBatch[font] ??= {};
|
|
193
|
+
const fontBatch = textBatch[font];
|
|
194
|
+
const textBatchKey = `${labelAlpha}|${nodeOptions.labelAlign}|${nodeOptions.labelColor}`;
|
|
195
|
+
fontBatch[textBatchKey] ??= [];
|
|
196
|
+
const textGroup = fontBatch[textBatchKey];
|
|
197
|
+
for (let i = 0; i < labelLines.length; i++) {
|
|
198
|
+
const line = labelLines[i];
|
|
199
|
+
textGroup.push({
|
|
200
|
+
text: line,
|
|
201
|
+
x: node.x,
|
|
202
|
+
y: y + i * textSize + i * nodeOptions.textGap,
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
}
|
|
291
206
|
if (nodeOptions.nodeExtraDraw) {
|
|
292
|
-
|
|
207
|
+
deferredNodeRender.push(() => {
|
|
293
208
|
nodeOptions?.nodeExtraDraw?.bind?.(this)?.(node, {
|
|
294
209
|
...nodeOptions,
|
|
295
210
|
radius,
|
|
@@ -303,12 +218,11 @@ function getDrawNode(nodeRenders, textRenders) {
|
|
|
303
218
|
});
|
|
304
219
|
});
|
|
305
220
|
}
|
|
306
|
-
/** Text draw */
|
|
307
221
|
const textLines = this.cachedNodeText[index];
|
|
308
|
-
if (
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
nodeOptions
|
|
222
|
+
if (textLines && textLines.length > 0) {
|
|
223
|
+
if (nodeOptions.textDraw) {
|
|
224
|
+
deferredTextRender.push(() => {
|
|
225
|
+
nodeOptions?.textDraw?.bind?.(this)?.(node, {
|
|
312
226
|
...nodeOptions,
|
|
313
227
|
radius,
|
|
314
228
|
alpha,
|
|
@@ -319,34 +233,32 @@ function getDrawNode(nodeRenders, textRenders) {
|
|
|
319
233
|
textShiftY,
|
|
320
234
|
textWeight,
|
|
321
235
|
});
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
textSize,
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
let y = node.y + textShiftY;
|
|
239
|
+
if (nodeOptions.shape === "circle") {
|
|
240
|
+
y += radius;
|
|
241
|
+
}
|
|
242
|
+
if (nodeOptions.shape === "square" || nodeOptions.shape === "text") {
|
|
243
|
+
y += height / 2;
|
|
244
|
+
}
|
|
245
|
+
const font = `${nodeOptions.textStyle} normal ${textWeight} ${textSize}px ${nodeOptions.textFont}`;
|
|
246
|
+
textBatch[font] ??= {};
|
|
247
|
+
const fontBatch = textBatch[font];
|
|
248
|
+
const textBatchKey = `${textAlpha}|${nodeOptions.textAlign}|${nodeOptions.textColor}`;
|
|
249
|
+
fontBatch[textBatchKey] ??= [];
|
|
250
|
+
const textGroup = fontBatch[textBatchKey];
|
|
251
|
+
for (let i = 0; i < textLines.length; i++) {
|
|
252
|
+
const line = textLines[i];
|
|
253
|
+
textGroup.push({
|
|
254
|
+
text: line,
|
|
342
255
|
x: node.x + textShiftX,
|
|
343
|
-
y,
|
|
344
|
-
textStyle: nodeOptions.textStyle,
|
|
345
|
-
textWeight,
|
|
346
|
-
textGap: nodeOptions.textGap,
|
|
256
|
+
y: y + i * textSize + i * nodeOptions.textGap,
|
|
347
257
|
});
|
|
348
|
-
|
|
349
|
-
|
|
258
|
+
}
|
|
259
|
+
if (nodeOptions.textExtraDraw) {
|
|
260
|
+
deferredTextRender.push(() => {
|
|
261
|
+
nodeOptions?.textExtraDraw?.bind?.(this)?.(node, {
|
|
350
262
|
...nodeOptions,
|
|
351
263
|
radius,
|
|
352
264
|
alpha,
|
|
@@ -357,8 +269,8 @@ function getDrawNode(nodeRenders, textRenders) {
|
|
|
357
269
|
textShiftY,
|
|
358
270
|
textWeight,
|
|
359
271
|
});
|
|
360
|
-
}
|
|
361
|
-
}
|
|
272
|
+
});
|
|
273
|
+
}
|
|
362
274
|
}
|
|
363
275
|
};
|
|
364
276
|
}
|