@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.
- package/lib/cjs/index.cjs +1909 -1321
- package/lib/cjs/index.cjs.map +1 -1
- package/lib/esm/constants/force-controls.js +141 -0
- package/lib/esm/constants/force-controls.js.map +1 -0
- package/lib/esm/constants/graph-controls.js +25 -0
- package/lib/esm/constants/graph-controls.js.map +1 -0
- package/lib/esm/constants/highlight-controls.js +452 -0
- package/lib/esm/constants/highlight-controls.js.map +1 -0
- package/lib/esm/constants/link-controls.js +219 -0
- package/lib/esm/constants/link-controls.js.map +1 -0
- package/lib/esm/constants/node-controls.js +345 -0
- package/lib/esm/constants/node-controls.js.map +1 -0
- package/lib/esm/index.js +24 -3
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/lib/fade-rgb.js.map +1 -1
- package/lib/esm/lib/rgb-animation-by-progress.js.map +1 -1
- package/lib/esm/module/GraphCanvas/GraphCanvas.js +29 -32
- package/lib/esm/module/GraphCanvas/GraphCanvas.js.map +1 -1
- package/lib/esm/module/GraphCanvas/constants/common-settings.js +7 -0
- package/lib/esm/module/GraphCanvas/constants/common-settings.js.map +1 -0
- package/lib/esm/module/GraphCanvas/constants/force-settings.js +29 -0
- package/lib/esm/module/GraphCanvas/constants/force-settings.js.map +1 -0
- package/lib/esm/module/GraphCanvas/constants/graph-settings.js +19 -0
- package/lib/esm/module/GraphCanvas/constants/graph-settings.js.map +1 -0
- package/lib/esm/module/GraphCanvas/constants/highlight-settings.js +62 -0
- package/lib/esm/module/GraphCanvas/constants/highlight-settings.js.map +1 -0
- package/lib/esm/module/GraphCanvas/constants/link-settings.js +31 -0
- package/lib/esm/module/GraphCanvas/constants/link-settings.js.map +1 -0
- package/lib/esm/module/GraphCanvas/constants/node-settings.js +50 -0
- package/lib/esm/module/GraphCanvas/constants/node-settings.js.map +1 -0
- package/lib/esm/module/GraphCanvas/lib/settings/force-settings-getter.js +3 -1
- package/lib/esm/module/GraphCanvas/lib/settings/force-settings-getter.js.map +1 -1
- package/lib/esm/module/GraphCanvas/lib/settings/graph-settings-getter.js +1 -1
- package/lib/esm/module/GraphCanvas/lib/settings/graph-settings-getter.js.map +1 -1
- package/lib/esm/module/GraphCanvas/lib/settings/highlight-settings-getter.js +13 -0
- package/lib/esm/module/GraphCanvas/lib/settings/highlight-settings-getter.js.map +1 -0
- package/lib/esm/module/GraphCanvas/lib/settings/link-settings-getter.js +13 -11
- package/lib/esm/module/GraphCanvas/lib/settings/link-settings-getter.js.map +1 -1
- package/lib/esm/module/GraphCanvas/lib/settings/node-settings-getter.js +22 -20
- package/lib/esm/module/GraphCanvas/lib/settings/node-settings-getter.js.map +1 -1
- package/lib/esm/module/GraphCanvas/lib/utils/calculate-link-position-by-node.js +8 -4
- package/lib/esm/module/GraphCanvas/lib/utils/calculate-link-position-by-node.js.map +1 -1
- package/lib/esm/module/GraphCanvas/lib/utils/drag-place-coefficient-getter.js.map +1 -1
- package/lib/esm/module/GraphCanvas/lib/utils/get-particle-position.js.map +1 -1
- package/lib/esm/module/GraphCanvas/lib/utils/is-node-visible.js +3 -1
- package/lib/esm/module/GraphCanvas/lib/utils/is-node-visible.js.map +1 -1
- package/lib/esm/module/GraphCanvas/lib/utils/is-overlaps-node.js.map +1 -1
- package/lib/esm/module/GraphCanvas/lib/utils/link-by-pointer-getter.js +2 -2
- package/lib/esm/module/GraphCanvas/lib/utils/link-by-pointer-getter.js.map +1 -1
- package/lib/esm/module/GraphCanvas/lib/utils/link-highlight.js +66 -0
- package/lib/esm/module/GraphCanvas/lib/utils/link-highlight.js.map +1 -0
- package/lib/esm/module/GraphCanvas/lib/utils/link-iteration-extractor.js +2 -3
- package/lib/esm/module/GraphCanvas/lib/utils/link-iteration-extractor.js.map +1 -1
- package/lib/esm/module/GraphCanvas/lib/utils/node-by-pointer-getter.js.map +1 -1
- package/lib/esm/module/GraphCanvas/lib/utils/node-highlight.js +115 -0
- package/lib/esm/module/GraphCanvas/lib/utils/node-highlight.js.map +1 -0
- package/lib/esm/module/GraphCanvas/lib/utils/node-iteration-extractor.js +2 -3
- package/lib/esm/module/GraphCanvas/lib/utils/node-iteration-extractor.js.map +1 -1
- package/lib/esm/module/GraphCanvas/slices/draw-links.js +90 -60
- package/lib/esm/module/GraphCanvas/slices/draw-links.js.map +1 -1
- package/lib/esm/module/GraphCanvas/slices/draw-nodes.js +214 -135
- package/lib/esm/module/GraphCanvas/slices/draw-nodes.js.map +1 -1
- package/lib/esm/module/GraphCanvas/slices/draw-text.js.map +1 -1
- package/lib/esm/module/GraphCanvas/slices/init-dnd.js +4 -4
- package/lib/esm/module/GraphCanvas/slices/init-dnd.js.map +1 -1
- package/lib/esm/module/GraphCanvas/slices/init-draw.js +4 -15
- package/lib/esm/module/GraphCanvas/slices/init-draw.js.map +1 -1
- package/lib/esm/module/GraphCanvas/slices/init-pointer.js +17 -17
- package/lib/esm/module/GraphCanvas/slices/init-pointer.js.map +1 -1
- package/lib/esm/module/GraphCanvas/slices/init-simulation.js +21 -22
- package/lib/esm/module/GraphCanvas/slices/init-simulation.js.map +1 -1
- package/lib/esm/module/GraphCanvas/slices/init-zoom.js +1 -1
- package/lib/esm/module/GraphCanvas/slices/init-zoom.js.map +1 -1
- package/lib/index.d.ts +436 -220
- package/package.json +1 -1
- package/lib/esm/lib/get-controls-info.js +0 -915
- package/lib/esm/lib/get-controls-info.js.map +0 -1
- package/lib/esm/module/GraphCanvas/constants/settings.js +0 -158
- 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 {
|
|
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
|
|
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.
|
|
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,
|
|
23
|
-
if (this.nodeSettings.
|
|
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
|
|
51
|
-
let
|
|
52
|
-
|
|
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
|
|
53
|
+
/** By Node Not Highlight */
|
|
55
54
|
if (!this.highlightedNeighbors.has(node.id) && this.highlightedNode.id != node.id) {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
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.
|
|
78
|
-
(this.
|
|
79
|
-
/**
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
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
|
|
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
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
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
|
-
/**
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
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
|
-
|
|
186
|
+
labelSize *= size.additionalSizeCoefficient;
|
|
183
187
|
}
|
|
184
188
|
/** Size by text in textNode */
|
|
185
|
-
if (nodeOptions.shape === "text" && nodeOptions.
|
|
186
|
-
textWidth = width;
|
|
189
|
+
if (nodeOptions.shape === "text" && nodeOptions.label) {
|
|
187
190
|
let lines;
|
|
188
191
|
let textNodeParameters;
|
|
189
|
-
const cachedLines = this.
|
|
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.
|
|
199
|
-
textAlign: nodeOptions.
|
|
200
|
-
textColor: nodeOptions.
|
|
201
|
-
textFont: nodeOptions.
|
|
202
|
-
textSize,
|
|
203
|
-
maxWidth:
|
|
204
|
-
textStyle: nodeOptions.
|
|
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,
|
|
210
|
+
textNodeParameters = [textInfo.currentMaxSize, labelSize];
|
|
208
211
|
lines = textInfo.lines;
|
|
209
|
-
this.
|
|
212
|
+
this.cachedNodeLabel[node.id] = lines;
|
|
210
213
|
this.cachedTextNodeParameters[node.id] = textNodeParameters;
|
|
211
214
|
}
|
|
212
|
-
const textSizeCoefficient =
|
|
215
|
+
const textSizeCoefficient = labelSize / textNodeParameters[1];
|
|
213
216
|
const maxSize = textNodeParameters[0] * textSizeCoefficient;
|
|
214
217
|
height =
|
|
215
|
-
lines.length *
|
|
216
|
-
(lines.length - 1) * nodeOptions.
|
|
217
|
-
nodeOptions.
|
|
218
|
-
width = maxSize + nodeOptions.
|
|
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 =
|
|
247
|
-
this.context.strokeStyle =
|
|
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
|
-
|
|
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
|
-
|
|
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.
|
|
263
|
-
if (nodeOptions.
|
|
338
|
+
const lines = this.cachedNodeLabel[node.id];
|
|
339
|
+
if (nodeOptions.label && lines)
|
|
264
340
|
drawText({
|
|
265
341
|
id: node.id,
|
|
266
|
-
cachedNodeText: this.
|
|
342
|
+
cachedNodeText: this.cachedNodeLabel,
|
|
267
343
|
context: this.context,
|
|
268
|
-
text: nodeOptions.
|
|
269
|
-
textAlign: nodeOptions.
|
|
270
|
-
textColor: nodeOptions.
|
|
271
|
-
textFont: nodeOptions.
|
|
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:
|
|
276
|
-
textStyle: nodeOptions.
|
|
351
|
+
maxWidth: nodeOptions.labelWidth,
|
|
352
|
+
textStyle: nodeOptions.labelStyle,
|
|
277
353
|
textWeight,
|
|
278
|
-
textGap: nodeOptions.
|
|
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
|
|
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
|
});
|