@krainovsd/graph 0.12.0-beta.5 → 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/esm/index.js CHANGED
@@ -34,14 +34,15 @@ import 'lodash';
34
34
  import 'd3-force';
35
35
  import 'd3-zoom';
36
36
  export { drawText } from './module/GraphCanvas/slices/draw-text.js';
37
+ export { GRAPH_CACHE_TYPE } from './module/GraphCanvas/constants/index.js';
38
+ export { FORCE_CONTROLS } from './constants/force-controls.js';
39
+ export { 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 } from './constants/highlight-controls.js';
40
+ export { LINK_OPTIONS_ARROW_CONTROLS, LINK_OPTIONS_LINK_CONTROLS, LINK_OPTIONS_PARTICLE_CONTROLS, LINK_SETTINGS_CONTROLS } from './constants/link-controls.js';
41
+ export { NODE_OPTIONS_LABEL_CONTROLS, NODE_OPTIONS_NODE_CONTROLS, NODE_OPTIONS_TEXT_CONTROLS, NODE_SETTINGS_CONTROLS } from './constants/node-controls.js';
37
42
  export { COMMON_SETTINGS } from './module/GraphCanvas/constants/common-settings.js';
38
43
  export { FORCE_SETTINGS } from './module/GraphCanvas/constants/force-settings.js';
39
44
  export { GRAPH_SETTINGS } from './module/GraphCanvas/constants/graph-settings.js';
40
45
  export { HIGHLIGHT_SETTINGS } from './module/GraphCanvas/constants/highlight-settings.js';
41
46
  export { LINK_OPTIONS, LINK_SETTINGS } from './module/GraphCanvas/constants/link-settings.js';
42
47
  export { NODE_OPTIONS, NODE_SETTINGS } from './module/GraphCanvas/constants/node-settings.js';
43
- export { FORCE_CONTROLS } from './constants/force-controls.js';
44
- export { 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 } from './constants/highlight-controls.js';
45
- export { LINK_OPTIONS_ARROW_CONTROLS, LINK_OPTIONS_LINK_CONTROLS, LINK_OPTIONS_PARTICLE_CONTROLS, LINK_SETTINGS_CONTROLS } from './constants/link-controls.js';
46
- export { NODE_OPTIONS_LABEL_CONTROLS, NODE_OPTIONS_NODE_CONTROLS, NODE_OPTIONS_TEXT_CONTROLS, NODE_SETTINGS_CONTROLS } from './constants/node-controls.js';
47
48
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -1,12 +1,13 @@
1
+ import { isArray } from '@krainovsd/js-helpers';
1
2
  import { forceLink } from 'd3-force';
2
3
  import { zoomIdentity } from 'd3-zoom';
4
+ import { GRAPH_CACHE_TYPE } from './constants/index.js';
3
5
  import { forceSettingsGetter } from './lib/settings/force-settings-getter.js';
4
6
  import { graphSettingsGetter } from './lib/settings/graph-settings-getter.js';
5
7
  import { linkSettingsGetter } from './lib/settings/link-settings-getter.js';
6
8
  import { listenersGetter } from './lib/settings/listeners-getter.js';
7
9
  import { nodeSettingsGetter } from './lib/settings/node-settings-getter.js';
8
10
  import { highlightSettingsGetter } from './lib/settings/highlight-settings-getter.js';
9
- import '@krainovsd/js-helpers';
10
11
  import 'd3-array';
11
12
  import { initArea } from './slices/init-area.js';
12
13
  import { initDnd } from './slices/init-dnd.js';
@@ -105,20 +106,38 @@ class GraphCanvas {
105
106
  }
106
107
  if (options.highlightSettings) {
107
108
  this.highlightSettings = highlightSettingsGetter(options.highlightSettings, this.highlightSettings);
108
- if (clearCache) {
109
- this.clearCache(["nodeOptionsCache", "linkOptionsCache"]);
109
+ if (clearCache === true) {
110
+ this.clearCache([
111
+ GRAPH_CACHE_TYPE.NodeOptions,
112
+ GRAPH_CACHE_TYPE.NodeText,
113
+ GRAPH_CACHE_TYPE.NodeLabel,
114
+ GRAPH_CACHE_TYPE.LinkOptions,
115
+ ]);
116
+ }
117
+ else {
118
+ this.clearCache(clearCache);
110
119
  }
111
120
  }
112
121
  if (options.linkSettings) {
113
122
  this.linkSettings = linkSettingsGetter(options.linkSettings, this.linkSettings);
114
123
  if (clearCache) {
115
- this.clearCache(["linkOptionsCache"]);
124
+ this.clearCache([GRAPH_CACHE_TYPE.LinkOptions]);
125
+ }
126
+ else {
127
+ this.clearCache(clearCache);
116
128
  }
117
129
  }
118
130
  if (options.nodeSettings) {
119
131
  this.nodeSettings = nodeSettingsGetter(options.nodeSettings, this.nodeSettings);
120
132
  if (clearCache) {
121
- this.clearCache(["nodeOptionsCache"]);
133
+ this.clearCache([
134
+ GRAPH_CACHE_TYPE.NodeOptions,
135
+ GRAPH_CACHE_TYPE.NodeText,
136
+ GRAPH_CACHE_TYPE.NodeLabel,
137
+ ]);
138
+ }
139
+ else {
140
+ this.clearCache(clearCache);
122
141
  }
123
142
  initCollideForce.call(this, true);
124
143
  }
@@ -141,22 +160,29 @@ class GraphCanvas {
141
160
  this.area.width = this.dpi * this.width;
142
161
  this.area.height = this.dpi * this.height;
143
162
  this.areaRect = this.area.getBoundingClientRect();
163
+ this.context = this.area.getContext("2d");
164
+ if (!this.context)
165
+ throw new Error("couldn't create canvas context");
166
+ this.context.scale(this.dpi, this.dpi);
144
167
  this.draw();
145
168
  }
146
169
  clearCache(keys) {
147
- if (!keys) {
148
- updateNodeCache.call(this);
170
+ if (keys === true) {
171
+ updateNodeCache.call(this, true);
149
172
  updateLinkCache.call(this);
150
173
  }
151
- else {
152
- for (let i = 0; i < keys.length; i++) {
153
- const key = keys[i];
154
- if (key === "nodeOptionsCache") {
155
- updateNodeCache.call(this);
156
- }
157
- else {
158
- updateLinkCache.call(this);
159
- }
174
+ else if (isArray(keys)) {
175
+ if (keys.some((k) => k === GRAPH_CACHE_TYPE.NodeText ||
176
+ k === GRAPH_CACHE_TYPE.NodeLabel ||
177
+ k === GRAPH_CACHE_TYPE.NodeOptions)) {
178
+ updateNodeCache.call(this, {
179
+ label: keys.includes(GRAPH_CACHE_TYPE.NodeLabel),
180
+ options: keys.includes(GRAPH_CACHE_TYPE.NodeOptions),
181
+ text: keys.includes(GRAPH_CACHE_TYPE.NodeOptions),
182
+ });
183
+ }
184
+ if (keys.includes(GRAPH_CACHE_TYPE.LinkOptions)) {
185
+ updateLinkCache.call(this);
160
186
  }
161
187
  }
162
188
  }
@@ -190,7 +216,7 @@ class GraphCanvas {
190
216
  }
191
217
  this.clearHTMLElements();
192
218
  this.clearState();
193
- this.clearCache();
219
+ this.clearCache(true);
194
220
  }
195
221
  clearHTMLElements() {
196
222
  this.root.replaceChildren();
@@ -217,7 +243,7 @@ class GraphCanvas {
217
243
  }
218
244
  updateData(alpha = 0.5, clearCache = true) {
219
245
  if (clearCache) {
220
- this.clearCache();
246
+ this.clearCache(clearCache);
221
247
  }
222
248
  if (this.simulation) {
223
249
  initCollideForce.call(this, false);
@@ -240,7 +266,7 @@ class GraphCanvas {
240
266
  }
241
267
  init() {
242
268
  initArea.call(this);
243
- updateNodeCache.call(this);
269
+ updateNodeCache.call(this, true);
244
270
  updateLinkCache.call(this);
245
271
  initSimulation.call(this);
246
272
  initDnd.call(this);
@@ -1 +1 @@
1
- {"version":3,"file":"GraphCanvas.js","sources":["../../../../src/module/GraphCanvas/GraphCanvas.ts"],"sourcesContent":["import { forceLink } from \"d3-force\";\nimport { type ZoomTransform, zoomIdentity } from \"d3-zoom\";\nimport {\n forceSettingsGetter,\n graphSettingsGetter,\n highlightSettingsGetter,\n linkSettingsGetter,\n listenersGetter,\n nodeSettingsGetter,\n} from \"./lib\";\nimport {\n initArea,\n initCollideForce,\n initDnd,\n initDraw,\n initPointer,\n initResize,\n initSimulation,\n initSimulationForces,\n initZoom,\n updateLinkCache,\n updateNodeCache,\n} from \"./slices\";\nimport type {\n CachedNodeTextInterface,\n ForceSettingsInterface,\n GraphCanvasInterface,\n GraphCanvasSimulation,\n GraphSettingsInterface,\n HighlightSettingsInterface,\n LinkInterface,\n LinkOptionsInterface,\n LinkParticle,\n LinkSettingsInterface,\n ListenersInterface,\n NodeInterface,\n NodeOptionsInterface,\n NodeSettingsInterface,\n} from \"./types\";\n\nexport class GraphCanvas<\n NodeData extends Record<string, unknown>,\n LinkData extends Record<string, unknown>,\n> {\n /** initial data */\n\n protected nodes: NodeInterface<NodeData>[];\n\n protected links: LinkInterface<NodeData, LinkData>[];\n\n protected particles: Record<string, LinkParticle[]> = {};\n\n protected width: number;\n\n protected height: number;\n\n protected root: HTMLElement;\n\n protected container: HTMLDivElement | undefined | null;\n\n protected area: HTMLCanvasElement | null | undefined;\n\n /** settings */\n\n protected graphSettings: Required<GraphSettingsInterface<NodeData>>;\n\n protected forceSettings: Required<ForceSettingsInterface<NodeData, LinkData>>;\n\n protected highlightSettings: Required<HighlightSettingsInterface>;\n\n protected nodeSettings: Required<Omit<NodeSettingsInterface<NodeData, LinkData>, \"options\">> &\n Pick<NodeSettingsInterface<NodeData, LinkData>, \"options\">;\n\n protected linkSettings: Required<Omit<LinkSettingsInterface<NodeData, LinkData>, \"options\">> &\n Pick<LinkSettingsInterface<NodeData, LinkData>, \"options\">;\n\n protected listeners: ListenersInterface<NodeData, LinkData>;\n\n /** service */\n\n protected context: CanvasRenderingContext2D | null | undefined;\n\n protected simulation: GraphCanvasSimulation<NodeData, LinkData> | undefined;\n\n protected areaTransform: ZoomTransform = zoomIdentity;\n\n protected areaRect: DOMRect | undefined;\n\n protected draw: (this: GraphCanvas<NodeData, LinkData>, recursive?: boolean) => void;\n\n protected eventAbortController: AbortController;\n\n protected cachedNodeText: CachedNodeTextInterface = {};\n\n protected cachedNodeLabel: CachedNodeTextInterface = {};\n\n protected linkOptionsCache: Record<string, Required<LinkOptionsInterface<NodeData, LinkData>>> =\n {};\n\n protected nodeOptionsCache: Record<string, Required<NodeOptionsInterface<NodeData, LinkData>>> =\n {};\n\n protected isDragging: boolean = false;\n\n protected highlightedNode: NodeInterface<NodeData> | null = null;\n\n protected highlightedLink: LinkInterface<NodeData, LinkData> | null = null;\n\n protected highlightedNeighbors: Set<string | number> | null = null;\n\n protected highlightProgress: number = 1;\n\n protected highlightWorking: boolean = false;\n\n protected get simulationWorking() {\n const simulationAlpha = this.simulation?.alpha?.() ?? 0;\n const simulationAlphaMin = this.simulation?.alphaMin?.() ?? 0;\n const simulationAlphaDecay = this.simulation?.alphaDecay?.() ?? 0;\n const force = (simulationAlpha - simulationAlphaMin) / simulationAlphaDecay;\n\n return force > 0;\n }\n\n constructor({\n links,\n nodes,\n root,\n forceSettings,\n linkSettings,\n listeners,\n nodeSettings,\n graphSettings,\n highlightSettings,\n }: GraphCanvasInterface<NodeData, LinkData>) {\n // root.style.position = \"relative\";\n root.style.overflow = \"hidden\";\n\n this.root = root;\n\n this.forceSettings = forceSettingsGetter(forceSettings);\n this.linkSettings = linkSettingsGetter(linkSettings);\n this.nodeSettings = nodeSettingsGetter(nodeSettings);\n this.listeners = listenersGetter(listeners);\n this.graphSettings = graphSettingsGetter(graphSettings);\n this.highlightSettings = highlightSettingsGetter(highlightSettings);\n\n this.eventAbortController = new AbortController();\n\n this.nodes = nodes;\n this.links = links;\n this.height = 0;\n this.width = 0;\n\n this.draw = initDraw.call<\n GraphCanvas<NodeData, LinkData>,\n Parameters<typeof initDraw>,\n ReturnType<typeof initDraw>\n >(this);\n\n this.init();\n }\n\n get dpi() {\n return devicePixelRatio;\n }\n\n getData(): Pick<GraphCanvasInterface<NodeData, LinkData>, \"nodes\" | \"links\"> {\n return {\n links: this.links,\n nodes: this.nodes,\n };\n }\n\n changeData(\n options: Pick<Partial<GraphCanvasInterface<NodeData, LinkData>>, \"links\" | \"nodes\">,\n alpha: number = 0.5,\n clearCache: boolean = true,\n ) {\n if (options.links != undefined) this.links = options.links;\n if (options.nodes != undefined) this.nodes = options.nodes;\n if (options.nodes != undefined || options.links != undefined)\n this.updateData(alpha, clearCache);\n }\n\n changeSettings(\n options: Omit<\n Partial<GraphCanvasInterface<NodeData, LinkData>>,\n \"links\" | \"nodes\" | \"listeners\"\n >,\n clearCache: boolean = true,\n ) {\n if (options.graphSettings) {\n this.graphSettings = graphSettingsGetter(options.graphSettings, this.graphSettings);\n\n this.draw = initDraw.call<\n GraphCanvas<NodeData, LinkData>,\n Parameters<typeof initDraw>,\n ReturnType<typeof initDraw>\n >(this);\n initZoom.call<\n GraphCanvas<NodeData, LinkData>,\n Parameters<typeof initZoom>,\n ReturnType<typeof initZoom>\n >(this, this.areaTransform);\n }\n if (options.forceSettings) {\n this.forceSettings = forceSettingsGetter(options.forceSettings, this.forceSettings);\n }\n if (options.highlightSettings) {\n this.highlightSettings = highlightSettingsGetter(\n options.highlightSettings,\n this.highlightSettings,\n );\n\n if (clearCache) {\n this.clearCache([\"nodeOptionsCache\", \"linkOptionsCache\"]);\n }\n }\n if (options.linkSettings) {\n this.linkSettings = linkSettingsGetter(options.linkSettings, this.linkSettings);\n\n if (clearCache) {\n this.clearCache([\"linkOptionsCache\"]);\n }\n }\n if (options.nodeSettings) {\n this.nodeSettings = nodeSettingsGetter(options.nodeSettings, this.nodeSettings);\n\n if (clearCache) {\n this.clearCache([\"nodeOptionsCache\"]);\n }\n\n initCollideForce.call<\n GraphCanvas<NodeData, LinkData>,\n Parameters<typeof initCollideForce>,\n ReturnType<typeof initCollideForce>\n >(this, true);\n }\n\n if (options.forceSettings) {\n return void this.updateSimulation();\n }\n\n this.tick();\n }\n\n updateRect() {\n if (!this.area) return;\n\n this.areaRect = this.area.getBoundingClientRect();\n }\n\n updateSize() {\n if (!this.area) return;\n\n const { width, height } = this.root.getBoundingClientRect();\n this.width = width;\n this.height = height;\n this.area.width = this.dpi * this.width;\n this.area.height = this.dpi * this.height;\n this.areaRect = this.area.getBoundingClientRect();\n\n this.draw();\n }\n\n clearCache(keys?: (\"nodeOptionsCache\" | \"linkOptionsCache\")[]) {\n if (!keys) {\n updateNodeCache.call<\n GraphCanvas<NodeData, LinkData>,\n Parameters<typeof updateNodeCache>,\n ReturnType<typeof updateNodeCache>\n >(this);\n updateLinkCache.call<\n GraphCanvas<NodeData, LinkData>,\n Parameters<typeof updateLinkCache>,\n ReturnType<typeof updateLinkCache>\n >(this);\n } else {\n for (let i = 0; i < keys.length; i++) {\n const key = keys[i];\n if (key === \"nodeOptionsCache\") {\n updateNodeCache.call<\n GraphCanvas<NodeData, LinkData>,\n Parameters<typeof updateNodeCache>,\n ReturnType<typeof updateNodeCache>\n >(this);\n } else {\n updateLinkCache.call<\n GraphCanvas<NodeData, LinkData>,\n Parameters<typeof updateLinkCache>,\n ReturnType<typeof updateLinkCache>\n >(this);\n }\n }\n }\n }\n\n tick() {\n if (!this.simulationWorking && !this.highlightWorking) this.draw();\n }\n\n restart(alpha?: number) {\n if (this.simulation) this.simulation.alpha(alpha ?? 1).restart();\n }\n\n start() {\n if (this.simulation) this.simulation.alpha(1).restart();\n if (this.container) this.container.style.display = \"block\";\n }\n\n stop() {\n if (this.simulation) this.simulation.stop();\n if (this.container) this.container.style.display = \"none\";\n }\n\n create() {\n this.init();\n }\n\n destroy() {\n if (this.simulation) {\n this.simulation.stop();\n this.simulation = undefined;\n }\n\n this.clearHTMLElements();\n this.clearState();\n this.clearCache();\n }\n\n protected clearHTMLElements() {\n this.root.replaceChildren();\n this.area = undefined;\n this.context = undefined;\n this.container = undefined;\n this.eventAbortController.abort();\n this.eventAbortController = new AbortController();\n }\n\n protected updateSimulation() {\n if (this.simulation) {\n initSimulationForces.call<\n GraphCanvas<NodeData, LinkData>,\n Parameters<typeof initSimulationForces>,\n ReturnType<typeof initSimulationForces>\n >(this);\n this.simulation.alpha(1);\n this.simulation.restart();\n }\n }\n\n protected clearState() {\n this.isDragging = false;\n this.highlightedNode = null;\n this.highlightedLink = null;\n this.highlightedNeighbors = null;\n this.highlightProgress = 0;\n this.highlightWorking = false;\n }\n\n protected updateData(alpha: number = 0.5, clearCache: boolean = true) {\n if (clearCache) {\n this.clearCache();\n }\n\n if (this.simulation) {\n initCollideForce.call<\n GraphCanvas<NodeData, LinkData>,\n Parameters<typeof initCollideForce>,\n ReturnType<typeof initCollideForce>\n >(this, false);\n\n this.simulation\n .nodes(this.nodes)\n .force(\n \"link\",\n forceLink<NodeInterface<NodeData>, LinkInterface<NodeData, LinkData>>(this.links)\n .id(this.nodeSettings.idGetter.bind(this))\n .distance(\n this.forceSettings.forces && this.forceSettings.linkForce\n ? this.forceSettings.linkDistance\n : 0,\n )\n .strength(\n this.forceSettings.forces && this.forceSettings.linkForce\n ? this.forceSettings.linkStrength\n : 0,\n )\n .iterations(\n this.forceSettings.forces && this.forceSettings.linkForce\n ? this.forceSettings.linkIterations\n : 0,\n ),\n )\n .alpha(alpha)\n .restart();\n }\n }\n\n protected init() {\n initArea.call<\n GraphCanvas<NodeData, LinkData>,\n Parameters<typeof initArea>,\n ReturnType<typeof initArea>\n >(this);\n updateNodeCache.call<\n GraphCanvas<NodeData, LinkData>,\n Parameters<typeof updateNodeCache>,\n ReturnType<typeof updateNodeCache>\n >(this);\n updateLinkCache.call<\n GraphCanvas<NodeData, LinkData>,\n Parameters<typeof updateLinkCache>,\n ReturnType<typeof updateLinkCache>\n >(this);\n initSimulation.call<\n GraphCanvas<NodeData, LinkData>,\n Parameters<typeof initSimulation>,\n ReturnType<typeof initSimulation>\n >(this);\n initDnd.call<\n GraphCanvas<NodeData, LinkData>,\n Parameters<typeof initDnd>,\n ReturnType<typeof initDnd>\n >(this);\n initZoom.call<\n GraphCanvas<NodeData, LinkData>,\n Parameters<typeof initZoom>,\n ReturnType<typeof initZoom>\n >(this);\n initResize.call<\n GraphCanvas<NodeData, LinkData>,\n Parameters<typeof initResize>,\n ReturnType<typeof initResize>\n >(this);\n initPointer.call<\n GraphCanvas<NodeData, LinkData>,\n Parameters<typeof initPointer>,\n ReturnType<typeof initPointer>\n >(this);\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;MAwCa,WAAW,CAAA;;AAMZ,IAAA,KAAK;AAEL,IAAA,KAAK;IAEL,SAAS,GAAmC,EAAE;AAE9C,IAAA,KAAK;AAEL,IAAA,MAAM;AAEN,IAAA,IAAI;AAEJ,IAAA,SAAS;AAET,IAAA,IAAI;;AAIJ,IAAA,aAAa;AAEb,IAAA,aAAa;AAEb,IAAA,iBAAiB;AAEjB,IAAA,YAAY;AAGZ,IAAA,YAAY;AAGZ,IAAA,SAAS;;AAIT,IAAA,OAAO;AAEP,IAAA,UAAU;IAEV,aAAa,GAAkB,YAAY;AAE3C,IAAA,QAAQ;AAER,IAAA,IAAI;AAEJ,IAAA,oBAAoB;IAEpB,cAAc,GAA4B,EAAE;IAE5C,eAAe,GAA4B,EAAE;IAE7C,gBAAgB,GACxB,EAAE;IAEM,gBAAgB,GACxB,EAAE;IAEM,UAAU,GAAY,KAAK;IAE3B,eAAe,GAAmC,IAAI;IAEtD,eAAe,GAA6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I,CAAC;AACP,QAAA,OAAO,CAAC,IAAI,CAIV,IAAI,CAAC;AACP,QAAA,QAAQ,CAAC,IAAI,CAIX,IAAI,CAAC;AACP,QAAA,UAAU,CAAC,IAAI,CAIb,IAAI,CAAC;AACP,QAAA,WAAW,CAAC,IAAI,CAId,IAAI,CAAC;;AAEV;;;;"}
1
+ {"version":3,"file":"GraphCanvas.js","sources":["../../../../src/module/GraphCanvas/GraphCanvas.ts"],"sourcesContent":["import { isArray } from \"@krainovsd/js-helpers\";\nimport { forceLink } from \"d3-force\";\nimport { type ZoomTransform, zoomIdentity } from \"d3-zoom\";\nimport { GRAPH_CACHE_TYPE } from \"./constants\";\nimport {\n forceSettingsGetter,\n graphSettingsGetter,\n highlightSettingsGetter,\n linkSettingsGetter,\n listenersGetter,\n nodeSettingsGetter,\n} from \"./lib\";\nimport {\n initArea,\n initCollideForce,\n initDnd,\n initDraw,\n initPointer,\n initResize,\n initSimulation,\n initSimulationForces,\n initZoom,\n updateLinkCache,\n updateNodeCache,\n} from \"./slices\";\nimport type {\n CachedNodeTextInterface,\n ForceSettingsInterface,\n GraphCanvasCacheKeys,\n GraphCanvasInterface,\n GraphCanvasSimulation,\n GraphSettingsInterface,\n HighlightSettingsInterface,\n LinkInterface,\n LinkOptionsInterface,\n LinkParticle,\n LinkSettingsInterface,\n ListenersInterface,\n NodeInterface,\n NodeOptionsInterface,\n NodeSettingsInterface,\n} from \"./types\";\n\nexport class GraphCanvas<\n NodeData extends Record<string, unknown>,\n LinkData extends Record<string, unknown>,\n> {\n /** initial data */\n\n protected nodes: NodeInterface<NodeData>[];\n\n protected links: LinkInterface<NodeData, LinkData>[];\n\n protected particles: Record<string, LinkParticle[]> = {};\n\n protected width: number;\n\n protected height: number;\n\n protected root: HTMLElement;\n\n protected container: HTMLDivElement | undefined | null;\n\n protected area: HTMLCanvasElement | null | undefined;\n\n /** settings */\n\n protected graphSettings: Required<GraphSettingsInterface<NodeData>>;\n\n protected forceSettings: Required<ForceSettingsInterface<NodeData, LinkData>>;\n\n protected highlightSettings: Required<HighlightSettingsInterface>;\n\n protected nodeSettings: Required<Omit<NodeSettingsInterface<NodeData, LinkData>, \"options\">> &\n Pick<NodeSettingsInterface<NodeData, LinkData>, \"options\">;\n\n protected linkSettings: Required<Omit<LinkSettingsInterface<NodeData, LinkData>, \"options\">> &\n Pick<LinkSettingsInterface<NodeData, LinkData>, \"options\">;\n\n protected listeners: ListenersInterface<NodeData, LinkData>;\n\n /** service */\n\n protected context: CanvasRenderingContext2D | null | undefined;\n\n protected simulation: GraphCanvasSimulation<NodeData, LinkData> | undefined;\n\n protected areaTransform: ZoomTransform = zoomIdentity;\n\n protected areaRect: DOMRect | undefined;\n\n protected draw: (this: GraphCanvas<NodeData, LinkData>, recursive?: boolean) => void;\n\n protected eventAbortController: AbortController;\n\n protected cachedNodeText: CachedNodeTextInterface = {};\n\n protected cachedNodeLabel: CachedNodeTextInterface = {};\n\n protected linkOptionsCache: Record<string, Required<LinkOptionsInterface<NodeData, LinkData>>> =\n {};\n\n protected nodeOptionsCache: Record<string, Required<NodeOptionsInterface<NodeData, LinkData>>> =\n {};\n\n protected isDragging: boolean = false;\n\n protected highlightedNode: NodeInterface<NodeData> | null = null;\n\n protected highlightedLink: LinkInterface<NodeData, LinkData> | null = null;\n\n protected highlightedNeighbors: Set<string | number> | null = null;\n\n protected highlightProgress: number = 1;\n\n protected highlightWorking: boolean = false;\n\n protected get simulationWorking() {\n const simulationAlpha = this.simulation?.alpha?.() ?? 0;\n const simulationAlphaMin = this.simulation?.alphaMin?.() ?? 0;\n const simulationAlphaDecay = this.simulation?.alphaDecay?.() ?? 0;\n const force = (simulationAlpha - simulationAlphaMin) / simulationAlphaDecay;\n\n return force > 0;\n }\n\n constructor({\n links,\n nodes,\n root,\n forceSettings,\n linkSettings,\n listeners,\n nodeSettings,\n graphSettings,\n highlightSettings,\n }: GraphCanvasInterface<NodeData, LinkData>) {\n // root.style.position = \"relative\";\n root.style.overflow = \"hidden\";\n\n this.root = root;\n\n this.forceSettings = forceSettingsGetter(forceSettings);\n this.linkSettings = linkSettingsGetter(linkSettings);\n this.nodeSettings = nodeSettingsGetter(nodeSettings);\n this.listeners = listenersGetter(listeners);\n this.graphSettings = graphSettingsGetter(graphSettings);\n this.highlightSettings = highlightSettingsGetter(highlightSettings);\n\n this.eventAbortController = new AbortController();\n\n this.nodes = nodes;\n this.links = links;\n this.height = 0;\n this.width = 0;\n\n this.draw = initDraw.call<\n GraphCanvas<NodeData, LinkData>,\n Parameters<typeof initDraw>,\n ReturnType<typeof initDraw>\n >(this);\n\n this.init();\n }\n\n get dpi() {\n return devicePixelRatio;\n }\n\n getData(): Pick<GraphCanvasInterface<NodeData, LinkData>, \"nodes\" | \"links\"> {\n return {\n links: this.links,\n nodes: this.nodes,\n };\n }\n\n changeData(\n options: Pick<Partial<GraphCanvasInterface<NodeData, LinkData>>, \"links\" | \"nodes\">,\n alpha: number = 0.5,\n clearCache: boolean | GraphCanvasCacheKeys[] = true,\n ) {\n if (options.links != undefined) this.links = options.links;\n if (options.nodes != undefined) this.nodes = options.nodes;\n if (options.nodes != undefined || options.links != undefined)\n this.updateData(alpha, clearCache);\n }\n\n changeSettings(\n options: Omit<\n Partial<GraphCanvasInterface<NodeData, LinkData>>,\n \"links\" | \"nodes\" | \"listeners\"\n >,\n clearCache: boolean | GraphCanvasCacheKeys[] = true,\n ) {\n if (options.graphSettings) {\n this.graphSettings = graphSettingsGetter(options.graphSettings, this.graphSettings);\n\n this.draw = initDraw.call<\n GraphCanvas<NodeData, LinkData>,\n Parameters<typeof initDraw>,\n ReturnType<typeof initDraw>\n >(this);\n initZoom.call<\n GraphCanvas<NodeData, LinkData>,\n Parameters<typeof initZoom>,\n ReturnType<typeof initZoom>\n >(this, this.areaTransform);\n }\n if (options.forceSettings) {\n this.forceSettings = forceSettingsGetter(options.forceSettings, this.forceSettings);\n }\n if (options.highlightSettings) {\n this.highlightSettings = highlightSettingsGetter(\n options.highlightSettings,\n this.highlightSettings,\n );\n\n if (clearCache === true) {\n this.clearCache([\n GRAPH_CACHE_TYPE.NodeOptions,\n GRAPH_CACHE_TYPE.NodeText,\n GRAPH_CACHE_TYPE.NodeLabel,\n GRAPH_CACHE_TYPE.LinkOptions,\n ]);\n } else {\n this.clearCache(clearCache);\n }\n }\n if (options.linkSettings) {\n this.linkSettings = linkSettingsGetter(options.linkSettings, this.linkSettings);\n\n if (clearCache) {\n this.clearCache([GRAPH_CACHE_TYPE.LinkOptions]);\n } else {\n this.clearCache(clearCache);\n }\n }\n if (options.nodeSettings) {\n this.nodeSettings = nodeSettingsGetter(options.nodeSettings, this.nodeSettings);\n\n if (clearCache) {\n this.clearCache([\n GRAPH_CACHE_TYPE.NodeOptions,\n GRAPH_CACHE_TYPE.NodeText,\n GRAPH_CACHE_TYPE.NodeLabel,\n ]);\n } else {\n this.clearCache(clearCache);\n }\n\n initCollideForce.call<\n GraphCanvas<NodeData, LinkData>,\n Parameters<typeof initCollideForce>,\n ReturnType<typeof initCollideForce>\n >(this, true);\n }\n\n if (options.forceSettings) {\n return void this.updateSimulation();\n }\n\n this.tick();\n }\n\n updateRect() {\n if (!this.area) return;\n\n this.areaRect = this.area.getBoundingClientRect();\n }\n\n updateSize() {\n if (!this.area) return;\n\n const { width, height } = this.root.getBoundingClientRect();\n this.width = width;\n this.height = height;\n this.area.width = this.dpi * this.width;\n this.area.height = this.dpi * this.height;\n this.areaRect = this.area.getBoundingClientRect();\n\n this.context = this.area.getContext(\"2d\");\n if (!this.context) throw new Error(\"couldn't create canvas context\");\n this.context.scale(this.dpi, this.dpi);\n this.draw();\n }\n\n clearCache(keys: boolean | GraphCanvasCacheKeys[]) {\n if (keys === true) {\n updateNodeCache.call<\n GraphCanvas<NodeData, LinkData>,\n Parameters<typeof updateNodeCache>,\n ReturnType<typeof updateNodeCache>\n >(this, true);\n updateLinkCache.call<\n GraphCanvas<NodeData, LinkData>,\n Parameters<typeof updateLinkCache>,\n ReturnType<typeof updateLinkCache>\n >(this);\n } else if (isArray(keys)) {\n if (\n keys.some(\n (k) =>\n k === GRAPH_CACHE_TYPE.NodeText ||\n k === GRAPH_CACHE_TYPE.NodeLabel ||\n k === GRAPH_CACHE_TYPE.NodeOptions,\n )\n ) {\n updateNodeCache.call<\n GraphCanvas<NodeData, LinkData>,\n Parameters<typeof updateNodeCache>,\n ReturnType<typeof updateNodeCache>\n >(this, {\n label: keys.includes(GRAPH_CACHE_TYPE.NodeLabel),\n options: keys.includes(GRAPH_CACHE_TYPE.NodeOptions),\n text: keys.includes(GRAPH_CACHE_TYPE.NodeOptions),\n });\n }\n\n if (keys.includes(GRAPH_CACHE_TYPE.LinkOptions)) {\n updateLinkCache.call<\n GraphCanvas<NodeData, LinkData>,\n Parameters<typeof updateLinkCache>,\n ReturnType<typeof updateLinkCache>\n >(this);\n }\n }\n }\n\n tick() {\n if (!this.simulationWorking && !this.highlightWorking) this.draw();\n }\n\n restart(alpha?: number) {\n if (this.simulation) this.simulation.alpha(alpha ?? 1).restart();\n }\n\n start() {\n if (this.simulation) this.simulation.alpha(1).restart();\n if (this.container) this.container.style.display = \"block\";\n }\n\n stop() {\n if (this.simulation) this.simulation.stop();\n if (this.container) this.container.style.display = \"none\";\n }\n\n create() {\n this.init();\n }\n\n destroy() {\n if (this.simulation) {\n this.simulation.stop();\n this.simulation = undefined;\n }\n\n this.clearHTMLElements();\n this.clearState();\n this.clearCache(true);\n }\n\n protected clearHTMLElements() {\n this.root.replaceChildren();\n this.area = undefined;\n this.context = undefined;\n this.container = undefined;\n this.eventAbortController.abort();\n this.eventAbortController = new AbortController();\n }\n\n protected updateSimulation() {\n if (this.simulation) {\n initSimulationForces.call<\n GraphCanvas<NodeData, LinkData>,\n Parameters<typeof initSimulationForces>,\n ReturnType<typeof initSimulationForces>\n >(this);\n this.simulation.alpha(1);\n this.simulation.restart();\n }\n }\n\n protected clearState() {\n this.isDragging = false;\n this.highlightedNode = null;\n this.highlightedLink = null;\n this.highlightedNeighbors = null;\n this.highlightProgress = 0;\n this.highlightWorking = false;\n }\n\n protected updateData(alpha: number = 0.5, clearCache: boolean | GraphCanvasCacheKeys[] = true) {\n if (clearCache) {\n this.clearCache(clearCache);\n }\n\n if (this.simulation) {\n initCollideForce.call<\n GraphCanvas<NodeData, LinkData>,\n Parameters<typeof initCollideForce>,\n ReturnType<typeof initCollideForce>\n >(this, false);\n\n this.simulation\n .nodes(this.nodes)\n .force(\n \"link\",\n forceLink<NodeInterface<NodeData>, LinkInterface<NodeData, LinkData>>(this.links)\n .id(this.nodeSettings.idGetter.bind(this))\n .distance(\n this.forceSettings.forces && this.forceSettings.linkForce\n ? this.forceSettings.linkDistance\n : 0,\n )\n .strength(\n this.forceSettings.forces && this.forceSettings.linkForce\n ? this.forceSettings.linkStrength\n : 0,\n )\n .iterations(\n this.forceSettings.forces && this.forceSettings.linkForce\n ? this.forceSettings.linkIterations\n : 0,\n ),\n )\n .alpha(alpha)\n .restart();\n }\n }\n\n protected init() {\n initArea.call<\n GraphCanvas<NodeData, LinkData>,\n Parameters<typeof initArea>,\n ReturnType<typeof initArea>\n >(this);\n updateNodeCache.call<\n GraphCanvas<NodeData, LinkData>,\n Parameters<typeof updateNodeCache>,\n ReturnType<typeof updateNodeCache>\n >(this, true);\n updateLinkCache.call<\n GraphCanvas<NodeData, LinkData>,\n Parameters<typeof updateLinkCache>,\n ReturnType<typeof updateLinkCache>\n >(this);\n initSimulation.call<\n GraphCanvas<NodeData, LinkData>,\n Parameters<typeof initSimulation>,\n ReturnType<typeof initSimulation>\n >(this);\n initDnd.call<\n GraphCanvas<NodeData, LinkData>,\n Parameters<typeof initDnd>,\n ReturnType<typeof initDnd>\n >(this);\n initZoom.call<\n GraphCanvas<NodeData, LinkData>,\n Parameters<typeof initZoom>,\n ReturnType<typeof initZoom>\n >(this);\n initResize.call<\n GraphCanvas<NodeData, LinkData>,\n Parameters<typeof initResize>,\n ReturnType<typeof initResize>\n >(this);\n initPointer.call<\n GraphCanvas<NodeData, LinkData>,\n Parameters<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aAAa,CAAC,MAAM,IAAI,IAAI,CAAC,aAAa,CAAC;AAC9C,kBAAE,IAAI,CAAC,aAAa,CAAC;kBACnB,CAAC;iBAEN,UAAU,CACT,IAAI,CAAC,aAAa,CAAC,MAAM,IAAI,IAAI,CAAC,aAAa,CAAC;AAC9C,kBAAE,IAAI,CAAC,aAAa,CAAC;kBACnB,CAAC,CACN;iBAEJ,KAAK,CAAC,KAAK;AACX,iBAAA,OAAO,EAAE;;;IAIN,IAAI,GAAA;AACZ,QAAA,QAAQ,CAAC,IAAI,CAIX,IAAI,CAAC;AACP,QAAA,eAAe,CAAC,IAAI,CAIlB,IAAI,EAAE,IAAI,CAAC;AACb,QAAA,eAAe,CAAC,IAAI,CAIlB,IAAI,CAAC;AACP,QAAA,cAAc,CAAC,IAAI,CAIjB,IAAI,CAAC;AACP,QAAA,OAAO,CAAC,IAAI,CAIV,IAAI,CAAC;AACP,QAAA,QAAQ,CAAC,IAAI,CAIX,IAAI,CAAC;AACP,QAAA,UAAU,CAAC,IAAI,CAIb,IAAI,CAAC;AACP,QAAA,WAAW,CAAC,IAAI,CAId,IAAI,CAAC;;AAEV;;;;"}
@@ -0,0 +1,12 @@
1
+ import '@krainovsd/js-helpers';
2
+ import 'd3-array';
3
+
4
+ const GRAPH_CACHE_TYPE = {
5
+ NodeOptions: "nodeOptions",
6
+ LinkOptions: "linkOptions",
7
+ NodeText: "nodeText",
8
+ NodeLabel: "nodeLabel",
9
+ };
10
+
11
+ export { GRAPH_CACHE_TYPE };
12
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../../../../../src/module/GraphCanvas/constants/index.ts"],"sourcesContent":["export * from \"./common-settings\";\nexport * from \"./force-settings\";\nexport * from \"./graph-settings\";\nexport * from \"./highlight-settings\";\nexport * from \"./link-settings\";\nexport * from \"./node-settings\";\n\nexport const GRAPH_CACHE_TYPE = {\n NodeOptions: \"nodeOptions\",\n LinkOptions: \"linkOptions\",\n NodeText: \"nodeText\",\n NodeLabel: \"nodeLabel\",\n} as const;\n"],"names":[],"mappings":";;;AAOa,MAAA,gBAAgB,GAAG;AAC9B,IAAA,WAAW,EAAE,aAAa;AAC1B,IAAA,WAAW,EAAE,aAAa;AAC1B,IAAA,QAAQ,EAAE,UAAU;AACpB,IAAA,SAAS,EAAE,WAAW;;;;;"}
@@ -11,9 +11,12 @@ function initZoom(currentZoom) {
11
11
  .scaleExtent(this.graphSettings.zoomExtent)
12
12
  .on("zoom", (event) => {
13
13
  this.listeners.onZoom?.call?.(this, event);
14
+ const oldTransform = this.areaTransform;
14
15
  this.areaTransform = event.transform;
15
- updateLinkCache.call(this);
16
- updateNodeCache.call(this);
16
+ if (this.areaTransform.k !== oldTransform.k) {
17
+ updateLinkCache.call(this);
18
+ updateNodeCache.call(this, true);
19
+ }
17
20
  if (!this.simulationWorking && !this.highlightWorking)
18
21
  requestAnimationFrame(() => this.draw());
19
22
  });
@@ -1 +1 @@
1
- {"version":3,"file":"init-zoom.js","sources":["../../../../../src/module/GraphCanvas/slices/init-zoom.ts"],"sourcesContent":["import { isArray } from \"@krainovsd/js-helpers\";\nimport { select as d3Select } from \"d3-selection\";\nimport { ZoomTransform, zoom } from \"d3-zoom\";\nimport type { GraphCanvas } from \"../GraphCanvas\";\nimport type { ZoomEventInterface } from \"../types\";\nimport { updateLinkCache } from \"./update-link-cache\";\nimport { updateNodeCache } from \"./update-node-cache\";\n\nexport function initZoom<\n NodeData extends Record<string, unknown>,\n LinkData extends Record<string, unknown>,\n>(this: GraphCanvas<NodeData, LinkData>, currentZoom?: ZoomTransform) {\n if (!this.area) throw new Error(\"bad init data\");\n\n const zoomInstance = zoom<HTMLCanvasElement, unknown>()\n .scaleExtent(this.graphSettings.zoomExtent)\n .on(\"zoom\", (event: ZoomEventInterface) => {\n this.listeners.onZoom?.call?.(this, event);\n this.areaTransform = event.transform;\n updateLinkCache.call<\n GraphCanvas<NodeData, LinkData>,\n Parameters<typeof updateLinkCache>,\n ReturnType<typeof updateLinkCache>\n >(this);\n updateNodeCache.call<\n GraphCanvas<NodeData, LinkData>,\n Parameters<typeof updateNodeCache>,\n ReturnType<typeof updateNodeCache>\n >(this);\n\n if (!this.simulationWorking && !this.highlightWorking)\n requestAnimationFrame(() => this.draw());\n });\n\n if (this.graphSettings.translateExtentEnable) {\n const coefficient = this.graphSettings.translateExtentCoefficient;\n const [coefficientX, coefficientY] = isArray(coefficient)\n ? coefficient\n : [coefficient, coefficient];\n\n const [\n [minX = -this.width * coefficientX, minY = -this.height * coefficientY],\n [maxX = this.width * coefficientX, maxY = this.height * coefficientY],\n ] = this.graphSettings.translateExtent;\n\n zoomInstance.translateExtent([\n [minX, minY],\n [maxX, maxY],\n ]);\n }\n\n d3Select(this.area).call(zoomInstance).on(\"dblclick.zoom\", null);\n\n const zoomInitial = currentZoom ?? this.graphSettings.zoomInitial;\n this.areaTransform = new ZoomTransform(\n zoomInitial?.k ?? 1,\n zoomInitial?.x ?? this.width / 2,\n zoomInitial?.y ?? this.height / 2,\n );\n zoom<HTMLCanvasElement, unknown>().transform(d3Select(this.area), this.areaTransform);\n}\n"],"names":["d3Select"],"mappings":";;;;;;AAQM,SAAU,QAAQ,CAGiB,WAA2B,EAAA;IAClE,IAAI,CAAC,IAAI,CAAC,IAAI;AAAE,QAAA,MAAM,IAAI,KAAK,CAAC,eAAe,CAAC;IAEhD,MAAM,YAAY,GAAG,IAAI;AACtB,SAAA,WAAW,CAAC,IAAI,CAAC,aAAa,CAAC,UAAU;AACzC,SAAA,EAAE,CAAC,MAAM,EAAE,CAAC,KAAyB,KAAI;AACxC,QAAA,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,GAAG,IAAI,EAAE,KAAK,CAAC;AAC1C,QAAA,IAAI,CAAC,aAAa,GAAG,KAAK,CAAC,SAAS;AACpC,QAAA,eAAe,CAAC,IAAI,CAIlB,IAAI,CAAC;AACP,QAAA,eAAe,CAAC,IAAI,CAIlB,IAAI,CAAC;QAEP,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MAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,IAAI,CAAC,aAAa,CAAC;AACvF;;;;"}
1
+ {"version":3,"file":"init-zoom.js","sources":["../../../../../src/module/GraphCanvas/slices/init-zoom.ts"],"sourcesContent":["import { isArray } from \"@krainovsd/js-helpers\";\nimport { select as d3Select } from \"d3-selection\";\nimport { ZoomTransform, zoom } from \"d3-zoom\";\nimport type { GraphCanvas } from \"../GraphCanvas\";\nimport type { ZoomEventInterface } from \"../types\";\nimport { updateLinkCache } from \"./update-link-cache\";\nimport { updateNodeCache } from \"./update-node-cache\";\n\nexport function initZoom<\n NodeData extends Record<string, unknown>,\n LinkData extends Record<string, unknown>,\n>(this: GraphCanvas<NodeData, LinkData>, currentZoom?: ZoomTransform) {\n if (!this.area) throw new Error(\"bad init data\");\n\n const zoomInstance = zoom<HTMLCanvasElement, unknown>()\n .scaleExtent(this.graphSettings.zoomExtent)\n .on(\"zoom\", (event: ZoomEventInterface) => {\n this.listeners.onZoom?.call?.(this, event);\n const oldTransform = this.areaTransform;\n this.areaTransform = event.transform;\n if (this.areaTransform.k !== oldTransform.k) {\n updateLinkCache.call<\n GraphCanvas<NodeData, LinkData>,\n Parameters<typeof updateLinkCache>,\n ReturnType<typeof updateLinkCache>\n >(this);\n updateNodeCache.call<\n GraphCanvas<NodeData, LinkData>,\n Parameters<typeof updateNodeCache>,\n ReturnType<typeof updateNodeCache>\n >(this, true);\n }\n\n if (!this.simulationWorking && !this.highlightWorking)\n requestAnimationFrame(() => this.draw());\n });\n\n if (this.graphSettings.translateExtentEnable) {\n const coefficient = this.graphSettings.translateExtentCoefficient;\n const [coefficientX, coefficientY] = isArray(coefficient)\n ? coefficient\n : [coefficient, coefficient];\n\n const [\n [minX = -this.width * coefficientX, minY = -this.height * coefficientY],\n [maxX = this.width * coefficientX, maxY = this.height * coefficientY],\n ] = this.graphSettings.translateExtent;\n\n zoomInstance.translateExtent([\n [minX, minY],\n [maxX, maxY],\n ]);\n }\n\n d3Select(this.area).call(zoomInstance).on(\"dblclick.zoom\", null);\n\n const zoomInitial = currentZoom ?? this.graphSettings.zoomInitial;\n this.areaTransform = new ZoomTransform(\n zoomInitial?.k ?? 1,\n zoomInitial?.x ?? this.width / 2,\n zoomInitial?.y ?? this.height / 2,\n );\n zoom<HTMLCanvasElement, unknown>().transform(d3Select(this.area), this.areaTransform);\n}\n"],"names":["d3Select"],"mappings":";;;;;;AAQM,SAAU,QAAQ,CAGiB,WAA2B,EAAA;IAClE,IAAI,CAAC,IAAI,CAAC,IAAI;AAAE,QAAA,MAAM,IAAI,KAAK,CAAC,eAAe,CAAC;IAEhD,MAAM,YAAY,GAAG,IAAI;AACtB,SAAA,WAAW,CAAC,IAAI,CAAC,aAAa,CAAC,UAAU;AACzC,SAAA,EAAE,CAAC,MAAM,EAAE,CAAC,KAAyB,KAAI;AACxC,QAAA,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,GAAG,IAAI,EAAE,KAAK,CAAC;AAC1C,QAAA,MAAM,YAAY,GAAG,IAAI,CAAC,aAAa;AACvC,QAAA,IAAI,CAAC,aAAa,GAAG,KAAK,CAAC,SAAS;QACpC,IAAI,IAAI,CAAC,aAAa,CAAC,CAAC,KAAK,YAAY,CAAC,CAAC,EAAE;AAC3C,YAAA,eAAe,CAAC,IAAI,CAIlB,IAAI,CAAC;AACP,YAAA,eAAe,CAAC,IAAI,CAIlB,IAAI,EAAE,IAAI,CAAC;;QAGf,IAAI,CAAC,IAAI,CAAC,iBAAiB,IAAI,CAAC,IAAI,CAAC,gBAAgB;YACnD,qBAAqB,CAAC,MAAM,IAAI,CAAC,IAAI,EAAE,CAAC;AAC5C,KAAC,CAAC;AAEJ,IAAA,IAAI,IAAI,CAAC,aAAa,CAAC,qBAAqB,EAAE;AAC5C,QAAA,MAAM,WAAW,GAAG,IAAI,CAAC,aAAa,CAAC,0BAA0B;QACjE,MAAM,CAAC,YAAY,EAAE,YAAY,CAAC,GAAG,OAAO,CAAC,WAAW;AACtD,cAAE;AACF,cAAE,CAAC,WAAW,EAAE,WAAW,CAAC;QAE9B,MAAM,CACJ,CAAC,IAAI,GAAG,CAAC,IAAI,CAAC,KAAK,GAAG,YAAY,EAAE,IAAI,GAAG,CAAC,IAAI,CAAC,MAAM,GAAG,YAAY,CAAC,EACvE,CAAC,IAAI,GAAG,IAAI,CAAC,KAAK,GAAG,YAAY,EAAE,IAAI,GAAG,IAAI,CAAC,MAAM,GAAG,YAAY,CAAC,EACtE,GAAG,IAAI,CAAC,aAAa,CAAC,eAAe;QAEtC,YAAY,CAAC,eAAe,CAAC;YAC3B,CAAC,IAAI,EAAE,IAAI,CAAC;YACZ,CAAC,IAAI,EAAE,IAAI,CAAC;AACb,SAAA,CAAC;;AAGJ,IAAAA,MAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,EAAE,CAAC,eAAe,EAAE,IAAI,CAAC;IAEhE,MAAM,WAAW,GAAG,WAAW,IAAI,IAAI,CAAC,aAAa,CAAC,WAAW;AACjE,IAAA,IAAI,CAAC,aAAa,GAAG,IAAI,aAAa,CACpC,WAAW,EAAE,CAAC,IAAI,CAAC,EACnB,WAAW,EAAE,CAAC,IAAI,IAAI,CAAC,KAAK,GAAG,CAAC,EAChC,WAAW,EAAE,CAAC,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC,CAClC;AACD,IAAA,IAAI,EAA8B,CAAC,SAAS,CAACA,MAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,IAAI,CAAC,aAAa,CAAC;AACvF;;;;"}
@@ -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,I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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;;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,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