@krainovsd/graph 0.12.0-beta.3 → 0.12.0-beta.4
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 +307 -223
- package/lib/cjs/index.cjs.map +1 -1
- package/lib/esm/constants/link-controls.js +0 -6
- package/lib/esm/constants/link-controls.js.map +1 -1
- package/lib/esm/constants/node-controls.js +71 -24
- package/lib/esm/constants/node-controls.js.map +1 -1
- package/lib/esm/module/GraphCanvas/GraphCanvas.js +15 -17
- package/lib/esm/module/GraphCanvas/GraphCanvas.js.map +1 -1
- package/lib/esm/module/GraphCanvas/constants/link-settings.js +0 -1
- package/lib/esm/module/GraphCanvas/constants/link-settings.js.map +1 -1
- package/lib/esm/module/GraphCanvas/constants/node-settings.js +10 -5
- package/lib/esm/module/GraphCanvas/constants/node-settings.js.map +1 -1
- package/lib/esm/module/GraphCanvas/lib/settings/node-settings-getter.js +20 -4
- package/lib/esm/module/GraphCanvas/lib/settings/node-settings-getter.js.map +1 -1
- package/lib/esm/module/GraphCanvas/slices/draw-links.js +7 -20
- package/lib/esm/module/GraphCanvas/slices/draw-links.js.map +1 -1
- package/lib/esm/module/GraphCanvas/slices/draw-nodes.js +25 -117
- package/lib/esm/module/GraphCanvas/slices/draw-nodes.js.map +1 -1
- package/lib/esm/module/GraphCanvas/slices/draw-text.js +1 -24
- package/lib/esm/module/GraphCanvas/slices/draw-text.js.map +1 -1
- package/lib/esm/module/GraphCanvas/slices/init-simulation.js +20 -8
- package/lib/esm/module/GraphCanvas/slices/init-simulation.js.map +1 -1
- package/lib/esm/module/GraphCanvas/slices/init-zoom.js +4 -2
- package/lib/esm/module/GraphCanvas/slices/init-zoom.js.map +1 -1
- package/lib/esm/module/GraphCanvas/slices/update-link-cache.js +19 -0
- package/lib/esm/module/GraphCanvas/slices/update-link-cache.js.map +1 -0
- package/lib/esm/module/GraphCanvas/slices/update-node-cache.js +136 -0
- package/lib/esm/module/GraphCanvas/slices/update-node-cache.js.map +1 -0
- package/lib/index.d.ts +28 -28
- package/package.json +1 -1
|
@@ -98,9 +98,12 @@ function initCollideForce(forceUpdate) {
|
|
|
98
98
|
const radius = nodeRadiusGetter({
|
|
99
99
|
radiusFlexible: this.nodeSettings.nodeRadiusFlexible,
|
|
100
100
|
radiusInitial: nodeOptions.radius,
|
|
101
|
-
radiusCoefficient: this.nodeSettings.nodeRadiusCoefficient,
|
|
102
|
-
radiusFactor: this.nodeSettings.nodeRadiusFactor,
|
|
103
101
|
linkCount: node.linkCount,
|
|
102
|
+
radiusIncrementByStep: this.nodeSettings.nodeRadiusIncrementByStep,
|
|
103
|
+
radiusLinkCountForStep: this.nodeSettings.nodeRadiusLinkCountForStep,
|
|
104
|
+
radiusMaxLinearSteps: this.nodeSettings.nodeRadiusMaxLinearSteps,
|
|
105
|
+
radiusLogFactor: this.nodeSettings.nodeRadiusLogFactor,
|
|
106
|
+
radiusLinkCountDividerForLog: this.nodeSettings.nodeRadiusLinkCountDividerForLog,
|
|
104
107
|
});
|
|
105
108
|
return radius + this.forceSettings.collideAdditionalRadius;
|
|
106
109
|
}
|
|
@@ -109,9 +112,12 @@ function initCollideForce(forceUpdate) {
|
|
|
109
112
|
heightInitial: nodeOptions.width,
|
|
110
113
|
widthInitial: nodeOptions.height,
|
|
111
114
|
linkCount: node.linkCount,
|
|
112
|
-
sizeCoefficient: this.nodeSettings.nodeSizeCoefficient,
|
|
113
|
-
sizeFactor: this.nodeSettings.nodeSizeFactor,
|
|
114
115
|
sizeFlexible: this.nodeSettings.nodeSizeFlexible,
|
|
116
|
+
sizeIncrementByStep: this.nodeSettings.nodeSizeIncrementByStep,
|
|
117
|
+
sizeLinkCountForStep: this.nodeSettings.nodeSizeLinkCountForStep,
|
|
118
|
+
sizeMaxLinearSteps: this.nodeSettings.nodeSizeMaxLinearSteps,
|
|
119
|
+
sizeLogFactor: this.nodeSettings.nodeSizeLogFactor,
|
|
120
|
+
sizeLinkCountDividerForLog: this.nodeSettings.nodeSizeLinkCountDividerForLog,
|
|
115
121
|
});
|
|
116
122
|
return (Math.sqrt(width ** 2 + height ** 2) / 2 +
|
|
117
123
|
this.forceSettings.collideAdditionalRadius);
|
|
@@ -121,9 +127,12 @@ function initCollideForce(forceUpdate) {
|
|
|
121
127
|
heightInitial: nodeOptions.width,
|
|
122
128
|
widthInitial: nodeOptions.height,
|
|
123
129
|
linkCount: node.linkCount,
|
|
124
|
-
sizeCoefficient: this.nodeSettings.nodeSizeCoefficient,
|
|
125
|
-
sizeFactor: this.nodeSettings.nodeSizeFactor,
|
|
126
130
|
sizeFlexible: this.nodeSettings.nodeSizeFlexible,
|
|
131
|
+
sizeIncrementByStep: this.nodeSettings.nodeSizeIncrementByStep,
|
|
132
|
+
sizeLinkCountForStep: this.nodeSettings.nodeSizeLinkCountForStep,
|
|
133
|
+
sizeMaxLinearSteps: this.nodeSettings.nodeSizeMaxLinearSteps,
|
|
134
|
+
sizeLogFactor: this.nodeSettings.nodeSizeLogFactor,
|
|
135
|
+
sizeLinkCountDividerForLog: this.nodeSettings.nodeSizeLinkCountDividerForLog,
|
|
127
136
|
});
|
|
128
137
|
if (this.context && nodeOptions.text) {
|
|
129
138
|
const textInfo = getTextLines({
|
|
@@ -153,8 +162,11 @@ function initCollideForce(forceUpdate) {
|
|
|
153
162
|
const radius = nodeRadiusGetter({
|
|
154
163
|
radiusFlexible: this.nodeSettings.nodeRadiusFlexible,
|
|
155
164
|
radiusInitial: nodeOptions.radius,
|
|
156
|
-
|
|
157
|
-
|
|
165
|
+
radiusIncrementByStep: this.nodeSettings.nodeRadiusIncrementByStep,
|
|
166
|
+
radiusLinkCountForStep: this.nodeSettings.nodeRadiusLinkCountForStep,
|
|
167
|
+
radiusMaxLinearSteps: this.nodeSettings.nodeRadiusMaxLinearSteps,
|
|
168
|
+
radiusLogFactor: this.nodeSettings.nodeRadiusLogFactor,
|
|
169
|
+
radiusLinkCountDividerForLog: this.nodeSettings.nodeRadiusLinkCountDividerForLog,
|
|
158
170
|
linkCount: node.linkCount,
|
|
159
171
|
});
|
|
160
172
|
return radius + this.forceSettings.collideAdditionalRadius;
|
|
@@ -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 {\n nodeIterationExtractor,\n nodeOptionsGetter,\n nodeRadiusGetter,\n nodeSizeGetter,\n} from \"../lib\";\nimport type { LinkInterface, NodeInterface } from \"../types\";\nimport { getTextLines } from \"./draw-text\";\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 = nodeIterationExtractor(\n node,\n index,\n this.nodes,\n this,\n this.nodeSettings.options ?? {},\n nodeOptionsGetter,\n );\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 const radius = nodeRadiusGetter({\n radiusFlexible: this.nodeSettings.nodeRadiusFlexible,\n radiusInitial: nodeOptions.radius,\n radiusCoefficient: this.nodeSettings.nodeRadiusCoefficient,\n radiusFactor: this.nodeSettings.nodeRadiusFactor,\n linkCount: node.linkCount,\n });\n\n return radius + this.forceSettings.collideAdditionalRadius;\n }\n case \"square\": {\n const { height, width } = nodeSizeGetter({\n heightInitial: nodeOptions.width,\n widthInitial: nodeOptions.height,\n linkCount: node.linkCount,\n sizeCoefficient: this.nodeSettings.nodeSizeCoefficient,\n sizeFactor: this.nodeSettings.nodeSizeFactor,\n sizeFlexible: this.nodeSettings.nodeSizeFlexible,\n });\n\n return (\n Math.sqrt(width ** 2 + height ** 2) / 2 +\n this.forceSettings.collideAdditionalRadius\n );\n }\n case \"text\": {\n let { height, width } = nodeSizeGetter({\n heightInitial: nodeOptions.width,\n widthInitial: nodeOptions.height,\n linkCount: node.linkCount,\n sizeCoefficient: this.nodeSettings.nodeSizeCoefficient,\n sizeFactor: this.nodeSettings.nodeSizeFactor,\n sizeFlexible: this.nodeSettings.nodeSizeFlexible,\n });\n\n if (this.context && nodeOptions.text) {\n const textInfo = getTextLines({\n context: this.context,\n text: nodeOptions.text,\n textAlign: nodeOptions.textAlign,\n textColor: nodeOptions.textColor,\n textFont: nodeOptions.textFont,\n textSize: nodeOptions.textSize,\n maxWidth: width,\n textStyle: nodeOptions.textStyle,\n textWeight: nodeOptions.textWeight,\n });\n\n height =\n textInfo.lines.length * nodeOptions.textSize +\n (textInfo.lines.length - 1) * nodeOptions.textGap +\n nodeOptions.labelYPadding;\n width = textInfo.currentMaxSize + nodeOptions.labelXPadding;\n }\n\n return (\n Math.sqrt(width ** 2 + 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 const radius = nodeRadiusGetter({\n radiusFlexible: this.nodeSettings.nodeRadiusFlexible,\n radiusInitial: nodeOptions.radius,\n radiusCoefficient: this.nodeSettings.nodeRadiusCoefficient,\n radiusFactor: this.nodeSettings.nodeRadiusFactor,\n linkCount: node.linkCount,\n });\n\n return radius + this.forceSettings.collideAdditionalRadius;\n }\n }\n })\n .strength(this.forceSettings.collideStrength)\n .iterations(this.forceSettings.collideIterations),\n );\n }\n }\n}\n"],"names":[],"mappings":";;;;;;;;SAqBgB,cAAc,GAAA;AAI5B,IAAA,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE;AACpB,QAAA,IAAI,CAAC,UAAU,GAAG,eAAe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I,CAAC,aAAa,CAAC,aAAa,EAChC,SAAS,CACV;;wBAEH,MAAM,MAAM,GAAG,gBAAgB,CAAC;AAC9B,4BAAA,cAAc,EAAE,IAAI,CAAC,YAAY,CAAC,kBAAkB;4BACpD,aAAa,EAAE,WAAW,CAAC,MAAM;AACjC,4BAAA,iBAAiB,EAAE,IAAI,CAAC,YAAY,CAAC,qBAAqB;AAC1D,4BAAA,YAAY,EAAE,IAAI,CAAC,YAAY,CAAC,gBAAgB;4BAChD,SAAS,EAAE,IAAI,CAAC,SAAS;AAC1B,yBAAA,CAAC;AAEF,wBAAA,OAAO,MAAM,GAAG,IAAI,CAAC,aAAa,CAAC,uBAAuB;;;AAGhE,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 {\n nodeIterationExtractor,\n nodeOptionsGetter,\n nodeRadiusGetter,\n nodeSizeGetter,\n} from \"../lib\";\nimport type { LinkInterface, NodeInterface } from \"../types\";\nimport { getTextLines } from \"./draw-text\";\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 = nodeIterationExtractor(\n node,\n index,\n this.nodes,\n this,\n this.nodeSettings.options ?? {},\n nodeOptionsGetter,\n );\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 const radius = nodeRadiusGetter({\n radiusFlexible: this.nodeSettings.nodeRadiusFlexible,\n radiusInitial: nodeOptions.radius,\n linkCount: node.linkCount,\n radiusIncrementByStep: this.nodeSettings.nodeRadiusIncrementByStep,\n radiusLinkCountForStep: this.nodeSettings.nodeRadiusLinkCountForStep,\n radiusMaxLinearSteps: this.nodeSettings.nodeRadiusMaxLinearSteps,\n radiusLogFactor: this.nodeSettings.nodeRadiusLogFactor,\n radiusLinkCountDividerForLog: this.nodeSettings.nodeRadiusLinkCountDividerForLog,\n });\n\n return radius + this.forceSettings.collideAdditionalRadius;\n }\n case \"square\": {\n const { height, width } = nodeSizeGetter({\n heightInitial: nodeOptions.width,\n widthInitial: nodeOptions.height,\n linkCount: node.linkCount,\n sizeFlexible: this.nodeSettings.nodeSizeFlexible,\n sizeIncrementByStep: this.nodeSettings.nodeSizeIncrementByStep,\n sizeLinkCountForStep: this.nodeSettings.nodeSizeLinkCountForStep,\n sizeMaxLinearSteps: this.nodeSettings.nodeSizeMaxLinearSteps,\n sizeLogFactor: this.nodeSettings.nodeSizeLogFactor,\n sizeLinkCountDividerForLog: this.nodeSettings.nodeSizeLinkCountDividerForLog,\n });\n\n return (\n Math.sqrt(width ** 2 + height ** 2) / 2 +\n this.forceSettings.collideAdditionalRadius\n );\n }\n case \"text\": {\n let { height, width } = nodeSizeGetter({\n heightInitial: nodeOptions.width,\n widthInitial: nodeOptions.height,\n linkCount: node.linkCount,\n sizeFlexible: this.nodeSettings.nodeSizeFlexible,\n sizeIncrementByStep: this.nodeSettings.nodeSizeIncrementByStep,\n sizeLinkCountForStep: this.nodeSettings.nodeSizeLinkCountForStep,\n sizeMaxLinearSteps: this.nodeSettings.nodeSizeMaxLinearSteps,\n sizeLogFactor: this.nodeSettings.nodeSizeLogFactor,\n sizeLinkCountDividerForLog: this.nodeSettings.nodeSizeLinkCountDividerForLog,\n });\n\n if (this.context && nodeOptions.text) {\n const textInfo = getTextLines({\n context: this.context,\n text: nodeOptions.text,\n textAlign: nodeOptions.textAlign,\n textColor: nodeOptions.textColor,\n textFont: nodeOptions.textFont,\n textSize: nodeOptions.textSize,\n maxWidth: width,\n textStyle: nodeOptions.textStyle,\n textWeight: nodeOptions.textWeight,\n });\n\n height =\n textInfo.lines.length * nodeOptions.textSize +\n (textInfo.lines.length - 1) * nodeOptions.textGap +\n nodeOptions.labelYPadding;\n width = textInfo.currentMaxSize + nodeOptions.labelXPadding;\n }\n\n return (\n Math.sqrt(width ** 2 + 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 const radius = nodeRadiusGetter({\n radiusFlexible: this.nodeSettings.nodeRadiusFlexible,\n radiusInitial: nodeOptions.radius,\n radiusIncrementByStep: this.nodeSettings.nodeRadiusIncrementByStep,\n radiusLinkCountForStep: this.nodeSettings.nodeRadiusLinkCountForStep,\n radiusMaxLinearSteps: this.nodeSettings.nodeRadiusMaxLinearSteps,\n radiusLogFactor: this.nodeSettings.nodeRadiusLogFactor,\n radiusLinkCountDividerForLog: this.nodeSettings.nodeRadiusLinkCountDividerForLog,\n linkCount: node.linkCount,\n });\n\n return radius + this.forceSettings.collideAdditionalRadius;\n }\n }\n })\n .strength(this.forceSettings.collideStrength)\n .iterations(this.forceSettings.collideIterations),\n );\n }\n }\n}\n"],"names":[],"mappings":";;;;;;;;SAqBgB,cAAc,GAAA;AAI5B,IAAA,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE;AACpB,QAAA,IAAI,CAAC,UAAU,GAAG,eAAe;AAC9B,aAAA,KAAK,CAAC,IAAI,CAAC,KAAK;aAChB,KAAK,CACJ,MAAM,EACN,SAAS,CAA6D,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAClF,IAAI,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ers';
|
|
2
2
|
import { select } from 'd3-selection';
|
|
3
3
|
import { zoom, ZoomTransform } from 'd3-zoom';
|
|
4
|
+
import { updateLinkCache } from './update-link-cache.js';
|
|
5
|
+
import { updateNodeCache } from './update-node-cache.js';
|
|
4
6
|
|
|
5
7
|
function initZoom(currentZoom) {
|
|
6
8
|
if (!this.area)
|
|
@@ -10,8 +12,8 @@ function initZoom(currentZoom) {
|
|
|
10
12
|
.on("zoom", (event) => {
|
|
11
13
|
this.listeners.onZoom?.call?.(this, event);
|
|
12
14
|
this.areaTransform = event.transform;
|
|
13
|
-
this
|
|
14
|
-
this
|
|
15
|
+
updateLinkCache.call(this);
|
|
16
|
+
updateNodeCache.call(this);
|
|
15
17
|
if (!this.simulationWorking && !this.highlightWorking)
|
|
16
18
|
requestAnimationFrame(() => this.draw());
|
|
17
19
|
});
|
|
@@ -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\";\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
|
|
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,EAA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I,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;;;;"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { linkOptionsGetter } from '../lib/settings/link-settings-getter.js';
|
|
2
|
+
import '@krainovsd/js-helpers';
|
|
3
|
+
import { linkIterationExtractor } from '../lib/utils/link-iteration-extractor.js';
|
|
4
|
+
import 'd3-array';
|
|
5
|
+
import { extractLinkPointIds } from '../lib/utils/extract-link-point-ids.js';
|
|
6
|
+
|
|
7
|
+
function updateLinkCache() {
|
|
8
|
+
this.linkOptionsCache = {};
|
|
9
|
+
for (let i = 0; i < this.links.length; i++) {
|
|
10
|
+
const link = this.links[i];
|
|
11
|
+
const { sourceId, targetId } = extractLinkPointIds(link);
|
|
12
|
+
const linkOptions = linkIterationExtractor(link, i, this.links, this, this.linkSettings.options ?? {}, linkOptionsGetter);
|
|
13
|
+
const id = `${targetId}${sourceId}`;
|
|
14
|
+
this.linkOptionsCache[id] = linkOptions;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export { updateLinkCache };
|
|
19
|
+
//# sourceMappingURL=update-link-cache.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"update-link-cache.js","sources":["../../../../../src/module/GraphCanvas/slices/update-link-cache.ts"],"sourcesContent":["import type { GraphCanvas } from \"../GraphCanvas\";\nimport { extractLinkPointIds, linkIterationExtractor, linkOptionsGetter } from \"../lib\";\n\nexport function updateLinkCache<\n NodeData extends Record<string, unknown>,\n LinkData extends Record<string, unknown>,\n>(this: GraphCanvas<NodeData, LinkData>) {\n this.linkOptionsCache = {};\n\n for (let i = 0; i < this.links.length; i++) {\n const link = this.links[i];\n const { sourceId, targetId } = extractLinkPointIds(link);\n\n const linkOptions = linkIterationExtractor(\n link,\n i,\n this.links,\n this,\n this.linkSettings.options ?? {},\n linkOptionsGetter,\n );\n const id = `${targetId}${sourceId}`;\n this.linkOptionsCache[id] = linkOptions;\n }\n}\n"],"names":[],"mappings":";;;;;;SAGgB,eAAe,GAAA;AAI7B,IAAA,IAAI,CAAC,gBAAgB,GAAG,EAAE;AAE1B,IAAA,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;QAC1C,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;QAC1B,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,GAAG,mBAAmB,CAAC,IAAI,CAAC;QAExD,MAAM,WAAW,GAAG,sBAAsB,CACxC,IAAI,EACJ,CAAC,EACD,IAAI,CAAC,KAAK,EACV,IAAI,EACJ,IAAI,CAAC,YAAY,CAAC,OAAO,IAAI,EAAE,EAC/B,iBAAiB,CAClB;AACD,QAAA,MAAM,EAAE,GAAG,CAAA,EAAG,QAAQ,CAAG,EAAA,QAAQ,EAAE;AACnC,QAAA,IAAI,CAAC,gBAAgB,CAAC,EAAE,CAAC,GAAG,WAAW;;AAE3C;;;;"}
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { nodeOptionsGetter, nodeRadiusGetter, nodeSizeGetter } from '../lib/settings/node-settings-getter.js';
|
|
2
|
+
import '@krainovsd/js-helpers';
|
|
3
|
+
import 'd3-array';
|
|
4
|
+
import { nodeIterationExtractor } from '../lib/utils/node-iteration-extractor.js';
|
|
5
|
+
import { getTextLines } from './draw-text.js';
|
|
6
|
+
|
|
7
|
+
function updateNodeCache() {
|
|
8
|
+
this.nodeOptionsCache = {};
|
|
9
|
+
if (!this.context)
|
|
10
|
+
return;
|
|
11
|
+
for (let i = 0; i < this.nodes.length; i++) {
|
|
12
|
+
const node = this.nodes[i];
|
|
13
|
+
const nodeOptions = nodeIterationExtractor(node, i, this.nodes, this, this.nodeSettings.options ?? {}, nodeOptionsGetter);
|
|
14
|
+
const radius = nodeOptions.shape === "circle"
|
|
15
|
+
? nodeRadiusGetter({
|
|
16
|
+
radiusFlexible: this.nodeSettings.nodeRadiusFlexible,
|
|
17
|
+
radiusInitial: nodeOptions.radius,
|
|
18
|
+
radiusIncrementByStep: this.nodeSettings.nodeRadiusIncrementByStep,
|
|
19
|
+
radiusLinkCountForStep: this.nodeSettings.nodeRadiusLinkCountForStep,
|
|
20
|
+
radiusMaxLinearSteps: this.nodeSettings.nodeRadiusMaxLinearSteps,
|
|
21
|
+
radiusLogFactor: this.nodeSettings.nodeRadiusLogFactor,
|
|
22
|
+
radiusLinkCountDividerForLog: this.nodeSettings.nodeRadiusLinkCountDividerForLog,
|
|
23
|
+
linkCount: node.linkCount,
|
|
24
|
+
})
|
|
25
|
+
: nodeOptions.radius;
|
|
26
|
+
let width = nodeOptions.width;
|
|
27
|
+
let height = nodeOptions.height;
|
|
28
|
+
let labelSize = nodeOptions.labelSize;
|
|
29
|
+
if (nodeOptions.shape === "square") {
|
|
30
|
+
const size = nodeSizeGetter({
|
|
31
|
+
heightInitial: nodeOptions.height,
|
|
32
|
+
widthInitial: nodeOptions.width,
|
|
33
|
+
linkCount: node.linkCount,
|
|
34
|
+
sizeFlexible: this.nodeSettings.nodeSizeFlexible,
|
|
35
|
+
sizeIncrementByStep: this.nodeSettings.nodeSizeIncrementByStep,
|
|
36
|
+
sizeLinkCountForStep: this.nodeSettings.nodeSizeLinkCountForStep,
|
|
37
|
+
sizeMaxLinearSteps: this.nodeSettings.nodeSizeMaxLinearSteps,
|
|
38
|
+
sizeLogFactor: this.nodeSettings.nodeSizeLogFactor,
|
|
39
|
+
sizeLinkCountDividerForLog: this.nodeSettings.nodeSizeLinkCountDividerForLog,
|
|
40
|
+
});
|
|
41
|
+
width = size.width;
|
|
42
|
+
height = size.height;
|
|
43
|
+
}
|
|
44
|
+
if (nodeOptions.shape === "text") {
|
|
45
|
+
width = nodeOptions.width;
|
|
46
|
+
const size = nodeSizeGetter({
|
|
47
|
+
heightInitial: nodeOptions.height,
|
|
48
|
+
widthInitial: width,
|
|
49
|
+
linkCount: node.linkCount,
|
|
50
|
+
sizeFlexible: this.nodeSettings.nodeSizeFlexible,
|
|
51
|
+
sizeIncrementByStep: this.nodeSettings.nodeSizeIncrementByStep,
|
|
52
|
+
sizeLinkCountForStep: this.nodeSettings.nodeSizeLinkCountForStep,
|
|
53
|
+
sizeMaxLinearSteps: this.nodeSettings.nodeSizeMaxLinearSteps,
|
|
54
|
+
sizeLogFactor: this.nodeSettings.nodeSizeLogFactor,
|
|
55
|
+
sizeLinkCountDividerForLog: this.nodeSettings.nodeSizeLinkCountDividerForLog,
|
|
56
|
+
});
|
|
57
|
+
labelSize *= size.additionalSizeCoefficient;
|
|
58
|
+
}
|
|
59
|
+
/** label in not text shape */
|
|
60
|
+
if (nodeOptions.shape !== "text" && nodeOptions.label) {
|
|
61
|
+
this.context.font = `${nodeOptions.labelStyle} normal ${nodeOptions.labelWeight} ${nodeOptions.labelSize}px ${nodeOptions.labelFont}`;
|
|
62
|
+
this.context.fillStyle = nodeOptions.labelColor;
|
|
63
|
+
this.context.textAlign = nodeOptions.labelAlign;
|
|
64
|
+
if (nodeOptions.labelWidth == undefined ||
|
|
65
|
+
this.context.measureText(nodeOptions.label).width <= nodeOptions.labelWidth) {
|
|
66
|
+
this.cachedNodeLabel[node.id] = [nodeOptions.label];
|
|
67
|
+
}
|
|
68
|
+
const { lines } = getTextLines({
|
|
69
|
+
context: this.context,
|
|
70
|
+
maxWidth: nodeOptions.labelWidth,
|
|
71
|
+
text: nodeOptions.label,
|
|
72
|
+
textAlign: nodeOptions.labelAlign,
|
|
73
|
+
textColor: nodeOptions.labelColor,
|
|
74
|
+
textFont: nodeOptions.labelFont,
|
|
75
|
+
textSize: nodeOptions.labelSize,
|
|
76
|
+
textStyle: nodeOptions.labelStyle,
|
|
77
|
+
textWeight: nodeOptions.labelWeight,
|
|
78
|
+
});
|
|
79
|
+
this.cachedNodeLabel[node.id] = lines;
|
|
80
|
+
}
|
|
81
|
+
/** label in text shape */
|
|
82
|
+
if (nodeOptions.shape === "text" && nodeOptions.label) {
|
|
83
|
+
const textInfo = getTextLines({
|
|
84
|
+
context: this.context,
|
|
85
|
+
text: nodeOptions.label,
|
|
86
|
+
textAlign: nodeOptions.labelAlign,
|
|
87
|
+
textColor: nodeOptions.labelColor,
|
|
88
|
+
textFont: nodeOptions.labelFont,
|
|
89
|
+
textSize: labelSize,
|
|
90
|
+
maxWidth: nodeOptions.labelWidth,
|
|
91
|
+
textStyle: nodeOptions.labelStyle,
|
|
92
|
+
textWeight: nodeOptions.textWeight,
|
|
93
|
+
});
|
|
94
|
+
const textNodeParameters = [textInfo.currentMaxSize, labelSize];
|
|
95
|
+
const lines = textInfo.lines;
|
|
96
|
+
const textSizeCoefficient = labelSize / textNodeParameters[1];
|
|
97
|
+
const maxSize = textNodeParameters[0] * textSizeCoefficient;
|
|
98
|
+
height =
|
|
99
|
+
lines.length * labelSize +
|
|
100
|
+
(lines.length - 1) * nodeOptions.labelGap +
|
|
101
|
+
nodeOptions.labelYPadding;
|
|
102
|
+
width = maxSize + nodeOptions.labelXPadding;
|
|
103
|
+
this.cachedNodeLabel[node.id] = lines;
|
|
104
|
+
}
|
|
105
|
+
nodeOptions.width = width;
|
|
106
|
+
nodeOptions.height = height;
|
|
107
|
+
nodeOptions.radius = radius;
|
|
108
|
+
nodeOptions.labelSize = labelSize;
|
|
109
|
+
/** text */
|
|
110
|
+
if (nodeOptions.text) {
|
|
111
|
+
this.context.font = `${nodeOptions.textStyle} normal ${nodeOptions.textWeight} ${nodeOptions.textSize}px ${nodeOptions.textFont}`;
|
|
112
|
+
this.context.fillStyle = nodeOptions.textColor;
|
|
113
|
+
this.context.textAlign = nodeOptions.textAlign;
|
|
114
|
+
if (nodeOptions.textWidth == undefined ||
|
|
115
|
+
this.context.measureText(nodeOptions.text).width <= nodeOptions.textWidth) {
|
|
116
|
+
this.cachedNodeText[node.id] = [nodeOptions.text];
|
|
117
|
+
}
|
|
118
|
+
const { lines } = getTextLines({
|
|
119
|
+
context: this.context,
|
|
120
|
+
maxWidth: nodeOptions.textWidth,
|
|
121
|
+
text: nodeOptions.text,
|
|
122
|
+
textAlign: nodeOptions.textAlign,
|
|
123
|
+
textColor: nodeOptions.textColor,
|
|
124
|
+
textFont: nodeOptions.textFont,
|
|
125
|
+
textSize: nodeOptions.textSize,
|
|
126
|
+
textStyle: nodeOptions.textStyle,
|
|
127
|
+
textWeight: nodeOptions.textWeight,
|
|
128
|
+
});
|
|
129
|
+
this.cachedNodeText[node.id] = lines;
|
|
130
|
+
}
|
|
131
|
+
this.nodeOptionsCache[node.id] = nodeOptions;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export { updateNodeCache };
|
|
136
|
+
//# sourceMappingURL=update-node-cache.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"update-node-cache.js","sources":["../../../../../src/module/GraphCanvas/slices/update-node-cache.ts"],"sourcesContent":["import type { GraphCanvas } from \"../GraphCanvas\";\nimport {\n nodeIterationExtractor,\n nodeOptionsGetter,\n nodeRadiusGetter,\n nodeSizeGetter,\n} from \"../lib\";\nimport { getTextLines } from \"./draw-text\";\n\nexport function updateNodeCache<\n NodeData extends Record<string, unknown>,\n LinkData extends Record<string, unknown>,\n>(this: GraphCanvas<NodeData, LinkData>) {\n this.nodeOptionsCache = {};\n if (!this.context) return;\n\n for (let i = 0; i < this.nodes.length; i++) {\n const node = this.nodes[i];\n const nodeOptions = nodeIterationExtractor(\n node,\n i,\n this.nodes,\n this,\n this.nodeSettings.options ?? {},\n nodeOptionsGetter,\n );\n const radius =\n nodeOptions.shape === \"circle\"\n ? nodeRadiusGetter({\n radiusFlexible: this.nodeSettings.nodeRadiusFlexible,\n radiusInitial: nodeOptions.radius,\n radiusIncrementByStep: this.nodeSettings.nodeRadiusIncrementByStep,\n radiusLinkCountForStep: this.nodeSettings.nodeRadiusLinkCountForStep,\n radiusMaxLinearSteps: this.nodeSettings.nodeRadiusMaxLinearSteps,\n radiusLogFactor: this.nodeSettings.nodeRadiusLogFactor,\n radiusLinkCountDividerForLog: this.nodeSettings.nodeRadiusLinkCountDividerForLog,\n linkCount: node.linkCount,\n })\n : nodeOptions.radius;\n\n let width = nodeOptions.width;\n let height = nodeOptions.height;\n let labelSize = nodeOptions.labelSize;\n if (nodeOptions.shape === \"square\") {\n const size = nodeSizeGetter({\n heightInitial: nodeOptions.height,\n widthInitial: nodeOptions.width,\n linkCount: node.linkCount,\n sizeFlexible: this.nodeSettings.nodeSizeFlexible,\n sizeIncrementByStep: this.nodeSettings.nodeSizeIncrementByStep,\n sizeLinkCountForStep: this.nodeSettings.nodeSizeLinkCountForStep,\n sizeMaxLinearSteps: this.nodeSettings.nodeSizeMaxLinearSteps,\n sizeLogFactor: this.nodeSettings.nodeSizeLogFactor,\n sizeLinkCountDividerForLog: this.nodeSettings.nodeSizeLinkCountDividerForLog,\n });\n width = size.width;\n height = size.height;\n }\n if (nodeOptions.shape === \"text\") {\n width = nodeOptions.width;\n const size = nodeSizeGetter({\n heightInitial: nodeOptions.height,\n widthInitial: width,\n linkCount: node.linkCount,\n sizeFlexible: this.nodeSettings.nodeSizeFlexible,\n sizeIncrementByStep: this.nodeSettings.nodeSizeIncrementByStep,\n sizeLinkCountForStep: this.nodeSettings.nodeSizeLinkCountForStep,\n sizeMaxLinearSteps: this.nodeSettings.nodeSizeMaxLinearSteps,\n sizeLogFactor: this.nodeSettings.nodeSizeLogFactor,\n sizeLinkCountDividerForLog: this.nodeSettings.nodeSizeLinkCountDividerForLog,\n });\n\n labelSize *= size.additionalSizeCoefficient;\n }\n /** label in not text shape */\n if (nodeOptions.shape !== \"text\" && nodeOptions.label) {\n this.context.font = `${nodeOptions.labelStyle} normal ${nodeOptions.labelWeight} ${nodeOptions.labelSize}px ${nodeOptions.labelFont}`;\n this.context.fillStyle = nodeOptions.labelColor;\n this.context.textAlign = nodeOptions.labelAlign;\n\n if (\n nodeOptions.labelWidth == undefined ||\n this.context.measureText(nodeOptions.label).width <= nodeOptions.labelWidth\n ) {\n this.cachedNodeLabel[node.id] = [nodeOptions.label];\n }\n\n const { lines } = getTextLines({\n context: this.context,\n maxWidth: nodeOptions.labelWidth,\n text: nodeOptions.label,\n textAlign: nodeOptions.labelAlign,\n textColor: nodeOptions.labelColor,\n textFont: nodeOptions.labelFont,\n textSize: nodeOptions.labelSize,\n textStyle: nodeOptions.labelStyle,\n textWeight: nodeOptions.labelWeight,\n });\n this.cachedNodeLabel[node.id] = lines;\n }\n /** label in text shape */\n if (nodeOptions.shape === \"text\" && nodeOptions.label) {\n const textInfo = getTextLines({\n context: this.context,\n text: nodeOptions.label,\n textAlign: nodeOptions.labelAlign,\n textColor: nodeOptions.labelColor,\n textFont: nodeOptions.labelFont,\n textSize: labelSize,\n maxWidth: nodeOptions.labelWidth,\n textStyle: nodeOptions.labelStyle,\n textWeight: nodeOptions.textWeight,\n });\n const textNodeParameters = [textInfo.currentMaxSize, labelSize];\n const lines = textInfo.lines;\n const textSizeCoefficient = labelSize / textNodeParameters[1];\n const maxSize = textNodeParameters[0] * textSizeCoefficient;\n\n height =\n lines.length * labelSize +\n (lines.length - 1) * nodeOptions.labelGap +\n nodeOptions.labelYPadding;\n\n width = maxSize + nodeOptions.labelXPadding;\n this.cachedNodeLabel[node.id] = lines;\n }\n\n nodeOptions.width = width;\n nodeOptions.height = height;\n nodeOptions.radius = radius;\n nodeOptions.labelSize = labelSize;\n\n /** text */\n if (nodeOptions.text) {\n this.context.font = `${nodeOptions.textStyle} normal ${nodeOptions.textWeight} ${nodeOptions.textSize}px ${nodeOptions.textFont}`;\n this.context.fillStyle = nodeOptions.textColor;\n this.context.textAlign = nodeOptions.textAlign;\n\n if (\n nodeOptions.textWidth == undefined ||\n this.context.measureText(nodeOptions.text).width <= nodeOptions.textWidth\n ) {\n this.cachedNodeText[node.id] = [nodeOptions.text];\n }\n\n const { lines } = getTextLines({\n context: this.context,\n maxWidth: nodeOptions.textWidth,\n text: nodeOptions.text,\n textAlign: nodeOptions.textAlign,\n textColor: nodeOptions.textColor,\n textFont: nodeOptions.textFont,\n textSize: nodeOptions.textSize,\n textStyle: nodeOptions.textStyle,\n textWeight: nodeOptions.textWeight,\n });\n this.cachedNodeText[node.id] = lines;\n }\n\n this.nodeOptionsCache[node.id] = nodeOptions;\n }\n}\n"],"names":[],"mappings":";;;;;;SASgB,eAAe,GAAA;AAI7B,IAAA,IAAI,CAAC,gBAAgB,GAAG,EAAE;IAC1B,IAAI,CAAC,IAAI,CAAC,OAAO;QAAE;AAEnB,IAAA,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;QAC1C,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;QAC1B,MAAM,WAAW,GAAG,sBAAsB,CACxC,IAAI,EACJ,CAAC,EACD,IAAI,CAAC,KAAK,EACV,IAAI,EACJ,IAAI,CAAC,YAAY,CAAC,OAAO,IAAI,EAAE,EAC/B,iBAAiB,CAClB;AACD,QAAA,MAAM,MAAM,GACV,WAAW,CAAC,KAAK,KAAK;cAClB,gBAAgB,CAAC;AACf,gBAAA,cAAc,EAAE,I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CAAC,SAAS;gBAC/B,IAAI,EAAE,WAAW,CAAC,IAAI;gBACtB,SAAS,EAAE,WAAW,CAAC,SAAS;gBAChC,SAAS,EAAE,WAAW,CAAC,SAAS;gBAChC,QAAQ,EAAE,WAAW,CAAC,QAAQ;gBAC9B,QAAQ,EAAE,WAAW,CAAC,QAAQ;gBAC9B,SAAS,EAAE,WAAW,CAAC,SAAS;gBAChC,UAAU,EAAE,WAAW,CAAC,UAAU;AACnC,aAAA,CAAC;YACF,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,EAAE,CAAC,GAAG,KAAK;;QAGtC,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,EAAE,CAAC,GAAG,WAAW;;AAEhD;;;;"}
|
package/lib/index.d.ts
CHANGED
|
@@ -25,12 +25,6 @@ interface NodeInterface<NodeData extends Record<string, unknown>> extends Simula
|
|
|
25
25
|
type NodeShape = "circle" | "square" | "text";
|
|
26
26
|
type TextStyleEnum = "normal" | "italic" | "oblique";
|
|
27
27
|
type CachedNodeTextInterface = Record<string | number, string[] | undefined>;
|
|
28
|
-
type CachedTextNodeParametersMap = Record<string | number, [number, number] | undefined>;
|
|
29
|
-
/**
|
|
30
|
-
* 1. Initial max size of text
|
|
31
|
-
* 2. Initial size of text
|
|
32
|
-
*/
|
|
33
|
-
type CachedTextNodeParametersInterface = [number, number];
|
|
34
28
|
|
|
35
29
|
interface LinkInterface<NodeData extends Record<string, unknown>, LinkData extends Record<string, unknown>> extends SimulationLinkDatum<NodeInterface<NodeData>> {
|
|
36
30
|
data?: LinkData;
|
|
@@ -177,7 +171,6 @@ type HighlightByLinkForArrowSettingsInterface = {
|
|
|
177
171
|
};
|
|
178
172
|
|
|
179
173
|
type LinkSettingsInterface<NodeData extends Record<string, unknown>, LinkData extends Record<string, unknown>> = {
|
|
180
|
-
cacheOptions?: boolean;
|
|
181
174
|
prettyDraw?: boolean;
|
|
182
175
|
arrow?: boolean;
|
|
183
176
|
arrowByHighlight?: boolean;
|
|
@@ -236,13 +229,18 @@ type ListenersInterface<NodeData extends Record<string, unknown>, LinkData exten
|
|
|
236
229
|
};
|
|
237
230
|
|
|
238
231
|
type NodeSettingsInterface<NodeData extends Record<string, unknown>, LinkData extends Record<string, unknown>> = {
|
|
239
|
-
cacheOptions?: boolean;
|
|
240
232
|
nodeRadiusFlexible?: boolean;
|
|
241
|
-
|
|
242
|
-
|
|
233
|
+
nodeRadiusLinkCountForStep?: number;
|
|
234
|
+
nodeRadiusIncrementByStep?: number;
|
|
235
|
+
nodeRadiusMaxLinearSteps?: number;
|
|
236
|
+
nodeRadiusLogFactor?: number;
|
|
237
|
+
nodeRadiusLinkCountDividerForLog?: number;
|
|
243
238
|
nodeSizeFlexible?: boolean;
|
|
244
|
-
|
|
245
|
-
|
|
239
|
+
nodeSizeLinkCountForStep?: number;
|
|
240
|
+
nodeSizeIncrementByStep?: number;
|
|
241
|
+
nodeSizeMaxLinearSteps?: number;
|
|
242
|
+
nodeSizeLogFactor?: number;
|
|
243
|
+
nodeSizeLinkCountDividerForLog?: number;
|
|
246
244
|
textNodeDebug?: boolean;
|
|
247
245
|
textScaleMin?: number;
|
|
248
246
|
textScaleMax?: number;
|
|
@@ -339,7 +337,6 @@ declare class GraphCanvas<NodeData extends Record<string, unknown>, LinkData ext
|
|
|
339
337
|
protected eventAbortController: AbortController;
|
|
340
338
|
protected cachedNodeText: CachedNodeTextInterface;
|
|
341
339
|
protected cachedNodeLabel: CachedNodeTextInterface;
|
|
342
|
-
protected cachedTextNodeParameters: CachedTextNodeParametersMap;
|
|
343
340
|
protected linkOptionsCache: Record<string, Required<LinkOptionsInterface<NodeData, LinkData>>>;
|
|
344
341
|
protected nodeOptionsCache: Record<string, Required<NodeOptionsInterface<NodeData, LinkData>>>;
|
|
345
342
|
protected isDragging: boolean;
|
|
@@ -356,7 +353,7 @@ declare class GraphCanvas<NodeData extends Record<string, unknown>, LinkData ext
|
|
|
356
353
|
changeSettings(options: Omit<Partial<GraphCanvasInterface<NodeData, LinkData>>, "links" | "nodes" | "listeners">, clearCache?: boolean): undefined;
|
|
357
354
|
updateRect(): void;
|
|
358
355
|
updateSize(): void;
|
|
359
|
-
clearCache(keys?: ("nodeOptionsCache" | "linkOptionsCache"
|
|
356
|
+
clearCache(keys?: ("nodeOptionsCache" | "linkOptionsCache")[]): void;
|
|
360
357
|
tick(): void;
|
|
361
358
|
restart(alpha?: number): void;
|
|
362
359
|
start(): void;
|
|
@@ -388,20 +385,26 @@ declare function nodeTextSizeGetter<NodeData extends Record<string, unknown>, Li
|
|
|
388
385
|
type NodeRadiusGetterOptions = {
|
|
389
386
|
linkCount: number | undefined;
|
|
390
387
|
radiusFlexible: boolean;
|
|
391
|
-
radiusCoefficient: number;
|
|
392
|
-
radiusFactor: number;
|
|
393
388
|
radiusInitial: number;
|
|
389
|
+
radiusLinkCountForStep: number;
|
|
390
|
+
radiusIncrementByStep: number;
|
|
391
|
+
radiusMaxLinearSteps: number;
|
|
392
|
+
radiusLogFactor: number;
|
|
393
|
+
radiusLinkCountDividerForLog: number;
|
|
394
394
|
};
|
|
395
|
-
declare function nodeRadiusGetter({ radiusFlexible, radiusInitial,
|
|
395
|
+
declare function nodeRadiusGetter({ radiusFlexible, linkCount, radiusInitial, radiusIncrementByStep, radiusLinkCountDividerForLog, radiusLinkCountForStep, radiusLogFactor, radiusMaxLinearSteps, }: NodeRadiusGetterOptions): number;
|
|
396
396
|
type NodeSizeGetterOptions = {
|
|
397
397
|
linkCount: number | undefined;
|
|
398
398
|
sizeFlexible: boolean;
|
|
399
|
-
sizeCoefficient: number;
|
|
400
|
-
sizeFactor: number;
|
|
401
399
|
widthInitial: number;
|
|
402
400
|
heightInitial: number;
|
|
401
|
+
sizeLinkCountForStep: number;
|
|
402
|
+
sizeIncrementByStep: number;
|
|
403
|
+
sizeMaxLinearSteps: number;
|
|
404
|
+
sizeLogFactor: number;
|
|
405
|
+
sizeLinkCountDividerForLog: number;
|
|
403
406
|
};
|
|
404
|
-
declare function nodeSizeGetter({ heightInitial, linkCount,
|
|
407
|
+
declare function nodeSizeGetter({ heightInitial, linkCount, sizeFlexible, widthInitial, sizeIncrementByStep, sizeLinkCountDividerForLog, sizeLinkCountForStep, sizeLogFactor, sizeMaxLinearSteps, }: NodeSizeGetterOptions): {
|
|
405
408
|
width: number;
|
|
406
409
|
height: number;
|
|
407
410
|
additionalSizeCoefficient: number;
|
|
@@ -553,15 +556,14 @@ declare function extractLinkPointIds<NodeData extends Record<string, unknown>, L
|
|
|
553
556
|
targetId: string | number;
|
|
554
557
|
};
|
|
555
558
|
|
|
556
|
-
declare function getDrawLink<NodeData extends Record<string, unknown>, LinkData extends Record<string, unknown>>(): (this: GraphCanvas<NodeData, LinkData>, link: LinkInterface<NodeData, LinkData
|
|
559
|
+
declare function getDrawLink<NodeData extends Record<string, unknown>, LinkData extends Record<string, unknown>>(): (this: GraphCanvas<NodeData, LinkData>, link: LinkInterface<NodeData, LinkData>) => void;
|
|
557
560
|
|
|
558
|
-
declare function getDrawNode<NodeData extends Record<string, unknown>, LinkData extends Record<string, unknown>>(nodeRenders: (() => void)[], textRenders: (() => void)[]): (this: GraphCanvas<NodeData, LinkData>, node: NodeInterface<NodeData
|
|
561
|
+
declare function getDrawNode<NodeData extends Record<string, unknown>, LinkData extends Record<string, unknown>>(nodeRenders: (() => void)[], textRenders: (() => void)[]): (this: GraphCanvas<NodeData, LinkData>, node: NodeInterface<NodeData>) => void;
|
|
559
562
|
|
|
560
563
|
type DrawTextOptions = {
|
|
561
|
-
|
|
564
|
+
lines: string[];
|
|
562
565
|
x: number;
|
|
563
566
|
y: number;
|
|
564
|
-
text: string;
|
|
565
567
|
textSize: number;
|
|
566
568
|
textStyle: TextStyleEnum;
|
|
567
569
|
textWeight: number;
|
|
@@ -570,10 +572,8 @@ type DrawTextOptions = {
|
|
|
570
572
|
textGap: number;
|
|
571
573
|
textAlign: CanvasTextAlign;
|
|
572
574
|
context: CanvasRenderingContext2D;
|
|
573
|
-
cachedNodeText: CachedNodeTextInterface;
|
|
574
|
-
maxWidth?: number;
|
|
575
575
|
};
|
|
576
|
-
declare function drawText({ context,
|
|
576
|
+
declare function drawText({ context, textAlign, textColor, textFont, textStyle, textGap, textWeight, textSize, x, y, lines, }: DrawTextOptions): void;
|
|
577
577
|
|
|
578
578
|
declare const COMMON_SETTINGS: {
|
|
579
579
|
nodeRadius: number;
|
|
@@ -674,4 +674,4 @@ declare const NODE_OPTIONS_TEXT_CONTROLS: GraphSettingsInputInterface<keyof Node
|
|
|
674
674
|
declare const NODE_OPTIONS_LABEL_CONTROLS: GraphSettingsInputInterface<keyof NodeOptionsLabelInterface>[];
|
|
675
675
|
|
|
676
676
|
export { COMMON_SETTINGS, FORCE_CONTROLS, FORCE_SETTINGS, GRAPH_SETTINGS, GraphCanvas, HIGHLIGHT_BY_LINK_FOR_ARROW_CONTROLS, HIGHLIGHT_BY_LINK_FOR_LABEL_CONTROLS, HIGHLIGHT_BY_LINK_FOR_LINK_CONTROLS, HIGHLIGHT_BY_LINK_FOR_NODE_CONTROLS, HIGHLIGHT_BY_LINK_FOR_TEXT_CONTROLS, HIGHLIGHT_BY_NODE_FOR_ARROW_CONTROLS, HIGHLIGHT_BY_NODE_FOR_LABEL_CONTROLS, HIGHLIGHT_BY_NODE_FOR_LINK_CONTROLS, HIGHLIGHT_BY_NODE_FOR_NODE_CONTROLS, HIGHLIGHT_BY_NODE_FOR_TEXT_CONTROLS, HIGHLIGHT_COMMON_CONTROLS, HIGHLIGHT_SETTINGS, LINK_OPTIONS, LINK_OPTIONS_ARROW_CONTROLS, LINK_OPTIONS_LINK_CONTROLS, LINK_OPTIONS_PARTICLE_CONTROLS, LINK_SETTINGS, LINK_SETTINGS_CONTROLS, NODE_OPTIONS, NODE_OPTIONS_LABEL_CONTROLS, NODE_OPTIONS_NODE_CONTROLS, NODE_OPTIONS_TEXT_CONTROLS, NODE_SETTINGS, NODE_SETTINGS_CONTROLS, animationByProgress, calculateLinkPositionByNode, colorGetter, colorToRgb, dragPlaceCoefficientGetter, drawText, extractLinkPointIds, extractRgb, fadeRgb, forceSettingsGetter, getDrawLink, getDrawNode, getParticlePosition, graphSettingsGetter, highlightSettingsGetter, isNodeVisible, isOverlapsNode, linkByPointerGetter, linkFade, linkHighlight, linkIterationExtractor, linkOptionsGetter, linkSettingsGetter, listenersGetter, nodeByPointerGetter, nodeFade, nodeHighlight, nodeIdGetter, nodeIterationExtractor, nodeOptionsGetter, nodeRadiusGetter, nodeSettingsGetter, nodeSizeGetter, nodeTextSizeGetter, pointerGetter, rgbAnimationByProgress };
|
|
677
|
-
export type { CachedNodeTextInterface,
|
|
677
|
+
export type { CachedNodeTextInterface, DragEventInterface, ForceSettingsInterface, GraphCanvasInterface, GraphCanvasSimulation, GraphSettingsInputInterface, GraphSettingsInterface, HighlighCommonSettingsInterface, HighlightByLinkForArrowSettingsInterface, HighlightByLinkForLabelSettingsInterface, HighlightByLinkForLinkSettingsInterface, HighlightByLinkForNodeSettingsInterface, HighlightByLinkForTextSettingsInterface, HighlightByNodeForArrowSettingsInterface, HighlightByNodeForLabelSettingsInterface, HighlightByNodeForLinkSettingsInterface, HighlightByNodeForNodeSettingsInterface, HighlightByNodeForTextSettingsInterface, HighlightSettingsInterface, LinkByPointerGetterOptions, LinkInterface, LinkIterationPropsInterface, LinkIterationPropsNoThisInterface, LinkOptionsArrowInterface, LinkOptionsInterface, LinkOptionsLinkInterface, LinkOptionsParticleInterface, LinkParticle, LinkSettingsInterface, ListenersInterface, NodeByPointerGetterOptions, NodeInterface, NodeIterationPropsInterface, NodeIterationPropsNoThisInterface, NodeOptionsInterface, NodeOptionsLabelInterface, NodeOptionsNodeInterface, NodeOptionsTextInterface, NodeRadiusGetterOptions, NodeSettingsInterface, NodeShape, NodeSizeGetterOptions, RGB, TextStyleEnum, ZoomEventInterface };
|