@krainovsd/graph 0.12.0-beta.6 → 0.13.0-beta3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (30) hide show
  1. package/lib/cjs/index.cjs +566 -371
  2. package/lib/cjs/index.cjs.map +1 -1
  3. package/lib/esm/index.js +5 -4
  4. package/lib/esm/index.js.map +1 -1
  5. package/lib/esm/module/GraphCanvas/GraphCanvas.js +41 -46
  6. package/lib/esm/module/GraphCanvas/GraphCanvas.js.map +1 -1
  7. package/lib/esm/module/GraphCanvas/constants/index.js +12 -0
  8. package/lib/esm/module/GraphCanvas/constants/index.js.map +1 -0
  9. package/lib/esm/module/GraphCanvas/constants/link-settings.js +1 -0
  10. package/lib/esm/module/GraphCanvas/constants/link-settings.js.map +1 -1
  11. package/lib/esm/module/GraphCanvas/lib/utils/calculate-curve-link-position-by-node.js +42 -0
  12. package/lib/esm/module/GraphCanvas/lib/utils/calculate-curve-link-position-by-node.js.map +1 -0
  13. package/lib/esm/module/GraphCanvas/lib/utils/calculate-link-position-by-node.js +37 -35
  14. package/lib/esm/module/GraphCanvas/lib/utils/calculate-link-position-by-node.js.map +1 -1
  15. package/lib/esm/module/GraphCanvas/lib/utils/link-by-pointer-getter.js +72 -22
  16. package/lib/esm/module/GraphCanvas/lib/utils/link-by-pointer-getter.js.map +1 -1
  17. package/lib/esm/module/GraphCanvas/slices/draw-links.js +70 -17
  18. package/lib/esm/module/GraphCanvas/slices/draw-links.js.map +1 -1
  19. package/lib/esm/module/GraphCanvas/slices/init-pointer.js +6 -0
  20. package/lib/esm/module/GraphCanvas/slices/init-pointer.js.map +1 -1
  21. package/lib/esm/module/GraphCanvas/slices/init-resize.js +7 -0
  22. package/lib/esm/module/GraphCanvas/slices/init-resize.js.map +1 -1
  23. package/lib/esm/module/GraphCanvas/slices/init-zoom.js +5 -2
  24. package/lib/esm/module/GraphCanvas/slices/init-zoom.js.map +1 -1
  25. package/lib/esm/module/GraphCanvas/slices/update-link-cache.js +30 -0
  26. package/lib/esm/module/GraphCanvas/slices/update-link-cache.js.map +1 -1
  27. package/lib/esm/module/GraphCanvas/slices/update-node-cache.js +103 -97
  28. package/lib/esm/module/GraphCanvas/slices/update-node-cache.js.map +1 -1
  29. package/lib/index.d.ts +71 -47
  30. package/package.json +3 -2
@@ -2,31 +2,34 @@ import { isObject } from '@krainovsd/js-helpers';
2
2
  import { greatest } from 'd3-array';
3
3
  import { pointerGetter } from './pointer-getter.js';
4
4
 
5
- function linkByPointerGetter({ areaRect, areaTransform, mouseEvent, links, linkHoverExtraZone, }) {
5
+ function linkByPointerGetter({ areaRect, areaTransform, mouseEvent, links, linkHoverExtraZone, curve, }) {
6
6
  if (!areaRect)
7
7
  return undefined;
8
8
  const [pointerX, pointerY] = pointerGetter(mouseEvent, areaRect, areaTransform);
9
9
  return greatest(links, (link) => {
10
- if (isNearLink(pointerX, pointerY, link, linkHoverExtraZone))
11
- return link.index;
10
+ if (!isObject(link.source) ||
11
+ !isObject(link.target) ||
12
+ link.source.visible === false ||
13
+ link.target.visible === false)
14
+ return;
15
+ const x1 = (link._x1 ?? link.source.x);
16
+ const y1 = (link._y1 ?? link.source.y);
17
+ const x2 = (link._x2 ?? link.target.x);
18
+ const y2 = (link._y2 ?? link.target.y);
19
+ const cx = link._cx ?? 0;
20
+ const cy = link._cy ?? 0;
21
+ return curve
22
+ ? hitTestQuadratic(pointerX, pointerY, x1, y1, cx, cy, x2, y2, linkHoverExtraZone)
23
+ ? link.index
24
+ : undefined
25
+ : isNearLink(pointerX, pointerY, x1, y1, x2, y2, linkHoverExtraZone)
26
+ ? link.index
27
+ : undefined;
12
28
  });
13
29
  }
14
- function isNearLink(mouseX, mouseY, link, threshold = 2) {
15
- if (!isObject(link.source) ||
16
- !isObject(link.target) ||
17
- link.source.visible === false ||
18
- link.target.visible === false)
19
- return false;
20
- const x1 = link.source.x;
21
- const y1 = link.source.y;
22
- const x2 = link.target.x;
23
- const y2 = link.target.y;
24
- const distance = distanceToLine(mouseX, mouseY, x1, y1, x2, y2);
25
- return distance <= threshold;
26
- }
27
- function distanceToLine(x, y, x1, y1, x2, y2) {
28
- const A = x - x1;
29
- const B = y - y1;
30
+ function isNearLink(px, py, x1, y1, x2, y2, threshold = 2) {
31
+ const A = px - x1;
32
+ const B = py - y1;
30
33
  const C = x2 - x1;
31
34
  const D = y2 - y1;
32
35
  const dot = A * C + B * D;
@@ -48,9 +51,56 @@ function distanceToLine(x, y, x1, y1, x2, y2) {
48
51
  xx = x1 + param * C;
49
52
  yy = y1 + param * D;
50
53
  }
51
- const dx = x - xx;
52
- const dy = y - yy;
53
- return Math.sqrt(dx * dx + dy * dy);
54
+ const dx = px - xx;
55
+ const dy = py - yy;
56
+ return Math.sqrt(dx * dx + dy * dy) <= threshold;
57
+ }
58
+ function hitTestQuadratic(px, py, x0, y0, xc, yc, x2, y2, tol) {
59
+ const bb = bezierBBox(x0, y0, xc, yc, x2, y2);
60
+ if (px < bb.minX - tol || px > bb.maxX + tol || py < bb.minY - tol || py > bb.maxY + tol) {
61
+ return false;
62
+ }
63
+ const chord = Math.hypot(x2 - x0, y2 - y0);
64
+ const contLen = Math.hypot(xc - x0, yc - y0) + Math.hypot(x2 - xc, y2 - yc);
65
+ const approxLen = (chord + contLen) / 2;
66
+ const steps = Math.max(16, Math.ceil(approxLen / 1));
67
+ const tol2 = tol * tol;
68
+ for (let i = 0; i <= steps; i++) {
69
+ const t = i / steps;
70
+ const mt = 1 - t;
71
+ const x = mt * mt * x0 + 2 * mt * t * xc + t * t * x2;
72
+ const y = mt * mt * y0 + 2 * mt * t * yc + t * t * y2;
73
+ const dx = px - x;
74
+ const dy = py - y;
75
+ if (dx * dx + dy * dy <= tol2)
76
+ return true;
77
+ }
78
+ return false;
79
+ }
80
+ function bezierBBox(x0, y0, x1, y1, x2, y2) {
81
+ function extrema(p0, p1, p2) {
82
+ const denom = p0 - 2 * p1 + p2;
83
+ if (denom === 0)
84
+ return [];
85
+ const t = (p0 - p1) / denom;
86
+ return t > 0 && t < 1 ? [t] : [];
87
+ }
88
+ const ts = [...extrema(x0, x1, x2), ...extrema(y0, y1, y2), 0, 1];
89
+ let maxX = -Infinity, maxY = -Infinity, minX = Infinity, minY = Infinity;
90
+ for (const t of ts) {
91
+ const mt = 1 - t;
92
+ const x = mt * mt * x0 + 2 * mt * t * x1 + t * t * x2;
93
+ const y = mt * mt * y0 + 2 * mt * t * y1 + t * t * y2;
94
+ if (x < minX)
95
+ minX = x;
96
+ if (x > maxX)
97
+ maxX = x;
98
+ if (y < minY)
99
+ minY = y;
100
+ if (y > maxY)
101
+ maxY = y;
102
+ }
103
+ return { minX, minY, maxX, maxY };
54
104
  }
55
105
 
56
106
  export { linkByPointerGetter };
@@ -1 +1 @@
1
- {"version":3,"file":"link-by-pointer-getter.js","sources":["../../../../../../src/module/GraphCanvas/lib/utils/link-by-pointer-getter.ts"],"sourcesContent":["import { isObject } from \"@krainovsd/js-helpers\";\nimport { greatest } from \"d3-array\";\nimport type { ZoomTransform } from \"d3-zoom\";\nimport type { LinkInterface } from \"../../types\";\nimport { pointerGetter } from \"./pointer-getter\";\n\nexport type LinkByPointerGetterOptions<\n NodeData extends Record<string, unknown>,\n LinkData extends Record<string, unknown>,\n> = {\n mouseEvent: MouseEvent | TouchEvent;\n areaRect: DOMRect | undefined;\n areaTransform: ZoomTransform;\n links: LinkInterface<NodeData, LinkData>[];\n linkHoverExtraZone: number;\n};\n\nexport function linkByPointerGetter<\n NodeData extends Record<string, unknown>,\n LinkData extends Record<string, unknown>,\n>({\n areaRect,\n areaTransform,\n mouseEvent,\n links,\n linkHoverExtraZone,\n}: LinkByPointerGetterOptions<NodeData, LinkData>): LinkInterface<NodeData, LinkData> | undefined {\n if (!areaRect) return undefined;\n\n const [pointerX, pointerY] = pointerGetter(mouseEvent, areaRect, areaTransform);\n\n return greatest(links, (link) => {\n if (isNearLink(pointerX, pointerY, link, linkHoverExtraZone)) return link.index;\n });\n}\n\nfunction isNearLink<\n NodeData extends Record<string, unknown>,\n LinkData extends Record<string, unknown>,\n>(mouseX: number, mouseY: number, link: LinkInterface<NodeData, LinkData>, threshold = 2) {\n if (\n !isObject(link.source) ||\n !isObject(link.target) ||\n link.source.visible === false ||\n link.target.visible === false\n )\n return false;\n\n const x1 = link.source.x as number;\n const y1 = link.source.y as number;\n const x2 = link.target.x as number;\n const y2 = link.target.y as number;\n\n const distance = distanceToLine(mouseX, mouseY, x1, y1, x2, y2);\n\n return distance <= threshold;\n}\n\nfunction distanceToLine(x: number, y: number, x1: number, y1: number, x2: number, y2: number) {\n const A = x - x1;\n const B = y - y1;\n const C = x2 - x1;\n const D = y2 - y1;\n\n const dot = A * C + B * D;\n const lenSq = C * C + D * D;\n let param = -1;\n\n if (lenSq !== 0) {\n param = dot / lenSq;\n }\n\n let xx, yy;\n\n if (param < 0) {\n xx = x1;\n yy = y1;\n } else if (param > 1) {\n xx = x2;\n yy = y2;\n } else {\n xx = x1 + param * C;\n yy = y1 + param * D;\n }\n\n const dx = x - xx;\n const dy = y - yy;\n\n return Math.sqrt(dx * dx + dy * dy);\n}\n"],"names":[],"mappings":";;;;AAiBgB,SAAA,mBAAmB,CAGjC,EACA,QAAQ,EACR,aAAa,EACb,UAAU,EACV,KAAK,EACL,kBAAkB,GAC6B,EAAA;AAC/C,IAAA,IAAI,CAAC,QAAQ;AAAE,QAAA,OAAO,SAAS;AAE/B,IAAA,MAAM,CAAC,QAAQ,EAAE,QAAQ,CAAC,GAAG,aAAa,CAAC,UAAU,EAAE,QAAQ,EAAE,aAAa,CAAC;AAE/E,IAAA,OAAO,QAAQ,CAAC,KAAK,EAAE,CAAC,IAAI,KAAI;QAC9B,IAAI,UAAU,CAAC,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE,kBAAkB,CAAC;YAAE,OAAO,IAAI,CAAC,KAAK;AACjF,KAAC,CAAC;AACJ;AAEA,SAAS,UAAU,CAGjB,MAAc,EAAE,MAAc,EAAE,IAAuC,EAAE,SAAS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AE,EAAE;AAEV,IAAA,IAAI,KAAK,GAAG,CAAC,EAAE;QACb,EAAE,GAAG,EAAE;QACP,EAAE,GAAG,EAAE;;AACF,SAAA,IAAI,KAAK,GAAG,CAAC,EAAE;QACpB,EAAE,GAAG,EAAE;QACP,EAAE,GAAG,EAAE;;SACF;AACL,QAAA,EAAE,GAAG,EAAE,GAAG,KAAK,GAAG,CAAC;AACnB,QAAA,EAAE,GAAG,EAAE,GAAG,KAAK,GAAG,CAAC;;AAGrB,IAAA,MAAM,EAAE,GAAG,CAAC,GAAG,EAAE;AACjB,IAAA,MAAM,EAAE,GAAG,CAAC,GAAG,EAAE;AAEjB,IAAA,OAAO,IAAI,CAAC,IAAI,CAAC,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC;AACrC;;;;"}
1
+ {"version":3,"file":"link-by-pointer-getter.js","sources":["../../../../../../src/module/GraphCanvas/lib/utils/link-by-pointer-getter.ts"],"sourcesContent":["import { isObject } from \"@krainovsd/js-helpers\";\nimport { greatest } from \"d3-array\";\nimport type { ZoomTransform } from \"d3-zoom\";\nimport type { LinkInterface } from \"../../types\";\nimport { pointerGetter } from \"./pointer-getter\";\n\nexport type LinkByPointerGetterOptions<\n NodeData extends Record<string, unknown>,\n LinkData extends Record<string, unknown>,\n> = {\n mouseEvent: MouseEvent | TouchEvent;\n areaRect: DOMRect | undefined;\n areaTransform: ZoomTransform;\n links: LinkInterface<NodeData, LinkData>[];\n linkHoverExtraZone: number;\n curve: boolean;\n};\n\nexport function linkByPointerGetter<\n NodeData extends Record<string, unknown>,\n LinkData extends Record<string, unknown>,\n>({\n areaRect,\n areaTransform,\n mouseEvent,\n links,\n linkHoverExtraZone,\n curve,\n}: LinkByPointerGetterOptions<NodeData, LinkData>): LinkInterface<NodeData, LinkData> | undefined {\n if (!areaRect) return undefined;\n\n const [pointerX, pointerY] = pointerGetter(mouseEvent, areaRect, areaTransform);\n\n return greatest(links, (link) => {\n if (\n !isObject(link.source) ||\n !isObject(link.target) ||\n link.source.visible === false ||\n link.target.visible === false\n )\n return;\n\n const x1 = (link._x1 ?? link.source.x) as number;\n const y1 = (link._y1 ?? link.source.y) as number;\n const x2 = (link._x2 ?? link.target.x) as number;\n const y2 = (link._y2 ?? link.target.y) as number;\n const cx = link._cx ?? 0;\n const cy = link._cy ?? 0;\n\n return curve\n ? hitTestQuadratic(pointerX, pointerY, x1, y1, cx, cy, x2, y2, linkHoverExtraZone)\n ? link.index\n : undefined\n : isNearLink(pointerX, pointerY, x1, y1, x2, y2, linkHoverExtraZone)\n ? link.index\n : undefined;\n });\n}\n\nfunction isNearLink(\n px: number,\n py: number,\n x1: number,\n y1: number,\n x2: number,\n y2: number,\n threshold = 2,\n) {\n const A = px - x1;\n const B = py - y1;\n const C = x2 - x1;\n const D = y2 - y1;\n\n const dot = A * C + B * D;\n const lenSq = C * C + D * D;\n let param = -1;\n\n if (lenSq !== 0) {\n param = dot / lenSq;\n }\n\n let xx, yy;\n\n if (param < 0) {\n xx = x1;\n yy = y1;\n } else if (param > 1) {\n xx = x2;\n yy = y2;\n } else {\n xx = x1 + param * C;\n yy = y1 + param * D;\n }\n\n const dx = px - xx;\n const dy = py - yy;\n\n return Math.sqrt(dx * dx + dy * dy) <= threshold;\n}\n\nfunction hitTestQuadratic(\n px: number,\n py: number,\n x0: number,\n y0: number,\n xc: number,\n yc: number,\n x2: number,\n y2: number,\n tol: number,\n): boolean {\n const bb = bezierBBox(x0, y0, xc, yc, x2, y2);\n if (px < bb.minX - tol || px > bb.maxX + tol || py < bb.minY - tol || py > bb.maxY + tol) {\n return false;\n }\n\n const chord = Math.hypot(x2 - x0, y2 - y0);\n const contLen = Math.hypot(xc - x0, yc - y0) + Math.hypot(x2 - xc, y2 - yc);\n const approxLen = (chord + contLen) / 2;\n const steps = Math.max(16, Math.ceil(approxLen / 1));\n\n const tol2 = tol * tol;\n for (let i = 0; i <= steps; i++) {\n const t = i / steps;\n const mt = 1 - t;\n const x = mt * mt * x0 + 2 * mt * t * xc + t * t * x2;\n const y = mt * mt * y0 + 2 * mt * t * yc + t * t * y2;\n const dx = px - x;\n const dy = py - y;\n if (dx * dx + dy * dy <= tol2) return true;\n }\n return false;\n}\n\nfunction bezierBBox(\n x0: number,\n y0: number,\n x1: number,\n y1: number,\n x2: number,\n y2: number,\n): { minX: number; maxX: number; minY: number; maxY: number } {\n function extrema(p0: number, p1: number, p2: number): number[] {\n const denom = p0 - 2 * p1 + p2;\n if (denom === 0) return [];\n const t = (p0 - p1) / denom;\n return t > 0 && t < 1 ? [t] : [];\n }\n\n const ts = [...extrema(x0, x1, x2), ...extrema(y0, y1, y2), 0, 1];\n\n let maxX = -Infinity,\n maxY = -Infinity,\n minX = Infinity,\n minY = Infinity;\n\n for (const t of ts) {\n const mt = 1 - t;\n const x = mt * mt * x0 + 2 * mt * t * x1 + t * t * x2;\n const y = mt * mt * y0 + 2 * mt * t * y1 + t * t * y2;\n if (x < minX) minX = x;\n if (x > maxX) maxX = x;\n if (y < minY) minY = y;\n if (y > maxY) maxY = y;\n }\n\n return { minX, minY, maxX, maxY };\n}\n"],"names":[],"mappings":";;;;AAkBgB,SAAA,mBAAmB,CAGjC,EACA,QAAQ,EACR,aAAa,EACb,UAAU,EACV,KAAK,EACL,kBAAkB,EAClB,KAAK,GAC0C,EAAA;AAC/C,IAAA,IAAI,CAAC,QAAQ;AAAE,QAAA,OAAO,SAAS;AAE/B,IAAA,MAAM,CAAC,QAAQ,EAAE,QAAQ,CAAC,GAAG,aAAa,CAAC,UAAU,EAAE,QAAQ,EAAE,aAAa,CAAC;AAE/E,IAAA,OAAO,QAAQ,CAAC,KAAK,EAAE,CAAC,IAAI,KAAI;AAC9B,QAAA,IACE,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC;AACtB,YAAA,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC;AACtB,YAAA,IAAI,CAAC,MAAM,CAAC,OAAO,KAAK,KAAK;AAC7B,YAAA,IAAI,CAAC,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AAI,GAAG,CAAC;;IAGxB,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE;AACnC;;;;"}
@@ -3,6 +3,7 @@ import 'd3-array';
3
3
  import { calculateLinkPositionByNode } from '../lib/utils/calculate-link-position-by-node.js';
4
4
  import { getParticlePosition } from '../lib/utils/get-particle-position.js';
5
5
  import { linkFade, linkHighlight } from '../lib/utils/link-highlight.js';
6
+ import { calculateCurveLinkPositionByNode } from '../lib/utils/calculate-curve-link-position-by-node.js';
6
7
 
7
8
  function getDrawLink() {
8
9
  return function drawLink(link) {
@@ -119,23 +120,62 @@ function getDrawLink() {
119
120
  let yStart = link.source.y;
120
121
  let xEnd = link.target.x;
121
122
  let yEnd = link.target.y;
123
+ let xControl = 0;
124
+ let yControl = 0;
125
+ let xEndArrow = xEnd;
126
+ let yEndArrow = yEnd;
122
127
  let linkDistance = 0;
123
- if (this.linkSettings.prettyDraw ||
124
- this.linkSettings.particleFlexSpeed ||
125
- (this.linkSettings.arrow && arrowAlpha > 0)) {
126
- const isHasArrow = this.linkSettings.arrow && arrowAlpha > 0;
127
- const position = calculateLinkPositionByNode(link, isHasArrow ? arrowSize : 0);
128
- if (position) {
129
- xStart = position.x1;
130
- xEnd = position.x2;
131
- yStart = position.y1;
132
- yEnd = position.y2;
128
+ const isHasArrow = this.linkSettings.arrow && arrowAlpha > 0;
129
+ if (!this.linkSettings.curve) {
130
+ if (this.linkSettings.prettyDraw ||
131
+ this.linkSettings.particleFlexSpeed ||
132
+ (this.linkSettings.arrow && arrowAlpha > 0)) {
133
+ const position = calculateLinkPositionByNode(xStart, yStart, xEnd, yEnd, link.source, link.target, isHasArrow ? arrowSize : 0);
134
+ xStart = position.xStart;
135
+ xEnd = position.xEnd;
136
+ yStart = position.yStart;
137
+ yEnd = position.yEnd;
138
+ xEndArrow = position.xEndArrow;
139
+ yEndArrow = position.yEndArrow;
133
140
  linkDistance = position.distance;
134
141
  }
142
+ link._x1 = xStart;
143
+ link._y1 = yStart;
144
+ link._x2 = xEnd;
145
+ link._y2 = yEnd;
146
+ link._ax = xEndArrow;
147
+ link._ay = yEndArrow;
148
+ this.context.moveTo(xStart, yStart);
149
+ this.context.lineTo(xEnd, yEnd);
150
+ this.context.stroke();
151
+ }
152
+ else {
153
+ const position = calculateCurveLinkPositionByNode(xStart, yStart, xEnd, yEnd, link.source, link.target, link._groupIndex ?? 0, isHasArrow ? arrowSize : 0);
154
+ xStart = position.xStart;
155
+ yStart = position.yStart;
156
+ xEnd = position.xEnd;
157
+ yEnd = position.yEnd;
158
+ xControl = position.xControl;
159
+ yControl = position.yControl;
160
+ xEndArrow = position.xEndArrow;
161
+ yEndArrow = position.yEndArrow;
162
+ link._x1 = position.xStart;
163
+ link._y1 = position.yStart;
164
+ link._x2 = position.xEnd;
165
+ link._y2 = position.yEnd;
166
+ link._cx = position.xControl;
167
+ link._cy = position.yControl;
168
+ link._ax = position.xEndArrow;
169
+ link._ay = position.yEndArrow;
170
+ this.context.beginPath();
171
+ this.context.moveTo(position.xStart, position.yStart);
172
+ this.context.quadraticCurveTo(position.xControl, position.yControl, position.xEnd, position.yEnd);
173
+ this.context.setLineDash([]);
174
+ // if (isDashed) {
175
+ // this.context.setLineDash([10, 5]);
176
+ // }
177
+ this.context.stroke();
135
178
  }
136
- this.context.moveTo(xStart, yStart);
137
- this.context.lineTo(xEnd, yEnd);
138
- this.context.stroke();
139
179
  /** Particle */
140
180
  if (this.linkSettings.particles &&
141
181
  ((this.highlightedNode &&
@@ -203,15 +243,28 @@ function getDrawLink() {
203
243
  }
204
244
  /** Arrow */
205
245
  if (this.linkSettings.arrow && arrowAlpha > 0) {
246
+ let angle = 0;
247
+ if (!this.linkSettings.curve) {
248
+ angle = Math.atan2(yEndArrow - yStart, xEndArrow - xStart);
249
+ }
250
+ else {
251
+ const tangentX = 2 * (xEndArrow - xControl);
252
+ const tangentY = 2 * (yEndArrow - yControl);
253
+ if (Math.abs(tangentX) < 0.001 && Math.abs(tangentY) < 0.001) {
254
+ angle = Math.atan2(yEndArrow - yControl, xEndArrow - xControl);
255
+ }
256
+ else {
257
+ angle = Math.atan2(tangentY, tangentX);
258
+ }
259
+ }
206
260
  this.context.beginPath();
207
261
  this.context.globalAlpha = arrowAlpha;
208
262
  this.context.strokeStyle = arrowBorderColor;
209
263
  this.context.lineWidth = arrowBorderWidth;
210
264
  this.context.fillStyle = arrowColor;
211
- const angle = Math.atan2(yEnd - yStart, xEnd - xStart);
212
- this.context.moveTo(xEnd, yEnd);
213
- this.context.lineTo(xEnd - arrowSize * Math.cos(angle - Math.PI / 6), yEnd - arrowSize * Math.sin(angle - Math.PI / 6));
214
- this.context.lineTo(xEnd - arrowSize * Math.cos(angle + Math.PI / 6), yEnd - arrowSize * Math.sin(angle + Math.PI / 6));
265
+ this.context.moveTo(xEndArrow, yEndArrow);
266
+ this.context.lineTo(xEndArrow - arrowSize * Math.cos(angle - Math.PI / 6), yEndArrow - arrowSize * Math.sin(angle - Math.PI / 6));
267
+ this.context.lineTo(xEndArrow - arrowSize * Math.cos(angle + Math.PI / 6), yEndArrow - arrowSize * Math.sin(angle + Math.PI / 6));
215
268
  this.context.closePath();
216
269
  this.context.fill();
217
270
  if (arrowBorderWidth > 0) {
@@ -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 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 ) {\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 id = `${link.target.id}${link.source.id}`;\n const linkOptions = this.linkOptionsCache[id];\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 /** Highlight */\n if (this.highlightedNeighbors && this.highlightedNode) {\n /** By Node Not Highlight */\n if (this.highlightedNode.id != link.source.id && this.highlightedNode.id != link.target.id) {\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 if (this.highlightedNeighbors && this.highlightedLink) {\n /** By Link Not Highlight */\n if (this.highlightedLink !== link) {\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\n this.context.globalAlpha = alpha;\n this.context.strokeStyle = color;\n this.context.lineWidth = 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 (\n this.linkSettings.prettyDraw ||\n this.linkSettings.particleFlexSpeed ||\n (this.linkSettings.arrow && arrowAlpha > 0)\n ) {\n const isHasArrow = this.linkSettings.arrow && arrowAlpha > 0;\n const position = calculateLinkPositionByNode(link, isHasArrow ? 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: LinkParticle[] = [];\n let prevParticle: LinkParticle | undefined;\n\n for (let i = 0; i < particleCount; i++) {\n const particle: LinkParticle = {\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 if (linkOptions.particleBorderWidth > 0) {\n this.context.stroke();\n }\n }\n });\n }\n }\n\n /** Arrow */\n if (this.linkSettings.arrow && arrowAlpha > 0) {\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 const angle = Math.atan2(yEnd - yStart, xEnd - xStart);\n this.context.moveTo(xEnd, yEnd);\n this.context.lineTo(\n xEnd - arrowSize * Math.cos(angle - Math.PI / 6),\n yEnd - arrowSize * Math.sin(angle - Math.PI / 6),\n );\n this.context.lineTo(\n xEnd - arrowSize * Math.cos(angle + Math.PI / 6),\n yEnd - 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":";;;;;;SAIgB,WAAW,GAAA;IAIzB,OAAO,SAAS,QAAQ,CAEtB,IAAuC,EAAA;QAEvC,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,OAA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,CAAC,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC;AAC/B,YAAA,IAAI,CAAC,OAAO,CAAC,MAAM,CACjB,IAAI,GAAG,SAAS,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,GAAG,IAAI,CAAC,EAAE,GAAG,CAAC,CAAC,EAChD,IAAI,GAAG,SAAS,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,GAAG,IAAI,CAAC,EAAE,GAAG,CAAC,CAAC,CACjD;AACD,YAAA,IAAI,CAAC,OAAO,CAAC,MAAM,CACjB,IAAI,GAAG,SAAS,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,GAAG,IAAI,CAAC,EAAE,GAAG,CAAC,CAAC,EAChD,IAAI,GAAG,SAAS,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,GAAG,IAAI,CAAC,EAAE,GAAG,CAAC,CAAC,CACjD;AACD,YAAA,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE;AACxB,YAAA,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE;AACnB,YAAA,IAAI,gBAAgB,GAAG,CAAC,EAAE;AACxB,gBAAA,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE;;;AAIzB,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
+ {"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 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 ) {\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 id = `${link.target.id}${link.source.id}`;\n const linkOptions = this.linkOptionsCache[id];\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 /** Highlight */\n if (this.highlightedNeighbors && this.highlightedNode) {\n /** By Node Not Highlight */\n if (this.highlightedNode.id != link.source.id && this.highlightedNode.id != link.target.id) {\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 if (this.highlightedNeighbors && this.highlightedLink) {\n /** By Link Not Highlight */\n if (this.highlightedLink !== link) {\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\n this.context.globalAlpha = alpha;\n this.context.strokeStyle = color;\n this.context.lineWidth = 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 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.particleFlexSpeed ||\n (this.linkSettings.arrow && arrowAlpha > 0)\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 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 (\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: LinkParticle[] = [];\n let prevParticle: LinkParticle | undefined;\n\n for (let i = 0; i < particleCount; i++) {\n const particle: LinkParticle = {\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 if (linkOptions.particleBorderWidth > 0) {\n this.context.stroke();\n }\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":";;;;;;;SAKgB,WAAW,GAAA;IAIzB,OAAO,SAAS,QAAQ,CAEtB,IAAuC,EAAA;QAEvC,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,C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C3C,YAAA,IAAI,CAAC,OAAO,CAAC,SAAS,GAAG,gBAAgB;AACzC,YAAA,IAAI,CAAC,OAAO,CAAC,SAAS,GAAG,UAAU;YACnC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,SAAS,EAAE,SAAS,CAAC;AACzC,YAAA,IAAI,CAAC,OAAO,CAAC,MAAM,CACjB,SAAS,GAAG,SAAS,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,GAAG,IAAI,CAAC,EAAE,GAAG,CAAC,CAAC,EACrD,SAAS,GAAG,SAAS,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,GAAG,IAAI,CAAC,EAAE,GAAG,CAAC,CAAC,CACtD;AACD,YAAA,IAAI,CAAC,OAAO,CAAC,MAAM,CACjB,SAAS,GAAG,SAAS,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,GAAG,IAAI,CAAC,EAAE,GAAG,CAAC,CAAC,EACrD,SAAS,GAAG,SAAS,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,GAAG,IAAI,CAAC,EAAE,GAAG,CAAC,CAAC,CACtD;AACD,YAAA,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE;AACxB,YAAA,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE;AACnB,YAAA,IAAI,gBAAgB,GAAG,CAAC,EAAE;AACxB,gBAAA,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE;;;AAIzB,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;;;;"}
@@ -36,6 +36,7 @@ function initPointer() {
36
36
  areaTransform: this.areaTransform,
37
37
  mouseEvent: event,
38
38
  links: this.links,
39
+ curve: this.linkSettings.curve,
39
40
  });
40
41
  if (currentLink?.highlight != undefined)
41
42
  highlightLink = currentLink?.highlight;
@@ -97,6 +98,7 @@ function initPointer() {
97
98
  areaTransform: this.areaTransform,
98
99
  mouseEvent: event,
99
100
  links: this.links,
101
+ curve: this.linkSettings.curve,
100
102
  });
101
103
  }
102
104
  if (!currentNode)
@@ -121,6 +123,7 @@ function initPointer() {
121
123
  areaTransform: this.areaTransform,
122
124
  mouseEvent: event,
123
125
  links: this.links,
126
+ curve: this.linkSettings.curve,
124
127
  });
125
128
  return void this.listeners.onWheelClick.call(this, event, undefined, currentLink);
126
129
  }
@@ -142,6 +145,7 @@ function initPointer() {
142
145
  areaTransform: this.areaTransform,
143
146
  mouseEvent: event,
144
147
  links: this.links,
148
+ curve: this.linkSettings.curve,
145
149
  });
146
150
  return void this.listeners.onContextMenu.call(this, event, undefined, currentLink);
147
151
  }
@@ -163,6 +167,7 @@ function initPointer() {
163
167
  areaTransform: this.areaTransform,
164
168
  mouseEvent: event,
165
169
  links: this.links,
170
+ curve: this.linkSettings.curve,
166
171
  });
167
172
  return void this.listeners.onDoubleClick.call(this, event, undefined, currentLink);
168
173
  }
@@ -184,6 +189,7 @@ function initPointer() {
184
189
  areaTransform: this.areaTransform,
185
190
  mouseEvent: event,
186
191
  links: this.links,
192
+ curve: this.linkSettings.curve,
187
193
  });
188
194
  return void this.listeners.onClick.call(this, event, undefined, currentLink);
189
195
  }
@@ -1 +1 @@
1
- {"version":3,"file":"init-pointer.js","sources":["../../../../../src/module/GraphCanvas/slices/init-pointer.ts"],"sourcesContent":["import { isObject } from \"lodash\";\nimport { checkType } from \"@/lib\";\nimport 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) 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 currentNode = nodeByPointerGetter({\n areaRect: this.areaRect,\n areaTransform: this.areaTransform,\n mouseEvent: event,\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 linkHoverExtraZone: this.highlightSettings.linkHoverExtraZone,\n areaRect: this.areaRect,\n areaTransform: this.areaTransform,\n mouseEvent: event,\n links: this.links,\n });\n if (currentLink?.highlight != undefined) highlightLink = currentLink?.highlight;\n\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 if (currentNode && highlightNode && this.highlightedNode !== currentNode) {\n this.highlightedNode = currentNode;\n this.highlightedLink = null;\n this.highlightedNeighbors = new Set(this.highlightedNode?.neighbors ?? []);\n this.highlightWorking = true;\n\n if (!this.simulationWorking)\n requestAnimationFrame(() => {\n this.draw();\n });\n } else if (\n currentLink &&\n highlightLink &&\n checkType<NodeInterface<NodeData>>(currentLink.source, isObject(currentLink.source)) &&\n checkType<NodeInterface<NodeData>>(currentLink.target, isObject(currentLink.target)) &&\n this.highlightedLink !== currentLink\n ) {\n this.highlightProgress = 0;\n this.highlightedLink = currentLink;\n this.highlightedNode = null;\n this.highlightedNeighbors = new Set([currentLink.source.id, currentLink.target.id]);\n this.highlightWorking = true;\n\n if (!this.simulationWorking)\n requestAnimationFrame(() => {\n this.draw();\n });\n } else if (!currentNode && !currentLink && (this.highlightedNode || this.highlightedLink)) {\n this.highlightWorking = false;\n if (!this.simulationWorking)\n requestAnimationFrame(() => {\n this.draw();\n });\n }\n\n if (!this.listeners.onMove) return;\n\n if (!currentNode && !checkHighlightNode)\n currentNode = nodeByPointerGetter({\n areaRect: this.areaRect,\n areaTransform: this.areaTransform,\n mouseEvent: event,\n nodes: this.nodes,\n });\n if (!currentNode && (!checkHighlightNode || (!checkHighlightLink && !currentLink))) {\n currentLink = linkByPointerGetter({\n linkHoverExtraZone: this.highlightSettings.linkHoverExtraZone,\n areaRect: this.areaRect,\n areaTransform: this.areaTransform,\n mouseEvent: event,\n links: this.links,\n });\n }\n\n if (!currentNode) return void this.listeners.onMove.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 currentNode = nodeByPointerGetter({\n areaRect: this.areaRect,\n areaTransform: this.areaTransform,\n mouseEvent: event,\n nodes: this.nodes,\n });\n\n if (!currentNode) {\n const currentLink = linkByPointerGetter({\n linkHoverExtraZone: this.highlightSettings.linkHoverExtraZone,\n areaRect: this.areaRect,\n areaTransform: this.areaTransform,\n mouseEvent: event,\n links: this.links,\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 currentNode = nodeByPointerGetter({\n areaRect: this.areaRect,\n areaTransform: this.areaTransform,\n mouseEvent: event,\n nodes: this.nodes,\n });\n\n if (!currentNode) {\n const currentLink = linkByPointerGetter({\n linkHoverExtraZone: this.highlightSettings.linkHoverExtraZone,\n areaRect: this.areaRect,\n areaTransform: this.areaTransform,\n mouseEvent: event,\n links: this.links,\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 currentNode = nodeByPointerGetter({\n areaRect: this.areaRect,\n areaTransform: this.areaTransform,\n mouseEvent: event,\n nodes: this.nodes,\n });\n if (!currentNode) {\n const currentLink = linkByPointerGetter({\n linkHoverExtraZone: this.highlightSettings.linkHoverExtraZone,\n areaRect: this.areaRect,\n areaTransform: this.areaTransform,\n mouseEvent: event,\n links: this.links,\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 currentNode = nodeByPointerGetter({\n areaRect: this.areaRect,\n areaTransform: this.areaTransform,\n mouseEvent: event,\n nodes: this.nodes,\n });\n if (!currentNode) {\n const currentLink = linkByPointerGetter({\n linkHoverExtraZone: this.highlightSettings.linkHoverExtraZone,\n areaRect: this.areaRect,\n areaTransform: this.areaTransform,\n mouseEvent: event,\n links: this.links,\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(\"cont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E,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;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 { isObject } from \"lodash\";\nimport { checkType } from \"@/lib\";\nimport 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) 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 currentNode = nodeByPointerGetter({\n areaRect: this.areaRect,\n areaTransform: this.areaTransform,\n mouseEvent: event,\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 linkHoverExtraZone: this.highlightSettings.linkHoverExtraZone,\n areaRect: this.areaRect,\n areaTransform: this.areaTransform,\n mouseEvent: event,\n links: this.links,\n curve: this.linkSettings.curve,\n });\n if (currentLink?.highlight != undefined) highlightLink = currentLink?.highlight;\n\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 if (currentNode && highlightNode && this.highlightedNode !== currentNode) {\n this.highlightedNode = currentNode;\n this.highlightedLink = null;\n this.highlightedNeighbors = new Set(this.highlightedNode?.neighbors ?? []);\n this.highlightWorking = true;\n\n if (!this.simulationWorking)\n requestAnimationFrame(() => {\n this.draw();\n });\n } else if (\n currentLink &&\n highlightLink &&\n checkType<NodeInterface<NodeData>>(currentLink.source, isObject(currentLink.source)) &&\n checkType<NodeInterface<NodeData>>(currentLink.target, isObject(currentLink.target)) &&\n this.highlightedLink !== currentLink\n ) {\n this.highlightProgress = 0;\n this.highlightedLink = currentLink;\n this.highlightedNode = null;\n this.highlightedNeighbors = new Set([currentLink.source.id, currentLink.target.id]);\n this.highlightWorking = true;\n\n if (!this.simulationWorking)\n requestAnimationFrame(() => {\n this.draw();\n });\n } else if (!currentNode && !currentLink && (this.highlightedNode || this.highlightedLink)) {\n this.highlightWorking = false;\n if (!this.simulationWorking)\n requestAnimationFrame(() => {\n this.draw();\n });\n }\n\n if (!this.listeners.onMove) return;\n\n if (!currentNode && !checkHighlightNode)\n currentNode = nodeByPointerGetter({\n areaRect: this.areaRect,\n areaTransform: this.areaTransform,\n mouseEvent: event,\n nodes: this.nodes,\n });\n if (!currentNode && (!checkHighlightNode || (!checkHighlightLink && !currentLink))) {\n currentLink = linkByPointerGetter({\n linkHoverExtraZone: this.highlightSettings.linkHoverExtraZone,\n areaRect: this.areaRect,\n areaTransform: this.areaTransform,\n mouseEvent: event,\n links: this.links,\n curve: this.linkSettings.curve,\n });\n }\n\n if (!currentNode) return void this.listeners.onMove.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 currentNode = nodeByPointerGetter({\n areaRect: this.areaRect,\n areaTransform: this.areaTransform,\n mouseEvent: event,\n nodes: this.nodes,\n });\n\n if (!currentNode) {\n const currentLink = linkByPointerGetter({\n linkHoverExtraZone: this.highlightSettings.linkHoverExtraZone,\n areaRect: this.areaRect,\n areaTransform: this.areaTransform,\n mouseEvent: event,\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 currentNode = nodeByPointerGetter({\n areaRect: this.areaRect,\n areaTransform: this.areaTransform,\n mouseEvent: event,\n nodes: this.nodes,\n });\n\n if (!currentNode) {\n const currentLink = linkByPointerGetter({\n linkHoverExtraZone: this.highlightSettings.linkHoverExtraZone,\n areaRect: this.areaRect,\n areaTransform: this.areaTransform,\n mouseEvent: event,\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 currentNode = nodeByPointerGetter({\n areaRect: this.areaRect,\n areaTransform: this.areaTransform,\n mouseEvent: event,\n nodes: this.nodes,\n });\n if (!currentNode) {\n const currentLink = linkByPointerGetter({\n linkHoverExtraZone: this.highlightSettings.linkHoverExtraZone,\n areaRect: this.areaRect,\n areaTransform: this.areaTransform,\n mouseEvent: event,\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 currentNode = nodeByPointerGetter({\n areaRect: this.areaRect,\n areaTransform: this.areaTransform,\n mouseEvent: event,\n nodes: this.nodes,\n });\n if (!currentNode) {\n const currentLink = linkByPointerGetter({\n linkHoverExtraZone: this.highlightSettings.linkHoverExtraZone,\n areaRect: this.areaRect,\n areaTransform: this.areaTransform,\n mouseEvent: event,\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":";;;;;;SAMgB,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;QACpF,IAAI,CAAC,IAAI,CAAC,IAAI;YAAE;AAEhB,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,kBAAkB,EAAE;YACtB,WAAW,GAAG,mBAAmB,CAAC;gBAChC,QAAQ,EAAE,IAAI,CAAC,QAAQ;gBACvB,aAAa,EAAE,IAAI,CAAC,aAAa;AACjC,gBAAA,UAAU,EAAE,KAAK;gBACjB,KAAK,EAAE,IAAI,CAAC,KAAK;AAClB,aAAA,CAAC;AACF,YAAA,IAAI,WAA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oB,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;;;;"}
@@ -13,12 +13,19 @@ function initResize() {
13
13
  return;
14
14
  }
15
15
  this.updateSize();
16
+ requestAnimationFrame(() => {
17
+ this.updateSize();
18
+ });
16
19
  });
17
20
  document.addEventListener("scroll", this.updateRect.bind(this), {
18
21
  capture: true,
19
22
  passive: true,
20
23
  signal: abortController.signal,
21
24
  });
25
+ document.addEventListener("visibilitychange", () => {
26
+ if (!document.hidden)
27
+ this.updateRect();
28
+ }, { signal: abortController.signal });
22
29
  observer.observe(this.area);
23
30
  }
24
31
 
@@ -1 +1 @@
1
- {"version":3,"file":"init-resize.js","sources":["../../../../../src/module/GraphCanvas/slices/init-resize.ts"],"sourcesContent":["import type { GraphCanvas } from \"../GraphCanvas\";\n\nexport function initResize<\n NodeData extends Record<string, unknown>,\n LinkData extends Record<string, unknown>,\n>(this: GraphCanvas<NodeData, LinkData>) {\n if (!this.area) throw new Error(\"bad init data\");\n\n let initialResizeCall = true;\n\n const abortController = this.eventAbortController;\n const observer = new ResizeObserver(() => {\n if (initialResizeCall) {\n initialResizeCall = false;\n\n return;\n }\n\n if (abortController.signal.aborted) {\n observer.disconnect();\n\n return;\n }\n\n this.updateSize();\n });\n\n document.addEventListener(\"scroll\", this.updateRect.bind(this), {\n capture: true,\n passive: true,\n signal: abortController.signal,\n });\n\n observer.observe(this.area);\n}\n"],"names":[],"mappings":"SAEgB,UAAU,GAAA;IAIxB,IAAI,CAAC,IAAI,CAAC,IAAI;AAAE,QAAA,MAAM,IAAI,KAAK,CAAC,eAAe,CAAC;IAEhD,IAAI,iBAAiB,GAAG,IAAI;AAE5B,IAAA,MAAM,eAAe,GAAG,IAAI,CAAC,oBAAoB;AACjD,IAAA,MAAM,QAAQ,GAAG,IAAI,cAAc,CAAC,MAAK;QACvC,IAAI,iBAAiB,EAAE;YACrB,iBAAiB,GAAG,KAAK;YAEzB;;AAGF,QAAA,IAAI,eAAe,CAAC,MAAM,CAAC,OAAO,EAAE;YAClC,QAAQ,CAAC,UAAU,EAAE;YAErB;;QAGF,IAAI,CAAC,UAAU,EAAE;AACnB,KAAC,CAAC;AAEF,IAAA,QAAQ,CAAC,gBAAgB,CAAC,QAAQ,EAAE,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;AAC9D,QAAA,OAAO,EAAE,IAAI;AACb,QAAA,OAAO,EAAE,IAAI;QACb,MAAM,EAAE,eAAe,CAAC,MAAM;AAC/B,KAAA,CAAC;AAEF,IAAA,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC;AAC7B;;;;"}
1
+ {"version":3,"file":"init-resize.js","sources":["../../../../../src/module/GraphCanvas/slices/init-resize.ts"],"sourcesContent":["import type { GraphCanvas } from \"../GraphCanvas\";\n\nexport function initResize<\n NodeData extends Record<string, unknown>,\n LinkData extends Record<string, unknown>,\n>(this: GraphCanvas<NodeData, LinkData>) {\n if (!this.area) throw new Error(\"bad init data\");\n\n let initialResizeCall = true;\n\n const abortController = this.eventAbortController;\n const observer = new ResizeObserver(() => {\n if (initialResizeCall) {\n initialResizeCall = false;\n\n return;\n }\n\n if (abortController.signal.aborted) {\n observer.disconnect();\n\n return;\n }\n\n this.updateSize();\n requestAnimationFrame(() => {\n this.updateSize();\n });\n });\n\n document.addEventListener(\"scroll\", this.updateRect.bind(this), {\n capture: true,\n passive: true,\n signal: abortController.signal,\n });\n\n document.addEventListener(\n \"visibilitychange\",\n () => {\n if (!document.hidden) this.updateRect();\n },\n { signal: abortController.signal },\n );\n\n observer.observe(this.area);\n}\n"],"names":[],"mappings":"SAEgB,UAAU,GAAA;IAIxB,IAAI,CAAC,IAAI,CAAC,IAAI;AAAE,QAAA,MAAM,IAAI,KAAK,CAAC,eAAe,CAAC;IAEhD,IAAI,iBAAiB,GAAG,IAAI;AAE5B,IAAA,MAAM,eAAe,GAAG,IAAI,CAAC,oBAAoB;AACjD,IAAA,MAAM,QAAQ,GAAG,IAAI,cAAc,CAAC,MAAK;QACvC,IAAI,iBAAiB,EAAE;YACrB,iBAAiB,GAAG,KAAK;YAEzB;;AAGF,QAAA,IAAI,eAAe,CAAC,MAAM,CAAC,OAAO,EAAE;YAClC,QAAQ,CAAC,UAAU,EAAE;YAErB;;QAGF,IAAI,CAAC,UAAU,EAAE;QACjB,qBAAqB,CAAC,MAAK;YACzB,IAAI,CAAC,UAAU,EAAE;AACnB,SAAC,CAAC;AACJ,KAAC,CAAC;AAEF,IAAA,QAAQ,CAAC,gBAAgB,CAAC,QAAQ,EAAE,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;AAC9D,QAAA,OAAO,EAAE,IAAI;AACb,QAAA,OAAO,EAAE,IAAI;QACb,MAAM,EAAE,eAAe,CAAC,MAAM;AAC/B,KAAA,CAAC;AAEF,IAAA,QAAQ,CAAC,gBAAgB,CACvB,kBAAkB,EAClB,MAAK;QACH,IAAI,CAAC,QAAQ,CAAC,MAAM;YAAE,IAAI,CAAC,UAAU,EAAE;KACxC,EACD,EAAE,MAAM,EAAE,eAAe,CAAC,MAAM,EAAE,CACnC;AAED,IAAA,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC;AAC7B;;;;"}
@@ -11,9 +11,12 @@ function initZoom(currentZoom) {
11
11
  .scaleExtent(this.graphSettings.zoomExtent)
12
12
  .on("zoom", (event) => {
13
13
  this.listeners.onZoom?.call?.(this, event);
14
+ const oldTransform = this.areaTransform;
14
15
  this.areaTransform = event.transform;
15
- updateLinkCache.call(this);
16
- updateNodeCache.call(this);
16
+ if (this.areaTransform.k !== oldTransform.k) {
17
+ updateLinkCache.call(this);
18
+ updateNodeCache.call(this, true);
19
+ }
17
20
  if (!this.simulationWorking && !this.highlightWorking)
18
21
  requestAnimationFrame(() => this.draw());
19
22
  });
@@ -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 type { ZoomEventInterface } from \"../types\";\nimport { updateLinkCache } from \"./update-link-cache\";\nimport { updateNodeCache } from \"./update-node-cache\";\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 zoomInstance = zoom<HTMLCanvasElement, unknown>()\n .scaleExtent(this.graphSettings.zoomExtent)\n .on(\"zoom\", (event: ZoomEventInterface) => {\n this.listeners.onZoom?.call?.(this, event);\n this.areaTransform = event.transform;\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 if (!this.simulationWorking && !this.highlightWorking)\n requestAnimationFrame(() => this.draw());\n });\n\n if (this.graphSettings.translateExtentEnable) {\n const coefficient = this.graphSettings.translateExtentCoefficient;\n const [coefficientX, coefficientY] = isArray(coefficient)\n ? coefficient\n : [coefficient, coefficient];\n\n const [\n [minX = -this.width * coefficientX, minY = -this.height * coefficientY],\n [maxX = this.width * coefficientX, maxY = this.height * coefficientY],\n ] = this.graphSettings.translateExtent;\n\n zoomInstance.translateExtent([\n [minX, minY],\n [maxX, maxY],\n ]);\n }\n\n d3Select(this.area).call(zoomInstance).on(\"dblclick.zoom\", null);\n\n const zoomInitial = currentZoom ?? this.graphSettings.zoomInitial;\n this.areaTransform = new ZoomTransform(\n zoomInitial?.k ?? 1,\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"],"names":["d3Select"],"mappings":";;;;;;AAQM,SAAU,QAAQ,CAGiB,WAA2B,EAAA;IAClE,IAAI,CAAC,IAAI,CAAC,IAAI;AAAE,QAAA,MAAM,IAAI,KAAK,CAAC,eAAe,CAAC;IAEhD,MAAM,YAAY,GAAG,IAAI;AACtB,SAAA,WAAW,CAAC,IAAI,CAAC,aAAa,CAAC,UAAU;AACzC,SAAA,EAAE,CAAC,MAAM,EAAE,CAAC,KAAyB,KAAI;AACxC,QAAA,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,GAAG,IAAI,EAAE,KAAK,CAAC;AAC1C,QAAA,IAAI,CAAC,aAAa,GAAG,KAAK,CAAC,SAAS;AACpC,QAAA,eAAe,CAAC,IAAI,CAIlB,IAAI,CAAC;AACP,QAAA,eAAe,CAAC,IAAI,CAIlB,IAAI,CAAC;QAEP,IAAI,CAAC,IAAI,CAAC,iBAAiB,IAAI,CAAC,IAAI,CAAC,gBAAgB;YACnD,qBAAqB,CAAC,MAAM,IAAI,CAAC,IAAI,EAAE,CAAC;AAC5C,KAAC,CAAC;AAEJ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"],"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 type { ZoomEventInterface } from \"../types\";\nimport { updateLinkCache } from \"./update-link-cache\";\nimport { updateNodeCache } from \"./update-node-cache\";\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 zoomInstance = zoom<HTMLCanvasElement, unknown>()\n .scaleExtent(this.graphSettings.zoomExtent)\n .on(\"zoom\", (event: ZoomEventInterface) => {\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, true);\n }\n\n if (!this.simulationWorking && !this.highlightWorking)\n requestAnimationFrame(() => this.draw());\n });\n\n if (this.graphSettings.translateExtentEnable) {\n const coefficient = this.graphSettings.translateExtentCoefficient;\n const [coefficientX, coefficientY] = isArray(coefficient)\n ? coefficient\n : [coefficient, coefficient];\n\n const [\n [minX = -this.width * coefficientX, minY = -this.height * coefficientY],\n [maxX = this.width * coefficientX, maxY = this.height * coefficientY],\n ] = this.graphSettings.translateExtent;\n\n zoomInstance.translateExtent([\n [minX, minY],\n [maxX, maxY],\n ]);\n }\n\n d3Select(this.area).call(zoomInstance).on(\"dblclick.zoom\", null);\n\n const zoomInitial = currentZoom ?? this.graphSettings.zoomInitial;\n this.areaTransform = new ZoomTransform(\n zoomInitial?.k ?? 1,\n zoomInitial?.x ?? this.width / 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AAC,IAAI,CAAC,MAAM,GAAG,YAAY,CAAC,EACvE,CAAC,IAAI,GAAG,IAAI,CAAC,KAAK,GAAG,YAAY,EAAE,IAAI,GAAG,IAAI,CAAC,MAAM,GAAG,YAAY,CAAC,EACtE,GAAG,IAAI,CAAC,aAAa,CAAC,eAAe;QAEtC,YAAY,CAAC,eAAe,CAAC;YAC3B,CAAC,IAAI,EAAE,IAAI,CAAC;YACZ,CAAC,IAAI,EAAE,IAAI,CAAC;AACb,SAAA,CAAC;;AAGJ,IAAAA,MAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,EAAE,CAAC,eAAe,EAAE,IAAI,CAAC;IAEhE,MAAM,WAAW,GAAG,WAAW,IAAI,IAAI,CAAC,aAAa,CAAC,WAAW;AACjE,IAAA,IAAI,CAAC,aAAa,GAAG,IAAI,aAAa,CACpC,WAAW,EAAE,CAAC,IAAI,CAAC,EACnB,WAAW,EAAE,CAAC,IAAI,IAAI,CAAC,KAAK,GAAG,CAAC,EAChC,WAAW,EAAE,CAAC,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC,CAClC;AACD,IAAA,IAAI,EAA8B,CAAC,SAAS,CAACA,MAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,IAAI,CAAC,aAAa,CAAC;AACvF;;;;"}
@@ -6,13 +6,43 @@ import { extractLinkPointIds } from '../lib/utils/extract-link-point-ids.js';
6
6
 
7
7
  function updateLinkCache() {
8
8
  this.linkOptionsCache = {};
9
+ const groupMap = {};
10
+ const groupSelfMap = {};
9
11
  for (let i = 0; i < this.links.length; i++) {
10
12
  const link = this.links[i];
11
13
  const { sourceId, targetId } = extractLinkPointIds(link);
12
14
  const linkOptions = linkIterationExtractor(link, i, this.links, this, this.linkSettings.options ?? {}, linkOptionsGetter);
13
15
  const id = `${targetId}${sourceId}`;
14
16
  this.linkOptionsCache[id] = linkOptions;
17
+ if (this.linkSettings.curve) {
18
+ if (sourceId === targetId) {
19
+ groupSelfMap[id] ??= 0;
20
+ link._groupIndex = ++groupSelfMap[id];
21
+ link._self = true;
22
+ continue;
23
+ }
24
+ const reverseId = `${sourceId}${targetId}`;
25
+ groupMap[reverseId] ??= 0;
26
+ groupMap[reverseId]++;
27
+ groupMap[id] ??= 0;
28
+ link._groupIndex = indexToPosition(++groupMap[id]);
29
+ link._self = false;
30
+ }
15
31
  }
32
+ if (this.linkSettings.curve) {
33
+ for (const link of this.links) {
34
+ const { sourceId, targetId } = extractLinkPointIds(link);
35
+ const id = `${targetId}${sourceId}`;
36
+ link._groupSize = link._self ? (groupSelfMap[id] ?? 1) : (groupMap[id] ?? 1);
37
+ }
38
+ }
39
+ }
40
+ function indexToPosition(n) {
41
+ if (n === 1)
42
+ return 0;
43
+ const index = n >> 1;
44
+ return n & 1 ? -(index * 2) : index * 2;
45
+ // return n & 1 ? -(n >> 1) : n >> 1;
16
46
  }
17
47
 
18
48
  export { updateLinkCache };