@krainovsd/graph 0.10.0-rc4 → 0.10.0-rc6

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 (79) hide show
  1. package/lib/cjs/index.cjs +1909 -1321
  2. package/lib/cjs/index.cjs.map +1 -1
  3. package/lib/esm/constants/force-controls.js +141 -0
  4. package/lib/esm/constants/force-controls.js.map +1 -0
  5. package/lib/esm/constants/graph-controls.js +25 -0
  6. package/lib/esm/constants/graph-controls.js.map +1 -0
  7. package/lib/esm/constants/highlight-controls.js +452 -0
  8. package/lib/esm/constants/highlight-controls.js.map +1 -0
  9. package/lib/esm/constants/link-controls.js +219 -0
  10. package/lib/esm/constants/link-controls.js.map +1 -0
  11. package/lib/esm/constants/node-controls.js +345 -0
  12. package/lib/esm/constants/node-controls.js.map +1 -0
  13. package/lib/esm/index.js +24 -3
  14. package/lib/esm/index.js.map +1 -1
  15. package/lib/esm/lib/fade-rgb.js.map +1 -1
  16. package/lib/esm/lib/rgb-animation-by-progress.js.map +1 -1
  17. package/lib/esm/module/GraphCanvas/GraphCanvas.js +29 -32
  18. package/lib/esm/module/GraphCanvas/GraphCanvas.js.map +1 -1
  19. package/lib/esm/module/GraphCanvas/constants/common-settings.js +7 -0
  20. package/lib/esm/module/GraphCanvas/constants/common-settings.js.map +1 -0
  21. package/lib/esm/module/GraphCanvas/constants/force-settings.js +29 -0
  22. package/lib/esm/module/GraphCanvas/constants/force-settings.js.map +1 -0
  23. package/lib/esm/module/GraphCanvas/constants/graph-settings.js +19 -0
  24. package/lib/esm/module/GraphCanvas/constants/graph-settings.js.map +1 -0
  25. package/lib/esm/module/GraphCanvas/constants/highlight-settings.js +62 -0
  26. package/lib/esm/module/GraphCanvas/constants/highlight-settings.js.map +1 -0
  27. package/lib/esm/module/GraphCanvas/constants/link-settings.js +31 -0
  28. package/lib/esm/module/GraphCanvas/constants/link-settings.js.map +1 -0
  29. package/lib/esm/module/GraphCanvas/constants/node-settings.js +50 -0
  30. package/lib/esm/module/GraphCanvas/constants/node-settings.js.map +1 -0
  31. package/lib/esm/module/GraphCanvas/lib/settings/force-settings-getter.js +3 -1
  32. package/lib/esm/module/GraphCanvas/lib/settings/force-settings-getter.js.map +1 -1
  33. package/lib/esm/module/GraphCanvas/lib/settings/graph-settings-getter.js +1 -1
  34. package/lib/esm/module/GraphCanvas/lib/settings/graph-settings-getter.js.map +1 -1
  35. package/lib/esm/module/GraphCanvas/lib/settings/highlight-settings-getter.js +13 -0
  36. package/lib/esm/module/GraphCanvas/lib/settings/highlight-settings-getter.js.map +1 -0
  37. package/lib/esm/module/GraphCanvas/lib/settings/link-settings-getter.js +13 -11
  38. package/lib/esm/module/GraphCanvas/lib/settings/link-settings-getter.js.map +1 -1
  39. package/lib/esm/module/GraphCanvas/lib/settings/node-settings-getter.js +22 -20
  40. package/lib/esm/module/GraphCanvas/lib/settings/node-settings-getter.js.map +1 -1
  41. package/lib/esm/module/GraphCanvas/lib/utils/calculate-link-position-by-node.js +8 -4
  42. package/lib/esm/module/GraphCanvas/lib/utils/calculate-link-position-by-node.js.map +1 -1
  43. package/lib/esm/module/GraphCanvas/lib/utils/drag-place-coefficient-getter.js.map +1 -1
  44. package/lib/esm/module/GraphCanvas/lib/utils/get-particle-position.js.map +1 -1
  45. package/lib/esm/module/GraphCanvas/lib/utils/is-node-visible.js +3 -1
  46. package/lib/esm/module/GraphCanvas/lib/utils/is-node-visible.js.map +1 -1
  47. package/lib/esm/module/GraphCanvas/lib/utils/is-overlaps-node.js.map +1 -1
  48. package/lib/esm/module/GraphCanvas/lib/utils/link-by-pointer-getter.js +2 -2
  49. package/lib/esm/module/GraphCanvas/lib/utils/link-by-pointer-getter.js.map +1 -1
  50. package/lib/esm/module/GraphCanvas/lib/utils/link-highlight.js +66 -0
  51. package/lib/esm/module/GraphCanvas/lib/utils/link-highlight.js.map +1 -0
  52. package/lib/esm/module/GraphCanvas/lib/utils/link-iteration-extractor.js +2 -3
  53. package/lib/esm/module/GraphCanvas/lib/utils/link-iteration-extractor.js.map +1 -1
  54. package/lib/esm/module/GraphCanvas/lib/utils/node-by-pointer-getter.js.map +1 -1
  55. package/lib/esm/module/GraphCanvas/lib/utils/node-highlight.js +115 -0
  56. package/lib/esm/module/GraphCanvas/lib/utils/node-highlight.js.map +1 -0
  57. package/lib/esm/module/GraphCanvas/lib/utils/node-iteration-extractor.js +2 -3
  58. package/lib/esm/module/GraphCanvas/lib/utils/node-iteration-extractor.js.map +1 -1
  59. package/lib/esm/module/GraphCanvas/slices/draw-links.js +90 -60
  60. package/lib/esm/module/GraphCanvas/slices/draw-links.js.map +1 -1
  61. package/lib/esm/module/GraphCanvas/slices/draw-nodes.js +214 -135
  62. package/lib/esm/module/GraphCanvas/slices/draw-nodes.js.map +1 -1
  63. package/lib/esm/module/GraphCanvas/slices/draw-text.js.map +1 -1
  64. package/lib/esm/module/GraphCanvas/slices/init-dnd.js +4 -4
  65. package/lib/esm/module/GraphCanvas/slices/init-dnd.js.map +1 -1
  66. package/lib/esm/module/GraphCanvas/slices/init-draw.js +4 -15
  67. package/lib/esm/module/GraphCanvas/slices/init-draw.js.map +1 -1
  68. package/lib/esm/module/GraphCanvas/slices/init-pointer.js +17 -17
  69. package/lib/esm/module/GraphCanvas/slices/init-pointer.js.map +1 -1
  70. package/lib/esm/module/GraphCanvas/slices/init-simulation.js +21 -22
  71. package/lib/esm/module/GraphCanvas/slices/init-simulation.js.map +1 -1
  72. package/lib/esm/module/GraphCanvas/slices/init-zoom.js +1 -1
  73. package/lib/esm/module/GraphCanvas/slices/init-zoom.js.map +1 -1
  74. package/lib/index.d.ts +436 -220
  75. package/package.json +1 -1
  76. package/lib/esm/lib/get-controls-info.js +0 -915
  77. package/lib/esm/lib/get-controls-info.js.map +0 -1
  78. package/lib/esm/module/GraphCanvas/constants/settings.js +0 -158
  79. package/lib/esm/module/GraphCanvas/constants/settings.js.map +0 -1
@@ -1,26 +1,22 @@
1
1
  import { isNumber } from '@krainovsd/js-helpers';
2
- import { colorToRgb } from '../../../lib/color-to-rgb.js';
3
- import { extractRgb } from '../../../lib/extract-rgb.js';
4
- import { fadeRgb } from '../../../lib/fade-rgb.js';
5
- import { rgbAnimationByProgress } from '../../../lib/rgb-animation-by-progress.js';
6
- import { nodeOptionsGetter, nodeRadiusGetter, nodeSizeGetter } from '../lib/settings/node-settings-getter.js';
2
+ import { nodeRadiusGetter, nodeSizeGetter, nodeOptionsGetter } from '../lib/settings/node-settings-getter.js';
7
3
  import 'd3-array';
8
4
  import { nodeIterationExtractor } from '../lib/utils/node-iteration-extractor.js';
9
- import { animationByProgress } from '../lib/utils/animation-by-progress.js';
10
5
  import { isNodeVisible } from '../lib/utils/is-node-visible.js';
6
+ import { nodeFade, nodeHighlight } from '../lib/utils/node-highlight.js';
11
7
  import { getTextLines, drawText } from './draw-text.js';
12
8
 
13
- function getDrawNode(nodeRenders, textRenders, state) {
9
+ function getDrawNode(nodeRenders, textRenders) {
14
10
  return function drawNode(node, index) {
15
11
  if (!this.context || !node.x || !node.y)
16
12
  return;
17
13
  let nodeOptions;
18
- if (this.nodeSettings.cache && this.nodeOptionsCache[node.id]) {
14
+ if (this.nodeSettings.cacheOptions && this.nodeOptionsCache[node.id]) {
19
15
  nodeOptions = this.nodeOptionsCache[node.id];
20
16
  }
21
17
  else {
22
- nodeOptions = nodeIterationExtractor(node, index, this.nodes, state, this.nodeSettings.options ?? {}, nodeOptionsGetter);
23
- if (this.nodeSettings.cache) {
18
+ nodeOptions = nodeIterationExtractor(node, index, this.nodes, this, this.nodeSettings.options ?? {}, nodeOptionsGetter);
19
+ if (this.nodeSettings.cacheOptions) {
24
20
  this.nodeOptionsCache[node.id] = nodeOptions;
25
21
  }
26
22
  }
@@ -39,6 +35,8 @@ function getDrawNode(nodeRenders, textRenders, state) {
39
35
  }
40
36
  let alpha = nodeOptions.alpha;
41
37
  let color = nodeOptions.color;
38
+ let borderColor = nodeOptions.borderColor;
39
+ let borderWidth = nodeOptions.borderWidth;
42
40
  let radiusInitial = nodeOptions.radius;
43
41
  let widthInitial = nodeOptions.width;
44
42
  let heightInitial = nodeOptions.height;
@@ -47,101 +45,107 @@ function getDrawNode(nodeRenders, textRenders, state) {
47
45
  let textShiftX = nodeOptions.textShiftX;
48
46
  let textShiftY = nodeOptions.textShiftY;
49
47
  let textWeight = nodeOptions.textWeight;
50
- let textWidth = nodeOptions.textWidth;
51
- let sizeCoefficient = 1;
52
- /** Node Highlight */
48
+ let labelSize = nodeOptions.labelSize;
49
+ let labelWeight = nodeOptions.labelWeight;
50
+ let labelAlpha = nodeOptions.labelAlpha;
51
+ /** Highlight */
53
52
  if (this.highlightedNeighbors && this.highlightedNode) {
54
- /** Not highlighted */
53
+ /** By Node Not Highlight */
55
54
  if (!this.highlightedNeighbors.has(node.id) && this.highlightedNode.id != node.id) {
56
- if (this.nodeSettings.highlightByNodeNodeFading) {
57
- const min = this.nodeSettings.highlightByNodeNodeFadingMin < alpha
58
- ? this.nodeSettings.highlightByNodeNodeFadingMin
59
- : alpha;
60
- alpha = animationByProgress(min, alpha - min, 1 - this.highlightProgress);
61
- }
62
- if (this.nodeSettings.highlightByNodeTextFading) {
63
- const min = this.nodeSettings.highlightByNodeTextFadingMin < textAlpha
64
- ? this.nodeSettings.highlightByNodeTextFadingMin
65
- : textAlpha;
66
- textAlpha = animationByProgress(min, textAlpha - min, 1 - this.highlightProgress);
67
- }
68
- if (this.nodeSettings.highlightByNodeNodeColor) {
69
- const colorRgb = extractRgb(colorToRgb(color));
70
- if (colorRgb) {
71
- const colorRgbFade = fadeRgb(colorRgb, this.nodeSettings.highlightByNodeNodeColorFadingMin);
72
- const colorFadeAnimation = rgbAnimationByProgress(colorRgb, colorRgbFade, this.highlightProgress);
73
- color = `rgb(${colorFadeAnimation.r}, ${colorFadeAnimation.g}, ${colorFadeAnimation.b})`;
74
- }
75
- }
55
+ const fadingOptions = nodeFade({
56
+ highlightProgress: this.highlightProgress,
57
+ nodeOptions,
58
+ highlightForLabelFadingMin: this.highlightSettings.highlightByNodeForLabelFadingMin,
59
+ highlightForNodeColorFading: this.highlightSettings.highlightByNodeForNodeColorFading,
60
+ highlightForNodeColorFadingMin: this.highlightSettings.highlightByNodeForNodeColorFadingMin,
61
+ highlightForNodeFadingMin: this.highlightSettings.highlightByNodeForNodeFadingMin,
62
+ highlightForTextFadingMin: this.highlightSettings.highlightByNodeForTextFadingMin,
63
+ });
64
+ alpha = fadingOptions.alpha;
65
+ color = fadingOptions.color;
66
+ textAlpha = fadingOptions.textAlpha;
67
+ labelAlpha = fadingOptions.labelAlpha;
76
68
  }
77
- else if (!this.nodeSettings.highlightByNodeOnlyRoot ||
78
- (this.nodeSettings.highlightByNodeOnlyRoot && this.highlightedNode.id === node.id)) {
79
- /** Highlighted */
80
- if (this.nodeSettings.highlightByNodeNodeSizing && nodeOptions.shape === "circle") {
81
- radiusInitial = animationByProgress(radiusInitial, this.nodeSettings.highlightByNodeNodeSizingAdditional, this.highlightProgress);
82
- }
83
- if (this.nodeSettings.highlightByNodeNodeSizing &&
84
- (nodeOptions.shape === "square" || nodeOptions.shape === "text")) {
85
- sizeCoefficient = animationByProgress(sizeCoefficient, this.nodeSettings.highlightByNodeNodeSizingAdditionalCoefficient, this.highlightProgress);
86
- widthInitial *= sizeCoefficient;
87
- heightInitial *= sizeCoefficient;
88
- }
89
- if (this.nodeSettings.highlightByNodeTextSizing) {
90
- textSize = animationByProgress(textSize, this.nodeSettings.highlightByNodeTextSizingAdditional, this.highlightProgress);
91
- textShiftX = animationByProgress(textShiftX, this.nodeSettings.highlightByNodeTextShiftXAdditional, this.highlightProgress);
92
- textShiftY = animationByProgress(textShiftY, this.nodeSettings.highlightByNodeTextShiftYAdditional, this.highlightProgress);
93
- textWeight = animationByProgress(textWeight, this.nodeSettings.highlightByNodeTextWeightAdditional, this.highlightProgress);
94
- textWidth = animationByProgress(textWidth, this.nodeSettings.highlightByNodeTextWidthAdditional, this.highlightProgress);
95
- }
69
+ else if (!this.highlightSettings.highlightByNodeOnlyRoot ||
70
+ (this.highlightSettings.highlightByNodeOnlyRoot && this.highlightedNode.id === node.id)) {
71
+ /** By Node Highlight */
72
+ const highlightOptions = nodeHighlight({
73
+ highlightProgress: this.highlightProgress,
74
+ nodeOptions,
75
+ highlightForLabelSizingAdditional: this.highlightSettings.highlightByNodeForLabelSizingAdditional,
76
+ highlightForLabelWeightAdditional: this.highlightSettings.highlightByNodeForLabelWeightAdditional,
77
+ highlightForNodeBorderColor: this.highlightSettings.highlightByNodeForNodeBorderColor,
78
+ highlightForNodeBorderSizingAdditional: this.highlightSettings.highlightByNodeForNodeBorderSizingAdditional,
79
+ highlightForNodeColor: this.highlightSettings.highlightByNodeForNodeColor,
80
+ highlightForNodeSizingAdditional: this.highlightSettings.highlightByNodeForNodeSizingAdditional,
81
+ highlightForNodeSizingAdditionalCoefficient: this.highlightSettings.highlightByNodeForNodeSizingAdditionalCoefficient,
82
+ highlightForTextShiftXAdditional: this.highlightSettings.highlightByNodeForTextShiftXAdditional,
83
+ highlightForTextShiftYAdditional: this.highlightSettings.highlightByNodeForTextShiftYAdditional,
84
+ highlightForTextSizingAdditional: this.highlightSettings.highlightByNodeForTextSizingAdditional,
85
+ highlightForTextWeightAdditional: this.highlightSettings.highlightByNodeForTextWeightAdditional,
86
+ });
87
+ color = highlightOptions.color;
88
+ borderColor = highlightOptions.borderColor;
89
+ borderWidth = highlightOptions.borderWidth;
90
+ radiusInitial = highlightOptions.radiusInitial;
91
+ widthInitial = highlightOptions.widthInitial;
92
+ heightInitial = highlightOptions.heightInitial;
93
+ textSize = highlightOptions.textSize;
94
+ textShiftX = highlightOptions.textShiftX;
95
+ textShiftY = highlightOptions.textShiftY;
96
+ textWeight = highlightOptions.textWeight;
97
+ labelSize = highlightOptions.labelSize;
98
+ labelWeight = highlightOptions.labelWeight;
96
99
  }
97
100
  }
98
- /** LinkHighlight */
99
101
  if (this.highlightedNeighbors && this.highlightedLink) {
100
- /** Not highlighted */
102
+ /** By Link Not Highlight */
101
103
  if (!this.highlightedNeighbors.has(node.id) &&
102
104
  this.highlightedLink.source !== node &&
103
105
  this.highlightedLink.target !== node) {
104
- if (this.nodeSettings.highlightByLinkNodeFading) {
105
- const min = this.nodeSettings.highlightByLinkNodeFadingMin < alpha
106
- ? this.nodeSettings.highlightByLinkNodeFadingMin
107
- : alpha;
108
- alpha = animationByProgress(min, alpha - min, 1 - this.highlightProgress);
109
- }
110
- if (this.nodeSettings.highlightByLinkTextFading) {
111
- const min = this.nodeSettings.highlightByLinkTextFadingMin < textAlpha
112
- ? this.nodeSettings.highlightByLinkTextFadingMin
113
- : textAlpha;
114
- textAlpha = animationByProgress(min, textAlpha - min, 1 - this.highlightProgress);
115
- }
116
- if (this.nodeSettings.highlightByLinkNodeColor) {
117
- const colorRgb = extractRgb(colorToRgb(color));
118
- if (colorRgb) {
119
- const colorRgbFade = fadeRgb(colorRgb, this.nodeSettings.highlightByLinkNodeColorFadingMin);
120
- const colorFadeAnimation = rgbAnimationByProgress(colorRgb, colorRgbFade, this.highlightProgress);
121
- color = `rgb(${colorFadeAnimation.r}, ${colorFadeAnimation.g}, ${colorFadeAnimation.b})`;
122
- }
123
- }
106
+ const fadingOptions = nodeFade({
107
+ highlightProgress: this.highlightProgress,
108
+ nodeOptions,
109
+ highlightForLabelFadingMin: this.highlightSettings.highlightByLinkForLabelFadingMin,
110
+ highlightForNodeColorFading: this.highlightSettings.highlightByLinkForNodeColorFading,
111
+ highlightForNodeColorFadingMin: this.highlightSettings.highlightByLinkForNodeColorFadingMin,
112
+ highlightForNodeFadingMin: this.highlightSettings.highlightByLinkForNodeFadingMin,
113
+ highlightForTextFadingMin: this.highlightSettings.highlightByLinkForTextFadingMin,
114
+ });
115
+ alpha = fadingOptions.alpha;
116
+ color = fadingOptions.color;
117
+ textAlpha = fadingOptions.textAlpha;
118
+ labelAlpha = fadingOptions.labelAlpha;
124
119
  }
125
120
  else {
126
- /** Highlighted */
127
- if (this.nodeSettings.highlightByLinkNodeSizing && nodeOptions.shape === "circle") {
128
- radiusInitial = animationByProgress(radiusInitial, this.nodeSettings.highlightByLinkNodeSizingAdditional, this.highlightProgress);
129
- }
130
- if (this.nodeSettings.highlightByLinkNodeSizing &&
131
- (nodeOptions.shape === "square" ||
132
- nodeOptions.shape === "text" ||
133
- nodeOptions.shape === "icon")) {
134
- sizeCoefficient = animationByProgress(sizeCoefficient, this.nodeSettings.highlightByNodeNodeSizingAdditionalCoefficient, this.highlightProgress);
135
- widthInitial *= sizeCoefficient;
136
- heightInitial *= sizeCoefficient;
137
- }
138
- if (this.nodeSettings.highlightByLinkTextSizing) {
139
- textSize = animationByProgress(textSize, this.nodeSettings.highlightByLinkTextSizingAdditional, this.highlightProgress);
140
- textShiftX = animationByProgress(textShiftX, this.nodeSettings.highlightByLinkTextShiftXAdditional, this.highlightProgress);
141
- textShiftY = animationByProgress(textShiftY, this.nodeSettings.highlightByLinkTextShiftYAdditional, this.highlightProgress);
142
- textWeight = animationByProgress(textWeight, this.nodeSettings.highlightByLinkTextWeightAdditional, this.highlightProgress);
143
- textWidth = animationByProgress(textWidth, this.nodeSettings.highlightByLinkTextWidthAdditional, this.highlightProgress);
144
- }
121
+ /** By Link Highlight */
122
+ const highlightOptions = nodeHighlight({
123
+ highlightProgress: this.highlightProgress,
124
+ nodeOptions,
125
+ highlightForLabelSizingAdditional: this.highlightSettings.highlightByLinkForLabelSizingAdditional,
126
+ highlightForLabelWeightAdditional: this.highlightSettings.highlightByLinkForLabelWeightAdditional,
127
+ highlightForNodeBorderColor: this.highlightSettings.highlightByLinkForNodeBorderColor,
128
+ highlightForNodeBorderSizingAdditional: this.highlightSettings.highlightByLinkForNodeBorderSizingAdditional,
129
+ highlightForNodeColor: this.highlightSettings.highlightByLinkForNodeColor,
130
+ highlightForNodeSizingAdditional: this.highlightSettings.highlightByLinkForNodeSizingAdditional,
131
+ highlightForNodeSizingAdditionalCoefficient: this.highlightSettings.highlightByLinkForNodeSizingAdditionalCoefficient,
132
+ highlightForTextShiftXAdditional: this.highlightSettings.highlightByLinkForTextShiftXAdditional,
133
+ highlightForTextShiftYAdditional: this.highlightSettings.highlightByLinkForTextShiftYAdditional,
134
+ highlightForTextSizingAdditional: this.highlightSettings.highlightByLinkForTextSizingAdditional,
135
+ highlightForTextWeightAdditional: this.highlightSettings.highlightByLinkForTextWeightAdditional,
136
+ });
137
+ color = highlightOptions.color;
138
+ borderColor = highlightOptions.borderColor;
139
+ borderWidth = highlightOptions.borderWidth;
140
+ radiusInitial = highlightOptions.radiusInitial;
141
+ widthInitial = highlightOptions.widthInitial;
142
+ heightInitial = highlightOptions.heightInitial;
143
+ textSize = highlightOptions.textSize;
144
+ textShiftX = highlightOptions.textShiftX;
145
+ textShiftY = highlightOptions.textShiftY;
146
+ textWeight = highlightOptions.textWeight;
147
+ labelSize = highlightOptions.labelSize;
148
+ labelWeight = highlightOptions.labelWeight;
145
149
  }
146
150
  }
147
151
  /** Flex radius */
@@ -179,14 +183,13 @@ function getDrawNode(nodeRenders, textRenders, state) {
179
183
  sizeFactor: this.nodeSettings.nodeSizeFactor,
180
184
  sizeFlexible: this.nodeSettings.nodeSizeFlexible,
181
185
  });
182
- textSize *= size.additionalSizeCoefficient;
186
+ labelSize *= size.additionalSizeCoefficient;
183
187
  }
184
188
  /** Size by text in textNode */
185
- if (nodeOptions.shape === "text" && nodeOptions.text) {
186
- textWidth = width;
189
+ if (nodeOptions.shape === "text" && nodeOptions.label) {
187
190
  let lines;
188
191
  let textNodeParameters;
189
- const cachedLines = this.cachedNodeText[node.id];
192
+ const cachedLines = this.cachedNodeLabel[node.id];
190
193
  const cachedTextNodeParameters = this.cachedTextNodeParameters[node.id];
191
194
  if (cachedLines != undefined && cachedTextNodeParameters != undefined) {
192
195
  lines = cachedLines;
@@ -195,30 +198,31 @@ function getDrawNode(nodeRenders, textRenders, state) {
195
198
  else {
196
199
  const textInfo = getTextLines({
197
200
  context: this.context,
198
- text: nodeOptions.text,
199
- textAlign: nodeOptions.textAlign,
200
- textColor: nodeOptions.textColor,
201
- textFont: nodeOptions.textFont,
202
- textSize,
203
- maxWidth: textWidth,
204
- textStyle: nodeOptions.textStyle,
201
+ text: nodeOptions.label,
202
+ textAlign: nodeOptions.labelAlign,
203
+ textColor: nodeOptions.labelColor,
204
+ textFont: nodeOptions.labelFont,
205
+ textSize: labelSize,
206
+ maxWidth: nodeOptions.labelWidth,
207
+ textStyle: nodeOptions.labelStyle,
205
208
  textWeight,
206
209
  });
207
- textNodeParameters = [textInfo.currentMaxSize, textSize];
210
+ textNodeParameters = [textInfo.currentMaxSize, labelSize];
208
211
  lines = textInfo.lines;
209
- this.cachedNodeText[node.id] = lines;
212
+ this.cachedNodeLabel[node.id] = lines;
210
213
  this.cachedTextNodeParameters[node.id] = textNodeParameters;
211
214
  }
212
- const textSizeCoefficient = textSize / textNodeParameters[1];
215
+ const textSizeCoefficient = labelSize / textNodeParameters[1];
213
216
  const maxSize = textNodeParameters[0] * textSizeCoefficient;
214
217
  height =
215
- lines.length * textSize +
216
- (lines.length - 1) * nodeOptions.textGap +
217
- nodeOptions.textNodeYPadding;
218
- width = maxSize + nodeOptions.textNodeXPadding;
218
+ lines.length * labelSize +
219
+ (lines.length - 1) * nodeOptions.labelGap +
220
+ nodeOptions.labelYPadding;
221
+ width = maxSize + nodeOptions.labelXPadding;
219
222
  }
220
223
  /** Node parameters */
221
224
  node._radius = radius;
225
+ node._borderWidth = borderWidth;
222
226
  node._width = width;
223
227
  node._height = height;
224
228
  node._borderRadius =
@@ -243,49 +247,127 @@ function getDrawNode(nodeRenders, textRenders, state) {
243
247
  return;
244
248
  this.context.beginPath();
245
249
  this.context.globalAlpha = alpha;
246
- this.context.lineWidth = nodeOptions.borderWidth;
247
- this.context.strokeStyle = nodeOptions.borderColor;
250
+ this.context.lineWidth = borderWidth;
251
+ this.context.strokeStyle = borderColor;
248
252
  this.context.fillStyle = color;
249
253
  switch (nodeOptions.shape) {
250
254
  case "circle": {
251
- this.context.arc(node.x, node.y, radius, 0, 2 * Math.PI);
255
+ if (!node.image) {
256
+ this.context.arc(node.x, node.y, radius, 0, 2 * Math.PI);
257
+ this.context.fill();
258
+ if (borderWidth > 0) {
259
+ this.context.stroke();
260
+ }
261
+ }
262
+ else {
263
+ this.context.arc(node.x, node.y, radius, 0, 2 * Math.PI);
264
+ this.context.closePath();
265
+ this.context.save();
266
+ this.context.clip();
267
+ this.context.drawImage(node.image, node.x - radius, node.y - radius, radius * 2, radius * 2);
268
+ this.context.restore();
269
+ if (borderWidth > 0) {
270
+ this.context.stroke();
271
+ }
272
+ }
273
+ if (node.label) {
274
+ this.context.globalAlpha = labelAlpha;
275
+ drawText({
276
+ context: this.context,
277
+ cachedNodeText: this.cachedNodeLabel,
278
+ id: node.id,
279
+ text: node.label,
280
+ textAlign: nodeOptions.labelAlign,
281
+ textColor: nodeOptions.labelColor,
282
+ textFont: nodeOptions.labelFont,
283
+ textGap: nodeOptions.labelGap,
284
+ textSize: labelSize,
285
+ textStyle: nodeOptions.labelStyle,
286
+ textWeight: labelWeight,
287
+ maxWidth: nodeOptions.labelWidth,
288
+ x: node.x,
289
+ y: node.y + labelSize / 3,
290
+ });
291
+ }
252
292
  break;
253
293
  }
254
294
  case "square": {
255
- this.context.roundRect(node.x - width / 2, node.y - height / 2, width, height, node._borderRadius);
295
+ if (!node.image) {
296
+ this.context.roundRect(node.x - width / 2, node.y - height / 2, width, height, node._borderRadius);
297
+ this.context.fill();
298
+ if (borderWidth > 0) {
299
+ this.context.stroke();
300
+ }
301
+ }
302
+ else {
303
+ this.context.roundRect(node.x - width / 2, node.y - height / 2, width, height, node._borderRadius);
304
+ this.context.closePath();
305
+ this.context.save();
306
+ this.context.clip();
307
+ this.context.drawImage(node.image, node.x - width / 2, node.y - height / 2, width, height);
308
+ this.context.restore();
309
+ if (borderWidth > 0) {
310
+ this.context.stroke();
311
+ }
312
+ }
313
+ if (node.label) {
314
+ this.context.globalAlpha = labelAlpha;
315
+ drawText({
316
+ context: this.context,
317
+ cachedNodeText: this.cachedNodeLabel,
318
+ id: node.id,
319
+ text: node.label,
320
+ textAlign: nodeOptions.labelAlign,
321
+ textColor: nodeOptions.labelColor,
322
+ textFont: nodeOptions.labelFont,
323
+ textGap: nodeOptions.labelGap,
324
+ textSize: labelSize,
325
+ textStyle: nodeOptions.labelStyle,
326
+ textWeight: labelWeight,
327
+ maxWidth: nodeOptions.labelWidth,
328
+ x: node.x,
329
+ y: node.y + labelSize / 3,
330
+ });
331
+ }
256
332
  break;
257
333
  }
258
334
  case "text": {
259
335
  if (this.nodeSettings.textNodeDebug) {
260
336
  this.context.strokeRect(node.x - width / 2, node.y - height / 2, width, height);
261
337
  }
262
- const lines = this.cachedNodeText[node.id];
263
- if (nodeOptions.text && lines)
338
+ const lines = this.cachedNodeLabel[node.id];
339
+ if (nodeOptions.label && lines)
264
340
  drawText({
265
341
  id: node.id,
266
- cachedNodeText: this.cachedNodeText,
342
+ cachedNodeText: this.cachedNodeLabel,
267
343
  context: this.context,
268
- text: nodeOptions.text,
269
- textAlign: nodeOptions.textAlign,
270
- textColor: nodeOptions.textColor,
271
- textFont: nodeOptions.textFont,
272
- textSize,
344
+ text: nodeOptions.label,
345
+ textAlign: nodeOptions.labelAlign,
346
+ textColor: nodeOptions.labelColor,
347
+ textFont: nodeOptions.labelFont,
348
+ textSize: labelSize,
273
349
  x: node.x,
274
350
  y: node.y + textSize / 4 - (lines.length - 1) * (textSize / 2),
275
- maxWidth: textWidth,
276
- textStyle: nodeOptions.textStyle,
351
+ maxWidth: nodeOptions.labelWidth,
352
+ textStyle: nodeOptions.labelStyle,
277
353
  textWeight,
278
- textGap: nodeOptions.textGap,
354
+ textGap: nodeOptions.labelGap,
279
355
  });
356
+ this.context.fill();
357
+ if (borderWidth > 0) {
358
+ this.context.stroke();
359
+ }
280
360
  break;
281
361
  }
282
362
  default: {
283
363
  this.context.arc(node.x, node.y, radius, 0, 2 * Math.PI);
364
+ this.context.fill();
365
+ if (borderWidth > 0) {
366
+ this.context.stroke();
367
+ }
284
368
  break;
285
369
  }
286
370
  }
287
- this.context.fill();
288
- this.context.stroke();
289
371
  });
290
372
  if (nodeOptions.nodeExtraDraw) {
291
373
  nodeRenders.push(() => {
@@ -299,12 +381,11 @@ function getDrawNode(nodeRenders, textRenders, state) {
299
381
  textShiftX,
300
382
  textShiftY,
301
383
  textWeight,
302
- textWidth,
303
384
  });
304
385
  });
305
386
  }
306
387
  /** Text draw */
307
- if (nodeOptions.textVisible && nodeOptions.text && nodeOptions.shape !== "text") {
388
+ if (nodeOptions.textVisible && nodeOptions.text) {
308
389
  textRenders.push(() => {
309
390
  if (nodeOptions.textDraw) {
310
391
  nodeOptions.textDraw.bind(this)(node, {
@@ -317,7 +398,6 @@ function getDrawNode(nodeRenders, textRenders, state) {
317
398
  textShiftX,
318
399
  textShiftY,
319
400
  textWeight,
320
- textWidth,
321
401
  });
322
402
  return;
323
403
  }
@@ -329,7 +409,7 @@ function getDrawNode(nodeRenders, textRenders, state) {
329
409
  if (nodeOptions.shape === "circle") {
330
410
  y += radius;
331
411
  }
332
- if (nodeOptions.shape === "square") {
412
+ if (nodeOptions.shape === "square" || nodeOptions.shape === "text") {
333
413
  y += height / 2;
334
414
  }
335
415
  drawText({
@@ -343,7 +423,7 @@ function getDrawNode(nodeRenders, textRenders, state) {
343
423
  textSize,
344
424
  x: node.x + textShiftX,
345
425
  y,
346
- maxWidth: textWidth,
426
+ maxWidth: nodeOptions.textWidth,
347
427
  textStyle: nodeOptions.textStyle,
348
428
  textWeight,
349
429
  textGap: nodeOptions.textGap,
@@ -359,7 +439,6 @@ function getDrawNode(nodeRenders, textRenders, state) {
359
439
  textShiftX,
360
440
  textShiftY,
361
441
  textWeight,
362
- textWidth,
363
442
  });
364
443
  }
365
444
  });