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

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 CHANGED
@@ -2,9 +2,9 @@
2
2
 
3
3
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
4
 
5
+ const jsHelpers = require('@krainovsd/js-helpers');
5
6
  const d3Force = require('d3-force');
6
7
  const d3Zoom = require('d3-zoom');
7
- const jsHelpers = require('@krainovsd/js-helpers');
8
8
  const d3Array = require('d3-array');
9
9
  const d3Selection = require('d3-selection');
10
10
  const d3Drag = require('d3-drag');
@@ -41,158 +41,6 @@ const FORCE_SETTINGS = {
41
41
  collideRadius: null,
42
42
  };
43
43
 
44
- const GRAPH_SETTINGS = {
45
- zoomExtent: [0.3, 10],
46
- translateExtent: [[], []],
47
- translateExtentEnable: true,
48
- translateExtentCoefficient: [3, 3],
49
- dragPlaceCoefficient: dragPlaceCoefficientGetter,
50
- zoomInitial: null,
51
- showDrawTime: true,
52
- showDrawTimeEveryTick: false,
53
- };
54
-
55
- const HIGHLIGHT_SETTINGS = {
56
- highlightByHoverNode: true,
57
- highlightByHoverLink: true,
58
- highlightUpFrames: 5,
59
- highlightDownFrames: 5,
60
- linkHoverExtraZone: 2,
61
- /** Node */
62
- highlightByNodeOnlyRoot: true,
63
- highlightByNodeForNodeColorFading: false,
64
- highlightByNodeForNodeColor: null,
65
- highlightByNodeForNodeSizingAdditional: 0.5,
66
- highlightByNodeForNodeSizingAdditionalCoefficient: 0.35,
67
- highlightByNodeForNodeFadingMin: 0.21,
68
- highlightByNodeForNodeBorderColor: null,
69
- highlightByNodeForNodeBorderSizingAdditional: 0,
70
- highlightByLinkForNodeColorFading: false,
71
- highlightByLinkForNodeColor: null,
72
- highlightByLinkForNodeSizingAdditional: 0.5,
73
- highlightByLinkForNodeSizingAdditionalCoefficient: 0.35,
74
- highlightByLinkForNodeFadingMin: 0.21,
75
- highlightByLinkForNodeBorderColor: null,
76
- highlightByLinkForNodeBorderSizingAdditional: 0,
77
- /** Text */
78
- highlightByNodeForTextShiftXAdditional: 0,
79
- highlightByNodeForTextShiftYAdditional: 2,
80
- highlightByNodeForTextSizingAdditional: 1,
81
- highlightByNodeForTextWeightAdditional: 0,
82
- highlightByNodeForTextFadingMin: 0.21,
83
- highlightByLinkForTextShiftXAdditional: 0,
84
- highlightByLinkForTextShiftYAdditional: 2,
85
- highlightByLinkForTextSizingAdditional: 1,
86
- highlightByLinkForTextWeightAdditional: 0,
87
- highlightByLinkForTextFadingMin: 0.21,
88
- /** Label */
89
- highlightByNodeForLabelFadingMin: 0.21,
90
- highlightByNodeForLabelSizingAdditional: 1,
91
- highlightByNodeForLabelWeightAdditional: 0,
92
- highlightByLinkForLabelFadingMin: 0.21,
93
- highlightByLinkForLabelSizingAdditional: 1,
94
- highlightByLinkForLabelWeightAdditional: 0,
95
- /** Link */
96
- highlightByNodeForLinkFadingMin: 0.21,
97
- highlightByNodeForLinkSizeAdditional: 0,
98
- highlightByNodeForLinkColor: null,
99
- highlightByLinkForLinkFadingMin: 0.21,
100
- highlightByLinkForLinkSizeAdditional: 0,
101
- highlightByLinkForLinkColor: null,
102
- /** Arrow */
103
- highlightByNodeForArrowFadingMin: 0.21,
104
- highlightByNodeForArrowSizeAdditional: 0,
105
- highlightByNodeForArrowColor: null,
106
- highlightByNodeForArrowBorderColor: null,
107
- highlightByNodeForArrowBorderSizingAdditional: 0,
108
- highlightByLinkForArrowFadingMin: 0.21,
109
- highlightByLinkForArrowSizeAdditional: 0,
110
- highlightByLinkForArrowColor: null,
111
- highlightByLinkForArrowBorderColor: null,
112
- highlightByLinkForArrowBorderSizingAdditional: 0,
113
- };
114
-
115
- const LINK_SETTINGS = {
116
- prettyDraw: true,
117
- linkScaleSwitch: 1,
118
- linkColorAfterScaleSwitch: "#000000FF",
119
- linkColorBeforeScaleSwitch: "#999",
120
- linkWidthAfterScaleSwitch: 0.1,
121
- linkWidthBeforeScaleSwitch: 1,
122
- arrow: true,
123
- arrowByHighlight: true,
124
- particles: true,
125
- particleFlexSpeed: true,
126
- particleFlexSpeedCoefficient: 4,
127
- };
128
- const LINK_OPTIONS = {
129
- alpha: 1,
130
- arrowAlpha: 1,
131
- arrowSize: 2,
132
- arrowBorderColor: "#000000FF",
133
- arrowBorderWidth: 0.1,
134
- particleAlpha: 1,
135
- particleColor: "#000000FF",
136
- particleBorderColor: "#000000FF",
137
- particleBorderWidth: 0.1,
138
- particleCount: 2,
139
- particleRadius: 0.5,
140
- particleSteps: 60,
141
- };
142
-
143
- const NODE_SETTINGS = {
144
- nodeRadiusFlexible: true,
145
- nodeRadiusLinkCountForStep: 5,
146
- nodeRadiusIncrementByStep: 1,
147
- nodeRadiusMaxLinearSteps: 5,
148
- nodeRadiusLinkCountDividerForLog: 25,
149
- nodeRadiusLogFactor: 2.5,
150
- nodeSizeFlexible: true,
151
- nodeSizeLinkCountForStep: 5,
152
- nodeSizeIncrementByStep: 0.1,
153
- nodeSizeMaxLinearSteps: 5,
154
- nodeSizeLinkCountDividerForLog: 25,
155
- nodeSizeLogFactor: 2.5,
156
- textScaleMin: 1.5,
157
- textScaleMax: 18,
158
- textSizeMin: 3.5,
159
- textSizeMax: 1.5,
160
- textShiftYMin: 4,
161
- textShiftYMax: 2.5,
162
- textNodeDebug: false,
163
- };
164
- const NODE_OPTIONS = {
165
- shape: "circle",
166
- height: 10,
167
- width: 15,
168
- borderRadius: 0,
169
- radius: 4,
170
- alpha: 1,
171
- labelXPadding: 1,
172
- labelYPadding: 1,
173
- borderWidth: 0.1,
174
- borderColor: "#000000FF",
175
- textAlpha: 1,
176
- textWidth: 20,
177
- textShiftX: 0,
178
- textFont: "Arial",
179
- textAlign: "center",
180
- textColor: "#333",
181
- textStyle: "normal",
182
- textWeight: 500,
183
- textGap: 0,
184
- label: null,
185
- labelAlpha: 1,
186
- labelAlign: "center",
187
- labelColor: "#333",
188
- labelFont: "Arial",
189
- labelGap: 0,
190
- labelSize: 3.5,
191
- labelStyle: "normal",
192
- labelWeight: 500,
193
- labelWidth: 20,
194
- };
195
-
196
44
  function forceSettingsGetter(settings, prevSettings) {
197
45
  return {
198
46
  ...(prevSettings ?? FORCE_SETTINGS),
@@ -1146,6 +994,165 @@ function extractLinkPointIds(link) {
1146
994
  return { sourceId, targetId };
1147
995
  }
1148
996
 
997
+ const GRAPH_SETTINGS = {
998
+ zoomExtent: [0.3, 10],
999
+ translateExtent: [[], []],
1000
+ translateExtentEnable: true,
1001
+ translateExtentCoefficient: [3, 3],
1002
+ dragPlaceCoefficient: dragPlaceCoefficientGetter,
1003
+ zoomInitial: null,
1004
+ showDrawTime: true,
1005
+ showDrawTimeEveryTick: false,
1006
+ };
1007
+
1008
+ const HIGHLIGHT_SETTINGS = {
1009
+ highlightByHoverNode: true,
1010
+ highlightByHoverLink: true,
1011
+ highlightUpFrames: 5,
1012
+ highlightDownFrames: 5,
1013
+ linkHoverExtraZone: 2,
1014
+ /** Node */
1015
+ highlightByNodeOnlyRoot: true,
1016
+ highlightByNodeForNodeColorFading: false,
1017
+ highlightByNodeForNodeColor: null,
1018
+ highlightByNodeForNodeSizingAdditional: 0.5,
1019
+ highlightByNodeForNodeSizingAdditionalCoefficient: 0.35,
1020
+ highlightByNodeForNodeFadingMin: 0.21,
1021
+ highlightByNodeForNodeBorderColor: null,
1022
+ highlightByNodeForNodeBorderSizingAdditional: 0,
1023
+ highlightByLinkForNodeColorFading: false,
1024
+ highlightByLinkForNodeColor: null,
1025
+ highlightByLinkForNodeSizingAdditional: 0.5,
1026
+ highlightByLinkForNodeSizingAdditionalCoefficient: 0.35,
1027
+ highlightByLinkForNodeFadingMin: 0.21,
1028
+ highlightByLinkForNodeBorderColor: null,
1029
+ highlightByLinkForNodeBorderSizingAdditional: 0,
1030
+ /** Text */
1031
+ highlightByNodeForTextShiftXAdditional: 0,
1032
+ highlightByNodeForTextShiftYAdditional: 2,
1033
+ highlightByNodeForTextSizingAdditional: 1,
1034
+ highlightByNodeForTextWeightAdditional: 0,
1035
+ highlightByNodeForTextFadingMin: 0.21,
1036
+ highlightByLinkForTextShiftXAdditional: 0,
1037
+ highlightByLinkForTextShiftYAdditional: 2,
1038
+ highlightByLinkForTextSizingAdditional: 1,
1039
+ highlightByLinkForTextWeightAdditional: 0,
1040
+ highlightByLinkForTextFadingMin: 0.21,
1041
+ /** Label */
1042
+ highlightByNodeForLabelFadingMin: 0.21,
1043
+ highlightByNodeForLabelSizingAdditional: 1,
1044
+ highlightByNodeForLabelWeightAdditional: 0,
1045
+ highlightByLinkForLabelFadingMin: 0.21,
1046
+ highlightByLinkForLabelSizingAdditional: 1,
1047
+ highlightByLinkForLabelWeightAdditional: 0,
1048
+ /** Link */
1049
+ highlightByNodeForLinkFadingMin: 0.21,
1050
+ highlightByNodeForLinkSizeAdditional: 0,
1051
+ highlightByNodeForLinkColor: null,
1052
+ highlightByLinkForLinkFadingMin: 0.21,
1053
+ highlightByLinkForLinkSizeAdditional: 0,
1054
+ highlightByLinkForLinkColor: null,
1055
+ /** Arrow */
1056
+ highlightByNodeForArrowFadingMin: 0.21,
1057
+ highlightByNodeForArrowSizeAdditional: 0,
1058
+ highlightByNodeForArrowColor: null,
1059
+ highlightByNodeForArrowBorderColor: null,
1060
+ highlightByNodeForArrowBorderSizingAdditional: 0,
1061
+ highlightByLinkForArrowFadingMin: 0.21,
1062
+ highlightByLinkForArrowSizeAdditional: 0,
1063
+ highlightByLinkForArrowColor: null,
1064
+ highlightByLinkForArrowBorderColor: null,
1065
+ highlightByLinkForArrowBorderSizingAdditional: 0,
1066
+ };
1067
+
1068
+ const LINK_SETTINGS = {
1069
+ prettyDraw: true,
1070
+ linkScaleSwitch: 1,
1071
+ linkColorAfterScaleSwitch: "#000000FF",
1072
+ linkColorBeforeScaleSwitch: "#999",
1073
+ linkWidthAfterScaleSwitch: 0.1,
1074
+ linkWidthBeforeScaleSwitch: 1,
1075
+ arrow: true,
1076
+ arrowByHighlight: true,
1077
+ particles: true,
1078
+ particleFlexSpeed: true,
1079
+ particleFlexSpeedCoefficient: 4,
1080
+ };
1081
+ const LINK_OPTIONS = {
1082
+ alpha: 1,
1083
+ arrowAlpha: 1,
1084
+ arrowSize: 2,
1085
+ arrowBorderColor: "#000000FF",
1086
+ arrowBorderWidth: 0.1,
1087
+ particleAlpha: 1,
1088
+ particleColor: "#000000FF",
1089
+ particleBorderColor: "#000000FF",
1090
+ particleBorderWidth: 0.1,
1091
+ particleCount: 2,
1092
+ particleRadius: 0.5,
1093
+ particleSteps: 60,
1094
+ };
1095
+
1096
+ const NODE_SETTINGS = {
1097
+ nodeRadiusFlexible: true,
1098
+ nodeRadiusLinkCountForStep: 5,
1099
+ nodeRadiusIncrementByStep: 1,
1100
+ nodeRadiusMaxLinearSteps: 5,
1101
+ nodeRadiusLinkCountDividerForLog: 25,
1102
+ nodeRadiusLogFactor: 2.5,
1103
+ nodeSizeFlexible: true,
1104
+ nodeSizeLinkCountForStep: 5,
1105
+ nodeSizeIncrementByStep: 0.1,
1106
+ nodeSizeMaxLinearSteps: 5,
1107
+ nodeSizeLinkCountDividerForLog: 25,
1108
+ nodeSizeLogFactor: 2.5,
1109
+ textScaleMin: 1.5,
1110
+ textScaleMax: 18,
1111
+ textSizeMin: 3.5,
1112
+ textSizeMax: 1.5,
1113
+ textShiftYMin: 4,
1114
+ textShiftYMax: 2.5,
1115
+ textNodeDebug: false,
1116
+ };
1117
+ const NODE_OPTIONS = {
1118
+ shape: "circle",
1119
+ height: 10,
1120
+ width: 15,
1121
+ borderRadius: 0,
1122
+ radius: 4,
1123
+ alpha: 1,
1124
+ labelXPadding: 1,
1125
+ labelYPadding: 1,
1126
+ borderWidth: 0.1,
1127
+ borderColor: "#000000FF",
1128
+ textAlpha: 1,
1129
+ textWidth: 20,
1130
+ textShiftX: 0,
1131
+ textFont: "Arial",
1132
+ textAlign: "center",
1133
+ textColor: "#333",
1134
+ textStyle: "normal",
1135
+ textWeight: 500,
1136
+ textGap: 0,
1137
+ label: null,
1138
+ labelAlpha: 1,
1139
+ labelAlign: "center",
1140
+ labelColor: "#333",
1141
+ labelFont: "Arial",
1142
+ labelGap: 0,
1143
+ labelSize: 3.5,
1144
+ labelStyle: "normal",
1145
+ labelWeight: 500,
1146
+ labelWidth: 20,
1147
+ };
1148
+
1149
+ const GRAPH_CACHE_TYPE = {
1150
+ NodeOptions: "nodeOptions",
1151
+ LinkOptions: "linkOptions",
1152
+ NodeText: "nodeText",
1153
+ NodeLabel: "nodeLabel",
1154
+ };
1155
+
1149
1156
  function initArea() {
1150
1157
  if (!this.area || !this.context || !this.container) {
1151
1158
  this.container = d3Selection.create("div")
@@ -2286,110 +2293,117 @@ function updateLinkCache() {
2286
2293
  }
2287
2294
  }
2288
2295
 
2289
- function updateNodeCache() {
2296
+ function updateNodeCache(types) {
2290
2297
  this.nodeOptionsCache = {};
2291
2298
  if (!this.context)
2292
2299
  return;
2293
2300
  for (let i = 0; i < this.nodes.length; i++) {
2294
2301
  const node = this.nodes[i];
2295
- const nodeOptions = nodeIterationExtractor(node, i, this.nodes, this, this.nodeSettings.options ?? {}, nodeOptionsGetter);
2296
- const radius = nodeOptions.shape === "circle"
2297
- ? nodeRadiusGetter({
2298
- radiusFlexible: this.nodeSettings.nodeRadiusFlexible,
2299
- radiusInitial: nodeOptions.radius,
2300
- radiusIncrementByStep: this.nodeSettings.nodeRadiusIncrementByStep,
2301
- radiusLinkCountForStep: this.nodeSettings.nodeRadiusLinkCountForStep,
2302
- radiusMaxLinearSteps: this.nodeSettings.nodeRadiusMaxLinearSteps,
2303
- radiusLogFactor: this.nodeSettings.nodeRadiusLogFactor,
2304
- radiusLinkCountDividerForLog: this.nodeSettings.nodeRadiusLinkCountDividerForLog,
2305
- linkCount: node.linkCount,
2306
- })
2307
- : nodeOptions.radius;
2308
- let width = nodeOptions.width;
2309
- let height = nodeOptions.height;
2310
- let labelSize = nodeOptions.labelSize;
2311
- if (nodeOptions.shape === "square") {
2312
- const size = nodeSizeGetter({
2313
- heightInitial: nodeOptions.height,
2314
- widthInitial: nodeOptions.width,
2315
- linkCount: node.linkCount,
2316
- sizeFlexible: this.nodeSettings.nodeSizeFlexible,
2317
- sizeIncrementByStep: this.nodeSettings.nodeSizeIncrementByStep,
2318
- sizeLinkCountForStep: this.nodeSettings.nodeSizeLinkCountForStep,
2319
- sizeMaxLinearSteps: this.nodeSettings.nodeSizeMaxLinearSteps,
2320
- sizeLogFactor: this.nodeSettings.nodeSizeLogFactor,
2321
- sizeLinkCountDividerForLog: this.nodeSettings.nodeSizeLinkCountDividerForLog,
2322
- });
2323
- width = size.width;
2324
- height = size.height;
2325
- }
2326
- if (nodeOptions.shape === "text") {
2327
- width = nodeOptions.width;
2328
- const size = nodeSizeGetter({
2329
- heightInitial: nodeOptions.height,
2330
- widthInitial: width,
2331
- linkCount: node.linkCount,
2332
- sizeFlexible: this.nodeSettings.nodeSizeFlexible,
2333
- sizeIncrementByStep: this.nodeSettings.nodeSizeIncrementByStep,
2334
- sizeLinkCountForStep: this.nodeSettings.nodeSizeLinkCountForStep,
2335
- sizeMaxLinearSteps: this.nodeSettings.nodeSizeMaxLinearSteps,
2336
- sizeLogFactor: this.nodeSettings.nodeSizeLogFactor,
2337
- sizeLinkCountDividerForLog: this.nodeSettings.nodeSizeLinkCountDividerForLog,
2338
- });
2339
- labelSize *= size.additionalSizeCoefficient;
2340
- }
2341
- /** label in not text shape */
2342
- if (nodeOptions.shape !== "text" && nodeOptions.label) {
2343
- this.context.font = `${nodeOptions.labelStyle} normal ${nodeOptions.labelWeight} ${nodeOptions.labelSize}px ${nodeOptions.labelFont}`;
2344
- this.context.fillStyle = nodeOptions.labelColor;
2345
- this.context.textAlign = nodeOptions.labelAlign;
2346
- if (nodeOptions.labelWidth == undefined ||
2347
- this.context.measureText(nodeOptions.label).width <= nodeOptions.labelWidth) {
2348
- this.cachedNodeLabel[node.id] = [nodeOptions.label];
2302
+ if (types === true || (jsHelpers.isObject(types) && types.options)) {
2303
+ const nodeOptions = nodeIterationExtractor(node, i, this.nodes, this, this.nodeSettings.options ?? {}, nodeOptionsGetter);
2304
+ const radius = nodeOptions.shape === "circle"
2305
+ ? nodeRadiusGetter({
2306
+ radiusFlexible: this.nodeSettings.nodeRadiusFlexible,
2307
+ radiusInitial: nodeOptions.radius,
2308
+ radiusIncrementByStep: this.nodeSettings.nodeRadiusIncrementByStep,
2309
+ radiusLinkCountForStep: this.nodeSettings.nodeRadiusLinkCountForStep,
2310
+ radiusMaxLinearSteps: this.nodeSettings.nodeRadiusMaxLinearSteps,
2311
+ radiusLogFactor: this.nodeSettings.nodeRadiusLogFactor,
2312
+ radiusLinkCountDividerForLog: this.nodeSettings.nodeRadiusLinkCountDividerForLog,
2313
+ linkCount: node.linkCount,
2314
+ })
2315
+ : nodeOptions.radius;
2316
+ let width = nodeOptions.width;
2317
+ let height = nodeOptions.height;
2318
+ let labelSize = nodeOptions.labelSize;
2319
+ if (nodeOptions.shape === "square") {
2320
+ const size = nodeSizeGetter({
2321
+ heightInitial: nodeOptions.height,
2322
+ widthInitial: nodeOptions.width,
2323
+ linkCount: node.linkCount,
2324
+ sizeFlexible: this.nodeSettings.nodeSizeFlexible,
2325
+ sizeIncrementByStep: this.nodeSettings.nodeSizeIncrementByStep,
2326
+ sizeLinkCountForStep: this.nodeSettings.nodeSizeLinkCountForStep,
2327
+ sizeMaxLinearSteps: this.nodeSettings.nodeSizeMaxLinearSteps,
2328
+ sizeLogFactor: this.nodeSettings.nodeSizeLogFactor,
2329
+ sizeLinkCountDividerForLog: this.nodeSettings.nodeSizeLinkCountDividerForLog,
2330
+ });
2331
+ width = size.width;
2332
+ height = size.height;
2333
+ }
2334
+ if (nodeOptions.shape === "text") {
2335
+ width = nodeOptions.width;
2336
+ const size = nodeSizeGetter({
2337
+ heightInitial: nodeOptions.height,
2338
+ widthInitial: width,
2339
+ linkCount: node.linkCount,
2340
+ sizeFlexible: this.nodeSettings.nodeSizeFlexible,
2341
+ sizeIncrementByStep: this.nodeSettings.nodeSizeIncrementByStep,
2342
+ sizeLinkCountForStep: this.nodeSettings.nodeSizeLinkCountForStep,
2343
+ sizeMaxLinearSteps: this.nodeSettings.nodeSizeMaxLinearSteps,
2344
+ sizeLogFactor: this.nodeSettings.nodeSizeLogFactor,
2345
+ sizeLinkCountDividerForLog: this.nodeSettings.nodeSizeLinkCountDividerForLog,
2346
+ });
2347
+ labelSize *= size.additionalSizeCoefficient;
2348
+ }
2349
+ nodeOptions.width = node.visible === false ? 0 : width;
2350
+ nodeOptions.height = node.visible === false ? 0 : height;
2351
+ nodeOptions.radius = node.visible === false ? 0 : radius;
2352
+ nodeOptions.labelSize = labelSize;
2353
+ this.nodeOptionsCache[node.id] = nodeOptions;
2354
+ }
2355
+ const nodeOptions = this.nodeOptionsCache[node.id];
2356
+ /** label */
2357
+ if (types === true || (jsHelpers.isObject(types) && types.label)) {
2358
+ /** label in not text shape */
2359
+ if (nodeOptions.shape !== "text" && nodeOptions.label) {
2360
+ this.context.font = `${nodeOptions.labelStyle} normal ${nodeOptions.labelWeight} ${nodeOptions.labelSize}px ${nodeOptions.labelFont}`;
2361
+ this.context.fillStyle = nodeOptions.labelColor;
2362
+ this.context.textAlign = nodeOptions.labelAlign;
2363
+ if (nodeOptions.labelWidth == undefined ||
2364
+ this.context.measureText(nodeOptions.label).width <= nodeOptions.labelWidth) {
2365
+ this.cachedNodeLabel[node.id] = [nodeOptions.label];
2366
+ }
2367
+ const { lines } = getTextLines({
2368
+ context: this.context,
2369
+ maxWidth: nodeOptions.labelWidth,
2370
+ text: nodeOptions.label,
2371
+ textAlign: nodeOptions.labelAlign,
2372
+ textColor: nodeOptions.labelColor,
2373
+ textFont: nodeOptions.labelFont,
2374
+ textSize: nodeOptions.labelSize,
2375
+ textStyle: nodeOptions.labelStyle,
2376
+ textWeight: nodeOptions.labelWeight,
2377
+ });
2378
+ this.cachedNodeLabel[node.id] = lines;
2379
+ /** label in text shape */
2380
+ }
2381
+ else if (nodeOptions.shape === "text" && nodeOptions.label) {
2382
+ const textInfo = getTextLines({
2383
+ context: this.context,
2384
+ text: nodeOptions.label,
2385
+ textAlign: nodeOptions.labelAlign,
2386
+ textColor: nodeOptions.labelColor,
2387
+ textFont: nodeOptions.labelFont,
2388
+ textSize: nodeOptions.labelSize,
2389
+ maxWidth: nodeOptions.labelWidth,
2390
+ textStyle: nodeOptions.labelStyle,
2391
+ textWeight: nodeOptions.textWeight,
2392
+ });
2393
+ const textNodeParameters = [textInfo.currentMaxSize, nodeOptions.labelSize];
2394
+ const lines = textInfo.lines;
2395
+ const textSizeCoefficient = nodeOptions.labelSize / textNodeParameters[1];
2396
+ const maxSize = textNodeParameters[0] * textSizeCoefficient;
2397
+ nodeOptions.height =
2398
+ lines.length * nodeOptions.labelSize +
2399
+ (lines.length - 1) * nodeOptions.labelGap +
2400
+ nodeOptions.labelYPadding;
2401
+ nodeOptions.width = maxSize + nodeOptions.labelXPadding;
2402
+ this.cachedNodeLabel[node.id] = lines;
2349
2403
  }
2350
- const { lines } = getTextLines({
2351
- context: this.context,
2352
- maxWidth: nodeOptions.labelWidth,
2353
- text: nodeOptions.label,
2354
- textAlign: nodeOptions.labelAlign,
2355
- textColor: nodeOptions.labelColor,
2356
- textFont: nodeOptions.labelFont,
2357
- textSize: nodeOptions.labelSize,
2358
- textStyle: nodeOptions.labelStyle,
2359
- textWeight: nodeOptions.labelWeight,
2360
- });
2361
- this.cachedNodeLabel[node.id] = lines;
2362
2404
  }
2363
- /** label in text shape */
2364
- if (nodeOptions.shape === "text" && nodeOptions.label) {
2365
- const textInfo = getTextLines({
2366
- context: this.context,
2367
- text: nodeOptions.label,
2368
- textAlign: nodeOptions.labelAlign,
2369
- textColor: nodeOptions.labelColor,
2370
- textFont: nodeOptions.labelFont,
2371
- textSize: labelSize,
2372
- maxWidth: nodeOptions.labelWidth,
2373
- textStyle: nodeOptions.labelStyle,
2374
- textWeight: nodeOptions.textWeight,
2375
- });
2376
- const textNodeParameters = [textInfo.currentMaxSize, labelSize];
2377
- const lines = textInfo.lines;
2378
- const textSizeCoefficient = labelSize / textNodeParameters[1];
2379
- const maxSize = textNodeParameters[0] * textSizeCoefficient;
2380
- height =
2381
- lines.length * labelSize +
2382
- (lines.length - 1) * nodeOptions.labelGap +
2383
- nodeOptions.labelYPadding;
2384
- width = maxSize + nodeOptions.labelXPadding;
2385
- this.cachedNodeLabel[node.id] = lines;
2386
- }
2387
- nodeOptions.width = node.visible === false ? 0 : width;
2388
- nodeOptions.height = node.visible === false ? 0 : height;
2389
- nodeOptions.radius = node.visible === false ? 0 : radius;
2390
- nodeOptions.labelSize = labelSize;
2391
2405
  /** text */
2392
- if (nodeOptions.text) {
2406
+ if (nodeOptions.text && (types === true || (jsHelpers.isObject(types) && types.text))) {
2393
2407
  this.context.font = `${nodeOptions.textStyle} normal ${nodeOptions.textWeight} ${nodeOptions.textSize}px ${nodeOptions.textFont}`;
2394
2408
  this.context.fillStyle = nodeOptions.textColor;
2395
2409
  this.context.textAlign = nodeOptions.textAlign;
@@ -2410,7 +2424,6 @@ function updateNodeCache() {
2410
2424
  });
2411
2425
  this.cachedNodeText[node.id] = lines;
2412
2426
  }
2413
- this.nodeOptionsCache[node.id] = nodeOptions;
2414
2427
  }
2415
2428
  }
2416
2429
 
@@ -2421,9 +2434,12 @@ function initZoom(currentZoom) {
2421
2434
  .scaleExtent(this.graphSettings.zoomExtent)
2422
2435
  .on("zoom", (event) => {
2423
2436
  this.listeners.onZoom?.call?.(this, event);
2437
+ const oldTransform = this.areaTransform;
2424
2438
  this.areaTransform = event.transform;
2425
- updateLinkCache.call(this);
2426
- updateNodeCache.call(this);
2439
+ if (this.areaTransform.k !== oldTransform.k) {
2440
+ updateLinkCache.call(this);
2441
+ updateNodeCache.call(this, true);
2442
+ }
2427
2443
  if (!this.simulationWorking && !this.highlightWorking)
2428
2444
  requestAnimationFrame(() => this.draw());
2429
2445
  });
@@ -2531,20 +2547,38 @@ class GraphCanvas {
2531
2547
  }
2532
2548
  if (options.highlightSettings) {
2533
2549
  this.highlightSettings = highlightSettingsGetter(options.highlightSettings, this.highlightSettings);
2534
- if (clearCache) {
2535
- this.clearCache(["nodeOptionsCache", "linkOptionsCache"]);
2550
+ if (clearCache === true) {
2551
+ this.clearCache([
2552
+ GRAPH_CACHE_TYPE.NodeOptions,
2553
+ GRAPH_CACHE_TYPE.NodeText,
2554
+ GRAPH_CACHE_TYPE.NodeLabel,
2555
+ GRAPH_CACHE_TYPE.LinkOptions,
2556
+ ]);
2557
+ }
2558
+ else {
2559
+ this.clearCache(clearCache);
2536
2560
  }
2537
2561
  }
2538
2562
  if (options.linkSettings) {
2539
2563
  this.linkSettings = linkSettingsGetter(options.linkSettings, this.linkSettings);
2540
2564
  if (clearCache) {
2541
- this.clearCache(["linkOptionsCache"]);
2565
+ this.clearCache([GRAPH_CACHE_TYPE.LinkOptions]);
2566
+ }
2567
+ else {
2568
+ this.clearCache(clearCache);
2542
2569
  }
2543
2570
  }
2544
2571
  if (options.nodeSettings) {
2545
2572
  this.nodeSettings = nodeSettingsGetter(options.nodeSettings, this.nodeSettings);
2546
2573
  if (clearCache) {
2547
- this.clearCache(["nodeOptionsCache"]);
2574
+ this.clearCache([
2575
+ GRAPH_CACHE_TYPE.NodeOptions,
2576
+ GRAPH_CACHE_TYPE.NodeText,
2577
+ GRAPH_CACHE_TYPE.NodeLabel,
2578
+ ]);
2579
+ }
2580
+ else {
2581
+ this.clearCache(clearCache);
2548
2582
  }
2549
2583
  initCollideForce.call(this, true);
2550
2584
  }
@@ -2572,48 +2606,24 @@ class GraphCanvas {
2572
2606
  throw new Error("couldn't create canvas context");
2573
2607
  this.context.scale(this.dpi, this.dpi);
2574
2608
  this.draw();
2575
- // this.clearHTMLElements();
2576
- // initArea.call<
2577
- // GraphCanvas<NodeData, LinkData>,
2578
- // Parameters<typeof initArea>,
2579
- // ReturnType<typeof initArea>
2580
- // >(this);
2581
- // initDnd.call<
2582
- // GraphCanvas<NodeData, LinkData>,
2583
- // Parameters<typeof initDnd>,
2584
- // ReturnType<typeof initDnd>
2585
- // >(this);
2586
- // initZoom.call<
2587
- // GraphCanvas<NodeData, LinkData>,
2588
- // Parameters<typeof initZoom>,
2589
- // ReturnType<typeof initZoom>
2590
- // >(this);
2591
- // initResize.call<
2592
- // GraphCanvas<NodeData, LinkData>,
2593
- // Parameters<typeof initResize>,
2594
- // ReturnType<typeof initResize>
2595
- // >(this);
2596
- // initPointer.call<
2597
- // GraphCanvas<NodeData, LinkData>,
2598
- // Parameters<typeof initPointer>,
2599
- // ReturnType<typeof initPointer>
2600
- // >(this);
2601
- // this.draw();
2602
2609
  }
2603
2610
  clearCache(keys) {
2604
- if (!keys) {
2605
- updateNodeCache.call(this);
2611
+ if (keys === true) {
2612
+ updateNodeCache.call(this, true);
2606
2613
  updateLinkCache.call(this);
2607
2614
  }
2608
- else {
2609
- for (let i = 0; i < keys.length; i++) {
2610
- const key = keys[i];
2611
- if (key === "nodeOptionsCache") {
2612
- updateNodeCache.call(this);
2613
- }
2614
- else {
2615
- updateLinkCache.call(this);
2616
- }
2615
+ else if (jsHelpers.isArray(keys)) {
2616
+ if (keys.some((k) => k === GRAPH_CACHE_TYPE.NodeText ||
2617
+ k === GRAPH_CACHE_TYPE.NodeLabel ||
2618
+ k === GRAPH_CACHE_TYPE.NodeOptions)) {
2619
+ updateNodeCache.call(this, {
2620
+ label: keys.includes(GRAPH_CACHE_TYPE.NodeLabel),
2621
+ options: keys.includes(GRAPH_CACHE_TYPE.NodeOptions),
2622
+ text: keys.includes(GRAPH_CACHE_TYPE.NodeOptions),
2623
+ });
2624
+ }
2625
+ if (keys.includes(GRAPH_CACHE_TYPE.LinkOptions)) {
2626
+ updateLinkCache.call(this);
2617
2627
  }
2618
2628
  }
2619
2629
  }
@@ -2647,7 +2657,7 @@ class GraphCanvas {
2647
2657
  }
2648
2658
  this.clearHTMLElements();
2649
2659
  this.clearState();
2650
- this.clearCache();
2660
+ this.clearCache(true);
2651
2661
  }
2652
2662
  clearHTMLElements() {
2653
2663
  this.root.replaceChildren();
@@ -2674,7 +2684,7 @@ class GraphCanvas {
2674
2684
  }
2675
2685
  updateData(alpha = 0.5, clearCache = true) {
2676
2686
  if (clearCache) {
2677
- this.clearCache();
2687
+ this.clearCache(clearCache);
2678
2688
  }
2679
2689
  if (this.simulation) {
2680
2690
  initCollideForce.call(this, false);
@@ -2697,7 +2707,7 @@ class GraphCanvas {
2697
2707
  }
2698
2708
  init() {
2699
2709
  initArea.call(this);
2700
- updateNodeCache.call(this);
2710
+ updateNodeCache.call(this, true);
2701
2711
  updateLinkCache.call(this);
2702
2712
  initSimulation.call(this);
2703
2713
  initDnd.call(this);
@@ -3884,6 +3894,7 @@ const NODE_OPTIONS_LABEL_CONTROLS = [
3884
3894
  exports.COMMON_SETTINGS = COMMON_SETTINGS;
3885
3895
  exports.FORCE_CONTROLS = FORCE_CONTROLS;
3886
3896
  exports.FORCE_SETTINGS = FORCE_SETTINGS;
3897
+ exports.GRAPH_CACHE_TYPE = GRAPH_CACHE_TYPE;
3887
3898
  exports.GRAPH_SETTINGS = GRAPH_SETTINGS;
3888
3899
  exports.GraphCanvas = GraphCanvas;
3889
3900
  exports.HIGHLIGHT_BY_LINK_FOR_ARROW_CONTROLS = HIGHLIGHT_BY_LINK_FOR_ARROW_CONTROLS;