@krainovsd/graph 0.10.0-rc1 → 0.10.0-rc3
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 +80 -45
- package/lib/cjs/index.cjs.map +1 -1
- package/lib/esm/module/GraphCanvas/GraphCanvas.js +5 -7
- package/lib/esm/module/GraphCanvas/GraphCanvas.js.map +1 -1
- package/lib/esm/module/GraphCanvas/constants/settings.js +5 -5
- package/lib/esm/module/GraphCanvas/constants/settings.js.map +1 -1
- package/lib/esm/module/GraphCanvas/lib/settings/node-settings-getter.js +7 -5
- package/lib/esm/module/GraphCanvas/lib/settings/node-settings-getter.js.map +1 -1
- package/lib/esm/module/GraphCanvas/slices/draw-nodes.js +53 -24
- package/lib/esm/module/GraphCanvas/slices/draw-nodes.js.map +1 -1
- package/lib/esm/module/GraphCanvas/slices/draw-text.js +9 -3
- package/lib/esm/module/GraphCanvas/slices/draw-text.js.map +1 -1
- package/lib/esm/module/GraphCanvas/slices/init-simulation.js +1 -1
- package/lib/esm/module/GraphCanvas/slices/init-simulation.js.map +1 -1
- package/lib/index.d.ts +45 -39
- package/package.json +1 -1
|
@@ -14,7 +14,7 @@ function drawText({ context, id, textAlign, textColor, textFont, textStyle, text
|
|
|
14
14
|
context.fillText(text, x, y);
|
|
15
15
|
return;
|
|
16
16
|
}
|
|
17
|
-
const lines = getTextLines({
|
|
17
|
+
const { lines } = getTextLines({
|
|
18
18
|
context,
|
|
19
19
|
maxWidth,
|
|
20
20
|
text,
|
|
@@ -38,6 +38,7 @@ function getTextLines({ context, textAlign, textColor, textFont, textStyle, text
|
|
|
38
38
|
const lines = [];
|
|
39
39
|
let lineWidth = 0;
|
|
40
40
|
let line = "";
|
|
41
|
+
let currentMaxSize = 0;
|
|
41
42
|
for (const word of text.split(" ")) {
|
|
42
43
|
const size = context.measureText(word).width;
|
|
43
44
|
lineWidth += size + spaceWidth;
|
|
@@ -46,7 +47,10 @@ function getTextLines({ context, textAlign, textColor, textFont, textStyle, text
|
|
|
46
47
|
continue;
|
|
47
48
|
}
|
|
48
49
|
if (lineWidth > maxWidth) {
|
|
49
|
-
|
|
50
|
+
const initialSize = lineWidth - size - spaceWidth;
|
|
51
|
+
if (initialSize > currentMaxSize)
|
|
52
|
+
currentMaxSize = initialSize;
|
|
53
|
+
lineWidth = size;
|
|
50
54
|
lines.push(line);
|
|
51
55
|
line = word;
|
|
52
56
|
}
|
|
@@ -57,7 +61,9 @@ function getTextLines({ context, textAlign, textColor, textFont, textStyle, text
|
|
|
57
61
|
}
|
|
58
62
|
if (line !== "")
|
|
59
63
|
lines.push(line);
|
|
60
|
-
|
|
64
|
+
if (lineWidth > currentMaxSize)
|
|
65
|
+
currentMaxSize = lineWidth;
|
|
66
|
+
return { lines, currentMaxSize };
|
|
61
67
|
}
|
|
62
68
|
|
|
63
69
|
export { drawText, getTextLines };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"draw-text.js","sources":["../../../../../src/module/GraphCanvas/slices/draw-text.ts"],"sourcesContent":["import type { CachedNodeTextInterface } from \"@/types\";\nimport type { TextStyleEnum } from \"../types\";\n\nexport type DrawTextOptions = {\n id: string | number;\n x: number;\n y: number;\n text: string;\n textSize: number;\n textStyle: TextStyleEnum;\n textWeight: number;\n textFont: string;\n textColor: string;\n textGap: number;\n textAlign: CanvasTextAlign;\n context: CanvasRenderingContext2D;\n cachedNodeText: CachedNodeTextInterface;\n maxWidth?: number;\n};\n\nconst SPACE = \" \";\n\nexport function drawText({\n context,\n id,\n textAlign,\n textColor,\n textFont,\n textStyle,\n textGap,\n textWeight,\n textSize,\n text,\n x,\n y,\n cachedNodeText,\n maxWidth,\n}: DrawTextOptions) {\n context.font = `${textStyle} normal ${textWeight} ${textSize}px ${textFont}`;\n context.fillStyle = textColor;\n context.textAlign = textAlign;\n\n if (cachedNodeText[id] != undefined) {\n cachedNodeText[id].forEach((line, index) => {\n context.fillText(line, x, y + index * textSize + index * textGap);\n });\n\n return;\n }\n\n if (maxWidth == undefined || context.measureText(text).width <= maxWidth) {\n cachedNodeText[id] = [text];\n context.fillText(text, x, y);\n\n return;\n }\n\n const lines = getTextLines({\n context,\n maxWidth,\n text,\n textAlign,\n textColor,\n textFont,\n textSize,\n textStyle,\n textWeight,\n });\n\n cachedNodeText[id] = lines;\n lines.forEach((line, index) => {\n context.fillText(line, x, y + index * textSize + index * textGap);\n });\n}\n\nexport type GetTextLines = {\n text: string;\n textSize: number;\n textStyle: TextStyleEnum;\n textWeight: number;\n textFont: string;\n textColor: string;\n textAlign: CanvasTextAlign;\n context: CanvasRenderingContext2D;\n maxWidth: number;\n};\nexport function getTextLines({\n context,\n textAlign,\n textColor,\n textFont,\n textStyle,\n textWeight,\n textSize,\n text,\n maxWidth,\n}: GetTextLines) {\n context.font = `${textStyle} normal ${textWeight} ${textSize}px ${textFont}`;\n context.fillStyle = textColor;\n context.textAlign = textAlign;\n\n const spaceWidth = context.measureText(\" \").width;\n const lines: string[] = [];\n let lineWidth = 0;\n let line = \"\";\n\n for (const word of text.split(\" \")) {\n const size = context.measureText(word).width;\n lineWidth += size + spaceWidth;\n\n if (line === \"\") {\n line = word;\n\n continue;\n }\n if (lineWidth > maxWidth) {\n lineWidth =
|
|
1
|
+
{"version":3,"file":"draw-text.js","sources":["../../../../../src/module/GraphCanvas/slices/draw-text.ts"],"sourcesContent":["import type { CachedNodeTextInterface } from \"@/types\";\nimport type { TextStyleEnum } from \"../types\";\n\nexport type DrawTextOptions = {\n id: string | number;\n x: number;\n y: number;\n text: string;\n textSize: number;\n textStyle: TextStyleEnum;\n textWeight: number;\n textFont: string;\n textColor: string;\n textGap: number;\n textAlign: CanvasTextAlign;\n context: CanvasRenderingContext2D;\n cachedNodeText: CachedNodeTextInterface;\n maxWidth?: number;\n};\n\nconst SPACE = \" \";\n\nexport function drawText({\n context,\n id,\n textAlign,\n textColor,\n textFont,\n textStyle,\n textGap,\n textWeight,\n textSize,\n text,\n x,\n y,\n cachedNodeText,\n maxWidth,\n}: DrawTextOptions) {\n context.font = `${textStyle} normal ${textWeight} ${textSize}px ${textFont}`;\n context.fillStyle = textColor;\n context.textAlign = textAlign;\n\n if (cachedNodeText[id] != undefined) {\n cachedNodeText[id].forEach((line, index) => {\n context.fillText(line, x, y + index * textSize + index * textGap);\n });\n\n return;\n }\n\n if (maxWidth == undefined || context.measureText(text).width <= maxWidth) {\n cachedNodeText[id] = [text];\n context.fillText(text, x, y);\n\n return;\n }\n\n const { lines } = getTextLines({\n context,\n maxWidth,\n text,\n textAlign,\n textColor,\n textFont,\n textSize,\n textStyle,\n textWeight,\n });\n\n cachedNodeText[id] = lines;\n lines.forEach((line, index) => {\n context.fillText(line, x, y + index * textSize + index * textGap);\n });\n}\n\nexport type GetTextLines = {\n text: string;\n textSize: number;\n textStyle: TextStyleEnum;\n textWeight: number;\n textFont: string;\n textColor: string;\n textAlign: CanvasTextAlign;\n context: CanvasRenderingContext2D;\n maxWidth: number;\n};\nexport function getTextLines({\n context,\n textAlign,\n textColor,\n textFont,\n textStyle,\n textWeight,\n textSize,\n text,\n maxWidth,\n}: GetTextLines) {\n context.font = `${textStyle} normal ${textWeight} ${textSize}px ${textFont}`;\n context.fillStyle = textColor;\n context.textAlign = textAlign;\n\n const spaceWidth = context.measureText(\" \").width;\n const lines: string[] = [];\n let lineWidth = 0;\n let line = \"\";\n let currentMaxSize = 0;\n\n for (const word of text.split(\" \")) {\n const size = context.measureText(word).width;\n lineWidth += size + spaceWidth;\n\n if (line === \"\") {\n line = word;\n\n continue;\n }\n if (lineWidth > maxWidth) {\n const initialSize = lineWidth - size - spaceWidth;\n if (initialSize > currentMaxSize) currentMaxSize = initialSize;\n\n lineWidth = size;\n lines.push(line);\n line = word;\n } else {\n lineWidth += spaceWidth;\n line += `${SPACE}${word}`;\n }\n }\n\n if (line !== \"\") lines.push(line);\n if (lineWidth > currentMaxSize) currentMaxSize = lineWidth;\n\n return { lines, currentMaxSize };\n}\n"],"names":[],"mappings":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IAAI,CAAC;YAChB,IAAI,GAAG,IAAI;;aACN;YACL,SAAS,IAAI,UAAU;AACvB,YAAA,IAAI,IAAI,CAAG,EAAA,KAAK,CAAG,EAAA,IAAI,EAAE;;;IAI7B,IAAI,IAAI,KAAK,EAAE;AAAE,QAAA,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC;IACjC,IAAI,SAAS,GAAG,cAAc;QAAE,cAAc,GAAG,SAAS;AAE1D,IAAA,OAAO,EAAE,KAAK,EAAE,cAAc,EAAE;AAClC;;;;"}
|
|
@@ -137,7 +137,7 @@ function initCollideForce(forceUpdate) {
|
|
|
137
137
|
maxWidth: width,
|
|
138
138
|
textStyle: nodeOptions.textStyle,
|
|
139
139
|
textWeight: nodeOptions.textWeight,
|
|
140
|
-
});
|
|
140
|
+
}).lines;
|
|
141
141
|
height =
|
|
142
142
|
lines.length * nodeOptions.textSize +
|
|
143
143
|
(lines.length - 1) * nodeOptions.textGap +
|
|
@@ -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 { LinkInterface, NodeInterface } from \"@/types\";\nimport type { GraphCanvas } from \"../GraphCanvas\";\nimport {\n nodeIterationExtractor,\n nodeOptionsGetter,\n nodeRadiusGetter,\n nodeSizeGetter,\n} from \"../lib\";\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,\n ),\n )\n .on(\"tick\", () => {\n this.draw();\n })\n .on(\"end\", () => {\n this.listeners.onSimulationEnd?.(this.state);\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(this.forceSettings.chargeDistanceMax)\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.state,\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.state,\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 lines =\n this.cachedNodeText[node.id] ??\n 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 lines.length * nodeOptions.textSize +\n (lines.length - 1) * nodeOptions.textGap +\n nodeOptions.textNodeYPadding;\n width += nodeOptions.textNodeXPadding;\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.state,\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;AAC9B,aAAA,KAAK,CAAC,IAAI,CAAC,KAAK;AAChB,aAAA,KAAK,CACJ,MAAM,EACN,SAAS,CAA6D,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAClF,IAAI,CAAC,YAAY,CAAC,QAAQ,CAC3B;AAEF,aAAA,EAAE,CAAC,MAAM,EAAE,MAAK;YACf,IAAI,CAAC,IAAI,EAAE;AACb,SAAC;AACA,aAAA,EAAE,CAAC,KAAK,EAAE,MAAK;YACd,IAAI,CAAC,SAAS,CAAC,eAAe,GAAG,IAAI,CAAC,KAAK,CAAC;AAE5C,YAAA,IAAI,IAAI,CAAC,aAAa,CAAC,YAAY,EAAE;AACnC,gBAAA,WAAW,EAAE;;AAEb,gBAAA,OAAO,CAAC,GAAG,CAAC,CAAU,OAAA,EAAA,IAAI,CAAC,KAAK,CAAC,MAAM,CAAA,UAAA,EAAa,IAAI,CAAC,KAAK,CAAC,MAAM,CAAA,CAAE,CAAC;AACxE,gBAAA,aAAa,EAAE;;AAEnB,SAAC,CAAC;AAEJ,QAAA,oBAAoB,CAAC,IAAI,CAIvB,IAAI,CAAC;;AAEX;SAEgB,oBAAoB,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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 { LinkInterface, NodeInterface } from \"@/types\";\nimport type { GraphCanvas } from \"../GraphCanvas\";\nimport {\n nodeIterationExtractor,\n nodeOptionsGetter,\n nodeRadiusGetter,\n nodeSizeGetter,\n} from \"../lib\";\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,\n ),\n )\n .on(\"tick\", () => {\n this.draw();\n })\n .on(\"end\", () => {\n this.listeners.onSimulationEnd?.(this.state);\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(this.forceSettings.chargeDistanceMax)\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.state,\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.state,\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 lines =\n this.cachedNodeText[node.id] ??\n 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 }).lines;\n\n height =\n lines.length * nodeOptions.textSize +\n (lines.length - 1) * nodeOptions.textGap +\n nodeOptions.textNodeYPadding;\n width += nodeOptions.textNodeXPadding;\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.state,\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;AAC9B,aAAA,KAAK,CAAC,IAAI,CAAC,KAAK;AAChB,aAAA,KAAK,CACJ,MAAM,EACN,SAAS,CAA6D,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAClF,IAAI,CAAC,YAAY,CAAC,QAAQ,CAC3B;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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;;;;"}
|
package/lib/index.d.ts
CHANGED
|
@@ -19,11 +19,50 @@ interface NodeInterface<NodeData extends Record<string, unknown>> extends Simula
|
|
|
19
19
|
}
|
|
20
20
|
type NodeShape = "circle" | "square" | "text" | "icon";
|
|
21
21
|
type CachedNodeTextInterface = Record<string | number, string[] | undefined>;
|
|
22
|
+
type CachedTextNodeParametersMap = Record<string | number, [number, number] | undefined>;
|
|
23
|
+
/**
|
|
24
|
+
* 1. Initial max size of text
|
|
25
|
+
* 2. Initial size of text
|
|
26
|
+
*/
|
|
27
|
+
type CachedTextNodeParametersInterface = [number, number];
|
|
22
28
|
|
|
23
29
|
interface LinkInterface<NodeData extends Record<string, unknown>, LinkData extends Record<string, unknown>> extends SimulationLinkDatum<NodeInterface<NodeData>> {
|
|
24
30
|
data?: LinkData;
|
|
25
31
|
}
|
|
26
32
|
|
|
33
|
+
type GraphSettingsInputRange<I extends string> = {
|
|
34
|
+
type: "range";
|
|
35
|
+
min: number;
|
|
36
|
+
max: number;
|
|
37
|
+
step: number;
|
|
38
|
+
initialValue: number;
|
|
39
|
+
id: I;
|
|
40
|
+
label: string;
|
|
41
|
+
};
|
|
42
|
+
type GraphSettingsInputCheckBox<I extends string> = {
|
|
43
|
+
type: "checkbox";
|
|
44
|
+
id: I;
|
|
45
|
+
initialValue: boolean;
|
|
46
|
+
label: string;
|
|
47
|
+
};
|
|
48
|
+
type GraphSettingsInputColorBox<I extends string> = {
|
|
49
|
+
type: "color";
|
|
50
|
+
id: I;
|
|
51
|
+
initialValue: string;
|
|
52
|
+
label: string;
|
|
53
|
+
};
|
|
54
|
+
type GraphSettingsInputSelect<I extends string> = {
|
|
55
|
+
type: "select";
|
|
56
|
+
id: I;
|
|
57
|
+
initialValue: string;
|
|
58
|
+
label: string;
|
|
59
|
+
options: {
|
|
60
|
+
label: string;
|
|
61
|
+
value: string;
|
|
62
|
+
}[];
|
|
63
|
+
};
|
|
64
|
+
type GraphSettingsInputInterface<I extends string> = GraphSettingsInputRange<I> | GraphSettingsInputCheckBox<I> | GraphSettingsInputColorBox<I> | GraphSettingsInputSelect<I>;
|
|
65
|
+
|
|
27
66
|
type ZoomEventInterface = D3ZoomEvent<HTMLCanvasElement, unknown>;
|
|
28
67
|
type DragEventInterface<NodeData extends Record<string, unknown>> = D3DragEvent<HTMLElement, unknown, NodeInterface<NodeData>>;
|
|
29
68
|
type ListenersInterface<NodeData extends Record<string, unknown>, LinkData extends Record<string, unknown>> = {
|
|
@@ -135,10 +174,10 @@ type NodeSettingsInterface<NodeData extends Record<string, unknown>, LinkData ex
|
|
|
135
174
|
options?: NodeIterationPropsInterface<NodeData, LinkData, NodeOptionsInterface<NodeData, LinkData>> | NodeOptionsInterface<NodeData, LinkData>;
|
|
136
175
|
};
|
|
137
176
|
type NodeOptionsInterface<NodeData extends Record<string, unknown>, LinkData extends Record<string, unknown>> = {
|
|
138
|
-
nodeDraw?: ((node: NodeInterface<NodeData>, options: Required<NodeOptionsInterface<NodeData, LinkData
|
|
139
|
-
textDraw?: ((node: NodeInterface<NodeData>, options: Required<NodeOptionsInterface<NodeData, LinkData
|
|
140
|
-
nodeExtraDraw?: ((node: NodeInterface<NodeData>, options: Required<NodeOptionsInterface<NodeData, LinkData
|
|
141
|
-
textExtraDraw?: ((node: NodeInterface<NodeData>, options: Required<NodeOptionsInterface<NodeData, LinkData
|
|
177
|
+
nodeDraw?: ((this: GraphCanvas<NodeData, LinkData>, node: NodeInterface<NodeData>, options: Required<NodeOptionsInterface<NodeData, LinkData>>) => void) | null;
|
|
178
|
+
textDraw?: ((this: GraphCanvas<NodeData, LinkData>, node: NodeInterface<NodeData>, options: Required<NodeOptionsInterface<NodeData, LinkData>>) => void) | null;
|
|
179
|
+
nodeExtraDraw?: ((this: GraphCanvas<NodeData, LinkData>, node: NodeInterface<NodeData>, options: Required<NodeOptionsInterface<NodeData, LinkData>>) => void) | null;
|
|
180
|
+
textExtraDraw?: ((this: GraphCanvas<NodeData, LinkData>, node: NodeInterface<NodeData>, options: Required<NodeOptionsInterface<NodeData, LinkData>>) => void) | null;
|
|
142
181
|
shape?: NodeShape;
|
|
143
182
|
width?: number;
|
|
144
183
|
height?: number;
|
|
@@ -281,6 +320,7 @@ declare class GraphCanvas<NodeData extends Record<string, unknown>, LinkData ext
|
|
|
281
320
|
protected draw: (this: GraphCanvas<NodeData, LinkData>) => void;
|
|
282
321
|
protected eventAbortController: AbortController;
|
|
283
322
|
protected cachedNodeText: CachedNodeTextInterface;
|
|
323
|
+
protected cachedTextNodeParameters: CachedTextNodeParametersMap;
|
|
284
324
|
protected linkOptionsCache: Record<string, Required<LinkOptionsInterface<NodeData, LinkData>>>;
|
|
285
325
|
protected nodeOptionsCache: Record<string, Required<NodeOptionsInterface<NodeData, LinkData>>>;
|
|
286
326
|
protected isDragging: boolean;
|
|
@@ -308,7 +348,6 @@ declare class GraphCanvas<NodeData extends Record<string, unknown>, LinkData ext
|
|
|
308
348
|
protected clearHTMLElements(): void;
|
|
309
349
|
protected updateSimulation(): void;
|
|
310
350
|
protected clearState(): void;
|
|
311
|
-
protected clearDataDependencies(): void;
|
|
312
351
|
protected updateData(alpha?: number): void;
|
|
313
352
|
protected updateSize(): void;
|
|
314
353
|
protected init(): void;
|
|
@@ -405,39 +444,6 @@ declare function fadeRgb(color: RGB, fade: number): RGB;
|
|
|
405
444
|
|
|
406
445
|
declare function rgbAnimationByProgress(start: RGB, end: RGB, progress: number): RGB;
|
|
407
446
|
|
|
408
|
-
type GraphSettingsInputRange<I extends string> = {
|
|
409
|
-
type: "range";
|
|
410
|
-
min: number;
|
|
411
|
-
max: number;
|
|
412
|
-
step: number;
|
|
413
|
-
initialValue: number;
|
|
414
|
-
id: I;
|
|
415
|
-
label: string;
|
|
416
|
-
};
|
|
417
|
-
type GraphSettingsInputCheckBox<I extends string> = {
|
|
418
|
-
type: "checkbox";
|
|
419
|
-
id: I;
|
|
420
|
-
initialValue: boolean;
|
|
421
|
-
label: string;
|
|
422
|
-
};
|
|
423
|
-
type GraphSettingsInputColorBox<I extends string> = {
|
|
424
|
-
type: "color";
|
|
425
|
-
id: I;
|
|
426
|
-
initialValue: string;
|
|
427
|
-
label: string;
|
|
428
|
-
};
|
|
429
|
-
type GraphSettingsInputSelect<I extends string> = {
|
|
430
|
-
type: "select";
|
|
431
|
-
id: I;
|
|
432
|
-
initialValue: string;
|
|
433
|
-
label: string;
|
|
434
|
-
options: {
|
|
435
|
-
label: string;
|
|
436
|
-
value: string;
|
|
437
|
-
}[];
|
|
438
|
-
};
|
|
439
|
-
type GraphSettingsInputInterface<I extends string> = GraphSettingsInputRange<I> | GraphSettingsInputCheckBox<I> | GraphSettingsInputColorBox<I> | GraphSettingsInputSelect<I>;
|
|
440
|
-
|
|
441
447
|
declare function getForceControls<NodeData extends Record<string, unknown>, LinkData extends Record<string, unknown>>(keys?: (keyof ForceSettingsInterface<NodeData, LinkData>)[]): GraphSettingsInputInterface<keyof ForceSettingsInterface<NodeData, LinkData>>[];
|
|
442
448
|
declare function getGraphControls<NodeData extends Record<string, unknown>>(keys?: (keyof GraphSettingsInterface<NodeData>)[]): GraphSettingsInputInterface<keyof GraphSettingsInterface<NodeData>>[];
|
|
443
449
|
declare function getNodeSettingControls<NodeData extends Record<string, unknown>, LinkData extends Record<string, unknown>>(keys?: keyof Omit<Required<NodeSettingsInterface<NodeData, LinkData>>, "options" | "idGetter">): GraphSettingsInputInterface<"cache" | "highlightByNodeOnlyRoot" | "highlightByNodeNodeFadingMin" | "highlightByNodeNodeColorFadingMin" | "highlightByNodeNodeSizingAdditional" | "highlightByNodeNodeSizingAdditionalCoefficient" | "highlightByNodeTextFadingMin" | "highlightByNodeTextSizingAdditional" | "highlightByNodeTextShiftXAdditional" | "highlightByNodeTextShiftYAdditional" | "highlightByNodeTextWeightAdditional" | "highlightByNodeTextWidthAdditional" | "highlightByLinkNodeFadingMin" | "highlightByLinkNodeColorFadingMin" | "highlightByLinkTextFadingMin" | "highlightByLinkNodeSizingAdditional" | "highlightByLinkNodeSizingAdditionalCoefficient" | "highlightByLinkTextSizingAdditional" | "highlightByLinkTextShiftXAdditional" | "highlightByLinkTextShiftYAdditional" | "highlightByLinkTextWeightAdditional" | "highlightByLinkTextWidthAdditional" | "highlightByHoverNode" | "highlightByNodeNodeFading" | "highlightByNodeNodeSizing" | "highlightByNodeTextFading" | "highlightByNodeTextSizing" | "highlightByNodeNodeColor" | "highlightByLinkNodeFading" | "highlightByLinkNodeSizing" | "highlightByLinkTextFading" | "highlightByLinkTextSizing" | "highlightByLinkNodeColor" | "nodeRadiusCoefficient" | "nodeRadiusFactor" | "nodeRadiusFlexible" | "nodeSizeFlexible" | "nodeSizeCoefficient" | "nodeSizeFactor" | "textNodeDebug">[];
|
|
@@ -445,4 +451,4 @@ declare function getNodeOptionsControls<NodeData extends Record<string, unknown>
|
|
|
445
451
|
declare function getLinkSettingsControls<NodeData extends Record<string, unknown>, LinkData extends Record<string, unknown>>(keys?: keyof Omit<Required<LinkSettingsInterface<NodeData, LinkData>>, "options">): GraphSettingsInputInterface<"cache" | "particles" | "pretty" | "arrow" | "arrowByHighlight" | "particleFlexSpeed" | "particleFlexSpeedCoefficient" | "highlightByNodeLinkFadingMin" | "highlightByNodeArrowFadingMin" | "highlightByLinkArrowFadingMin" | "highlightByLinkLinkFadingMin" | "highlightByHoverLink" | "highlightByNodeLinkFading" | "highlightByNodeArrowFading" | "highlightByLinkLinkFading" | "highlightByLinkArrowFading" | "hoverLinkThreshold">[];
|
|
446
452
|
declare function getLinkOptionsControls<NodeData extends Record<string, unknown>, LinkData extends Record<string, unknown>>(keys?: (keyof LinkOptionsInterface<NodeData, LinkData>)[]): GraphSettingsInputInterface<keyof LinkOptionsInterface<NodeData, LinkData>>[];
|
|
447
453
|
|
|
448
|
-
export { type CachedNodeTextInterface, type DragEventInterface, type ForceSettingsInterface, GraphCanvas, type GraphCanvasInterface, type GraphCanvasSimulation, type GraphParticle, type GraphSettingsInterface, type GraphState, type LinkInterface, type LinkIterationPropsInterface, type LinkOptionsInterface, type LinkSettingsInterface, type ListenersInterface, type NodeInterface, type NodeIterationPropsInterface, type NodeOptionsInterface, type NodeSettingsInterface, type NodeShape, type RGB, type TextStyleEnum, type ZoomEventInterface, animationByProgress, calculateLinkPositionByNode, colorToRgb, drawText, extractRgb, fadeRgb, getDrawLink, getDrawNode, getForceControls, getGraphControls, getLinkOptionsControls, getLinkSettingsControls, getNodeOptionsControls, getNodeSettingControls, getParticlePosition, linkByPointerGetter, linkIterationExtractor, linkOptionsGetter, nodeByPointerGetter, nodeIterationExtractor, nodeOptionsGetter, nodeRadiusGetter, rgbAnimationByProgress };
|
|
454
|
+
export { type CachedNodeTextInterface, type CachedTextNodeParametersInterface, type CachedTextNodeParametersMap, type DragEventInterface, type ForceSettingsInterface, GraphCanvas, type GraphCanvasInterface, type GraphCanvasSimulation, type GraphParticle, type GraphSettingsInputInterface, type GraphSettingsInterface, type GraphState, type LinkInterface, type LinkIterationPropsInterface, type LinkOptionsInterface, type LinkSettingsInterface, type ListenersInterface, type NodeInterface, type NodeIterationPropsInterface, type NodeOptionsInterface, type NodeSettingsInterface, type NodeShape, type RGB, type TextStyleEnum, type ZoomEventInterface, animationByProgress, calculateLinkPositionByNode, colorToRgb, drawText, extractRgb, fadeRgb, getDrawLink, getDrawNode, getForceControls, getGraphControls, getLinkOptionsControls, getLinkSettingsControls, getNodeOptionsControls, getNodeSettingControls, getParticlePosition, linkByPointerGetter, linkIterationExtractor, linkOptionsGetter, nodeByPointerGetter, nodeIterationExtractor, nodeOptionsGetter, nodeRadiusGetter, rgbAnimationByProgress };
|