@krainovsd/graph 0.13.0-beta3 → 0.14.0-beta-7.2
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 +1044 -528
- package/lib/cjs/index.cjs.map +1 -1
- package/lib/esm/constants/force-controls.js +4 -2
- package/lib/esm/constants/force-controls.js.map +1 -1
- package/lib/esm/constants/highlight-controls.js +9 -16
- package/lib/esm/constants/highlight-controls.js.map +1 -1
- package/lib/esm/constants/link-controls.js +17 -30
- package/lib/esm/constants/link-controls.js.map +1 -1
- package/lib/esm/constants/node-controls.js +4 -2
- package/lib/esm/constants/node-controls.js.map +1 -1
- package/lib/esm/index.js +8 -7
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/module/GraphCanvas/GraphCanvas.js +303 -78
- package/lib/esm/module/GraphCanvas/GraphCanvas.js.map +1 -1
- package/lib/esm/module/GraphCanvas/constants/force-settings.js +11 -1
- package/lib/esm/module/GraphCanvas/constants/force-settings.js.map +1 -1
- package/lib/esm/module/GraphCanvas/constants/graph-settings.js +17 -5
- package/lib/esm/module/GraphCanvas/constants/graph-settings.js.map +1 -1
- package/lib/esm/module/GraphCanvas/constants/highlight-settings.js +5 -3
- package/lib/esm/module/GraphCanvas/constants/highlight-settings.js.map +1 -1
- package/lib/esm/module/GraphCanvas/constants/index.js +5 -2
- package/lib/esm/module/GraphCanvas/constants/index.js.map +1 -1
- package/lib/esm/module/GraphCanvas/constants/link-settings.js +19 -10
- package/lib/esm/module/GraphCanvas/constants/link-settings.js.map +1 -1
- package/lib/esm/module/GraphCanvas/constants/node-settings.js +13 -3
- package/lib/esm/module/GraphCanvas/constants/node-settings.js.map +1 -1
- package/lib/esm/module/GraphCanvas/lib/settings/force-settings-getter.js +4 -2
- package/lib/esm/module/GraphCanvas/lib/settings/force-settings-getter.js.map +1 -1
- package/lib/esm/module/GraphCanvas/lib/settings/graph-settings-getter.js +4 -0
- package/lib/esm/module/GraphCanvas/lib/settings/graph-settings-getter.js.map +1 -1
- package/lib/esm/module/GraphCanvas/lib/settings/highlight-settings-getter.js +4 -2
- package/lib/esm/module/GraphCanvas/lib/settings/highlight-settings-getter.js.map +1 -1
- package/lib/esm/module/GraphCanvas/lib/settings/link-settings-getter.js +8 -5
- package/lib/esm/module/GraphCanvas/lib/settings/link-settings-getter.js.map +1 -1
- package/lib/esm/module/GraphCanvas/lib/settings/node-settings-getter.js +14 -2
- package/lib/esm/module/GraphCanvas/lib/settings/node-settings-getter.js.map +1 -1
- package/lib/esm/module/GraphCanvas/lib/utils/calculate-curve-link-position-by-node.js +5 -2
- package/lib/esm/module/GraphCanvas/lib/utils/calculate-curve-link-position-by-node.js.map +1 -1
- package/lib/esm/module/GraphCanvas/lib/utils/calculate-link-position-by-node.js +5 -2
- package/lib/esm/module/GraphCanvas/lib/utils/calculate-link-position-by-node.js.map +1 -1
- package/lib/esm/module/GraphCanvas/lib/utils/compute-graph-bounds.js +26 -0
- package/lib/esm/module/GraphCanvas/lib/utils/compute-graph-bounds.js.map +1 -0
- package/lib/esm/module/GraphCanvas/lib/utils/get-particle-position.js +40 -30
- package/lib/esm/module/GraphCanvas/lib/utils/get-particle-position.js.map +1 -1
- package/lib/esm/module/GraphCanvas/lib/utils/is-empty-object.js +11 -0
- package/lib/esm/module/GraphCanvas/lib/utils/is-empty-object.js.map +1 -0
- package/lib/esm/module/GraphCanvas/lib/utils/is-node-visible.js +5 -2
- package/lib/esm/module/GraphCanvas/lib/utils/is-node-visible.js.map +1 -1
- package/lib/esm/module/GraphCanvas/lib/utils/link-by-pointer-getter.js +1 -5
- package/lib/esm/module/GraphCanvas/lib/utils/link-by-pointer-getter.js.map +1 -1
- package/lib/esm/module/GraphCanvas/lib/utils/node-by-pointer-getter.js +1 -5
- 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 +16 -8
- package/lib/esm/module/GraphCanvas/lib/utils/pointer-getter.js.map +1 -1
- package/lib/esm/module/GraphCanvas/slices/draw-links.js +47 -62
- package/lib/esm/module/GraphCanvas/slices/draw-links.js.map +1 -1
- package/lib/esm/module/GraphCanvas/slices/draw-nodes.js +9 -4
- package/lib/esm/module/GraphCanvas/slices/draw-nodes.js.map +1 -1
- package/lib/esm/module/GraphCanvas/slices/init-area.js +1 -1
- package/lib/esm/module/GraphCanvas/slices/init-area.js.map +1 -1
- package/lib/esm/module/GraphCanvas/slices/init-dnd.js +20 -13
- package/lib/esm/module/GraphCanvas/slices/init-dnd.js.map +1 -1
- package/lib/esm/module/GraphCanvas/slices/init-draw.js +14 -52
- package/lib/esm/module/GraphCanvas/slices/init-draw.js.map +1 -1
- package/lib/esm/module/GraphCanvas/slices/init-pointer.js +45 -72
- package/lib/esm/module/GraphCanvas/slices/init-pointer.js.map +1 -1
- package/lib/esm/module/GraphCanvas/slices/init-resize.js +14 -2
- package/lib/esm/module/GraphCanvas/slices/init-resize.js.map +1 -1
- package/lib/esm/module/GraphCanvas/slices/init-selection.js +152 -0
- package/lib/esm/module/GraphCanvas/slices/init-selection.js.map +1 -0
- package/lib/esm/module/GraphCanvas/slices/init-simulation.js +12 -2
- package/lib/esm/module/GraphCanvas/slices/init-simulation.js.map +1 -1
- package/lib/esm/module/GraphCanvas/slices/init-zoom.js +88 -16
- package/lib/esm/module/GraphCanvas/slices/init-zoom.js.map +1 -1
- package/lib/esm/module/GraphCanvas/slices/update-link-cache.js +33 -3
- package/lib/esm/module/GraphCanvas/slices/update-link-cache.js.map +1 -1
- package/lib/esm/module/GraphCanvas/slices/update-node-cache.js +61 -16
- package/lib/esm/module/GraphCanvas/slices/update-node-cache.js.map +1 -1
- package/lib/index.d.ts +106 -56
- package/package.json +3 -2
|
@@ -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 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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AAE,IAAI,CAAC,oBAAoB,CAAC,MAAM;AACzC,KAAA,CAAC;;AAGF,IAAA,IAAI,CAAC,IAAI,CAAC,gBAAgB,CAAC,WAAW,EAAE,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;AAC/D,QAAA,MAAM,EAAE,IAAI,CAAC,oBAAoB,CAAC,MAAM;AACzC,KAAA,CAAC;;AAGF,IAAA,IAAI,CAAC,IAAI,CAAC,gBAAgB,CAAC,OAAO,EAAE,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;AACtD,QAAA,MAAM,EAAE,IAAI,CAAC,oBAAoB,CAAC,MAAM;AACzC,KAAA,CAAC;;AAGF,IAAA,IAAI,CAAC,IAAI,CAAC,gBAAgB,CAAC,aAAa,EAAE,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;AACjE,QAAA,MAAM,EAAE,IAAI,CAAC,oBAAoB,CAAC,MAAM;AACzC,KAAA,CAAC;AACJ;;;;"}
|
|
1
|
+
{"version":3,"file":"init-pointer.js","sources":["../../../../../src/module/GraphCanvas/slices/init-pointer.ts"],"sourcesContent":["import type { GraphCanvas } from \"../GraphCanvas\";\nimport { linkByPointerGetter, nodeByPointerGetter } from \"../lib\";\nimport type { LinkInterface, NodeInterface } from \"../types\";\n\nexport function initPointer<\n NodeData extends Record<string, unknown>,\n LinkData extends Record<string, unknown>,\n>(this: GraphCanvas<NodeData, LinkData>) {\n if (!this.area || !this.nodes) throw new Error(\"bad init data\");\n\n function onHover(this: GraphCanvas<NodeData, LinkData>, event: MouseEvent | TouchEvent) {\n if (!this.area || this.isSelecting) return;\n\n let currentNode: NodeInterface<NodeData> | undefined;\n let currentLink: LinkInterface<NodeData, LinkData> | undefined;\n const checkHighlightNode = this.highlightSettings.highlightByHoverNode && !this.isDragging;\n const checkHighlightLink = this.highlightSettings.highlightByHoverLink && !this.isDragging;\n let highlightNode = true;\n let highlightLink = true;\n\n if (checkHighlightNode) {\n const [pointerX, pointerY] = this.getPointerAreaPosition(event);\n currentNode = nodeByPointerGetter({\n pointerX,\n pointerY,\n nodes: this.nodes,\n });\n if (currentNode?.highlight != undefined) highlightNode = currentNode.highlight;\n }\n if (currentNode && highlightNode) {\n this.area.style.cursor = \"pointer\";\n } else if (checkHighlightLink) {\n const [pointerX, pointerY] = this.getPointerAreaPosition(event);\n currentLink = linkByPointerGetter({\n pointerX,\n pointerY,\n linkHoverExtraZone: this.highlightSettings.linkHoverExtraZone,\n links: this.links,\n curve: this.linkSettings.curve,\n });\n if (currentLink?.highlight != undefined) highlightLink = currentLink?.highlight;\n if (currentLink && highlightLink) {\n this.area.style.cursor = \"pointer\";\n } else {\n this.area.style.cursor = \"default\";\n }\n } else {\n this.area.style.cursor = \"default\";\n }\n this.animateHighlight(\n highlightNode ? currentNode : undefined,\n highlightLink ? currentLink : undefined,\n );\n\n if (!this.listeners.onMove) return;\n if (!currentNode && !checkHighlightNode) {\n const [pointerX, pointerY] = this.getPointerAreaPosition(event);\n currentNode = nodeByPointerGetter({\n pointerX,\n pointerY,\n nodes: this.nodes,\n });\n }\n if (!currentNode && (!checkHighlightNode || (!checkHighlightLink && !currentLink))) {\n const [pointerX, pointerY] = this.getPointerAreaPosition(event);\n currentLink = linkByPointerGetter({\n pointerX,\n pointerY,\n linkHoverExtraZone: this.highlightSettings.linkHoverExtraZone,\n links: this.links,\n curve: this.linkSettings.curve,\n });\n }\n 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 [pointerX, pointerY] = this.getPointerAreaPosition(event);\n const currentNode = nodeByPointerGetter({\n pointerX,\n pointerY,\n nodes: this.nodes,\n });\n\n if (!currentNode) {\n const [pointerX, pointerY] = this.getPointerAreaPosition(event);\n const currentLink = linkByPointerGetter({\n pointerX,\n pointerY,\n linkHoverExtraZone: this.highlightSettings.linkHoverExtraZone,\n links: this.links,\n curve: this.linkSettings.curve,\n });\n\n return void this.listeners.onWheelClick.call(this, event, undefined, currentLink);\n }\n\n return void this.listeners.onWheelClick.call(this, event, currentNode, undefined);\n }\n function onRightClick(this: GraphCanvas<NodeData, LinkData>, event: MouseEvent) {\n if (!this.listeners.onContextMenu) return;\n\n const [pointerX, pointerY] = this.getPointerAreaPosition(event);\n const currentNode = nodeByPointerGetter({\n pointerX,\n pointerY,\n nodes: this.nodes,\n });\n\n if (!currentNode) {\n const [pointerX, pointerY] = this.getPointerAreaPosition(event);\n const currentLink = linkByPointerGetter({\n pointerX,\n pointerY,\n linkHoverExtraZone: this.highlightSettings.linkHoverExtraZone,\n links: this.links,\n curve: this.linkSettings.curve,\n });\n\n return void this.listeners.onContextMenu.call(this, event, undefined, currentLink);\n }\n\n return void this.listeners.onContextMenu.call(this, event, currentNode, undefined);\n }\n function onDoubleClick(this: GraphCanvas<NodeData, LinkData>, event: MouseEvent | TouchEvent) {\n if (!this.listeners.onDoubleClick) return;\n\n const [pointerX, pointerY] = this.getPointerAreaPosition(event);\n const currentNode = nodeByPointerGetter({\n pointerX,\n pointerY,\n nodes: this.nodes,\n });\n if (!currentNode) {\n const [pointerX, pointerY] = this.getPointerAreaPosition(event);\n const currentLink = linkByPointerGetter({\n pointerX,\n pointerY,\n linkHoverExtraZone: this.highlightSettings.linkHoverExtraZone,\n links: this.links,\n curve: this.linkSettings.curve,\n });\n\n return void this.listeners.onDoubleClick.call(this, event, undefined, currentLink);\n }\n\n return void this.listeners.onDoubleClick.call(this, event, currentNode, undefined);\n }\n function onClick(this: GraphCanvas<NodeData, LinkData>, event: MouseEvent | TouchEvent) {\n if (this.isDragging || !this.listeners.onClick || (\"button\" in event && event.button !== 0))\n return;\n const [pointerX, pointerY] = this.getPointerAreaPosition(event);\n const currentNode = nodeByPointerGetter({\n pointerX,\n pointerY,\n nodes: this.nodes,\n });\n if (!currentNode) {\n const [pointerX, pointerY] = this.getPointerAreaPosition(event);\n const currentLink = linkByPointerGetter({\n pointerX,\n pointerY,\n linkHoverExtraZone: this.highlightSettings.linkHoverExtraZone,\n links: this.links,\n curve: this.linkSettings.curve,\n });\n\n return void this.listeners.onClick.call(this, event, undefined, currentLink);\n }\n\n return void this.listeners.onClick.call(this, event, currentNode, undefined);\n }\n\n /** hover */\n this.area.addEventListener(\"mousemove\", onHover.bind(this), {\n signal: this.eventAbortController.signal,\n });\n this.area.addEventListener(\"touchmove\", onHover.bind(this), {\n signal: this.eventAbortController.signal,\n });\n\n /** dblclick */\n this.area.addEventListener(\"dblclick\", onDoubleClick.bind(this), {\n signal: this.eventAbortController.signal,\n });\n\n /** wheel click */\n this.area.addEventListener(\"mousedown\", onWheelClick.bind(this), {\n signal: this.eventAbortController.signal,\n });\n\n /** click */\n this.area.addEventListener(\"click\", onClick.bind(this), {\n signal: this.eventAbortController.signal,\n });\n\n /** right click */\n this.area.addEventListener(\"contextmenu\", onRightClick.bind(this), {\n signal: this.eventAbortController.signal,\n });\n}\n"],"names":[],"mappings":";;;;;;;;;SAIgB,WAAW,GAAA;IAIzB,IAAI,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,KAAK;AAAE,QAAA,MAAM,IAAI,KAAK,CAAC,eAAe,CAAC;IAE/D,SAAS,OAAO,CAAwC,KAA8B,EAAA;AACpF,QAAA,IAAI,CAAC,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,WAAW;YAAE;AAEpC,QAAA,IAAI,WAAgD;AACpD,QAAA,IAAI,WAA0D;AAC9D,QAAA,MAAM,kBAAkB,GAAG,IAAI,CAAC,iBAAiB,CAAC,oBAAoB,IAAI,CAAC,IAAI,CAAC,UAAU;AAC1F,QAAA,MAAM,kBAAkB,GAAG,IAAI,CAAC,iBAAiB,CAAC,oBAAoB,IAAI,CAAC,IAAI,CAAC,UAAU;QAC1F,IAAI,aAAa,GAAG,IAAI;QACxB,IAAI,aAAa,GAA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D,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;;;;"}
|
|
@@ -23,8 +23,20 @@ function initResize() {
|
|
|
23
23
|
signal: abortController.signal,
|
|
24
24
|
});
|
|
25
25
|
document.addEventListener("visibilitychange", () => {
|
|
26
|
-
if (
|
|
27
|
-
this.
|
|
26
|
+
if (document.hidden) {
|
|
27
|
+
this.highlightController?.abort();
|
|
28
|
+
this.highlightedNode = null;
|
|
29
|
+
this.highlightedLink = null;
|
|
30
|
+
this.highlightedNeighbors = null;
|
|
31
|
+
this.highlightProgress = 0;
|
|
32
|
+
this.highlightStart = null;
|
|
33
|
+
this.highlightPositive = false;
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
this.updateSize();
|
|
37
|
+
requestAnimationFrame(() => {
|
|
38
|
+
this.updateSize();
|
|
39
|
+
});
|
|
28
40
|
}, { signal: abortController.signal });
|
|
29
41
|
observer.observe(this.area);
|
|
30
42
|
}
|
|
@@ -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 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 (
|
|
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) {\n this.highlightController?.abort();\n this.highlightedNode = null;\n this.highlightedLink = null;\n this.highlightedNeighbors = null;\n this.highlightProgress = 0;\n this.highlightStart = null;\n this.highlightPositive = false;\n return;\n }\n this.updateSize();\n requestAnimationFrame(() => {\n this.updateSize();\n });\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;AACH,QAAA,IAAI,QAAQ,CAAC,MAAM,EAAE;AACnB,YAAA,IAAI,CAAC,mBAAmB,EAAE,KAAK,EAAE;AACjC,YAAA,IAAI,CAAC,eAAe,GAAG,IAAI;AAC3B,YAAA,IAAI,CAAC,eAAe,GAAG,IAAI;AAC3B,YAAA,IAAI,CAAC,oBAAoB,GAAG,IAAI;AAChC,YAAA,IAAI,CAAC,iBAAiB,GAAG,CAAC;AAC1B,YAAA,IAAI,CAAC,cAAc,GAAG,IAAI;AAC1B,YAAA,IAAI,CAAC,iBAAiB,GAAG,KAAK;YAC9B;;QAEF,IAAI,CAAC,UAAU,EAAE;QACjB,qBAAqB,CAAC,MAAK;YACzB,IAAI,CAAC,UAAU,EAAE;AACnB,SAAC,CAAC;KACH,EACD,EAAE,MAAM,EAAE,eAAe,CAAC,MAAM,EAAE,CACnC;AAED,IAAA,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC;AAC7B;;;;"}
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
function initSelection() {
|
|
2
|
+
if (!this.area)
|
|
3
|
+
throw new Error("bad init data");
|
|
4
|
+
this.isSelecting = false;
|
|
5
|
+
this.selectionRect = null;
|
|
6
|
+
let selectedNodesSet = new Set();
|
|
7
|
+
let selectedLinksSet = new Set();
|
|
8
|
+
let localSelection = false;
|
|
9
|
+
function onMouseDown(event) {
|
|
10
|
+
if (event.button !== 0 || !event.shiftKey)
|
|
11
|
+
return;
|
|
12
|
+
if (!this.area)
|
|
13
|
+
return;
|
|
14
|
+
event.stopPropagation();
|
|
15
|
+
event.preventDefault();
|
|
16
|
+
const [startX, startY] = this.getPointerAreaPosition(event);
|
|
17
|
+
this.isSelecting = true;
|
|
18
|
+
localSelection = true;
|
|
19
|
+
this.selectionRect = { x1: startX, y1: startY, x2: startX, y2: startY };
|
|
20
|
+
selectedNodesSet = new Set();
|
|
21
|
+
selectedLinksSet = new Set();
|
|
22
|
+
const controller = new AbortController();
|
|
23
|
+
this.area.addEventListener("mousemove", onMouseMove.bind(this), {
|
|
24
|
+
signal: controller.signal,
|
|
25
|
+
});
|
|
26
|
+
this.area.addEventListener("mouseup", () => {
|
|
27
|
+
onMouseUp.call(this, controller);
|
|
28
|
+
}, {
|
|
29
|
+
signal: controller.signal,
|
|
30
|
+
});
|
|
31
|
+
window.addEventListener("keyup", (event) => {
|
|
32
|
+
if (event.key === "Shift") {
|
|
33
|
+
onMouseUp.call(this, controller);
|
|
34
|
+
}
|
|
35
|
+
}, { signal: controller.signal });
|
|
36
|
+
}
|
|
37
|
+
function onMouseMove(event) {
|
|
38
|
+
if (!this.isSelecting || !this.selectionRect)
|
|
39
|
+
return;
|
|
40
|
+
event.stopPropagation();
|
|
41
|
+
const [x, y] = this.getPointerAreaPosition(event);
|
|
42
|
+
this.selectionRect.x2 = x;
|
|
43
|
+
this.selectionRect.y2 = y;
|
|
44
|
+
const rect = normalizeRect(this.selectionRect);
|
|
45
|
+
const newNodes = new Set();
|
|
46
|
+
for (let i = 0; i < this.nodes.length; i++) {
|
|
47
|
+
const node = this.nodes[i];
|
|
48
|
+
if (node.x == undefined || node.y == undefined)
|
|
49
|
+
continue;
|
|
50
|
+
if (node.visible === false)
|
|
51
|
+
continue;
|
|
52
|
+
const cache = this.nodeOptionsCache[i];
|
|
53
|
+
if (isNodeInRect(node, rect, cache)) {
|
|
54
|
+
newNodes.add(node);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
const newLinks = new Set();
|
|
58
|
+
for (const link of this.links) {
|
|
59
|
+
const source = link.source;
|
|
60
|
+
const target = link.target;
|
|
61
|
+
if (newNodes.has(source) && newNodes.has(target)) {
|
|
62
|
+
newLinks.add(link);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
for (const node of selectedNodesSet) {
|
|
66
|
+
if (!newNodes.has(node)) {
|
|
67
|
+
node._selected = false;
|
|
68
|
+
this.listeners.onSelectionOut?.call(this, node, undefined);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
for (const link of selectedLinksSet) {
|
|
72
|
+
if (!newLinks.has(link)) {
|
|
73
|
+
link._selected = false;
|
|
74
|
+
this.listeners.onSelectionOut?.call(this, undefined, link);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
for (const node of newNodes) {
|
|
78
|
+
if (!selectedNodesSet.has(node)) {
|
|
79
|
+
node._selected = true;
|
|
80
|
+
this.listeners.onSelectionIn?.call(this, node, undefined);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
for (const link of newLinks) {
|
|
84
|
+
if (!selectedLinksSet.has(link)) {
|
|
85
|
+
link._selected = true;
|
|
86
|
+
this.listeners.onSelectionIn?.call(this, undefined, link);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
selectedNodesSet = newNodes;
|
|
90
|
+
selectedLinksSet = newLinks;
|
|
91
|
+
this.draw();
|
|
92
|
+
}
|
|
93
|
+
function onMouseUp(controller) {
|
|
94
|
+
controller.abort();
|
|
95
|
+
if (!this.isSelecting)
|
|
96
|
+
return;
|
|
97
|
+
const nodes = Array.from(selectedNodesSet);
|
|
98
|
+
const links = Array.from(selectedLinksSet);
|
|
99
|
+
for (const node of nodes) {
|
|
100
|
+
node._selected = false;
|
|
101
|
+
}
|
|
102
|
+
for (const link of links) {
|
|
103
|
+
link._selected = false;
|
|
104
|
+
}
|
|
105
|
+
this.isSelecting = false;
|
|
106
|
+
this.selectionRect = null;
|
|
107
|
+
selectedNodesSet = new Set();
|
|
108
|
+
selectedLinksSet = new Set();
|
|
109
|
+
this.listeners.onSelectionEnd?.call(this, nodes, links);
|
|
110
|
+
this.tick();
|
|
111
|
+
}
|
|
112
|
+
function onSelectionEnd(event) {
|
|
113
|
+
if (localSelection) {
|
|
114
|
+
event.stopImmediatePropagation();
|
|
115
|
+
localSelection = false;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
this.area.addEventListener("mousedown", onMouseDown.bind(this), {
|
|
119
|
+
signal: this.eventAbortController.signal,
|
|
120
|
+
});
|
|
121
|
+
this.area.addEventListener("click", onSelectionEnd, { signal: this.eventAbortController.signal });
|
|
122
|
+
}
|
|
123
|
+
function normalizeRect(rect) {
|
|
124
|
+
const x = Math.min(rect.x1, rect.x2);
|
|
125
|
+
const y = Math.min(rect.y1, rect.y2);
|
|
126
|
+
const width = Math.abs(rect.x2 - rect.x1);
|
|
127
|
+
const height = Math.abs(rect.y2 - rect.y1);
|
|
128
|
+
return { x, y, width, height };
|
|
129
|
+
}
|
|
130
|
+
function isNodeInRect(node, rect, cache) {
|
|
131
|
+
const nx = node.x;
|
|
132
|
+
const ny = node.y;
|
|
133
|
+
if (nx == undefined || ny == undefined)
|
|
134
|
+
return false;
|
|
135
|
+
if (cache?.shape === "circle") {
|
|
136
|
+
const r = cache.radius ?? 0;
|
|
137
|
+
const closestX = Math.max(rect.x, Math.min(nx, rect.x + rect.width));
|
|
138
|
+
const closestY = Math.max(rect.y, Math.min(ny, rect.y + rect.height));
|
|
139
|
+
const dx = nx - closestX;
|
|
140
|
+
const dy = ny - closestY;
|
|
141
|
+
return dx * dx + dy * dy <= r * r;
|
|
142
|
+
}
|
|
143
|
+
const hw = (cache?.width ?? 0) / 2;
|
|
144
|
+
const hh = (cache?.height ?? 0) / 2;
|
|
145
|
+
return (nx - hw >= rect.x &&
|
|
146
|
+
nx + hw <= rect.x + rect.width &&
|
|
147
|
+
ny - hh >= rect.y &&
|
|
148
|
+
ny + hh <= rect.y + rect.height);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
export { initSelection };
|
|
152
|
+
//# sourceMappingURL=init-selection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"init-selection.js","sources":["../../../../../src/module/GraphCanvas/slices/init-selection.ts"],"sourcesContent":["import type { GraphCanvas } from \"../GraphCanvas\";\nimport type { LinkInterface, NodeInterface, NodeOptionsInterface } from \"../types\";\n\nexport function initSelection<\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 this.isSelecting = false;\n this.selectionRect = null;\n let selectedNodesSet = new Set<NodeInterface<NodeData>>();\n let selectedLinksSet = new Set<LinkInterface<NodeData, LinkData>>();\n let localSelection = false;\n\n function onMouseDown(this: GraphCanvas<NodeData, LinkData>, event: MouseEvent) {\n if (event.button !== 0 || !event.shiftKey) return;\n if (!this.area) return;\n event.stopPropagation();\n event.preventDefault();\n\n const [startX, startY] = this.getPointerAreaPosition(event);\n this.isSelecting = true;\n localSelection = true;\n this.selectionRect = { x1: startX, y1: startY, x2: startX, y2: startY };\n selectedNodesSet = new Set<NodeInterface<NodeData>>();\n selectedLinksSet = new Set<LinkInterface<NodeData, LinkData>>();\n const controller = new AbortController();\n this.area.addEventListener(\"mousemove\", onMouseMove.bind(this), {\n signal: controller.signal,\n });\n this.area.addEventListener(\n \"mouseup\",\n () => {\n onMouseUp.call(this, controller);\n },\n {\n signal: controller.signal,\n },\n );\n window.addEventListener(\n \"keyup\",\n (event) => {\n if (event.key === \"Shift\") {\n onMouseUp.call(this, controller);\n }\n },\n { signal: controller.signal },\n );\n }\n\n function onMouseMove(this: GraphCanvas<NodeData, LinkData>, event: MouseEvent) {\n if (!this.isSelecting || !this.selectionRect) return;\n event.stopPropagation();\n const [x, y] = this.getPointerAreaPosition(event);\n this.selectionRect.x2 = x;\n this.selectionRect.y2 = y;\n const rect = normalizeRect(this.selectionRect);\n const newNodes = new Set<NodeInterface<NodeData>>();\n for (let i = 0; i < this.nodes.length; i++) {\n const node = this.nodes[i];\n if (node.x == undefined || node.y == undefined) continue;\n if (node.visible === false) continue;\n const cache = this.nodeOptionsCache[i];\n if (isNodeInRect(node, rect, cache)) {\n newNodes.add(node);\n }\n }\n const newLinks = new Set<LinkInterface<NodeData, LinkData>>();\n for (const link of this.links) {\n const source = link.source as NodeInterface<NodeData>;\n const target = link.target as NodeInterface<NodeData>;\n if (newNodes.has(source) && newNodes.has(target)) {\n newLinks.add(link);\n }\n }\n for (const node of selectedNodesSet) {\n if (!newNodes.has(node)) {\n node._selected = false;\n this.listeners.onSelectionOut?.call(this, node, undefined);\n }\n }\n for (const link of selectedLinksSet) {\n if (!newLinks.has(link)) {\n link._selected = false;\n this.listeners.onSelectionOut?.call(this, undefined, link);\n }\n }\n for (const node of newNodes) {\n if (!selectedNodesSet.has(node)) {\n node._selected = true;\n this.listeners.onSelectionIn?.call(this, node, undefined);\n }\n }\n for (const link of newLinks) {\n if (!selectedLinksSet.has(link)) {\n link._selected = true;\n this.listeners.onSelectionIn?.call(this, undefined, link);\n }\n }\n selectedNodesSet = newNodes;\n selectedLinksSet = newLinks;\n this.draw();\n }\n\n function onMouseUp(this: GraphCanvas<NodeData, LinkData>, controller: AbortController) {\n controller.abort();\n if (!this.isSelecting) return;\n const nodes = Array.from(selectedNodesSet);\n const links = Array.from(selectedLinksSet);\n for (const node of nodes) {\n node._selected = false;\n }\n for (const link of links) {\n link._selected = false;\n }\n this.isSelecting = false;\n this.selectionRect = null;\n selectedNodesSet = new Set<NodeInterface<NodeData>>();\n selectedLinksSet = new Set<LinkInterface<NodeData, LinkData>>();\n this.listeners.onSelectionEnd?.call(this, nodes, links);\n this.tick();\n }\n\n function onSelectionEnd(event: MouseEvent) {\n if (localSelection) {\n event.stopImmediatePropagation();\n localSelection = false;\n }\n }\n\n this.area.addEventListener(\"mousedown\", onMouseDown.bind(this), {\n signal: this.eventAbortController.signal,\n });\n this.area.addEventListener(\"click\", onSelectionEnd, { signal: this.eventAbortController.signal });\n}\n\nfunction normalizeRect(rect: { x1: number; y1: number; x2: number; y2: number }): {\n x: number;\n y: number;\n width: number;\n height: number;\n} {\n const x = Math.min(rect.x1, rect.x2);\n const y = Math.min(rect.y1, rect.y2);\n const width = Math.abs(rect.x2 - rect.x1);\n const height = Math.abs(rect.y2 - rect.y1);\n return { x, y, width, height };\n}\n\nfunction isNodeInRect<\n NodeData extends Record<string, unknown>,\n LinkData extends Record<string, unknown>,\n>(\n node: NodeInterface<NodeData>,\n rect: { x: number; y: number; width: number; height: number },\n cache: Required<NodeOptionsInterface<NodeData, LinkData>> | undefined,\n): boolean {\n const nx = node.x;\n const ny = node.y;\n if (nx == undefined || ny == undefined) return false;\n if (cache?.shape === \"circle\") {\n const r = cache.radius ?? 0;\n const closestX = Math.max(rect.x, Math.min(nx, rect.x + rect.width));\n const closestY = Math.max(rect.y, Math.min(ny, rect.y + rect.height));\n const dx = nx - closestX;\n const dy = ny - closestY;\n return dx * dx + dy * dy <= r * r;\n }\n const hw = (cache?.width ?? 0) / 2;\n const hh = (cache?.height ?? 0) / 2;\n return (\n nx - hw >= rect.x &&\n nx + hw <= rect.x + rect.width &&\n ny - hh >= rect.y &&\n ny + hh <= rect.y + rect.height\n );\n}\n"],"names":[],"mappings":"SAGgB,aAAa,GAAA;IAI3B,IAAI,CAAC,IAAI,CAAC,IAAI;AAAE,QAAA,MAAM,IAAI,KAAK,CAAC,eAAe,CAAC;AAEhD,IAAA,IAAI,CAAC,WAAW,GAAG,KAAK;AACxB,IAAA,IAAI,CAAC,aAAa,GAAG,IAAI;AACzB,IAAA,IAAI,gBAAgB,GAAG,IAAI,GAAG,EAA2B;AACzD,IAAA,IAAI,gBAAgB,GAAG,IAAI,GAAG,EAAqC;IACnE,IAAI,cAAc,GAAG,KAAK;IAE1B,SAAS,WAAW,CAAwC,KAAiB,EAAA;QAC3E,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ;YAAE;QAC3C,IAAI,CAAC,IAAI,CAAC,IAAI;YAAE;QAChB,KAAK,CAAC,eAAe,EAAE;QACvB,KAAK,CAAC,cAAc,EAAE;AAEtB,QAAA,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,IAAI,CAAC,sBAAsB,CAAC,KAAK,CAAC;AAC3D,QAAA,IAAI,CAAC,WAAW,GAAG,IAAI;QACvB,cAAc,GAAG,IAAI;QACrB,IAAI,CAAC,aAAa,GAAG,EAAE,EAAE,E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jB,EAAE,GAAG,EAAE,IAAI,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC,MAAM;AAEnC;;;;"}
|
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
import { forceCollide, forceX, forceY, forceManyBody, forceCenter, forceSimulation, forceLink } from 'd3-force';
|
|
2
2
|
import '@krainovsd/js-helpers';
|
|
3
3
|
import { getDrawTime, resetDrawTime } from '../../../lib/draw-time.js';
|
|
4
|
+
import '../constants/force-settings.js';
|
|
5
|
+
import '../constants/graph-settings.js';
|
|
6
|
+
import '../constants/highlight-settings.js';
|
|
7
|
+
import '../constants/link-settings.js';
|
|
8
|
+
import '../constants/node-settings.js';
|
|
4
9
|
import 'd3-array';
|
|
5
10
|
import { nodeIterationExtractor } from '../lib/utils/node-iteration-extractor.js';
|
|
11
|
+
import { initZoom } from './init-zoom.js';
|
|
6
12
|
|
|
7
13
|
function initSimulation() {
|
|
8
14
|
if (!this.simulation) {
|
|
@@ -14,13 +20,17 @@ function initSimulation() {
|
|
|
14
20
|
})
|
|
15
21
|
.on("end", () => {
|
|
16
22
|
this.listeners.onSimulationEnd?.call?.(this);
|
|
23
|
+
if (this.area) {
|
|
24
|
+
initZoom.call(this, this.areaTransform);
|
|
25
|
+
}
|
|
17
26
|
if (this.graphSettings.showDrawTime) {
|
|
18
27
|
getDrawTime();
|
|
19
28
|
// eslint-disable-next-line no-console
|
|
20
29
|
console.log(`nodes: ${this.nodes.length} | links: ${this.links.length}`);
|
|
21
30
|
resetDrawTime();
|
|
22
31
|
}
|
|
23
|
-
})
|
|
32
|
+
})
|
|
33
|
+
.stop();
|
|
24
34
|
initSimulationForces.call(this);
|
|
25
35
|
}
|
|
26
36
|
}
|
|
@@ -87,7 +97,7 @@ function initCollideForce(forceUpdate) {
|
|
|
87
97
|
else if (!this.simulation.force("collide") || forceUpdate) {
|
|
88
98
|
this.simulation.force("collide", forceCollide()
|
|
89
99
|
.radius((node, index) => {
|
|
90
|
-
const nodeOptions = this.nodeOptionsCache[
|
|
100
|
+
const nodeOptions = this.nodeOptionsCache[index];
|
|
91
101
|
if (!nodeOptions)
|
|
92
102
|
return 0;
|
|
93
103
|
switch (nodeOptions.shape) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"init-simulation.js","sources":["../../../../../src/module/GraphCanvas/slices/init-simulation.ts"],"sourcesContent":["import {\n type ForceLink,\n forceCenter,\n forceCollide,\n forceLink,\n forceManyBody,\n forceSimulation,\n forceX,\n forceY,\n} from \"d3-force\";\nimport { getDrawTime, resetDrawTime } from \"@/lib\";\nimport type { GraphCanvas } from \"../GraphCanvas\";\nimport { nodeIterationExtractor } from \"../lib\";\nimport type { LinkInterface, NodeInterface } from \"../types\";\n\nexport function initSimulation<\n NodeData extends Record<string, unknown>,\n LinkData extends Record<string, unknown>,\n>(this: GraphCanvas<NodeData, LinkData>) {\n if (!this.simulation) {\n this.simulation = forceSimulation<NodeInterface<NodeData>, LinkInterface<NodeData, LinkData>>()\n .nodes(this.nodes)\n .force(\n \"link\",\n forceLink<NodeInterface<NodeData>, LinkInterface<NodeData, LinkData>>(this.links).id(\n this.nodeSettings.idGetter.bind(this),\n ),\n )\n .on(\"tick\", () => {\n this.draw();\n })\n .on(\"end\", () => {\n this.listeners.onSimulationEnd?.call?.(this);\n\n if (this.graphSettings.showDrawTime) {\n getDrawTime();\n // eslint-disable-next-line no-console\n console.log(`nodes: ${this.nodes.length} | links: ${this.links.length}`);\n resetDrawTime();\n }\n });\n\n initSimulationForces.call<\n GraphCanvas<NodeData, LinkData>,\n Parameters<typeof initSimulationForces>,\n ReturnType<typeof initSimulationForces>\n >(this);\n }\n}\n\nexport function initSimulationForces<\n NodeData extends Record<string, unknown>,\n LinkData extends Record<string, unknown>,\n>(this: GraphCanvas<NodeData, LinkData>) {\n if (!this.simulation) return;\n\n const linkForce = this.simulation.force(\"link\") as\n | ForceLink<NodeInterface<NodeData>, LinkInterface<NodeData, LinkData>>\n | undefined;\n\n if (!linkForce) return;\n\n if ((!this.forceSettings.forces || !this.forceSettings.xForce) && this.simulation.force(\"x\")) {\n this.simulation.force(\"x\", null);\n }\n if ((!this.forceSettings.forces || !this.forceSettings.yForce) && this.simulation.force(\"y\")) {\n this.simulation.force(\"y\", null);\n }\n if (\n (!this.forceSettings.forces || !this.forceSettings.chargeForce) &&\n this.simulation.force(\"charge\")\n ) {\n this.simulation.force(\"charge\", null);\n }\n if (\n (!this.forceSettings.forces || !this.forceSettings.centerForce) &&\n this.simulation.force(\"center\")\n ) {\n this.simulation.force(\"center\", null);\n }\n if (!this.forceSettings.forces || !this.forceSettings.linkForce) {\n linkForce.distance(0).strength(0).iterations(0);\n }\n\n if (this.forceSettings.forces && this.forceSettings.linkForce) {\n linkForce\n .distance(this.forceSettings.linkDistance)\n .strength(this.forceSettings.linkStrength)\n .iterations(this.forceSettings.linkIterations);\n }\n if (this.forceSettings.forces && this.forceSettings.xForce) {\n this.simulation.force(\n \"x\",\n forceX<NodeInterface<NodeData>>(this.forceSettings.xPosition).strength(\n this.forceSettings.xStrength,\n ),\n );\n }\n if (this.forceSettings.forces && this.forceSettings.yForce) {\n this.simulation.force(\n \"y\",\n forceY<NodeInterface<NodeData>>(this.forceSettings.yPosition).strength(\n this.forceSettings.yStrength,\n ),\n );\n }\n if (this.forceSettings.forces && this.forceSettings.chargeForce) {\n this.simulation.force(\n \"charge\",\n forceManyBody<NodeInterface<NodeData>>()\n .strength(this.forceSettings.chargeStrength)\n .distanceMax(Infinity)\n .distanceMin(this.forceSettings.chargeDistanceMin),\n );\n }\n if (this.forceSettings.forces && this.forceSettings.centerForce) {\n this.simulation.force(\n \"center\",\n forceCenter<NodeInterface<NodeData>>(\n this.forceSettings.centerPosition.x ?? 0,\n this.forceSettings.centerPosition.y ?? 0,\n ).strength(this.forceSettings.centerStrength),\n );\n }\n\n initCollideForce.call<\n GraphCanvas<NodeData, LinkData>,\n Parameters<typeof initCollideForce>,\n ReturnType<typeof initCollideForce>\n >(this, true);\n}\n\nexport function initCollideForce<\n NodeData extends Record<string, unknown>,\n LinkData extends Record<string, unknown>,\n>(this: GraphCanvas<NodeData, LinkData>, forceUpdate: boolean) {\n if (!this.simulation) return;\n\n if (\n (!this.forceSettings.collideForce || !this.forceSettings.forces) &&\n this.simulation.force(\"collide\")\n ) {\n this.simulation.force(\"collide\", null);\n }\n\n if (this.forceSettings.forces && this.forceSettings.collideForce) {\n const isHasMax =\n this.forceSettings.collideOffMax.links != 0 && this.forceSettings.collideOffMax.nodes != 0;\n const isMaxCollideNodes =\n isHasMax && this.forceSettings.collideOffMax.nodes < this.nodes.length;\n const isMaxCollideLinks =\n isHasMax && this.forceSettings.collideOffMax.links < this.links.length;\n if (isMaxCollideNodes && isMaxCollideLinks) {\n this.simulation.force(\"collide\", null);\n } else if (!this.simulation.force(\"collide\") || forceUpdate) {\n this.simulation.force(\n \"collide\",\n forceCollide<NodeInterface<NodeData>>()\n .radius((node, index) => {\n const nodeOptions = this.nodeOptionsCache[node.id];\n if (!nodeOptions) return 0;\n\n switch (nodeOptions.shape) {\n case \"circle\": {\n if (this.forceSettings.collideRadius) {\n return nodeIterationExtractor(\n node,\n index,\n this.nodes,\n this,\n this.forceSettings.collideRadius,\n undefined,\n );\n }\n\n return nodeOptions.radius + this.forceSettings.collideAdditionalRadius;\n }\n case \"square\": {\n return (\n Math.sqrt(nodeOptions.width ** 2 + nodeOptions.height ** 2) / 2 +\n this.forceSettings.collideAdditionalRadius\n );\n }\n case \"text\": {\n return (\n Math.sqrt(nodeOptions.width ** 2 + nodeOptions.height ** 2) / 2 +\n this.forceSettings.collideAdditionalRadius\n );\n }\n default: {\n if (this.forceSettings.collideRadius) {\n return nodeIterationExtractor(\n node,\n index,\n this.nodes,\n this,\n this.forceSettings.collideRadius,\n undefined,\n );\n }\n\n return nodeOptions.radius + this.forceSettings.collideAdditionalRadius;\n }\n }\n })\n .strength(this.forceSettings.collideStrength)\n .iterations(this.forceSettings.collideIterations),\n );\n }\n }\n}\n"],"names":[],"mappings":";;;;;;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K,QAAQ,EAAE;AACb,wBAAA,IAAI,IAAI,CAAC,aAAa,CAAC,aAAa,EAAE;4BACpC,OAAO,sBAAsB,CAC3B,IAAI,EACJ,KAAK,EACL,IAAI,CAAC,KAAK,EACV,IAAI,EACJ,IAAI,CAAC,aAAa,CAAC,aAAa,EAChC,SAAS,CACV;;wBAGH,OAAO,WAAW,CAAC,MAAM,GAAG,IAAI,CAAC,aAAa,CAAC,uBAAuB;;oBAExE,KAAK,QAAQ,EAAE;AACb,wBAAA,QACE,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,KAAK,IAAI,CAAC,GAAG,WAAW,CAAC,MAAM,IAAI,CAAC,CAAC,GAAG,CAAC;AAC/D,4BAAA,IAAI,CAAC,aAAa,CAAC,uBAAuB;;oBAG9C,KAAK,MAAM,EAAE;AACX,wBAAA,QACE,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,KAAK,IAAI,CAAC,GAAG,WAAW,CAAC,MAAM,IAAI,CAAC,CAAC,GAAG,CAAC;AAC/D,4BAAA,IAAI,CAAC,aAAa,CAAC,uBAAuB;;oBAG9C,SAAS;AACP,wBAAA,IAAI,IAAI,CAAC,aAAa,CAAC,aAAa,EAAE;4BACpC,OAAO,sBAAsB,CAC3B,IAAI,EACJ,KAAK,EACL,IAAI,CAAC,KAAK,EACV,IAAI,EACJ,IAAI,CAAC,aAAa,CAAC,aAAa,EAChC,SAAS,CACV;;wBAGH,OAAO,WAAW,CAAC,MAAM,GAAG,IAAI,CAAC,aAAa,CAAC,uBAAuB;;;AAG5E,aAAC;AACA,iBAAA,QAAQ,CAAC,IAAI,CAAC,aAAa,CAAC,eAAe;iBAC3C,UAAU,CAAC,IAAI,CAAC,aAAa,CAAC,iBAAiB,CAAC,CACpD;;;AAGP;;;;"}
|
|
1
|
+
{"version":3,"file":"init-simulation.js","sources":["../../../../../src/module/GraphCanvas/slices/init-simulation.ts"],"sourcesContent":["import {\n type ForceLink,\n forceCenter,\n forceCollide,\n forceLink,\n forceManyBody,\n forceSimulation,\n forceX,\n forceY,\n} from \"d3-force\";\nimport { getDrawTime, resetDrawTime } from \"@/lib\";\nimport type { GraphCanvas } from \"../GraphCanvas\";\nimport { nodeIterationExtractor } from \"../lib\";\nimport type { LinkInterface, NodeInterface } from \"../types\";\nimport { initZoom } from \"./init-zoom\";\n\nexport function initSimulation<\n NodeData extends Record<string, unknown>,\n LinkData extends Record<string, unknown>,\n>(this: GraphCanvas<NodeData, LinkData>) {\n if (!this.simulation) {\n this.simulation = forceSimulation<NodeInterface<NodeData>, LinkInterface<NodeData, LinkData>>()\n .nodes(this.nodes)\n .force(\n \"link\",\n forceLink<NodeInterface<NodeData>, LinkInterface<NodeData, LinkData>>(this.links).id(\n this.nodeSettings.idGetter.bind(this),\n ),\n )\n .on(\"tick\", () => {\n this.draw();\n })\n .on(\"end\", () => {\n this.listeners.onSimulationEnd?.call?.(this);\n if (this.area) {\n initZoom.call<\n GraphCanvas<NodeData, LinkData>,\n Parameters<typeof initZoom>,\n ReturnType<typeof initZoom>\n >(this, this.areaTransform);\n }\n if (this.graphSettings.showDrawTime) {\n getDrawTime();\n // eslint-disable-next-line no-console\n console.log(`nodes: ${this.nodes.length} | links: ${this.links.length}`);\n resetDrawTime();\n }\n })\n .stop();\n initSimulationForces.call<\n GraphCanvas<NodeData, LinkData>,\n Parameters<typeof initSimulationForces>,\n ReturnType<typeof initSimulationForces>\n >(this);\n }\n}\n\nexport function initSimulationForces<\n NodeData extends Record<string, unknown>,\n LinkData extends Record<string, unknown>,\n>(this: GraphCanvas<NodeData, LinkData>) {\n if (!this.simulation) return;\n\n const linkForce = this.simulation.force(\"link\") as\n | ForceLink<NodeInterface<NodeData>, LinkInterface<NodeData, LinkData>>\n | undefined;\n\n if (!linkForce) return;\n\n if ((!this.forceSettings.forces || !this.forceSettings.xForce) && this.simulation.force(\"x\")) {\n this.simulation.force(\"x\", null);\n }\n if ((!this.forceSettings.forces || !this.forceSettings.yForce) && this.simulation.force(\"y\")) {\n this.simulation.force(\"y\", null);\n }\n if (\n (!this.forceSettings.forces || !this.forceSettings.chargeForce) &&\n this.simulation.force(\"charge\")\n ) {\n this.simulation.force(\"charge\", null);\n }\n if (\n (!this.forceSettings.forces || !this.forceSettings.centerForce) &&\n this.simulation.force(\"center\")\n ) {\n this.simulation.force(\"center\", null);\n }\n if (!this.forceSettings.forces || !this.forceSettings.linkForce) {\n linkForce.distance(0).strength(0).iterations(0);\n }\n\n if (this.forceSettings.forces && this.forceSettings.linkForce) {\n linkForce\n .distance(this.forceSettings.linkDistance)\n .strength(this.forceSettings.linkStrength)\n .iterations(this.forceSettings.linkIterations);\n }\n if (this.forceSettings.forces && this.forceSettings.xForce) {\n this.simulation.force(\n \"x\",\n forceX<NodeInterface<NodeData>>(this.forceSettings.xPosition).strength(\n this.forceSettings.xStrength,\n ),\n );\n }\n if (this.forceSettings.forces && this.forceSettings.yForce) {\n this.simulation.force(\n \"y\",\n forceY<NodeInterface<NodeData>>(this.forceSettings.yPosition).strength(\n this.forceSettings.yStrength,\n ),\n );\n }\n if (this.forceSettings.forces && this.forceSettings.chargeForce) {\n this.simulation.force(\n \"charge\",\n forceManyBody<NodeInterface<NodeData>>()\n .strength(this.forceSettings.chargeStrength)\n .distanceMax(Infinity)\n .distanceMin(this.forceSettings.chargeDistanceMin),\n );\n }\n if (this.forceSettings.forces && this.forceSettings.centerForce) {\n this.simulation.force(\n \"center\",\n forceCenter<NodeInterface<NodeData>>(\n this.forceSettings.centerPosition.x ?? 0,\n this.forceSettings.centerPosition.y ?? 0,\n ).strength(this.forceSettings.centerStrength),\n );\n }\n\n initCollideForce.call<\n GraphCanvas<NodeData, LinkData>,\n Parameters<typeof initCollideForce>,\n ReturnType<typeof initCollideForce>\n >(this, true);\n}\n\nexport function initCollideForce<\n NodeData extends Record<string, unknown>,\n LinkData extends Record<string, unknown>,\n>(this: GraphCanvas<NodeData, LinkData>, forceUpdate: boolean) {\n if (!this.simulation) return;\n\n if (\n (!this.forceSettings.collideForce || !this.forceSettings.forces) &&\n this.simulation.force(\"collide\")\n ) {\n this.simulation.force(\"collide\", null);\n }\n\n if (this.forceSettings.forces && this.forceSettings.collideForce) {\n const isHasMax =\n this.forceSettings.collideOffMax.links != 0 && this.forceSettings.collideOffMax.nodes != 0;\n const isMaxCollideNodes =\n isHasMax && this.forceSettings.collideOffMax.nodes < this.nodes.length;\n const isMaxCollideLinks =\n isHasMax && this.forceSettings.collideOffMax.links < this.links.length;\n if (isMaxCollideNodes && isMaxCollideLinks) {\n this.simulation.force(\"collide\", null);\n } else if (!this.simulation.force(\"collide\") || forceUpdate) {\n this.simulation.force(\n \"collide\",\n forceCollide<NodeInterface<NodeData>>()\n .radius((node, index) => {\n const nodeOptions = this.nodeOptionsCache[index];\n if (!nodeOptions) return 0;\n\n switch (nodeOptions.shape) {\n case \"circle\": {\n if (this.forceSettings.collideRadius) {\n return nodeIterationExtractor(\n node,\n index,\n this.nodes,\n this,\n this.forceSettings.collideRadius,\n undefined,\n );\n }\n\n return nodeOptions.radius + this.forceSettings.collideAdditionalRadius;\n }\n case \"square\": {\n return (\n Math.sqrt(nodeOptions.width ** 2 + nodeOptions.height ** 2) / 2 +\n this.forceSettings.collideAdditionalRadius\n );\n }\n case \"text\": {\n return (\n Math.sqrt(nodeOptions.width ** 2 + nodeOptions.height ** 2) / 2 +\n this.forceSettings.collideAdditionalRadius\n );\n }\n default: {\n if (this.forceSettings.collideRadius) {\n return nodeIterationExtractor(\n node,\n index,\n this.nodes,\n this,\n this.forceSettings.collideRadius,\n undefined,\n );\n }\n\n return nodeOptions.radius + this.forceSettings.collideAdditionalRadius;\n }\n }\n })\n .strength(this.forceSettings.collideStrength)\n .iterations(this.forceSettings.collideIterations),\n );\n }\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;;;SAgBgB,cAAc,GAAA;AAI5B,IAAA,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE;AACpB,QAAA,IAAI,CAAC,UAAU,GAAG,eAAe;AAC9B,aAAA,KAAK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+
import '../constants/force-settings.js';
|
|
5
|
+
import '../constants/graph-settings.js';
|
|
6
|
+
import '../constants/highlight-settings.js';
|
|
7
|
+
import '../constants/link-settings.js';
|
|
8
|
+
import '../constants/node-settings.js';
|
|
9
|
+
import { computeGraphBounds } from '../lib/utils/compute-graph-bounds.js';
|
|
10
|
+
import 'd3-array';
|
|
4
11
|
import { updateLinkCache } from './update-link-cache.js';
|
|
5
12
|
import { updateNodeCache } from './update-node-cache.js';
|
|
6
13
|
|
|
14
|
+
const DEFAULT_ZOOM_EXTENT = [0.3, 10];
|
|
15
|
+
const DEFAULT_TRANSLATE_EXTENT_COEFFICIENT = 8;
|
|
16
|
+
const DEFAULT_MARGIN = 0.25;
|
|
7
17
|
function initZoom(currentZoom) {
|
|
8
18
|
if (!this.area)
|
|
9
19
|
throw new Error("bad init data");
|
|
20
|
+
const bounds = computeGraphBounds(this.nodes);
|
|
21
|
+
const zoomExtent = resolveZoomExtent(this.graphSettings.zoomExtent, this.width, this.height, this.graphSettings.zoomExtentMargin ?? DEFAULT_MARGIN, bounds);
|
|
22
|
+
const translateExtent = resolveTranslateExtent(this.graphSettings.translateExtent, this.graphSettings.translateExtentCoefficient, this.graphSettings.translateExtentOverlap, this.width, this.height, zoomExtent, bounds);
|
|
23
|
+
this._translateExtent = translateExtent;
|
|
10
24
|
const zoomInstance = zoom()
|
|
11
|
-
.scaleExtent(
|
|
25
|
+
.scaleExtent(zoomExtent)
|
|
26
|
+
.filter((event) => {
|
|
27
|
+
return !(event instanceof MouseEvent && event.shiftKey);
|
|
28
|
+
})
|
|
12
29
|
.on("zoom", (event) => {
|
|
30
|
+
if (this._zoomAnimating)
|
|
31
|
+
return;
|
|
13
32
|
this.listeners.onZoom?.call?.(this, event);
|
|
14
33
|
const oldTransform = this.areaTransform;
|
|
15
34
|
this.areaTransform = event.transform;
|
|
16
35
|
if (this.areaTransform.k !== oldTransform.k) {
|
|
17
36
|
updateLinkCache.call(this);
|
|
18
|
-
updateNodeCache.call(this
|
|
37
|
+
updateNodeCache.call(this);
|
|
19
38
|
}
|
|
20
|
-
|
|
21
|
-
requestAnimationFrame(() => this.draw());
|
|
39
|
+
this.tick();
|
|
22
40
|
});
|
|
23
|
-
|
|
24
|
-
const coefficient = this.graphSettings.translateExtentCoefficient;
|
|
25
|
-
const [coefficientX, coefficientY] = isArray(coefficient)
|
|
26
|
-
? coefficient
|
|
27
|
-
: [coefficient, coefficient];
|
|
28
|
-
const [[minX = -this.width * coefficientX, minY = -this.height * coefficientY], [maxX = this.width * coefficientX, maxY = this.height * coefficientY],] = this.graphSettings.translateExtent;
|
|
29
|
-
zoomInstance.translateExtent([
|
|
30
|
-
[minX, minY],
|
|
31
|
-
[maxX, maxY],
|
|
32
|
-
]);
|
|
33
|
-
}
|
|
41
|
+
zoomInstance.translateExtent(translateExtent);
|
|
34
42
|
select(this.area).call(zoomInstance).on("dblclick.zoom", null);
|
|
35
43
|
const zoomInitial = currentZoom ?? this.graphSettings.zoomInitial;
|
|
36
|
-
this.areaTransform = new ZoomTransform(zoomInitial?.k ?? 1, zoomInitial?.x ?? this.width / 2, zoomInitial?.y ?? this.height / 2);
|
|
44
|
+
this.areaTransform = new ZoomTransform(Math.max(zoomInitial?.k ?? 1, zoomExtent[0]), zoomInitial?.x ?? this.width / 2, zoomInitial?.y ?? this.height / 2);
|
|
37
45
|
zoom().transform(select(this.area), this.areaTransform);
|
|
38
46
|
}
|
|
47
|
+
function resolveZoomExtent(userExtent, viewWidth, viewHeight, margin, bounds) {
|
|
48
|
+
if (userExtent &&
|
|
49
|
+
userExtent.length === 2 &&
|
|
50
|
+
userExtent[0] != undefined &&
|
|
51
|
+
userExtent[1] != undefined) {
|
|
52
|
+
return userExtent;
|
|
53
|
+
}
|
|
54
|
+
if (!bounds)
|
|
55
|
+
return DEFAULT_ZOOM_EXTENT;
|
|
56
|
+
const graphWidth = bounds.maxX - bounds.minX;
|
|
57
|
+
const graphHeight = bounds.maxY - bounds.minY;
|
|
58
|
+
if (graphWidth === 0 || graphHeight === 0)
|
|
59
|
+
return DEFAULT_ZOOM_EXTENT;
|
|
60
|
+
const scaleToFit = (1 - margin) / Math.max(graphWidth / viewWidth, graphHeight / viewHeight);
|
|
61
|
+
return [scaleToFit, DEFAULT_ZOOM_EXTENT[1]];
|
|
62
|
+
}
|
|
63
|
+
function resolveTranslateExtent(userExtent, userCoefficient, overlap, viewWidth, viewHeight, zoomExtent, bounds) {
|
|
64
|
+
if (userExtent && userExtent.length >= 2 && isArray(userExtent[0]) && isArray(userExtent[1])) {
|
|
65
|
+
return [
|
|
66
|
+
[
|
|
67
|
+
userExtent[0][0] ?? -viewWidth * DEFAULT_TRANSLATE_EXTENT_COEFFICIENT,
|
|
68
|
+
userExtent[0][1] ?? -viewHeight * DEFAULT_TRANSLATE_EXTENT_COEFFICIENT,
|
|
69
|
+
],
|
|
70
|
+
[
|
|
71
|
+
userExtent[1][0] ?? viewWidth * DEFAULT_TRANSLATE_EXTENT_COEFFICIENT,
|
|
72
|
+
userExtent[1][1] ?? viewHeight * DEFAULT_TRANSLATE_EXTENT_COEFFICIENT,
|
|
73
|
+
],
|
|
74
|
+
];
|
|
75
|
+
}
|
|
76
|
+
if (userCoefficient) {
|
|
77
|
+
const [cx, cy] = isArray(userCoefficient)
|
|
78
|
+
? userCoefficient
|
|
79
|
+
: [userCoefficient, userCoefficient];
|
|
80
|
+
return [
|
|
81
|
+
[-viewWidth * cx, -viewHeight * cy],
|
|
82
|
+
[viewWidth * cx, viewHeight * cy],
|
|
83
|
+
];
|
|
84
|
+
}
|
|
85
|
+
if (!bounds) {
|
|
86
|
+
return [
|
|
87
|
+
[
|
|
88
|
+
-viewWidth * DEFAULT_TRANSLATE_EXTENT_COEFFICIENT,
|
|
89
|
+
-viewHeight * DEFAULT_TRANSLATE_EXTENT_COEFFICIENT,
|
|
90
|
+
],
|
|
91
|
+
[
|
|
92
|
+
viewWidth * DEFAULT_TRANSLATE_EXTENT_COEFFICIENT,
|
|
93
|
+
viewHeight * DEFAULT_TRANSLATE_EXTENT_COEFFICIENT,
|
|
94
|
+
],
|
|
95
|
+
];
|
|
96
|
+
}
|
|
97
|
+
const minZoom = zoomExtent[0];
|
|
98
|
+
const zoomViewWidth = viewWidth / minZoom;
|
|
99
|
+
const zoomViewHeight = viewHeight / minZoom;
|
|
100
|
+
const graphWidth = bounds.maxX - bounds.minX;
|
|
101
|
+
const graphHeight = bounds.maxY - bounds.minY;
|
|
102
|
+
const minX = bounds.minX + overlap * graphWidth - zoomViewWidth;
|
|
103
|
+
const maxX = bounds.maxX - overlap * graphWidth + zoomViewWidth;
|
|
104
|
+
const minY = bounds.minY + overlap * graphHeight - zoomViewHeight;
|
|
105
|
+
const maxY = bounds.maxY - overlap * graphHeight + zoomViewHeight;
|
|
106
|
+
return [
|
|
107
|
+
[minX, minY],
|
|
108
|
+
[maxX, maxY],
|
|
109
|
+
];
|
|
110
|
+
}
|
|
39
111
|
|
|
40
112
|
export { initZoom };
|
|
41
113
|
//# sourceMappingURL=init-zoom.js.map
|
|
@@ -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(
|
|
1
|
+
{"version":3,"file":"init-zoom.js","sources":["../../../../../src/module/GraphCanvas/slices/init-zoom.ts"],"sourcesContent":["import { isArray } from \"@krainovsd/js-helpers\";\nimport { select as d3Select } from \"d3-selection\";\nimport { ZoomTransform, zoom } from \"d3-zoom\";\nimport type { GraphCanvas } from \"../GraphCanvas\";\nimport { computeGraphBounds } from \"../lib\";\nimport type { ZoomEventInterface } from \"../types\";\nimport { updateLinkCache } from \"./update-link-cache\";\nimport { updateNodeCache } from \"./update-node-cache\";\n\nconst DEFAULT_ZOOM_EXTENT: [number, number] = [0.3, 10];\nconst DEFAULT_TRANSLATE_EXTENT_COEFFICIENT = 8;\nconst DEFAULT_MARGIN = 0.25;\n\nexport function initZoom<\n NodeData extends Record<string, unknown>,\n LinkData extends Record<string, unknown>,\n>(this: GraphCanvas<NodeData, LinkData>, currentZoom?: ZoomTransform) {\n if (!this.area) throw new Error(\"bad init data\");\n\n const bounds = computeGraphBounds(this.nodes);\n const zoomExtent = resolveZoomExtent(\n this.graphSettings.zoomExtent,\n this.width,\n this.height,\n this.graphSettings.zoomExtentMargin ?? DEFAULT_MARGIN,\n bounds,\n );\n const translateExtent = resolveTranslateExtent(\n this.graphSettings.translateExtent,\n this.graphSettings.translateExtentCoefficient,\n this.graphSettings.translateExtentOverlap,\n this.width,\n this.height,\n zoomExtent,\n bounds,\n );\n this._translateExtent = translateExtent;\n\n const zoomInstance = zoom<HTMLCanvasElement, unknown>()\n .scaleExtent(zoomExtent)\n .filter((event) => {\n return !(event instanceof MouseEvent && event.shiftKey);\n })\n .on(\"zoom\", (event: ZoomEventInterface) => {\n if (this._zoomAnimating) return;\n this.listeners.onZoom?.call?.(this, event);\n const oldTransform = this.areaTransform;\n this.areaTransform = event.transform;\n if (this.areaTransform.k !== oldTransform.k) {\n updateLinkCache.call<\n GraphCanvas<NodeData, LinkData>,\n Parameters<typeof updateLinkCache>,\n ReturnType<typeof updateLinkCache>\n >(this);\n updateNodeCache.call<\n GraphCanvas<NodeData, LinkData>,\n Parameters<typeof updateNodeCache>,\n ReturnType<typeof updateNodeCache>\n >(this);\n }\n this.tick();\n });\n\n zoomInstance.translateExtent(translateExtent);\n d3Select(this.area).call(zoomInstance).on(\"dblclick.zoom\", null);\n\n const zoomInitial = currentZoom ?? this.graphSettings.zoomInitial;\n this.areaTransform = new ZoomTransform(\n Math.max(zoomInitial?.k ?? 1, zoomExtent[0]),\n zoomInitial?.x ?? this.width / 2,\n zoomInitial?.y ?? this.height / 2,\n );\n zoom<HTMLCanvasElement, unknown>().transform(d3Select(this.area), this.areaTransform);\n}\n\nfunction resolveZoomExtent(\n userExtent: [number, number] | null,\n viewWidth: number,\n viewHeight: number,\n margin: number,\n bounds: ReturnType<typeof computeGraphBounds>,\n): [number, number] {\n if (\n userExtent &&\n userExtent.length === 2 &&\n userExtent[0] != undefined &&\n userExtent[1] != undefined\n ) {\n return userExtent;\n }\n if (!bounds) return DEFAULT_ZOOM_EXTENT;\n const graphWidth = bounds.maxX - bounds.minX;\n const graphHeight = bounds.maxY - bounds.minY;\n if (graphWidth === 0 || graphHeight === 0) return DEFAULT_ZOOM_EXTENT;\n const scaleToFit = (1 - margin) / Math.max(graphWidth / viewWidth, graphHeight / viewHeight);\n return [scaleToFit, DEFAULT_ZOOM_EXTENT[1]];\n}\n\nfunction resolveTranslateExtent(\n userExtent: [[number?, number?], [number?, number?]] | null,\n userCoefficient: number | [number, number] | null,\n overlap: number,\n viewWidth: number,\n viewHeight: number,\n zoomExtent: [number, number],\n bounds: ReturnType<typeof computeGraphBounds>,\n): [[number, number], [number, number]] {\n if (userExtent && userExtent.length >= 2 && isArray(userExtent[0]) && isArray(userExtent[1])) {\n return [\n [\n userExtent[0][0] ?? -viewWidth * DEFAULT_TRANSLATE_EXTENT_COEFFICIENT,\n userExtent[0][1] ?? -viewHeight * DEFAULT_TRANSLATE_EXTENT_COEFFICIENT,\n ],\n [\n userExtent[1][0] ?? viewWidth * DEFAULT_TRANSLATE_EXTENT_COEFFICIENT,\n userExtent[1][1] ?? viewHeight * DEFAULT_TRANSLATE_EXTENT_COEFFICIENT,\n ],\n ];\n }\n if (userCoefficient) {\n const [cx, cy] = isArray(userCoefficient)\n ? userCoefficient\n : [userCoefficient, userCoefficient];\n return [\n [-viewWidth * cx, -viewHeight * cy],\n [viewWidth * cx, viewHeight * cy],\n ];\n }\n if (!bounds) {\n return [\n [\n -viewWidth * DEFAULT_TRANSLATE_EXTENT_COEFFICIENT,\n -viewHeight * DEFAULT_TRANSLATE_EXTENT_COEFFICIENT,\n ],\n [\n viewWidth * DEFAULT_TRANSLATE_EXTENT_COEFFICIENT,\n viewHeight * DEFAULT_TRANSLATE_EXTENT_COEFFICIENT,\n ],\n ];\n }\n\n const minZoom = zoomExtent[0];\n const zoomViewWidth = viewWidth / minZoom;\n const zoomViewHeight = viewHeight / minZoom;\n const graphWidth = bounds.maxX - bounds.minX;\n const graphHeight = bounds.maxY - bounds.minY;\n\n const minX = bounds.minX + overlap * graphWidth - zoomViewWidth;\n const maxX = bounds.maxX - overlap * graphWidth + zoomViewWidth;\n const minY = bounds.minY + overlap * graphHeight - zoomViewHeight;\n const maxY = bounds.maxY - overlap * graphHeight + zoomViewHeight;\n\n return [\n [minX, minY],\n [maxX, maxY],\n ];\n}\n"],"names":["d3Select"],"mappings":";;;;;;;;;;;;;AASA,MAAM,mBAAmB,GAAqB,CAAC,GAAG,EAAE,EAAE,CAAC;AACvD,MAAM,oCAAoC,GAAG,CAAC;AAC9C,MAAM,cAAc,GAAG,IAAI;AAErB,SAAU,QAAQ,CAGiB,WAA2B,EAAA;IAClE,IAAI,CAAC,IAAI,CAAC,IAAI;AAAE,QAAA,MAAM,IAAI,KAAK,CAAC,eAAe,CAAC;IAEhD,MAAM,MAAM,GAAG,kBAAkB,CAAC,IAAI,CAAC,KAAK,CAAC;AAC7C,IAAA,MAAM,UAAU,GAAG,iBAAiB,CAClC,IAAI,CAAC,aAAa,CAAC,UAAU,EAC7B,IAAI,CAAC,KAAK,EACV,IAAI,CAAC,MAAM,EACX,IAAI,CAAC,aAAa,CAAC,gBAAgB,IAAI,cAAc,EACrD,MAAM,CACP;AACD,IAAA,MAA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,CAAC,IAAI;IAC5C,MAAM,WAAW,GAAG,MAAM,CAAC,IAAI,GAAG,MAAM,CAAC,IAAI;IAE7C,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,GAAG,OAAO,GAAG,UAAU,GAAG,aAAa;IAC/D,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,GAAG,OAAO,GAAG,UAAU,GAAG,aAAa;IAC/D,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,GAAG,OAAO,GAAG,WAAW,GAAG,cAAc;IACjE,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,GAAG,OAAO,GAAG,WAAW,GAAG,cAAc;IAEjE,OAAO;QACL,CAAC,IAAI,EAAE,IAAI,CAAC;QACZ,CAAC,IAAI,EAAE,IAAI,CAAC;KACb;AACH;;;;"}
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
import '../constants/force-settings.js';
|
|
2
|
+
import '../constants/graph-settings.js';
|
|
3
|
+
import '../constants/highlight-settings.js';
|
|
4
|
+
import '../constants/link-settings.js';
|
|
5
|
+
import '../constants/node-settings.js';
|
|
1
6
|
import { linkOptionsGetter } from '../lib/settings/link-settings-getter.js';
|
|
2
7
|
import '@krainovsd/js-helpers';
|
|
3
8
|
import { linkIterationExtractor } from '../lib/utils/link-iteration-extractor.js';
|
|
@@ -5,16 +10,41 @@ import 'd3-array';
|
|
|
5
10
|
import { extractLinkPointIds } from '../lib/utils/extract-link-point-ids.js';
|
|
6
11
|
|
|
7
12
|
function updateLinkCache() {
|
|
8
|
-
this.
|
|
13
|
+
if (!this.context)
|
|
14
|
+
return;
|
|
15
|
+
const current = this.areaTransform.k;
|
|
16
|
+
if (this.linkSettings.smartCache &&
|
|
17
|
+
this._lastLinkZoomK !== undefined &&
|
|
18
|
+
this.linkOptionsCache.length > 0) {
|
|
19
|
+
const corner = this.linkSettings.linkScaleSwitch;
|
|
20
|
+
const prev = this._lastLinkZoomK;
|
|
21
|
+
this._lastLinkZoomK = current;
|
|
22
|
+
if (!((prev <= corner && current >= corner) || (prev >= corner && current <= corner))) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
for (let i = 0; i < this.links.length; i++) {
|
|
26
|
+
const link = this.links[i];
|
|
27
|
+
const linkOptions = linkIterationExtractor(link, i, this.links, this, this.linkSettings.options ?? {}, linkOptionsGetter);
|
|
28
|
+
const cache = this.linkOptionsCache[i];
|
|
29
|
+
if (cache) {
|
|
30
|
+
cache.color = linkOptions.color;
|
|
31
|
+
cache.arrowColor = linkOptions.arrowColor;
|
|
32
|
+
cache.width = linkOptions.width;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
this._lastLinkZoomK = current;
|
|
38
|
+
this.linkOptionsCache.length = 0;
|
|
9
39
|
const groupMap = {};
|
|
10
40
|
const groupSelfMap = {};
|
|
11
41
|
for (let i = 0; i < this.links.length; i++) {
|
|
12
42
|
const link = this.links[i];
|
|
13
43
|
const { sourceId, targetId } = extractLinkPointIds(link);
|
|
14
44
|
const linkOptions = linkIterationExtractor(link, i, this.links, this, this.linkSettings.options ?? {}, linkOptionsGetter);
|
|
15
|
-
|
|
16
|
-
this.linkOptionsCache[id] = linkOptions;
|
|
45
|
+
this.linkOptionsCache[i] = linkOptions;
|
|
17
46
|
if (this.linkSettings.curve) {
|
|
47
|
+
const id = `${targetId}${sourceId}`;
|
|
18
48
|
if (sourceId === targetId) {
|
|
19
49
|
groupSelfMap[id] ??= 0;
|
|
20
50
|
link._groupIndex = ++groupSelfMap[id];
|