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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (30) hide show
  1. package/lib/cjs/index.cjs +566 -371
  2. package/lib/cjs/index.cjs.map +1 -1
  3. package/lib/esm/index.js +5 -4
  4. package/lib/esm/index.js.map +1 -1
  5. package/lib/esm/module/GraphCanvas/GraphCanvas.js +41 -46
  6. package/lib/esm/module/GraphCanvas/GraphCanvas.js.map +1 -1
  7. package/lib/esm/module/GraphCanvas/constants/index.js +12 -0
  8. package/lib/esm/module/GraphCanvas/constants/index.js.map +1 -0
  9. package/lib/esm/module/GraphCanvas/constants/link-settings.js +1 -0
  10. package/lib/esm/module/GraphCanvas/constants/link-settings.js.map +1 -1
  11. package/lib/esm/module/GraphCanvas/lib/utils/calculate-curve-link-position-by-node.js +42 -0
  12. package/lib/esm/module/GraphCanvas/lib/utils/calculate-curve-link-position-by-node.js.map +1 -0
  13. package/lib/esm/module/GraphCanvas/lib/utils/calculate-link-position-by-node.js +37 -35
  14. package/lib/esm/module/GraphCanvas/lib/utils/calculate-link-position-by-node.js.map +1 -1
  15. package/lib/esm/module/GraphCanvas/lib/utils/link-by-pointer-getter.js +72 -22
  16. package/lib/esm/module/GraphCanvas/lib/utils/link-by-pointer-getter.js.map +1 -1
  17. package/lib/esm/module/GraphCanvas/slices/draw-links.js +70 -17
  18. package/lib/esm/module/GraphCanvas/slices/draw-links.js.map +1 -1
  19. package/lib/esm/module/GraphCanvas/slices/init-pointer.js +6 -0
  20. package/lib/esm/module/GraphCanvas/slices/init-pointer.js.map +1 -1
  21. package/lib/esm/module/GraphCanvas/slices/init-resize.js +7 -0
  22. package/lib/esm/module/GraphCanvas/slices/init-resize.js.map +1 -1
  23. package/lib/esm/module/GraphCanvas/slices/init-zoom.js +5 -2
  24. package/lib/esm/module/GraphCanvas/slices/init-zoom.js.map +1 -1
  25. package/lib/esm/module/GraphCanvas/slices/update-link-cache.js +30 -0
  26. package/lib/esm/module/GraphCanvas/slices/update-link-cache.js.map +1 -1
  27. package/lib/esm/module/GraphCanvas/slices/update-node-cache.js +103 -97
  28. package/lib/esm/module/GraphCanvas/slices/update-node-cache.js.map +1 -1
  29. package/lib/index.d.ts +71 -47
  30. package/package.json +3 -2
@@ -1 +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;;;;"}
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 const groupMap: Record<string, number> = {};\n const groupSelfMap: Record<string, number> = {};\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 if (this.linkSettings.curve) {\n if (sourceId === targetId) {\n groupSelfMap[id] ??= 0;\n link._groupIndex = ++groupSelfMap[id];\n link._self = true;\n continue;\n }\n const reverseId = `${sourceId}${targetId}`;\n groupMap[reverseId] ??= 0;\n groupMap[reverseId]++;\n groupMap[id] ??= 0;\n link._groupIndex = indexToPosition(++groupMap[id]);\n link._self = false;\n }\n }\n if (this.linkSettings.curve) {\n for (const link of this.links) {\n const { sourceId, targetId } = extractLinkPointIds(link);\n const id = `${targetId}${sourceId}`;\n link._groupSize = link._self ? (groupSelfMap[id] ?? 1) : (groupMap[id] ?? 1);\n }\n }\n}\n\nfunction indexToPosition(n: number): number {\n if (n === 1) return 0;\n\n const index = n >> 1;\n return n & 1 ? -(index * 2) : index * 2;\n\n // return n & 1 ? -(n >> 1) : n >> 1;\n}\n"],"names":[],"mappings":";;;;;;SAGgB,eAAe,GAAA;AAI7B,IAAA,IAAI,CAA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AAG,KAAK;;;AAGtB,IAAA,IAAI,IAAI,CAAC,YAAY,CAAC,KAAK,EAAE;AAC3B,QAAA,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC,KAAK,EAAE;YAC7B,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,GAAG,mBAAmB,CAAC,IAAI,CAAC;AACxD,YAAA,MAAM,EAAE,GAAG,CAAA,EAAG,QAAQ,CAAG,EAAA,QAAQ,EAAE;AACnC,YAAA,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,KAAK,IAAI,YAAY,CAAC,EAAE,CAAC,IAAI,CAAC,KAAK,QAAQ,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC;;;AAGlF;AAEA,SAAS,eAAe,CAAC,CAAS,EAAA;IAChC,IAAI,CAAC,KAAK,CAAC;AAAE,QAAA,OAAO,CAAC;AAErB,IAAA,MAAM,KAAK,GAAG,CAAC,IAAI,CAAC;AACpB,IAAA,OAAO,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,GAAG,CAAC,CAAC,GAAG,KAAK,GAAG,CAAC;;AAGzC;;;;"}
@@ -1,113 +1,120 @@
1
+ import { isObject } from '@krainovsd/js-helpers';
1
2
  import { nodeOptionsGetter, nodeRadiusGetter, nodeSizeGetter } from '../lib/settings/node-settings-getter.js';
2
- import '@krainovsd/js-helpers';
3
3
  import 'd3-array';
4
4
  import { nodeIterationExtractor } from '../lib/utils/node-iteration-extractor.js';
5
5
  import { getTextLines } from './draw-text.js';
6
6
 
7
- function updateNodeCache() {
7
+ function updateNodeCache(types) {
8
8
  this.nodeOptionsCache = {};
9
9
  if (!this.context)
10
10
  return;
11
11
  for (let i = 0; i < this.nodes.length; i++) {
12
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];
13
+ if (types === true || (isObject(types) && types.options)) {
14
+ const nodeOptions = nodeIterationExtractor(node, i, this.nodes, this, this.nodeSettings.options ?? {}, nodeOptionsGetter);
15
+ const radius = nodeOptions.shape === "circle"
16
+ ? nodeRadiusGetter({
17
+ radiusFlexible: this.nodeSettings.nodeRadiusFlexible,
18
+ radiusInitial: nodeOptions.radius,
19
+ radiusIncrementByStep: this.nodeSettings.nodeRadiusIncrementByStep,
20
+ radiusLinkCountForStep: this.nodeSettings.nodeRadiusLinkCountForStep,
21
+ radiusMaxLinearSteps: this.nodeSettings.nodeRadiusMaxLinearSteps,
22
+ radiusLogFactor: this.nodeSettings.nodeRadiusLogFactor,
23
+ radiusLinkCountDividerForLog: this.nodeSettings.nodeRadiusLinkCountDividerForLog,
24
+ linkCount: node.linkCount,
25
+ })
26
+ : nodeOptions.radius;
27
+ let width = nodeOptions.width;
28
+ let height = nodeOptions.height;
29
+ let labelSize = nodeOptions.labelSize;
30
+ if (nodeOptions.shape === "square") {
31
+ const size = nodeSizeGetter({
32
+ heightInitial: nodeOptions.height,
33
+ widthInitial: nodeOptions.width,
34
+ linkCount: node.linkCount,
35
+ sizeFlexible: this.nodeSettings.nodeSizeFlexible,
36
+ sizeIncrementByStep: this.nodeSettings.nodeSizeIncrementByStep,
37
+ sizeLinkCountForStep: this.nodeSettings.nodeSizeLinkCountForStep,
38
+ sizeMaxLinearSteps: this.nodeSettings.nodeSizeMaxLinearSteps,
39
+ sizeLogFactor: this.nodeSettings.nodeSizeLogFactor,
40
+ sizeLinkCountDividerForLog: this.nodeSettings.nodeSizeLinkCountDividerForLog,
41
+ });
42
+ width = size.width;
43
+ height = size.height;
67
44
  }
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;
45
+ if (nodeOptions.shape === "text") {
46
+ width = nodeOptions.width;
47
+ const size = nodeSizeGetter({
48
+ heightInitial: nodeOptions.height,
49
+ widthInitial: width,
50
+ linkCount: node.linkCount,
51
+ sizeFlexible: this.nodeSettings.nodeSizeFlexible,
52
+ sizeIncrementByStep: this.nodeSettings.nodeSizeIncrementByStep,
53
+ sizeLinkCountForStep: this.nodeSettings.nodeSizeLinkCountForStep,
54
+ sizeMaxLinearSteps: this.nodeSettings.nodeSizeMaxLinearSteps,
55
+ sizeLogFactor: this.nodeSettings.nodeSizeLogFactor,
56
+ sizeLinkCountDividerForLog: this.nodeSettings.nodeSizeLinkCountDividerForLog,
57
+ });
58
+ labelSize *= size.additionalSizeCoefficient;
59
+ }
60
+ nodeOptions.width = node.visible === false ? 0 : width;
61
+ nodeOptions.height = node.visible === false ? 0 : height;
62
+ nodeOptions.radius = node.visible === false ? 0 : radius;
63
+ nodeOptions.labelSize = labelSize;
64
+ this.nodeOptionsCache[node.id] = nodeOptions;
80
65
  }
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;
66
+ const nodeOptions = this.nodeOptionsCache[node.id];
67
+ /** label */
68
+ if (types === true || (isObject(types) && types.label)) {
69
+ /** label in not text shape */
70
+ if (nodeOptions.shape !== "text" && nodeOptions.label) {
71
+ this.context.font = `${nodeOptions.labelStyle} normal ${nodeOptions.labelWeight} ${nodeOptions.labelSize}px ${nodeOptions.labelFont}`;
72
+ this.context.fillStyle = nodeOptions.labelColor;
73
+ this.context.textAlign = nodeOptions.labelAlign;
74
+ if (nodeOptions.labelWidth == undefined ||
75
+ this.context.measureText(nodeOptions.label).width <= nodeOptions.labelWidth) {
76
+ this.cachedNodeLabel[node.id] = [nodeOptions.label];
77
+ }
78
+ const { lines } = getTextLines({
79
+ context: this.context,
80
+ maxWidth: nodeOptions.labelWidth,
81
+ text: nodeOptions.label,
82
+ textAlign: nodeOptions.labelAlign,
83
+ textColor: nodeOptions.labelColor,
84
+ textFont: nodeOptions.labelFont,
85
+ textSize: nodeOptions.labelSize,
86
+ textStyle: nodeOptions.labelStyle,
87
+ textWeight: nodeOptions.labelWeight,
88
+ });
89
+ this.cachedNodeLabel[node.id] = lines;
90
+ /** label in text shape */
91
+ }
92
+ else if (nodeOptions.shape === "text" && nodeOptions.label) {
93
+ const textInfo = getTextLines({
94
+ context: this.context,
95
+ text: nodeOptions.label,
96
+ textAlign: nodeOptions.labelAlign,
97
+ textColor: nodeOptions.labelColor,
98
+ textFont: nodeOptions.labelFont,
99
+ textSize: nodeOptions.labelSize,
100
+ maxWidth: nodeOptions.labelWidth,
101
+ textStyle: nodeOptions.labelStyle,
102
+ textWeight: nodeOptions.textWeight,
103
+ });
104
+ const textNodeParameters = [textInfo.currentMaxSize, nodeOptions.labelSize];
105
+ const lines = textInfo.lines;
106
+ const textSizeCoefficient = nodeOptions.labelSize / textNodeParameters[1];
107
+ const maxSize = textNodeParameters[0] * textSizeCoefficient;
108
+ nodeOptions.height =
109
+ lines.length * nodeOptions.labelSize +
110
+ (lines.length - 1) * nodeOptions.labelGap +
111
+ nodeOptions.labelYPadding;
112
+ nodeOptions.width = maxSize + nodeOptions.labelXPadding;
113
+ this.cachedNodeLabel[node.id] = lines;
114
+ }
104
115
  }
105
- nodeOptions.width = node.visible === false ? 0 : width;
106
- nodeOptions.height = node.visible === false ? 0 : height;
107
- nodeOptions.radius = node.visible === false ? 0 : radius;
108
- nodeOptions.labelSize = labelSize;
109
116
  /** text */
110
- if (nodeOptions.text) {
117
+ if (nodeOptions.text && (types === true || (isObject(types) && types.text))) {
111
118
  this.context.font = `${nodeOptions.textStyle} normal ${nodeOptions.textWeight} ${nodeOptions.textSize}px ${nodeOptions.textFont}`;
112
119
  this.context.fillStyle = nodeOptions.textColor;
113
120
  this.context.textAlign = nodeOptions.textAlign;
@@ -128,7 +135,6 @@ function updateNodeCache() {
128
135
  });
129
136
  this.cachedNodeText[node.id] = lines;
130
137
  }
131
- this.nodeOptionsCache[node.id] = nodeOptions;
132
138
  }
133
139
  }
134
140
 
@@ -1 +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 = node.visible === false ? 0 : width;\n nodeOptions.height = node.visible === false ? 0 : height;\n nodeOptions.radius = node.visible === false ? 0 : 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,IAA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CAAC,IAAI,CAAC;;AAGnD,YAAA,MAAM,EAAE,KAAK,EAAE,GAAG,YAAY,CAAC;gBAC7B,OAAO,EAAE,IAAI,CAAC,OAAO;gBACrB,QAAQ,EAAE,WAAW,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;;;;"}
1
+ {"version":3,"file":"update-node-cache.js","sources":["../../../../../src/module/GraphCanvas/slices/update-node-cache.ts"],"sourcesContent":["import { isObject } from \"@krainovsd/js-helpers\";\nimport type { GraphCanvas } from \"../GraphCanvas\";\nimport {\n nodeIterationExtractor,\n nodeOptionsGetter,\n nodeRadiusGetter,\n nodeSizeGetter,\n} from \"../lib\";\nimport { getTextLines } from \"./draw-text\";\n\ntype NodeCache = {\n options: boolean;\n text: boolean;\n label: boolean;\n};\n\nexport function updateNodeCache<\n NodeData extends Record<string, unknown>,\n LinkData extends Record<string, unknown>,\n>(this: GraphCanvas<NodeData, LinkData>, types: boolean | NodeCache) {\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 if (types === true || (isObject(types) && types.options)) {\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\n nodeOptions.width = node.visible === false ? 0 : width;\n nodeOptions.height = node.visible === false ? 0 : height;\n nodeOptions.radius = node.visible === false ? 0 : radius;\n nodeOptions.labelSize = labelSize;\n this.nodeOptionsCache[node.id] = nodeOptions;\n }\n\n const nodeOptions = this.nodeOptionsCache[node.id];\n /** label */\n if (types === true || (isObject(types) && types.label)) {\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 /** label in text shape */\n } else 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: nodeOptions.labelSize,\n maxWidth: nodeOptions.labelWidth,\n textStyle: nodeOptions.labelStyle,\n textWeight: nodeOptions.textWeight,\n });\n const textNodeParameters = [textInfo.currentMaxSize, nodeOptions.labelSize];\n const lines = textInfo.lines;\n const textSizeCoefficient = nodeOptions.labelSize / textNodeParameters[1];\n const maxSize = textNodeParameters[0] * textSizeCoefficient;\n\n nodeOptions.height =\n lines.length * nodeOptions.labelSize +\n (lines.length - 1) * nodeOptions.labelGap +\n nodeOptions.labelYPadding;\n\n nodeOptions.width = maxSize + nodeOptions.labelXPadding;\n this.cachedNodeLabel[node.id] = lines;\n }\n }\n\n /** text */\n if (nodeOptions.text && (types === true || (isObject(types) && types.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}\n"],"names":[],"mappings":";;;;;;AAgBM,SAAU,eAAe,CAGU,KAA0B,EAAA;AACjE,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;AAC1B,QAAA,IAAI,KAAK,KAAK,IAAI,KAAK,QAAQ,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,OAAO,CAAC,EAAE;YACxD,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,YAAA,MAAM,MAAM,GACV,WAAW,CAAC,KAAK,KAAK;kBACl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,CAAC,SAAS,CAAW,QAAA,EAAA,WAAW,CAAC,UAAU,CAAA,CAAA,EAAI,WAAW,CAAC,QAAQ,MAAM,WAAW,CAAC,QAAQ,CAAA,CAAE;YACjI,IAAI,CAAC,OAAO,CAAC,SAAS,GAAG,WAAW,CAAC,SAAS;YAC9C,IAAI,CAAC,OAAO,CAAC,SAAS,GAAG,WAAW,CAAC,SAAS;AAE9C,YAAA,IACE,WAAW,CAAC,SAAS,IAAI,SAAS;AAClC,gBAAA,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,KAAK,IAAI,WAAW,CAAC,SAAS,EACzE;AACA,gBAAA,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,EAAE,CAAC,GAAG,CAAC,WAAW,CAAC,IAAI,CAAC;;AAGnD,YAAA,MAAM,EAAE,KAAK,EAAE,GAAG,YAAY,CAAC;gBAC7B,OAAO,EAAE,IAAI,CAAC,OAAO;gBACrB,QAAQ,EAAE,WAAW,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;;;AAG1C;;;;"}
package/lib/index.d.ts CHANGED
@@ -1,7 +1,13 @@
1
1
  import { D3ZoomEvent, ZoomTransform } from 'd3-zoom';
2
+ import { ValueOf } from '@krainovsd/js-helpers';
2
3
  import { SimulationNodeDatum, SimulationLinkDatum, Simulation } from 'd3-force';
3
4
  import { D3DragEvent } from 'd3-drag';
4
5
 
6
+ declare const COMMON_SETTINGS: {
7
+ nodeRadius: number;
8
+ nodeSize: number;
9
+ };
10
+
5
11
  interface NodeInterface<NodeData extends Record<string, unknown>> extends SimulationNodeDatum {
6
12
  id: number | string;
7
13
  linkCount?: number;
@@ -30,6 +36,17 @@ interface LinkInterface<NodeData extends Record<string, unknown>, LinkData exten
30
36
  data?: LinkData;
31
37
  highlight?: boolean;
32
38
  visible?: boolean;
39
+ _groupIndex?: number;
40
+ _groupSize?: number;
41
+ _self?: boolean;
42
+ _x1?: number;
43
+ _y1?: number;
44
+ _x2?: number;
45
+ _y2?: number;
46
+ _cx?: number;
47
+ _cy?: number;
48
+ _ax?: number;
49
+ _ay?: number;
33
50
  }
34
51
  type LinkParticle = {
35
52
  step: number;
@@ -79,6 +96,8 @@ type ForceSettingsInterface<NodeData extends Record<string, unknown>, LinkData e
79
96
  yStrength?: NodeIterationPropsNoThisInterface<NodeData> | number;
80
97
  };
81
98
 
99
+ declare const FORCE_SETTINGS: Required<ForceSettingsInterface<Record<string, unknown>, Record<string, unknown>>>;
100
+
82
101
  type GraphSettingsInterface<NodeData extends Record<string, unknown>> = {
83
102
  zoomExtent?: [number, number];
84
103
  translateExtent?: [[number?, number?], [number?, number?]];
@@ -94,6 +113,8 @@ type GraphSettingsInterface<NodeData extends Record<string, unknown>> = {
94
113
  showDrawTimeEveryTick?: boolean;
95
114
  };
96
115
 
116
+ declare const GRAPH_SETTINGS: Required<GraphSettingsInterface<Record<string, unknown>>>;
117
+
97
118
  type HighlightSettingsInterface = HighlighCommonSettingsInterface & HighlightByNodeForNodeSettingsInterface & HighlightByNodeForLabelSettingsInterface & HighlightByNodeForTextSettingsInterface & HighlightByNodeForLinkSettingsInterface & HighlightByNodeForArrowSettingsInterface & HighlightByLinkForNodeSettingsInterface & HighlightByLinkForTextSettingsInterface & HighlightByLinkForLabelSettingsInterface & HighlightByLinkForLinkSettingsInterface & HighlightByLinkForArrowSettingsInterface;
98
119
  type HighlighCommonSettingsInterface = {
99
120
  highlightDownFrames?: number;
@@ -170,8 +191,11 @@ type HighlightByLinkForArrowSettingsInterface = {
170
191
  highlightByLinkForArrowBorderColor?: string | null;
171
192
  };
172
193
 
194
+ declare const HIGHLIGHT_SETTINGS: Required<HighlightSettingsInterface>;
195
+
173
196
  type LinkSettingsInterface<NodeData extends Record<string, unknown>, LinkData extends Record<string, unknown>> = {
174
197
  prettyDraw?: boolean;
198
+ curve?: boolean;
175
199
  arrow?: boolean;
176
200
  arrowByHighlight?: boolean;
177
201
  particles?: boolean;
@@ -210,23 +234,8 @@ type LinkOptionsParticleInterface = {
210
234
  particleBorderColor?: string;
211
235
  };
212
236
 
213
- type ZoomEventInterface = D3ZoomEvent<HTMLCanvasElement, unknown>;
214
- type DragEventInterface<NodeData extends Record<string, unknown>> = D3DragEvent<HTMLElement, unknown, NodeInterface<NodeData>>;
215
- type ListenersInterface<NodeData extends Record<string, unknown>, LinkData extends Record<string, unknown>> = {
216
- onContextMenu?: (this: GraphCanvas<NodeData, LinkData>, event: MouseEvent, node: NodeInterface<NodeData> | undefined, link: LinkInterface<NodeData, LinkData> | undefined) => void;
217
- onClick?: (this: GraphCanvas<NodeData, LinkData>, event: MouseEvent | TouchEvent, node: NodeInterface<NodeData> | undefined, link: LinkInterface<NodeData, LinkData> | undefined) => void;
218
- onDoubleClick?: (this: GraphCanvas<NodeData, LinkData>, event: MouseEvent | TouchEvent, node: NodeInterface<NodeData> | undefined, link: LinkInterface<NodeData, LinkData> | undefined) => void;
219
- onWheelClick?: (this: GraphCanvas<NodeData, LinkData>, event: MouseEvent, node: NodeInterface<NodeData> | undefined, link: LinkInterface<NodeData, LinkData> | undefined) => void;
220
- onMove?: (this: GraphCanvas<NodeData, LinkData>, event: MouseEvent | TouchEvent, node: NodeInterface<NodeData> | undefined, link: LinkInterface<NodeData, LinkData> | undefined) => void;
221
- onZoom?: (this: GraphCanvas<NodeData, LinkData>, event: ZoomEventInterface) => void;
222
- onDragSubject?: (this: GraphCanvas<NodeData, LinkData>, event: DragEventInterface<NodeData>) => NodeInterface<NodeData> | undefined;
223
- onDraw?: (this: GraphCanvas<NodeData, LinkData>) => void;
224
- onStartDragFinished?: (this: GraphCanvas<NodeData, LinkData>, event: DragEventInterface<NodeData>) => void;
225
- onMoveDragFinished?: (this: GraphCanvas<NodeData, LinkData>, event: DragEventInterface<NodeData>) => void;
226
- onEndDragFinished?: (this: GraphCanvas<NodeData, LinkData>, event: DragEventInterface<NodeData>) => void;
227
- onDrawFinished?: (this: GraphCanvas<NodeData, LinkData>) => void;
228
- onSimulationEnd?: (this: GraphCanvas<NodeData, LinkData>) => void;
229
- };
237
+ declare const LINK_SETTINGS: Omit<Required<LinkSettingsInterface<Record<string, unknown>, Record<string, unknown>>>, "options">;
238
+ declare const LINK_OPTIONS: Omit<Required<LinkOptionsInterface<Record<string, unknown>, Record<string, unknown>>>, "color" | "width" | "drawLink" | "drawExtraLink" | "arrowColor">;
230
239
 
231
240
  type NodeSettingsInterface<NodeData extends Record<string, unknown>, LinkData extends Record<string, unknown>> = {
232
241
  nodeRadiusFlexible?: boolean;
@@ -298,6 +307,34 @@ type NodeOptionsLabelInterface = {
298
307
  label?: string | null;
299
308
  };
300
309
 
310
+ declare const NODE_SETTINGS: Omit<Required<NodeSettingsInterface<Record<string, unknown>, Record<string, unknown>>>, "options" | "idGetter">;
311
+ declare const NODE_OPTIONS: Omit<Required<NodeOptionsInterface<Record<string, unknown>, Record<string, unknown>>>, "color" | "text" | "textVisible" | "textSize" | "textShiftY" | "nodeDraw" | "nodeExtraDraw" | "textDraw" | "textExtraDraw">;
312
+
313
+ declare const GRAPH_CACHE_TYPE: {
314
+ readonly NodeOptions: "nodeOptions";
315
+ readonly LinkOptions: "linkOptions";
316
+ readonly NodeText: "nodeText";
317
+ readonly NodeLabel: "nodeLabel";
318
+ };
319
+
320
+ type ZoomEventInterface = D3ZoomEvent<HTMLCanvasElement, unknown>;
321
+ type DragEventInterface<NodeData extends Record<string, unknown>> = D3DragEvent<HTMLElement, unknown, NodeInterface<NodeData>>;
322
+ type ListenersInterface<NodeData extends Record<string, unknown>, LinkData extends Record<string, unknown>> = {
323
+ onContextMenu?: (this: GraphCanvas<NodeData, LinkData>, event: MouseEvent, node: NodeInterface<NodeData> | undefined, link: LinkInterface<NodeData, LinkData> | undefined) => void;
324
+ onClick?: (this: GraphCanvas<NodeData, LinkData>, event: MouseEvent | TouchEvent, node: NodeInterface<NodeData> | undefined, link: LinkInterface<NodeData, LinkData> | undefined) => void;
325
+ onDoubleClick?: (this: GraphCanvas<NodeData, LinkData>, event: MouseEvent | TouchEvent, node: NodeInterface<NodeData> | undefined, link: LinkInterface<NodeData, LinkData> | undefined) => void;
326
+ onWheelClick?: (this: GraphCanvas<NodeData, LinkData>, event: MouseEvent, node: NodeInterface<NodeData> | undefined, link: LinkInterface<NodeData, LinkData> | undefined) => void;
327
+ onMove?: (this: GraphCanvas<NodeData, LinkData>, event: MouseEvent | TouchEvent, node: NodeInterface<NodeData> | undefined, link: LinkInterface<NodeData, LinkData> | undefined) => void;
328
+ onZoom?: (this: GraphCanvas<NodeData, LinkData>, event: ZoomEventInterface) => void;
329
+ onDragSubject?: (this: GraphCanvas<NodeData, LinkData>, event: DragEventInterface<NodeData>) => NodeInterface<NodeData> | undefined;
330
+ onDraw?: (this: GraphCanvas<NodeData, LinkData>) => void;
331
+ onStartDragFinished?: (this: GraphCanvas<NodeData, LinkData>, event: DragEventInterface<NodeData>) => void;
332
+ onMoveDragFinished?: (this: GraphCanvas<NodeData, LinkData>, event: DragEventInterface<NodeData>) => void;
333
+ onEndDragFinished?: (this: GraphCanvas<NodeData, LinkData>, event: DragEventInterface<NodeData>) => void;
334
+ onDrawFinished?: (this: GraphCanvas<NodeData, LinkData>) => void;
335
+ onSimulationEnd?: (this: GraphCanvas<NodeData, LinkData>) => void;
336
+ };
337
+
301
338
  type GraphCanvasInterface<NodeData extends Record<string, unknown>, LinkData extends Record<string, unknown>> = {
302
339
  nodes: NodeInterface<NodeData>[];
303
340
  links: LinkInterface<NodeData, LinkData>[];
@@ -310,6 +347,7 @@ type GraphCanvasInterface<NodeData extends Record<string, unknown>, LinkData ext
310
347
  highlightSettings?: HighlightSettingsInterface;
311
348
  };
312
349
  type GraphCanvasSimulation<NodeData extends Record<string, unknown>, LinkData extends Record<string, unknown>> = Simulation<NodeInterface<NodeData>, LinkInterface<NodeData, LinkData>>;
350
+ type GraphCanvasCacheKeys = ValueOf<typeof GRAPH_CACHE_TYPE>;
313
351
 
314
352
  declare class GraphCanvas<NodeData extends Record<string, unknown>, LinkData extends Record<string, unknown>> {
315
353
  /** initial data */
@@ -349,11 +387,11 @@ declare class GraphCanvas<NodeData extends Record<string, unknown>, LinkData ext
349
387
  constructor({ links, nodes, root, forceSettings, linkSettings, listeners, nodeSettings, graphSettings, highlightSettings, }: GraphCanvasInterface<NodeData, LinkData>);
350
388
  get dpi(): number;
351
389
  getData(): Pick<GraphCanvasInterface<NodeData, LinkData>, "nodes" | "links">;
352
- changeData(options: Pick<Partial<GraphCanvasInterface<NodeData, LinkData>>, "links" | "nodes">, alpha?: number, clearCache?: boolean): void;
353
- changeSettings(options: Omit<Partial<GraphCanvasInterface<NodeData, LinkData>>, "links" | "nodes" | "listeners">, clearCache?: boolean): undefined;
390
+ changeData(options: Pick<Partial<GraphCanvasInterface<NodeData, LinkData>>, "links" | "nodes">, alpha?: number, clearCache?: boolean | GraphCanvasCacheKeys[]): void;
391
+ changeSettings(options: Omit<Partial<GraphCanvasInterface<NodeData, LinkData>>, "links" | "nodes" | "listeners">, clearCache?: boolean | GraphCanvasCacheKeys[]): undefined;
354
392
  updateRect(): void;
355
393
  updateSize(): void;
356
- clearCache(keys?: ("nodeOptionsCache" | "linkOptionsCache")[]): void;
394
+ clearCache(keys: boolean | GraphCanvasCacheKeys[]): void;
357
395
  tick(): void;
358
396
  restart(alpha?: number): void;
359
397
  start(): void;
@@ -363,7 +401,7 @@ declare class GraphCanvas<NodeData extends Record<string, unknown>, LinkData ext
363
401
  protected clearHTMLElements(): void;
364
402
  protected updateSimulation(): void;
365
403
  protected clearState(): void;
366
- protected updateData(alpha?: number, clearCache?: boolean): void;
404
+ protected updateData(alpha?: number, clearCache?: boolean | GraphCanvasCacheKeys[]): void;
367
405
  protected init(): void;
368
406
  }
369
407
 
@@ -433,13 +471,15 @@ declare function nodeByPointerGetter<NodeData extends Record<string, unknown>>({
433
471
  declare function nodeIterationExtractor<NodeData extends Record<string, unknown>, LinkData extends Record<string, unknown>, Result extends string | number | boolean | Record<string, unknown> | unknown[] | undefined | null>(node: NodeInterface<NodeData>, i: number, nodes: NodeInterface<NodeData>[], state: GraphCanvas<NodeData, LinkData>, option: NodeIterationPropsInterface<NodeData, LinkData, Result> | Result, optionConstantGetter: undefined): Result;
434
472
  declare function nodeIterationExtractor<NodeData extends Record<string, unknown>, LinkData extends Record<string, unknown>, Result extends string | number | boolean | Record<string, unknown> | unknown[] | undefined | null>(node: NodeInterface<NodeData>, i: number, nodes: NodeInterface<NodeData>[], state: GraphCanvas<NodeData, LinkData>, option: NodeIterationPropsInterface<NodeData, LinkData, Result> | Result, optionConstantGetter: NodeIterationPropsInterface<NodeData, LinkData, Result> | Result): Required<Result>;
435
473
 
436
- declare function calculateLinkPositionByNode<NodeData extends Record<string, unknown>, LinkData extends Record<string, unknown>>(link: LinkInterface<NodeData, LinkData>, arrowSize?: number): {
437
- x1: number;
438
- y1: number;
439
- x2: number;
440
- y2: number;
474
+ declare function calculateLinkPositionByNode<NodeData extends Record<string, unknown>>(xStart: number, yStart: number, xEnd: number, yEnd: number, sourceNode: NodeInterface<NodeData>, targetNode: NodeInterface<NodeData>, arrowSize?: number): {
475
+ xStart: number;
476
+ yStart: number;
477
+ xEnd: number;
478
+ yEnd: number;
479
+ xEndArrow: number;
480
+ yEndArrow: number;
441
481
  distance: number;
442
- } | null;
482
+ };
443
483
 
444
484
  declare function animationByProgress(initial: number, additional: number, progress: number): number;
445
485
 
@@ -469,8 +509,9 @@ type LinkByPointerGetterOptions<NodeData extends Record<string, unknown>, LinkDa
469
509
  areaTransform: ZoomTransform;
470
510
  links: LinkInterface<NodeData, LinkData>[];
471
511
  linkHoverExtraZone: number;
512
+ curve: boolean;
472
513
  };
473
- declare function linkByPointerGetter<NodeData extends Record<string, unknown>, LinkData extends Record<string, unknown>>({ areaRect, areaTransform, mouseEvent, links, linkHoverExtraZone, }: LinkByPointerGetterOptions<NodeData, LinkData>): LinkInterface<NodeData, LinkData> | undefined;
514
+ declare function linkByPointerGetter<NodeData extends Record<string, unknown>, LinkData extends Record<string, unknown>>({ areaRect, areaTransform, mouseEvent, links, linkHoverExtraZone, curve, }: LinkByPointerGetterOptions<NodeData, LinkData>): LinkInterface<NodeData, LinkData> | undefined;
474
515
 
475
516
  type NodeHighlightOptions<NodeData extends Record<string, unknown>, LinkData extends Record<string, unknown>> = {
476
517
  nodeOptions: Required<NodeOptionsInterface<NodeData, LinkData>>;
@@ -575,23 +616,6 @@ type DrawTextOptions = {
575
616
  };
576
617
  declare function drawText({ context, textAlign, textColor, textFont, textStyle, textGap, textWeight, textSize, x, y, lines, }: DrawTextOptions): void;
577
618
 
578
- declare const COMMON_SETTINGS: {
579
- nodeRadius: number;
580
- nodeSize: number;
581
- };
582
-
583
- declare const FORCE_SETTINGS: Required<ForceSettingsInterface<Record<string, unknown>, Record<string, unknown>>>;
584
-
585
- declare const GRAPH_SETTINGS: Required<GraphSettingsInterface<Record<string, unknown>>>;
586
-
587
- declare const HIGHLIGHT_SETTINGS: Required<HighlightSettingsInterface>;
588
-
589
- declare const LINK_SETTINGS: Omit<Required<LinkSettingsInterface<Record<string, unknown>, Record<string, unknown>>>, "options">;
590
- declare const LINK_OPTIONS: Omit<Required<LinkOptionsInterface<Record<string, unknown>, Record<string, unknown>>>, "color" | "width" | "drawLink" | "drawExtraLink" | "arrowColor">;
591
-
592
- declare const NODE_SETTINGS: Omit<Required<NodeSettingsInterface<Record<string, unknown>, Record<string, unknown>>>, "options" | "idGetter">;
593
- declare const NODE_OPTIONS: Omit<Required<NodeOptionsInterface<Record<string, unknown>, Record<string, unknown>>>, "color" | "text" | "textVisible" | "textSize" | "textShiftY" | "nodeDraw" | "nodeExtraDraw" | "textDraw" | "textExtraDraw">;
594
-
595
619
  type GraphSettingsInputRange<I extends string> = {
596
620
  type: "range";
597
621
  min: number;
@@ -673,5 +697,5 @@ declare const NODE_OPTIONS_NODE_CONTROLS: GraphSettingsInputInterface<keyof Node
673
697
  declare const NODE_OPTIONS_TEXT_CONTROLS: GraphSettingsInputInterface<keyof NodeOptionsTextInterface>[];
674
698
  declare const NODE_OPTIONS_LABEL_CONTROLS: GraphSettingsInputInterface<keyof NodeOptionsLabelInterface>[];
675
699
 
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, 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 };
700
+ export { COMMON_SETTINGS, FORCE_CONTROLS, FORCE_SETTINGS, GRAPH_CACHE_TYPE, 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 };
701
+ export type { CachedNodeTextInterface, DragEventInterface, ForceSettingsInterface, GraphCanvasCacheKeys, 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 };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@krainovsd/graph",
3
- "version": "0.12.0-beta.6",
3
+ "version": "0.13.0-beta3",
4
4
  "description": "Krainov graph",
5
5
  "type": "module",
6
6
  "author": "KrainovSD <denislosev48@gmail.com>",
@@ -28,6 +28,7 @@
28
28
  ],
29
29
  "scripts": {
30
30
  "publish-package": "npm run lint && npm run build && npm publish",
31
+ "publish-package-beta": "npm run lint && npm run build && npm publish --tag beta",
31
32
  "dev": "vite --host --force",
32
33
  "clear": "rm -rf ./lib",
33
34
  "build-dev": "vite build",
@@ -43,7 +44,7 @@
43
44
  "type-debug": "tsc --showConfig > typescript-config.json"
44
45
  },
45
46
  "devDependencies": {
46
- "@krainovsd/presets": "0.3.6",
47
+ "@krainovsd/presets": "0.4.0",
47
48
  "rollup": "4.34.9",
48
49
  "prettier": "3.6.1",
49
50
  "eslint": "9.29.0",