@krainovsd/graph 0.8.4 → 0.10.0-rc1
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 +2819 -1574
- package/lib/cjs/index.cjs.map +1 -1
- package/lib/esm/index.js +14 -4
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/lib/draw-time.js +5 -1
- package/lib/esm/lib/draw-time.js.map +1 -1
- package/lib/esm/lib/get-controls-info.js +525 -151
- package/lib/esm/lib/get-controls-info.js.map +1 -1
- package/lib/esm/module/GraphCanvas/GraphCanvas.js +42 -746
- package/lib/esm/module/GraphCanvas/GraphCanvas.js.map +1 -1
- package/lib/esm/module/GraphCanvas/constants/settings.js +83 -39
- package/lib/esm/module/GraphCanvas/constants/settings.js.map +1 -1
- package/lib/esm/module/GraphCanvas/lib/settings/node-settings-getter.js +10 -1
- package/lib/esm/module/GraphCanvas/lib/settings/node-settings-getter.js.map +1 -1
- package/lib/esm/module/GraphCanvas/lib/utils/calculate-link-position-by-node.js +270 -0
- package/lib/esm/module/GraphCanvas/lib/utils/calculate-link-position-by-node.js.map +1 -0
- package/lib/esm/module/GraphCanvas/lib/utils/drag-place-coefficient-getter.js +2 -2
- package/lib/esm/module/GraphCanvas/lib/utils/drag-place-coefficient-getter.js.map +1 -1
- package/lib/esm/module/GraphCanvas/lib/utils/get-particle-position.js +19 -4
- 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 +29 -4
- 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 +53 -4
- package/lib/esm/module/GraphCanvas/lib/utils/is-overlaps-node.js.map +1 -1
- package/lib/esm/module/GraphCanvas/lib/utils/link-by-pointer-getter.js +55 -0
- package/lib/esm/module/GraphCanvas/lib/utils/link-by-pointer-getter.js.map +1 -0
- package/lib/esm/module/GraphCanvas/lib/utils/node-by-pointer-getter.js +3 -13
- package/lib/esm/module/GraphCanvas/lib/utils/node-by-pointer-getter.js.map +1 -1
- package/lib/esm/module/GraphCanvas/lib/utils/pointer-getter.js +8 -2
- package/lib/esm/module/GraphCanvas/lib/utils/pointer-getter.js.map +1 -1
- package/lib/esm/module/GraphCanvas/slices/draw-links.js +207 -0
- package/lib/esm/module/GraphCanvas/slices/draw-links.js.map +1 -0
- package/lib/esm/module/GraphCanvas/slices/draw-nodes.js +342 -0
- package/lib/esm/module/GraphCanvas/slices/draw-nodes.js.map +1 -0
- package/lib/esm/module/GraphCanvas/{lib/utils → slices}/draw-text.js +23 -6
- package/lib/esm/module/GraphCanvas/slices/draw-text.js.map +1 -0
- package/lib/esm/module/GraphCanvas/slices/init-area.js +31 -0
- package/lib/esm/module/GraphCanvas/slices/init-area.js.map +1 -0
- package/lib/esm/module/GraphCanvas/slices/init-dnd.js +62 -0
- package/lib/esm/module/GraphCanvas/slices/init-dnd.js.map +1 -0
- package/lib/esm/module/GraphCanvas/slices/init-draw.js +84 -0
- package/lib/esm/module/GraphCanvas/slices/init-draw.js.map +1 -0
- package/lib/esm/module/GraphCanvas/slices/init-pointer.js +211 -0
- package/lib/esm/module/GraphCanvas/slices/init-pointer.js.map +1 -0
- package/lib/esm/module/GraphCanvas/slices/init-resize.js +28 -0
- package/lib/esm/module/GraphCanvas/slices/init-resize.js.map +1 -0
- package/lib/esm/module/GraphCanvas/slices/init-simulation.js +172 -0
- package/lib/esm/module/GraphCanvas/slices/init-simulation.js.map +1 -0
- package/lib/esm/module/GraphCanvas/slices/init-zoom.js +36 -0
- package/lib/esm/module/GraphCanvas/slices/init-zoom.js.map +1 -0
- package/lib/index.d.ts +192 -114
- package/package.json +1 -1
- package/lib/esm/module/GraphCanvas/lib/utils/calculate-link-position-by-radius.js +0 -20
- package/lib/esm/module/GraphCanvas/lib/utils/calculate-link-position-by-radius.js.map +0 -1
- package/lib/esm/module/GraphCanvas/lib/utils/draw-text.js.map +0 -1
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
function pointerGetter(mouseEvent, areaRect, areaTransform) {
|
|
2
|
-
const
|
|
3
|
-
|
|
2
|
+
const clientX = "clientX" in mouseEvent
|
|
3
|
+
? mouseEvent.clientX
|
|
4
|
+
: (mouseEvent.touches[0]?.clientX ?? mouseEvent.changedTouches[0]?.clientX);
|
|
5
|
+
const clientY = "clientX" in mouseEvent
|
|
6
|
+
? mouseEvent.clientY
|
|
7
|
+
: (mouseEvent.touches[0]?.clientY ?? mouseEvent.changedTouches[0]?.clientY);
|
|
8
|
+
const px = (clientX - areaRect.left - areaTransform.x) / areaTransform.k;
|
|
9
|
+
const py = (clientY - areaRect.top - areaTransform.y) / areaTransform.k;
|
|
4
10
|
return [px, py];
|
|
5
11
|
}
|
|
6
12
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pointer-getter.js","sources":["../../../../../../src/module/GraphCanvas/lib/utils/pointer-getter.ts"],"sourcesContent":["import type { ZoomTransform } from \"d3-zoom\";\n\nexport function pointerGetter(\n mouseEvent: MouseEvent,\n areaRect: DOMRect,\n areaTransform: ZoomTransform,\n) {\n const
|
|
1
|
+
{"version":3,"file":"pointer-getter.js","sources":["../../../../../../src/module/GraphCanvas/lib/utils/pointer-getter.ts"],"sourcesContent":["import type { ZoomTransform } from \"d3-zoom\";\n\nexport function pointerGetter(\n mouseEvent: MouseEvent | TouchEvent,\n areaRect: DOMRect,\n areaTransform: ZoomTransform,\n) {\n const clientX =\n \"clientX\" in mouseEvent\n ? mouseEvent.clientX\n : (mouseEvent.touches[0]?.clientX ?? mouseEvent.changedTouches[0]?.clientX);\n const clientY =\n \"clientX\" in mouseEvent\n ? mouseEvent.clientY\n : (mouseEvent.touches[0]?.clientY ?? mouseEvent.changedTouches[0]?.clientY);\n\n const px = (clientX - areaRect.left - areaTransform.x) / areaTransform.k;\n const py = (clientY - areaRect.top - areaTransform.y) / areaTransform.k;\n\n return [px, py];\n}\n"],"names":[],"mappings":"SAEgB,aAAa,CAC3B,UAAmC,EACnC,QAAiB,EACjB,aAA4B,EAAA;AAE5B,IAAA,MAAM,OAAO,GACX,SAAS,IAAI;UACT,UAAU,CAAC;WACV,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,OAAO,IAAI,UAAU,CAAC,cAAc,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC;AAC/E,IAAA,MAAM,OAAO,GACX,SAAS,IAAI;UACT,UAAU,CAAC;WACV,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,OAAO,IAAI,UAAU,CAAC,cAAc,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC;AAE/E,IAAA,MAAM,EAAE,GAAG,CAAC,OAAO,GAAG,QAAQ,CAAC,IAAI,GAAG,aAAa,CAAC,CAAC,IAAI,aAAa,CAAC,CAAC;AACxE,IAAA,MAAM,EAAE,GAAG,CAAC,OAAO,GAAG,QAAQ,CAAC,GAAG,GAAG,aAAa,CAAC,CAAC,IAAI,aAAa,CAAC,CAAC;AAEvE,IAAA,OAAO,CAAC,EAAE,EAAE,EAAE,CAAC;AACjB;;;;"}
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
import { linkOptionsGetter } from '../lib/settings/link-settings-getter.js';
|
|
2
|
+
import '@krainovsd/js-helpers';
|
|
3
|
+
import { linkIterationExtractor } from '../lib/utils/link-iteration-extractor.js';
|
|
4
|
+
import 'd3-array';
|
|
5
|
+
import { calculateLinkPositionByNode } from '../lib/utils/calculate-link-position-by-node.js';
|
|
6
|
+
import { animationByProgress } from '../lib/utils/animation-by-progress.js';
|
|
7
|
+
import { getParticlePosition } from '../lib/utils/get-particle-position.js';
|
|
8
|
+
|
|
9
|
+
function getDrawLink(state) {
|
|
10
|
+
return function drawLink(link, index) {
|
|
11
|
+
if (!this.context ||
|
|
12
|
+
typeof link.source !== "object" ||
|
|
13
|
+
typeof link.target !== "object" ||
|
|
14
|
+
!link.source.x ||
|
|
15
|
+
!link.source.y ||
|
|
16
|
+
!link.target.x ||
|
|
17
|
+
!link.target.y)
|
|
18
|
+
return;
|
|
19
|
+
if (!link.source._visible && !link.target._visible)
|
|
20
|
+
return;
|
|
21
|
+
const id = `${link.target.id}${link.source.id}`;
|
|
22
|
+
let linkOptions;
|
|
23
|
+
if (this.linkSettings.cache && this.linkOptionsCache[id]) {
|
|
24
|
+
linkOptions = this.linkOptionsCache[id];
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
linkOptions = linkIterationExtractor(link, index, this.links, state, this.linkSettings.options ?? {}, linkOptionsGetter);
|
|
28
|
+
if (this.linkSettings.cache) {
|
|
29
|
+
this.linkOptionsCache[id] = linkOptions;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
if (linkOptions.drawLink) {
|
|
33
|
+
linkOptions.drawLink(link, linkOptions, state);
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
let alpha = linkOptions.alpha;
|
|
37
|
+
let arrowAlpha = this.linkSettings.arrowByHighlight ? 0 : linkOptions.arrowAlpha;
|
|
38
|
+
/** NODE HIGHLIGHT */
|
|
39
|
+
if (this.highlightedNeighbors && this.highlightedNode) {
|
|
40
|
+
/** Not highlighted */
|
|
41
|
+
if (this.highlightedNode.id != link.source.id && this.highlightedNode.id != link.target.id) {
|
|
42
|
+
if (this.linkSettings.highlightByNodeLinkFading) {
|
|
43
|
+
const min = this.linkSettings.highlightByNodeLinkFadingMin < alpha
|
|
44
|
+
? this.linkSettings.highlightByNodeLinkFadingMin
|
|
45
|
+
: alpha;
|
|
46
|
+
alpha = animationByProgress(min, alpha - min, 1 - this.highlightProgress);
|
|
47
|
+
}
|
|
48
|
+
if (this.linkSettings.arrow &&
|
|
49
|
+
this.linkSettings.highlightByNodeArrowFading &&
|
|
50
|
+
!this.linkSettings.arrowByHighlight) {
|
|
51
|
+
const min = this.linkSettings.highlightByNodeArrowFadingMin < arrowAlpha
|
|
52
|
+
? this.linkSettings.highlightByNodeArrowFadingMin
|
|
53
|
+
: arrowAlpha;
|
|
54
|
+
arrowAlpha = animationByProgress(min, arrowAlpha - min, 1 - this.highlightProgress);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
// eslint-disable-next-line no-lonely-if
|
|
59
|
+
if (this.linkSettings.arrow && this.linkSettings.arrowByHighlight) {
|
|
60
|
+
/** Highlighted */
|
|
61
|
+
arrowAlpha = animationByProgress(0, linkOptions.arrowAlpha, this.highlightProgress);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
/** LINK HIGHLIGHT */
|
|
66
|
+
if (this.highlightedNeighbors && this.highlightedLink) {
|
|
67
|
+
/** Not highlighted */
|
|
68
|
+
if (this.highlightedLink !== link) {
|
|
69
|
+
if (this.linkSettings.highlightByLinkLinkFading) {
|
|
70
|
+
const min = this.linkSettings.highlightByLinkLinkFadingMin < alpha
|
|
71
|
+
? this.linkSettings.highlightByLinkLinkFadingMin
|
|
72
|
+
: alpha;
|
|
73
|
+
alpha = animationByProgress(min, alpha - min, 1 - this.highlightProgress);
|
|
74
|
+
}
|
|
75
|
+
if (this.linkSettings.arrow &&
|
|
76
|
+
this.linkSettings.highlightByLinkArrowFading &&
|
|
77
|
+
!this.linkSettings.arrowByHighlight) {
|
|
78
|
+
const min = this.linkSettings.highlightByLinkArrowFadingMin < arrowAlpha
|
|
79
|
+
? this.linkSettings.highlightByLinkArrowFadingMin
|
|
80
|
+
: arrowAlpha;
|
|
81
|
+
arrowAlpha = animationByProgress(min, arrowAlpha - min, 1 - this.highlightProgress);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
// eslint-disable-next-line no-lonely-if
|
|
86
|
+
if (this.linkSettings.arrow && this.linkSettings.arrowByHighlight) {
|
|
87
|
+
/** Highlighted */
|
|
88
|
+
arrowAlpha = animationByProgress(0, linkOptions.arrowAlpha, this.highlightProgress);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
/** Link */
|
|
93
|
+
this.context.beginPath();
|
|
94
|
+
this.context.globalAlpha = alpha;
|
|
95
|
+
this.context.strokeStyle = linkOptions.color;
|
|
96
|
+
this.context.lineWidth = linkOptions.width;
|
|
97
|
+
let xStart = link.source.x;
|
|
98
|
+
let yStart = link.source.y;
|
|
99
|
+
let xEnd = link.target.x;
|
|
100
|
+
let yEnd = link.target.y;
|
|
101
|
+
let linkDistance = 0;
|
|
102
|
+
if (this.linkSettings.pretty || this.linkSettings.particleFlexSpeed) {
|
|
103
|
+
const isHasArrow = this.linkSettings.arrow && arrowAlpha > 0;
|
|
104
|
+
const position = calculateLinkPositionByNode(link, isHasArrow ? linkOptions.arrowSize : 0);
|
|
105
|
+
if (position) {
|
|
106
|
+
xStart = position.x1;
|
|
107
|
+
xEnd = position.x2;
|
|
108
|
+
yStart = position.y1;
|
|
109
|
+
yEnd = position.y2;
|
|
110
|
+
linkDistance = position.distance;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
this.context.moveTo(xStart, yStart);
|
|
114
|
+
this.context.lineTo(xEnd, yEnd);
|
|
115
|
+
this.context.stroke();
|
|
116
|
+
/** Particle */
|
|
117
|
+
if (this.linkSettings.particles &&
|
|
118
|
+
((this.highlightedNode &&
|
|
119
|
+
(this.highlightedNode.id === link.source.id ||
|
|
120
|
+
this.highlightedNode.id === link.target.id)) ||
|
|
121
|
+
(this.highlightedLink && this.highlightedLink === link))) {
|
|
122
|
+
const particleSteps = this.linkSettings.particleFlexSpeed
|
|
123
|
+
? linkDistance <= 0
|
|
124
|
+
? 0
|
|
125
|
+
: linkDistance * this.linkSettings.particleFlexSpeedCoefficient
|
|
126
|
+
: linkOptions.particleSteps;
|
|
127
|
+
const particleCount = linkOptions.particleCount;
|
|
128
|
+
if (!this.particles[id]) {
|
|
129
|
+
const sourceId = link.source.id;
|
|
130
|
+
const targetId = link.target.id;
|
|
131
|
+
const particles = [];
|
|
132
|
+
let prevParticle;
|
|
133
|
+
for (let i = 0; i < particleCount; i++) {
|
|
134
|
+
const particle = {
|
|
135
|
+
step: 0,
|
|
136
|
+
sourceId,
|
|
137
|
+
targetId,
|
|
138
|
+
prev: prevParticle,
|
|
139
|
+
next: undefined,
|
|
140
|
+
index: i,
|
|
141
|
+
};
|
|
142
|
+
if (prevParticle)
|
|
143
|
+
prevParticle.next = particle;
|
|
144
|
+
particles.push(particle);
|
|
145
|
+
prevParticle = particle;
|
|
146
|
+
}
|
|
147
|
+
if (particles.length >= 2) {
|
|
148
|
+
particles[0].prev = particles[particles.length - 1];
|
|
149
|
+
particles[particles.length - 1].next = particles[0];
|
|
150
|
+
}
|
|
151
|
+
this.particles[id] = particles;
|
|
152
|
+
}
|
|
153
|
+
if (particleSteps !== 0) {
|
|
154
|
+
this.particles[id].forEach((particle) => {
|
|
155
|
+
if (!this.context)
|
|
156
|
+
return;
|
|
157
|
+
const distance = particleSteps / particleCount;
|
|
158
|
+
getParticlePosition({
|
|
159
|
+
distance,
|
|
160
|
+
particle,
|
|
161
|
+
totalSteps: particleSteps,
|
|
162
|
+
xEnd,
|
|
163
|
+
xStart,
|
|
164
|
+
yEnd,
|
|
165
|
+
yStart,
|
|
166
|
+
});
|
|
167
|
+
if (particle.x != undefined && particle.y != undefined) {
|
|
168
|
+
this.context.beginPath();
|
|
169
|
+
this.context.strokeStyle = linkOptions.particleBorderColor;
|
|
170
|
+
this.context.lineWidth = linkOptions.particleBorderWidth;
|
|
171
|
+
this.context.arc(particle.x, particle.y, linkOptions.particleRadius, 0, Math.PI * 2);
|
|
172
|
+
this.context.fillStyle = linkOptions.particleColor;
|
|
173
|
+
this.context.fill();
|
|
174
|
+
this.context.stroke();
|
|
175
|
+
}
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
/** Arrow */
|
|
180
|
+
if (this.linkSettings.arrow && arrowAlpha > 0) {
|
|
181
|
+
const { x1: xStart, x2: xEnd, y1: yStart, y2: yEnd, } = calculateLinkPositionByNode(link) ?? {
|
|
182
|
+
x1: 0,
|
|
183
|
+
x2: 0,
|
|
184
|
+
y1: 0,
|
|
185
|
+
y2: 0,
|
|
186
|
+
};
|
|
187
|
+
this.context.beginPath();
|
|
188
|
+
this.context.globalAlpha = arrowAlpha;
|
|
189
|
+
this.context.strokeStyle = linkOptions.arrowBorderColor;
|
|
190
|
+
this.context.lineWidth = linkOptions.arrowBorderWidth;
|
|
191
|
+
this.context.fillStyle = linkOptions.arrowColor;
|
|
192
|
+
const angle = Math.atan2(yEnd - yStart, xEnd - xStart);
|
|
193
|
+
this.context.moveTo(xEnd, yEnd);
|
|
194
|
+
this.context.lineTo(xEnd - linkOptions.arrowSize * Math.cos(angle - Math.PI / 6), yEnd - linkOptions.arrowSize * Math.sin(angle - Math.PI / 6));
|
|
195
|
+
this.context.lineTo(xEnd - linkOptions.arrowSize * Math.cos(angle + Math.PI / 6), yEnd - linkOptions.arrowSize * Math.sin(angle + Math.PI / 6));
|
|
196
|
+
this.context.closePath();
|
|
197
|
+
this.context.fill();
|
|
198
|
+
this.context.stroke();
|
|
199
|
+
}
|
|
200
|
+
if (linkOptions.drawExtraLink) {
|
|
201
|
+
linkOptions.drawExtraLink(link, { ...linkOptions, alpha }, state);
|
|
202
|
+
}
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
export { getDrawLink };
|
|
207
|
+
//# sourceMappingURL=draw-links.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"draw-links.js","sources":["../../../../../src/module/GraphCanvas/slices/draw-links.ts"],"sourcesContent":["import type { LinkInterface } from \"@/types\";\nimport type { GraphCanvas } from \"../GraphCanvas\";\nimport {\n animationByProgress,\n calculateLinkPositionByNode,\n getParticlePosition,\n linkIterationExtractor,\n linkOptionsGetter,\n} from \"../lib\";\nimport type { GraphParticle, GraphState, LinkOptionsInterface } from \"../types\";\n\nexport function getDrawLink<\n NodeData extends Record<string, unknown>,\n LinkData extends Record<string, unknown>,\n>(state: GraphState<NodeData, LinkData>) {\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 (!link.source._visible && !link.target._visible) return;\n\n const id = `${link.target.id}${link.source.id}`;\n let linkOptions: Required<LinkOptionsInterface<NodeData, LinkData>>;\n if (this.linkSettings.cache && this.linkOptionsCache[id]) {\n linkOptions = this.linkOptionsCache[id];\n } else {\n linkOptions = linkIterationExtractor(\n link,\n index,\n this.links,\n state,\n this.linkSettings.options ?? {},\n linkOptionsGetter,\n );\n if (this.linkSettings.cache) {\n this.linkOptionsCache[id] = linkOptions;\n }\n }\n\n if (linkOptions.drawLink) {\n linkOptions.drawLink(link, linkOptions, state);\n\n return;\n }\n\n let alpha = linkOptions.alpha;\n let arrowAlpha = this.linkSettings.arrowByHighlight ? 0 : linkOptions.arrowAlpha;\n\n /** NODE HIGHLIGHT */\n if (this.highlightedNeighbors && this.highlightedNode) {\n /** Not highlighted */\n if (this.highlightedNode.id != link.source.id && this.highlightedNode.id != link.target.id) {\n if (this.linkSettings.highlightByNodeLinkFading) {\n const min =\n this.linkSettings.highlightByNodeLinkFadingMin < alpha\n ? this.linkSettings.highlightByNodeLinkFadingMin\n : alpha;\n alpha = animationByProgress(min, alpha - min, 1 - this.highlightProgress);\n }\n if (\n this.linkSettings.arrow &&\n this.linkSettings.highlightByNodeArrowFading &&\n !this.linkSettings.arrowByHighlight\n ) {\n const min =\n this.linkSettings.highlightByNodeArrowFadingMin < arrowAlpha\n ? this.linkSettings.highlightByNodeArrowFadingMin\n : arrowAlpha;\n arrowAlpha = animationByProgress(min, arrowAlpha - min, 1 - this.highlightProgress);\n }\n } else {\n // eslint-disable-next-line no-lonely-if\n if (this.linkSettings.arrow && this.linkSettings.arrowByHighlight) {\n /** Highlighted */\n arrowAlpha = animationByProgress(0, linkOptions.arrowAlpha, this.highlightProgress);\n }\n }\n }\n /** LINK HIGHLIGHT */\n if (this.highlightedNeighbors && this.highlightedLink) {\n /** Not highlighted */\n if (this.highlightedLink !== link) {\n if (this.linkSettings.highlightByLinkLinkFading) {\n const min =\n this.linkSettings.highlightByLinkLinkFadingMin < alpha\n ? this.linkSettings.highlightByLinkLinkFadingMin\n : alpha;\n alpha = animationByProgress(min, alpha - min, 1 - this.highlightProgress);\n }\n if (\n this.linkSettings.arrow &&\n this.linkSettings.highlightByLinkArrowFading &&\n !this.linkSettings.arrowByHighlight\n ) {\n const min =\n this.linkSettings.highlightByLinkArrowFadingMin < arrowAlpha\n ? this.linkSettings.highlightByLinkArrowFadingMin\n : arrowAlpha;\n arrowAlpha = animationByProgress(min, arrowAlpha - min, 1 - this.highlightProgress);\n }\n } else {\n // eslint-disable-next-line no-lonely-if\n if (this.linkSettings.arrow && this.linkSettings.arrowByHighlight) {\n /** Highlighted */\n arrowAlpha = animationByProgress(0, linkOptions.arrowAlpha, this.highlightProgress);\n }\n }\n }\n\n /** Link */\n this.context.beginPath();\n\n this.context.globalAlpha = alpha;\n this.context.strokeStyle = linkOptions.color;\n this.context.lineWidth = linkOptions.width;\n\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 linkDistance = 0;\n if (this.linkSettings.pretty || this.linkSettings.particleFlexSpeed) {\n const isHasArrow = this.linkSettings.arrow && arrowAlpha > 0;\n const position = calculateLinkPositionByNode(link, isHasArrow ? linkOptions.arrowSize : 0);\n\n if (position) {\n xStart = position.x1;\n xEnd = position.x2;\n yStart = position.y1;\n yEnd = position.y2;\n linkDistance = position.distance;\n }\n }\n this.context.moveTo(xStart, yStart);\n this.context.lineTo(xEnd, yEnd);\n this.context.stroke();\n\n /** Particle */\n if (\n this.linkSettings.particles &&\n ((this.highlightedNode &&\n (this.highlightedNode.id === link.source.id ||\n this.highlightedNode.id === link.target.id)) ||\n (this.highlightedLink && this.highlightedLink === link))\n ) {\n const particleSteps = this.linkSettings.particleFlexSpeed\n ? linkDistance <= 0\n ? 0\n : linkDistance * this.linkSettings.particleFlexSpeedCoefficient\n : linkOptions.particleSteps;\n const particleCount = linkOptions.particleCount;\n\n if (!this.particles[id]) {\n const sourceId = link.source.id;\n const targetId = link.target.id;\n\n const particles: GraphParticle[] = [];\n let prevParticle: GraphParticle | undefined;\n\n for (let i = 0; i < particleCount; i++) {\n const particle: GraphParticle = {\n step: 0,\n sourceId,\n targetId,\n prev: prevParticle,\n next: undefined,\n index: i,\n };\n if (prevParticle) prevParticle.next = particle;\n particles.push(particle);\n prevParticle = particle;\n }\n if (particles.length >= 2) {\n particles[0].prev = particles[particles.length - 1];\n particles[particles.length - 1].next = particles[0];\n }\n this.particles[id] = particles;\n }\n\n if (particleSteps !== 0) {\n this.particles[id].forEach((particle) => {\n if (!this.context) return;\n\n const distance = particleSteps / particleCount;\n getParticlePosition({\n distance,\n particle,\n totalSteps: particleSteps,\n totalCount: particleCount,\n xEnd,\n xStart,\n yEnd,\n yStart,\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 this.context.stroke();\n }\n });\n }\n }\n\n /** Arrow */\n if (this.linkSettings.arrow && arrowAlpha > 0) {\n const {\n x1: xStart,\n x2: xEnd,\n y1: yStart,\n y2: yEnd,\n } = calculateLinkPositionByNode(link) ?? {\n x1: 0,\n x2: 0,\n y1: 0,\n y2: 0,\n };\n\n this.context.beginPath();\n this.context.globalAlpha = arrowAlpha;\n this.context.strokeStyle = linkOptions.arrowBorderColor;\n this.context.lineWidth = linkOptions.arrowBorderWidth;\n this.context.fillStyle = linkOptions.arrowColor;\n const angle = Math.atan2(yEnd - yStart, xEnd - xStart);\n this.context.moveTo(xEnd, yEnd);\n this.context.lineTo(\n xEnd - linkOptions.arrowSize * Math.cos(angle - Math.PI / 6),\n yEnd - linkOptions.arrowSize * Math.sin(angle - Math.PI / 6),\n );\n this.context.lineTo(\n xEnd - linkOptions.arrowSize * Math.cos(angle + Math.PI / 6),\n yEnd - linkOptions.arrowSize * Math.sin(angle + Math.PI / 6),\n );\n this.context.closePath();\n this.context.fill();\n this.context.stroke();\n }\n\n if (linkOptions.drawExtraLink) {\n linkOptions.drawExtraLink(link, { ...linkOptions, alpha }, state);\n }\n };\n}\n"],"names":[],"mappings":";;;;;;;;AAWM,SAAU,WAAW,CAGzB,KAAqC,EAAA;AACrC,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;AAEF,QAAA,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ;YAAE;AAEpD,QAAA,MAAM,EAAE,GAAG,CAAG,EAAA,IAAI,CAAC,MAAM,CAAC,EAAE,CAAA,EAAG,IAAI,CAAC,MAAM,CAAC,EAAE,EAAE;AAC/C,QAAA,IAAI,WAA+D;AACnE,QAAA,IAAI,IAAI,CAAC,YAAY,CAAC,KAAK,IAAI,IAAI,CAAC,gBAAgB,CAAC,EAAE,CAAC,EAAE;AACxD,YAAA,WAAW,GAAG,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AC,CAAC,EAC5D,IAAI,GAAG,WAAW,CAAC,SAAS,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,GAAG,IAAI,CAAC,EAAE,GAAG,CAAC,CAAC,CAC7D;AACD,YAAA,IAAI,CAAC,OAAO,CAAC,MAAM,CACjB,IAAI,GAAG,WAAW,CAAC,SAAS,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,GAAG,IAAI,CAAC,EAAE,GAAG,CAAC,CAAC,EAC5D,IAAI,GAAG,WAAW,CAAC,SAAS,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,GAAG,IAAI,CAAC,EAAE,GAAG,CAAC,CAAC,CAC7D;AACD,YAAA,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE;AACxB,YAAA,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE;AACnB,YAAA,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE;;AAGvB,QAAA,IAAI,WAAW,CAAC,aAAa,EAAE;AAC7B,YAAA,WAAW,CAAC,aAAa,CAAC,IAAI,EAAE,EAAE,GAAG,WAAW,EAAE,KAAK,EAAE,EAAE,KAAK,CAAC;;AAErE,KAAC;AACH;;;;"}
|
|
@@ -0,0 +1,342 @@
|
|
|
1
|
+
import { isNumber } from '@krainovsd/js-helpers';
|
|
2
|
+
import { colorToRgb } from '../../../lib/color-to-rgb.js';
|
|
3
|
+
import { extractRgb } from '../../../lib/extract-rgb.js';
|
|
4
|
+
import { fadeRgb } from '../../../lib/fade-rgb.js';
|
|
5
|
+
import { rgbAnimationByProgress } from '../../../lib/rgb-animation-by-progress.js';
|
|
6
|
+
import { nodeOptionsGetter, nodeRadiusGetter, nodeSizeGetter } from '../lib/settings/node-settings-getter.js';
|
|
7
|
+
import 'd3-array';
|
|
8
|
+
import { nodeIterationExtractor } from '../lib/utils/node-iteration-extractor.js';
|
|
9
|
+
import { animationByProgress } from '../lib/utils/animation-by-progress.js';
|
|
10
|
+
import { isNodeVisible } from '../lib/utils/is-node-visible.js';
|
|
11
|
+
import { getTextLines, drawText } from './draw-text.js';
|
|
12
|
+
|
|
13
|
+
function getDrawNode(nodeRenders, textRenders, state) {
|
|
14
|
+
return function drawNode(node, index) {
|
|
15
|
+
if (!this.context || !node.x || !node.y)
|
|
16
|
+
return;
|
|
17
|
+
let nodeOptions;
|
|
18
|
+
if (this.nodeSettings.cache && this.nodeOptionsCache[node.id]) {
|
|
19
|
+
nodeOptions = this.nodeOptionsCache[node.id];
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
nodeOptions = nodeIterationExtractor(node, index, this.nodes, state, this.nodeSettings.options ?? {}, nodeOptionsGetter);
|
|
23
|
+
if (this.nodeSettings.cache) {
|
|
24
|
+
this.nodeOptionsCache[node.id] = nodeOptions;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
if (nodeOptions.nodeDraw && nodeOptions.textDraw) {
|
|
28
|
+
nodeRenders.push(() => {
|
|
29
|
+
nodeOptions?.nodeDraw?.(node, nodeOptions, state);
|
|
30
|
+
});
|
|
31
|
+
textRenders.push(() => {
|
|
32
|
+
nodeOptions?.textDraw?.(node, nodeOptions, state);
|
|
33
|
+
});
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
let alpha = nodeOptions.alpha;
|
|
37
|
+
let color = nodeOptions.color;
|
|
38
|
+
let radiusInitial = nodeOptions.radius;
|
|
39
|
+
let widthInitial = nodeOptions.width;
|
|
40
|
+
let heightInitial = nodeOptions.height;
|
|
41
|
+
let textAlpha = nodeOptions.textAlpha;
|
|
42
|
+
let textSize = nodeOptions.textSize;
|
|
43
|
+
let textShiftX = nodeOptions.textShiftX;
|
|
44
|
+
let textShiftY = nodeOptions.textShiftY;
|
|
45
|
+
let textWeight = nodeOptions.textWeight;
|
|
46
|
+
let textWidth = nodeOptions.textWidth;
|
|
47
|
+
/** Node Highlight */
|
|
48
|
+
if (this.highlightedNeighbors && this.highlightedNode) {
|
|
49
|
+
/** Not highlighted */
|
|
50
|
+
if (!this.highlightedNeighbors.has(node.id) && this.highlightedNode.id != node.id) {
|
|
51
|
+
if (this.nodeSettings.highlightByNodeNodeFading) {
|
|
52
|
+
const min = this.nodeSettings.highlightByNodeNodeFadingMin < alpha
|
|
53
|
+
? this.nodeSettings.highlightByNodeNodeFadingMin
|
|
54
|
+
: alpha;
|
|
55
|
+
alpha = animationByProgress(min, alpha - min, 1 - this.highlightProgress);
|
|
56
|
+
}
|
|
57
|
+
if (this.nodeSettings.highlightByNodeTextFading) {
|
|
58
|
+
const min = this.nodeSettings.highlightByNodeTextFadingMin < textAlpha
|
|
59
|
+
? this.nodeSettings.highlightByNodeTextFadingMin
|
|
60
|
+
: textAlpha;
|
|
61
|
+
textAlpha = animationByProgress(min, textAlpha - min, 1 - this.highlightProgress);
|
|
62
|
+
}
|
|
63
|
+
if (this.nodeSettings.highlightByNodeNodeColor) {
|
|
64
|
+
const colorRgb = extractRgb(colorToRgb(color));
|
|
65
|
+
if (colorRgb) {
|
|
66
|
+
const colorRgbFade = fadeRgb(colorRgb, this.nodeSettings.highlightByNodeNodeColorFadingMin);
|
|
67
|
+
const colorFadeAnimation = rgbAnimationByProgress(colorRgb, colorRgbFade, this.highlightProgress);
|
|
68
|
+
color = `rgb(${colorFadeAnimation.r}, ${colorFadeAnimation.g}, ${colorFadeAnimation.b})`;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
else if (!this.nodeSettings.highlightByNodeOnlyRoot ||
|
|
73
|
+
(this.nodeSettings.highlightByNodeOnlyRoot && this.highlightedNode.id === node.id)) {
|
|
74
|
+
/** Highlighted */
|
|
75
|
+
if (this.nodeSettings.highlightByNodeNodeSizing && nodeOptions.shape === "circle") {
|
|
76
|
+
radiusInitial = animationByProgress(radiusInitial, this.nodeSettings.highlightByNodeNodeSizingAdditional, this.highlightProgress);
|
|
77
|
+
}
|
|
78
|
+
if (this.nodeSettings.highlightByLinkNodeSizing &&
|
|
79
|
+
(nodeOptions.shape === "square" || nodeOptions.shape === "text")) {
|
|
80
|
+
const widthCoefficient = animationByProgress(1, this.nodeSettings.highlightByNodeNodeSizingAdditionalCoefficient, this.highlightProgress);
|
|
81
|
+
const heightCoefficient = animationByProgress(1, this.nodeSettings.highlightByNodeNodeSizingAdditionalCoefficient, this.highlightProgress);
|
|
82
|
+
widthInitial *= widthCoefficient;
|
|
83
|
+
heightInitial *= heightCoefficient;
|
|
84
|
+
}
|
|
85
|
+
if (this.nodeSettings.highlightByNodeTextSizing) {
|
|
86
|
+
textSize = animationByProgress(textSize, this.nodeSettings.highlightByNodeTextSizingAdditional, this.highlightProgress);
|
|
87
|
+
textShiftX = animationByProgress(textShiftX, this.nodeSettings.highlightByNodeTextShiftXAdditional, this.highlightProgress);
|
|
88
|
+
textShiftY = animationByProgress(textShiftY, this.nodeSettings.highlightByNodeTextShiftYAdditional, this.highlightProgress);
|
|
89
|
+
textWeight = animationByProgress(textWeight, this.nodeSettings.highlightByNodeTextWeightAdditional, this.highlightProgress);
|
|
90
|
+
textWidth = animationByProgress(textWidth, this.nodeSettings.highlightByNodeTextWidthAdditional, this.highlightProgress);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
/** LinkHighlight */
|
|
95
|
+
if (this.highlightedNeighbors && this.highlightedLink) {
|
|
96
|
+
/** Not highlighted */
|
|
97
|
+
if (!this.highlightedNeighbors.has(node.id) &&
|
|
98
|
+
this.highlightedLink.source !== node &&
|
|
99
|
+
this.highlightedLink.target !== node) {
|
|
100
|
+
if (this.nodeSettings.highlightByLinkNodeFading) {
|
|
101
|
+
const min = this.nodeSettings.highlightByLinkNodeFadingMin < alpha
|
|
102
|
+
? this.nodeSettings.highlightByLinkNodeFadingMin
|
|
103
|
+
: alpha;
|
|
104
|
+
alpha = animationByProgress(min, alpha - min, 1 - this.highlightProgress);
|
|
105
|
+
}
|
|
106
|
+
if (this.nodeSettings.highlightByLinkTextFading) {
|
|
107
|
+
const min = this.nodeSettings.highlightByLinkTextFadingMin < textAlpha
|
|
108
|
+
? this.nodeSettings.highlightByLinkTextFadingMin
|
|
109
|
+
: textAlpha;
|
|
110
|
+
textAlpha = animationByProgress(min, textAlpha - min, 1 - this.highlightProgress);
|
|
111
|
+
}
|
|
112
|
+
if (this.nodeSettings.highlightByLinkNodeColor) {
|
|
113
|
+
const colorRgb = extractRgb(colorToRgb(color));
|
|
114
|
+
if (colorRgb) {
|
|
115
|
+
const colorRgbFade = fadeRgb(colorRgb, this.nodeSettings.highlightByLinkNodeColorFadingMin);
|
|
116
|
+
const colorFadeAnimation = rgbAnimationByProgress(colorRgb, colorRgbFade, this.highlightProgress);
|
|
117
|
+
color = `rgb(${colorFadeAnimation.r}, ${colorFadeAnimation.g}, ${colorFadeAnimation.b})`;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
else {
|
|
122
|
+
/** Highlighted */
|
|
123
|
+
if (this.nodeSettings.highlightByLinkNodeSizing && nodeOptions.shape === "circle") {
|
|
124
|
+
radiusInitial = animationByProgress(radiusInitial, this.nodeSettings.highlightByLinkNodeSizingAdditional, this.highlightProgress);
|
|
125
|
+
}
|
|
126
|
+
if (this.nodeSettings.highlightByLinkNodeSizing &&
|
|
127
|
+
(nodeOptions.shape === "square" ||
|
|
128
|
+
nodeOptions.shape === "text" ||
|
|
129
|
+
nodeOptions.shape === "icon")) {
|
|
130
|
+
const widthCoefficient = animationByProgress(1, this.nodeSettings.highlightByLinkNodeSizingAdditionalCoefficient, this.highlightProgress);
|
|
131
|
+
const heightCoefficient = animationByProgress(1, this.nodeSettings.highlightByLinkNodeSizingAdditionalCoefficient, this.highlightProgress);
|
|
132
|
+
widthInitial *= widthCoefficient;
|
|
133
|
+
heightInitial *= heightCoefficient;
|
|
134
|
+
}
|
|
135
|
+
if (this.nodeSettings.highlightByLinkTextSizing) {
|
|
136
|
+
textSize = animationByProgress(textSize, this.nodeSettings.highlightByLinkTextSizingAdditional, this.highlightProgress);
|
|
137
|
+
textShiftX = animationByProgress(textShiftX, this.nodeSettings.highlightByLinkTextShiftXAdditional, this.highlightProgress);
|
|
138
|
+
textShiftY = animationByProgress(textShiftY, this.nodeSettings.highlightByLinkTextShiftYAdditional, this.highlightProgress);
|
|
139
|
+
textWeight = animationByProgress(textWeight, this.nodeSettings.highlightByLinkTextWeightAdditional, this.highlightProgress);
|
|
140
|
+
textWidth = animationByProgress(textWidth, this.nodeSettings.highlightByLinkTextWidthAdditional, this.highlightProgress);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
/** Flex radius */
|
|
145
|
+
const radius = nodeOptions.shape === "circle"
|
|
146
|
+
? nodeRadiusGetter({
|
|
147
|
+
radiusFlexible: this.nodeSettings.nodeRadiusFlexible,
|
|
148
|
+
radiusInitial,
|
|
149
|
+
radiusCoefficient: this.nodeSettings.nodeRadiusCoefficient,
|
|
150
|
+
radiusFactor: this.nodeSettings.nodeRadiusFactor,
|
|
151
|
+
linkCount: node.linkCount,
|
|
152
|
+
})
|
|
153
|
+
: radiusInitial;
|
|
154
|
+
/** Flex size */
|
|
155
|
+
let height = heightInitial;
|
|
156
|
+
let width = widthInitial;
|
|
157
|
+
if (nodeOptions.shape === "square" || nodeOptions.shape === "text") {
|
|
158
|
+
const size = nodeSizeGetter({
|
|
159
|
+
heightInitial,
|
|
160
|
+
widthInitial,
|
|
161
|
+
linkCount: node.linkCount,
|
|
162
|
+
sizeCoefficient: this.nodeSettings.nodeSizeCoefficient,
|
|
163
|
+
sizeFactor: this.nodeSettings.nodeSizeFactor,
|
|
164
|
+
sizeFlexible: this.nodeSettings.nodeSizeFlexible,
|
|
165
|
+
});
|
|
166
|
+
width = size.width;
|
|
167
|
+
height = size.height;
|
|
168
|
+
}
|
|
169
|
+
if (nodeOptions.shape === "text" && nodeOptions.text) {
|
|
170
|
+
const lines = this.cachedNodeText[node.id] ??
|
|
171
|
+
getTextLines({
|
|
172
|
+
context: this.context,
|
|
173
|
+
text: nodeOptions.text,
|
|
174
|
+
textAlign: nodeOptions.textAlign,
|
|
175
|
+
textColor: nodeOptions.textColor,
|
|
176
|
+
textFont: nodeOptions.textFont,
|
|
177
|
+
textSize,
|
|
178
|
+
maxWidth: width,
|
|
179
|
+
textStyle: nodeOptions.textStyle,
|
|
180
|
+
textWeight,
|
|
181
|
+
});
|
|
182
|
+
if (!this.cachedNodeText[node.id]) {
|
|
183
|
+
this.cachedNodeText[node.id] = lines;
|
|
184
|
+
}
|
|
185
|
+
height =
|
|
186
|
+
lines.length * textSize +
|
|
187
|
+
(lines.length - 1) * nodeOptions.textGap +
|
|
188
|
+
nodeOptions.textNodeYPadding;
|
|
189
|
+
width += nodeOptions.textNodeXPadding;
|
|
190
|
+
}
|
|
191
|
+
/** Node parameters */
|
|
192
|
+
node._radius = radius;
|
|
193
|
+
node._width = width;
|
|
194
|
+
node._height = height;
|
|
195
|
+
node._borderRadius =
|
|
196
|
+
isNumber(nodeOptions.borderRadius) && nodeOptions.borderRadius > 0
|
|
197
|
+
? Math.min(nodeOptions.borderRadius, nodeOptions.width / 2, nodeOptions.height / 2)
|
|
198
|
+
: 0;
|
|
199
|
+
node._shape = nodeOptions.shape ?? "circle";
|
|
200
|
+
/** Node Visibility */
|
|
201
|
+
if (!isNodeVisible({
|
|
202
|
+
height: this.height,
|
|
203
|
+
width: this.width,
|
|
204
|
+
transform: this.areaTransform,
|
|
205
|
+
node,
|
|
206
|
+
})) {
|
|
207
|
+
node._visible = false;
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
node._visible = true;
|
|
211
|
+
/** Node draw */
|
|
212
|
+
nodeRenders.push(() => {
|
|
213
|
+
if (!this.context || !node.x || !node.y)
|
|
214
|
+
return;
|
|
215
|
+
this.context.beginPath();
|
|
216
|
+
this.context.globalAlpha = alpha;
|
|
217
|
+
this.context.lineWidth = nodeOptions.borderWidth;
|
|
218
|
+
this.context.strokeStyle = nodeOptions.borderColor;
|
|
219
|
+
this.context.fillStyle = color;
|
|
220
|
+
switch (nodeOptions.shape) {
|
|
221
|
+
case "circle": {
|
|
222
|
+
this.context.arc(node.x, node.y, radius, 0, 2 * Math.PI);
|
|
223
|
+
break;
|
|
224
|
+
}
|
|
225
|
+
case "square": {
|
|
226
|
+
this.context.roundRect(node.x - width / 2, node.y - height / 2, width, height, node._borderRadius);
|
|
227
|
+
break;
|
|
228
|
+
}
|
|
229
|
+
case "text": {
|
|
230
|
+
if (this.nodeSettings.textNodeDebug) {
|
|
231
|
+
this.context.strokeRect(node.x - width / 2, node.y - height / 2, width, height);
|
|
232
|
+
}
|
|
233
|
+
const lines = this.cachedNodeText[node.id];
|
|
234
|
+
if (nodeOptions.text && lines)
|
|
235
|
+
drawText({
|
|
236
|
+
id: node.id,
|
|
237
|
+
cachedNodeText: this.cachedNodeText,
|
|
238
|
+
context: this.context,
|
|
239
|
+
text: nodeOptions.text,
|
|
240
|
+
textAlign: nodeOptions.textAlign,
|
|
241
|
+
textColor: nodeOptions.textColor,
|
|
242
|
+
textFont: nodeOptions.textFont,
|
|
243
|
+
textSize,
|
|
244
|
+
x: node.x,
|
|
245
|
+
y: node.y + textSize / 4 - (lines.length - 1) * (textSize / 2),
|
|
246
|
+
maxWidth: widthInitial,
|
|
247
|
+
textStyle: nodeOptions.textStyle,
|
|
248
|
+
textWeight,
|
|
249
|
+
textGap: nodeOptions.textGap,
|
|
250
|
+
});
|
|
251
|
+
break;
|
|
252
|
+
}
|
|
253
|
+
default: {
|
|
254
|
+
this.context.arc(node.x, node.y, radius, 0, 2 * Math.PI);
|
|
255
|
+
break;
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
this.context.fill();
|
|
259
|
+
this.context.stroke();
|
|
260
|
+
});
|
|
261
|
+
if (nodeOptions.nodeExtraDraw) {
|
|
262
|
+
nodeRenders.push(() => {
|
|
263
|
+
nodeOptions?.nodeExtraDraw?.(node, {
|
|
264
|
+
...nodeOptions,
|
|
265
|
+
radius,
|
|
266
|
+
alpha,
|
|
267
|
+
color,
|
|
268
|
+
textAlpha,
|
|
269
|
+
textSize,
|
|
270
|
+
textShiftX,
|
|
271
|
+
textShiftY,
|
|
272
|
+
textWeight,
|
|
273
|
+
textWidth,
|
|
274
|
+
}, state);
|
|
275
|
+
});
|
|
276
|
+
}
|
|
277
|
+
/** Text draw */
|
|
278
|
+
if (nodeOptions.textVisible && nodeOptions.text && nodeOptions.shape !== "text") {
|
|
279
|
+
textRenders.push(() => {
|
|
280
|
+
if (nodeOptions.textDraw) {
|
|
281
|
+
nodeOptions.textDraw(node, {
|
|
282
|
+
...nodeOptions,
|
|
283
|
+
radius,
|
|
284
|
+
alpha,
|
|
285
|
+
color,
|
|
286
|
+
textAlpha,
|
|
287
|
+
textSize,
|
|
288
|
+
textShiftX,
|
|
289
|
+
textShiftY,
|
|
290
|
+
textWeight,
|
|
291
|
+
textWidth,
|
|
292
|
+
}, state);
|
|
293
|
+
return;
|
|
294
|
+
}
|
|
295
|
+
if (!this.context || !node.x || !node.y || !nodeOptions.text)
|
|
296
|
+
return;
|
|
297
|
+
this.context.beginPath();
|
|
298
|
+
this.context.globalAlpha = textAlpha;
|
|
299
|
+
let y = node.y + textShiftY;
|
|
300
|
+
if (nodeOptions.shape === "circle") {
|
|
301
|
+
y += radius;
|
|
302
|
+
}
|
|
303
|
+
if (nodeOptions.shape === "square") {
|
|
304
|
+
y += height / 2;
|
|
305
|
+
}
|
|
306
|
+
drawText({
|
|
307
|
+
id: node.id,
|
|
308
|
+
cachedNodeText: this.cachedNodeText,
|
|
309
|
+
context: this.context,
|
|
310
|
+
text: nodeOptions.text,
|
|
311
|
+
textAlign: nodeOptions.textAlign,
|
|
312
|
+
textColor: nodeOptions.textColor,
|
|
313
|
+
textFont: nodeOptions.textFont,
|
|
314
|
+
textSize,
|
|
315
|
+
x: node.x + textShiftX,
|
|
316
|
+
y,
|
|
317
|
+
maxWidth: textWidth,
|
|
318
|
+
textStyle: nodeOptions.textStyle,
|
|
319
|
+
textWeight,
|
|
320
|
+
textGap: nodeOptions.textGap,
|
|
321
|
+
});
|
|
322
|
+
if (nodeOptions.textExtraDraw) {
|
|
323
|
+
nodeOptions.textExtraDraw(node, {
|
|
324
|
+
...nodeOptions,
|
|
325
|
+
radius,
|
|
326
|
+
alpha,
|
|
327
|
+
color,
|
|
328
|
+
textAlpha,
|
|
329
|
+
textSize,
|
|
330
|
+
textShiftX,
|
|
331
|
+
textShiftY,
|
|
332
|
+
textWeight,
|
|
333
|
+
textWidth,
|
|
334
|
+
}, state);
|
|
335
|
+
}
|
|
336
|
+
});
|
|
337
|
+
}
|
|
338
|
+
};
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
export { getDrawNode };
|
|
342
|
+
//# sourceMappingURL=draw-nodes.js.map
|