@krainovsd/graph 0.10.0-rc1 → 0.10.0-rc2

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.
@@ -39,6 +39,7 @@ class GraphCanvas {
39
39
  draw;
40
40
  eventAbortController;
41
41
  cachedNodeText = {};
42
+ cachedTextNodeParameters = {};
42
43
  linkOptionsCache = {};
43
44
  nodeOptionsCache = {};
44
45
  isDragging = false;
@@ -130,6 +131,7 @@ class GraphCanvas {
130
131
  if (options.nodeSettings) {
131
132
  this.nodeSettings = nodeSettingsGetter(options.nodeSettings, this.nodeSettings);
132
133
  this.cachedNodeText = {};
134
+ this.cachedTextNodeParameters = {};
133
135
  this.nodeOptionsCache = {};
134
136
  initCollideForce.call(this, true);
135
137
  }
@@ -146,6 +148,7 @@ class GraphCanvas {
146
148
  this.nodeOptionsCache = {};
147
149
  this.linkOptionsCache = {};
148
150
  this.cachedNodeText = {};
151
+ this.cachedTextNodeParameters = {};
149
152
  }
150
153
  tick() {
151
154
  if (!this.simulationWorking && !this.highlightWorking)
@@ -177,7 +180,7 @@ class GraphCanvas {
177
180
  }
178
181
  this.clearHTMLElements();
179
182
  this.clearState();
180
- this.clearDataDependencies();
183
+ this.clearCache();
181
184
  }
182
185
  clearHTMLElements() {
183
186
  this.root.replaceChildren();
@@ -203,13 +206,8 @@ class GraphCanvas {
203
206
  this.highlightWorking = false;
204
207
  this.highlightDrawing = false;
205
208
  }
206
- clearDataDependencies() {
207
- this.cachedNodeText = {};
208
- this.nodeOptionsCache = {};
209
- this.linkOptionsCache = {};
210
- }
211
209
  updateData(alpha) {
212
- this.clearDataDependencies();
210
+ this.clearCache();
213
211
  if (this.simulation) {
214
212
  initCollideForce.call(this, false);
215
213
  this.simulation
@@ -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 type { LinkInterface } from \"@/types/links\";\nimport type { CachedNodeTextInterface, NodeInterface } from \"@/types/nodes\";\nimport {\n forceSettingsGetter,\n graphSettingsGetter,\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} from \"./slices\";\nimport type {\n ForceSettingsInterface,\n GraphCanvasInterface,\n GraphCanvasSimulation,\n GraphParticle,\n GraphSettingsInterface,\n GraphState,\n LinkOptionsInterface,\n LinkSettingsInterface,\n ListenersInterface,\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, GraphParticle[]> = {};\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 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>) => void;\n\n protected eventAbortController: AbortController;\n\n protected cachedNodeText: 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 highlightDrawing: 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 protected get state(): GraphState<NodeData, LinkData> {\n return {\n areaTransform: this.areaTransform,\n cachedNodeText: this.cachedNodeText,\n context: this.context,\n eventAbortController: this.eventAbortController,\n highlightProgress: this.highlightProgress,\n highlightDrawing: this.highlightDrawing,\n highlightedNeighbors: this.highlightedNeighbors,\n highlightedNode: this.highlightedNode,\n highlightedLink: this.highlightedLink,\n highlightWorking: this.highlightWorking,\n isDragging: this.isDragging,\n simulation: this.simulation,\n simulationWorking: this.simulationWorking,\n height: this.height,\n links: this.links,\n nodes: this.nodes,\n width: this.width,\n forceSettings: this.forceSettings,\n graphSettings: this.graphSettings,\n linkSettings: this.linkSettings,\n nodeSettings: this.nodeSettings,\n };\n }\n\n constructor({\n links,\n nodes,\n root,\n forceSettings,\n linkSettings,\n listeners,\n nodeSettings,\n graphSettings,\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\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,\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) this.updateData(alpha);\n }\n\n changeSettings(\n options: Omit<\n Partial<GraphCanvasInterface<NodeData, LinkData>>,\n \"links\" | \"nodes\" | \"listeners\"\n >,\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.linkSettings) {\n this.linkSettings = linkSettingsGetter(options.linkSettings, this.linkSettings);\n this.linkOptionsCache = {};\n }\n if (options.nodeSettings) {\n this.nodeSettings = nodeSettingsGetter(options.nodeSettings, this.nodeSettings);\n this.cachedNodeText = {};\n this.nodeOptionsCache = {};\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) this.areaRect = this.area.getBoundingClientRect();\n }\n\n clearCache() {\n this.nodeOptionsCache = {};\n this.linkOptionsCache = {};\n this.cachedNodeText = {};\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.clearDataDependencies();\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 this.highlightDrawing = false;\n }\n\n protected clearDataDependencies() {\n this.cachedNodeText = {};\n this.nodeOptionsCache = {};\n this.linkOptionsCache = {};\n }\n\n protected updateData(alpha?: number) {\n this.clearDataDependencies();\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)\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 ?? 0.5)\n .restart();\n }\n }\n\n protected updateSize() {\n this.clearHTMLElements();\n\n initArea.call<\n GraphCanvas<NodeData, LinkData>,\n Parameters<typeof initArea>,\n ReturnType<typeof initArea>\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 if (!this.simulationWorking && !this.highlightWorking) this.draw();\n }\n\n protected init() {\n initArea.call<\n GraphCanvas<NodeData, LinkData>,\n Parameters<typeof initArea>,\n ReturnType<typeof initArea>\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>,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AAC9C,kBAAE,IAAI,CAAC,aAAa,CAAC;kBACnB,CAAC,CACN;AAEJ,iBAAA,KAAK,CAAC,KAAK,IAAI,GAAG;AAClB,iBAAA,OAAO,EAAE;;;IAIN,UAAU,GAAA;QAClB,IAAI,CAAC,iBAAiB,EAAE;AAExB,QAAA,QAAQ,CAAC,IAAI,CAIX,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;QAEP,IAAI,CAAC,IAAI,CAAC,iBAAiB,IAAI,CAAC,IAAI,CAAC,gBAAgB;YAAE,IAAI,CAAC,IAAI,EAAE;;IAG1D,IAAI,GAAA;AACZ,QAAA,QAAQ,CAAC,IAAI,CAIX,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;;;;"}
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 type { LinkInterface } from \"@/types/links\";\nimport type {\n CachedNodeTextInterface,\n CachedTextNodeParametersMap,\n NodeInterface,\n} from \"@/types/nodes\";\nimport {\n forceSettingsGetter,\n graphSettingsGetter,\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} from \"./slices\";\nimport type {\n ForceSettingsInterface,\n GraphCanvasInterface,\n GraphCanvasSimulation,\n GraphParticle,\n GraphSettingsInterface,\n GraphState,\n LinkOptionsInterface,\n LinkSettingsInterface,\n ListenersInterface,\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, GraphParticle[]> = {};\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 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>) => void;\n\n protected eventAbortController: AbortController;\n\n protected cachedNodeText: CachedNodeTextInterface = {};\n\n protected cachedTextNodeParameters: CachedTextNodeParametersMap = {};\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 highlightDrawing: 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 protected get state(): GraphState<NodeData, LinkData> {\n return {\n areaTransform: this.areaTransform,\n cachedNodeText: this.cachedNodeText,\n context: this.context,\n eventAbortController: this.eventAbortController,\n highlightProgress: this.highlightProgress,\n highlightDrawing: this.highlightDrawing,\n highlightedNeighbors: this.highlightedNeighbors,\n highlightedNode: this.highlightedNode,\n highlightedLink: this.highlightedLink,\n highlightWorking: this.highlightWorking,\n isDragging: this.isDragging,\n simulation: this.simulation,\n simulationWorking: this.simulationWorking,\n height: this.height,\n links: this.links,\n nodes: this.nodes,\n width: this.width,\n forceSettings: this.forceSettings,\n graphSettings: this.graphSettings,\n linkSettings: this.linkSettings,\n nodeSettings: this.nodeSettings,\n };\n }\n\n constructor({\n links,\n nodes,\n root,\n forceSettings,\n linkSettings,\n listeners,\n nodeSettings,\n graphSettings,\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\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,\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) this.updateData(alpha);\n }\n\n changeSettings(\n options: Omit<\n Partial<GraphCanvasInterface<NodeData, LinkData>>,\n \"links\" | \"nodes\" | \"listeners\"\n >,\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.linkSettings) {\n this.linkSettings = linkSettingsGetter(options.linkSettings, this.linkSettings);\n this.linkOptionsCache = {};\n }\n if (options.nodeSettings) {\n this.nodeSettings = nodeSettingsGetter(options.nodeSettings, this.nodeSettings);\n this.cachedNodeText = {};\n this.cachedTextNodeParameters = {};\n this.nodeOptionsCache = {};\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) this.areaRect = this.area.getBoundingClientRect();\n }\n\n clearCache() {\n this.nodeOptionsCache = {};\n this.linkOptionsCache = {};\n this.cachedNodeText = {};\n this.cachedTextNodeParameters = {};\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 this.highlightDrawing = false;\n }\n\n protected updateData(alpha?: number) {\n this.clearCache();\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)\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 ?? 0.5)\n .restart();\n }\n }\n\n protected updateSize() {\n this.clearHTMLElements();\n\n initArea.call<\n GraphCanvas<NodeData, LinkData>,\n Parameters<typeof initArea>,\n ReturnType<typeof initArea>\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 if (!this.simulationWorking && !this.highlightWorking) this.draw();\n }\n\n protected init() {\n initArea.call<\n GraphCanvas<NodeData, LinkData>,\n Parameters<typeof initArea>,\n ReturnType<typeof initArea>\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,GAAoC,EAAE;AAE/C,IAAA,KAAK;AAEL,IAAA,MAAM;AAEN,IAAA,IAAI;AAEJ,IAAA,S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AAQ,CAAC,IAAI,CAIX,IAAI,CAAC;AACP,QAAA,UAAU,CAAC,IAAI,CAIb,IAAI,CAAC;AACP,QAAA,WAAW,CAAC,IAAI,CAId,IAAI,CAAC;QAEP,IAAI,CAAC,IAAI,CAAC,iBAAiB,IAAI,CAAC,IAAI,CAAC,gBAAgB;YAAE,IAAI,CAAC,IAAI,EAAE;;IAG1D,IAAI,GAAA;AACZ,QAAA,QAAQ,CAAC,IAAI,CAIX,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;;;;"}
@@ -46,7 +46,7 @@ const NODE_SETTINGS = {
46
46
  highlightByHoverNode: true,
47
47
  nodeRadiusFlexible: true,
48
48
  nodeSizeFlexible: true,
49
- textNodeDebug: false,
49
+ textNodeDebug: true,
50
50
  highlightByNodeNodeFading: true,
51
51
  highlightByNodeNodeColor: false,
52
52
  highlightByNodeNodeSizing: true,
@@ -62,7 +62,7 @@ const NODE_SETTINGS = {
62
62
  nodeSizeCoefficient: 5,
63
63
  nodeSizeFactor: 0.1,
64
64
  highlightByNodeNodeSizingAdditional: 0.5,
65
- highlightByLinkNodeSizingAdditionalCoefficient: 0.35,
65
+ highlightByNodeNodeSizingAdditionalCoefficient: 0.35,
66
66
  highlightByNodeNodeColorFadingMin: 0.15,
67
67
  highlightByNodeTextShiftXAdditional: 0,
68
68
  highlightByNodeTextShiftYAdditional: 2,
@@ -72,7 +72,7 @@ const NODE_SETTINGS = {
72
72
  highlightByNodeNodeFadingMin: 0.21,
73
73
  highlightByNodeTextFadingMin: 0.21,
74
74
  highlightByLinkNodeSizingAdditional: 0.5,
75
- highlightByNodeNodeSizingAdditionalCoefficient: 0.35,
75
+ highlightByLinkNodeSizingAdditionalCoefficient: 0.35,
76
76
  highlightByLinkNodeColorFadingMin: 0.15,
77
77
  highlightByLinkTextShiftXAdditional: 0,
78
78
  highlightByLinkTextShiftYAdditional: 2,
@@ -89,8 +89,8 @@ const NODE_OPTIONS = {
89
89
  borderRadius: 0,
90
90
  radius: 4,
91
91
  alpha: 1,
92
- textNodeXPadding: 5,
93
- textNodeYPadding: 3,
92
+ textNodeXPadding: 1,
93
+ textNodeYPadding: 1,
94
94
  borderWidth: 0.1,
95
95
  borderColor: "#000000FF",
96
96
  textAlpha: 1,
@@ -1 +1 @@
1
- {"version":3,"file":"settings.js","sources":["../../../../../src/module/GraphCanvas/constants/settings.ts"],"sourcesContent":["import type { LinkData, NodeData } from \"@/app/types\";\nimport { dragPlaceCoefficientGetter } from \"../lib\";\nimport type {\n ForceSettingsInterface,\n GraphSettingsInterface,\n LinkOptionsInterface,\n LinkSettingsInterface,\n NodeOptionsInterface,\n NodeSettingsInterface,\n} from \"../types\";\n\nexport const FORCE_SETTINGS: Required<\n ForceSettingsInterface<Record<string, unknown>, Record<string, unknown>>\n> = {\n forces: true,\n centerForce: true,\n chargeForce: true,\n linkForce: true,\n xForce: true,\n yForce: true,\n collideForce: true,\n centerPosition: {},\n centerStrength: 1,\n collideStrength: 0.1,\n collideAdditionalRadius: 4,\n collideIterations: 2,\n collideOffMax: { links: 0, nodes: 0 },\n chargeStrength: -40,\n chargeDistanceMax: Infinity,\n chargeDistanceMin: 1,\n xPosition: 0,\n xStrength: 0.1,\n yPosition: 0,\n yStrength: 0.1,\n linkDistance: 30,\n linkIterations: 1,\n linkStrength: 1,\n collideRadius: null,\n};\n\nexport const GRAPH_SETTINGS: Required<GraphSettingsInterface<Record<string, unknown>>> = {\n zoomExtent: [0.3, 10] as [number, number],\n translateExtent: [[], []],\n translateExtentEnable: true,\n translateExtentCoefficient: [3, 3],\n highlightUpFrames: 5,\n highlightDownFrames: 5,\n dragPlaceCoefficient: dragPlaceCoefficientGetter,\n zoomInitial: null,\n showDrawTime: true,\n showDrawTimeEveryTick: false,\n};\n\nexport const NODE_SETTINGS: Omit<\n Required<NodeSettingsInterface<NodeData, LinkData>>,\n \"options\" | \"idGetter\"\n> = {\n cache: true,\n highlightByNodeOnlyRoot: true,\n highlightByHoverNode: true,\n nodeRadiusFlexible: true,\n nodeSizeFlexible: true,\n textNodeDebug: false,\n highlightByNodeNodeFading: true,\n highlightByNodeNodeColor: false,\n highlightByNodeNodeSizing: true,\n highlightByNodeTextFading: true,\n highlightByNodeTextSizing: true,\n highlightByLinkNodeFading: false,\n highlightByLinkNodeColor: false,\n highlightByLinkNodeSizing: true,\n highlightByLinkTextFading: false,\n highlightByLinkTextSizing: true,\n nodeRadiusCoefficient: 5,\n nodeRadiusFactor: 1,\n nodeSizeCoefficient: 5,\n nodeSizeFactor: 0.1,\n highlightByNodeNodeSizingAdditional: 0.5,\n highlightByLinkNodeSizingAdditionalCoefficient: 0.35,\n highlightByNodeNodeColorFadingMin: 0.15,\n highlightByNodeTextShiftXAdditional: 0,\n highlightByNodeTextShiftYAdditional: 2,\n highlightByNodeTextSizingAdditional: 1,\n highlightByNodeTextWeightAdditional: 0,\n highlightByNodeTextWidthAdditional: 10,\n highlightByNodeNodeFadingMin: 0.21,\n highlightByNodeTextFadingMin: 0.21,\n highlightByLinkNodeSizingAdditional: 0.5,\n highlightByNodeNodeSizingAdditionalCoefficient: 0.35,\n highlightByLinkNodeColorFadingMin: 0.15,\n highlightByLinkTextShiftXAdditional: 0,\n highlightByLinkTextShiftYAdditional: 2,\n highlightByLinkTextSizingAdditional: 1,\n highlightByLinkTextWeightAdditional: 0,\n highlightByLinkTextWidthAdditional: 10,\n highlightByLinkNodeFadingMin: 0.21,\n highlightByLinkTextFadingMin: 0.21,\n};\n\nexport const NODE_OPTIONS: Omit<\n Required<NodeOptionsInterface<Record<string, unknown>, Record<string, unknown>>>,\n | \"color\"\n | \"text\"\n | \"textVisible\"\n | \"textSize\"\n | \"textShiftY\"\n | \"nodeDraw\"\n | \"nodeExtraDraw\"\n | \"textDraw\"\n | \"textExtraDraw\"\n> = {\n shape: \"text\",\n height: 10,\n width: 15,\n borderRadius: 0,\n radius: 4,\n alpha: 1,\n textNodeXPadding: 5,\n textNodeYPadding: 3,\n borderWidth: 0.1,\n borderColor: \"#000000FF\",\n textAlpha: 1,\n textWidth: 20,\n textShiftX: 0,\n textFont: \"Arial\",\n textAlign: \"center\" as CanvasTextAlign,\n textColor: \"#333\",\n textStyle: \"normal\",\n textWeight: 500,\n textGap: 0,\n};\n\nexport const LINK_SETTINGS: Omit<Required<LinkSettingsInterface<NodeData, LinkData>>, \"options\"> = {\n cache: true,\n particles: true,\n particleFlexSpeed: true,\n pretty: true,\n arrow: true,\n highlightByHoverLink: true,\n arrowByHighlight: true,\n highlightByNodeLinkFading: true,\n highlightByNodeArrowFading: true,\n highlightByLinkLinkFading: false,\n highlightByLinkArrowFading: false,\n particleFlexSpeedCoefficient: 4,\n hoverLinkThreshold: 2,\n highlightByNodeLinkFadingMin: 0.21,\n highlightByNodeArrowFadingMin: 0.21,\n highlightByLinkArrowFadingMin: 0.21,\n highlightByLinkLinkFadingMin: 0.21,\n};\n\nexport const LINK_OPTIONS: Omit<\n Required<LinkOptionsInterface<Record<string, unknown>, Record<string, unknown>>>,\n \"color\" | \"width\" | \"drawLink\" | \"drawExtraLink\" | \"arrowColor\"\n> = {\n alpha: 1,\n arrowAlpha: 1,\n arrowSize: 2,\n arrowBorderColor: \"#000000FF\",\n arrowBorderWidth: 0.1,\n particleAlpha: 1,\n particleColor: \"#000000FF\",\n particleBorderColor: \"#000000FF\",\n particleBorderWidth: 0.1,\n particleCount: 2,\n particleRadius: 0.5,\n particleSteps: 60,\n};\n\nexport const COMMON_SETTINGS = {\n linkColorZoomFar: \"#999\",\n linkColorZoomNear: \"#000000FF\",\n linkWidthZoomFar: 1,\n linkWidthZoomNear: 0.1,\n linkWidthZoomBorder: 1,\n linkColorZoomBorder: 1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B,EAAE,KAAK;AACjC,IAAA,4BAA4B,EAAE,CAAC;AAC/B,IAAA,kBAAkB,EAAE,CAAC;AACrB,IAAA,4BAA4B,EAAE,IAAI;AAClC,IAAA,6BAA6B,EAAE,IAAI;AACnC,IAAA,6BAA6B,EAAE,IAAI;AACnC,IAAA,4BAA4B,EAAE,IAAI;;AAGvB,MAAA,YAAY,GAGrB;AACF,IAAA,KAAK,EAAE,CAAC;AACR,IAAA,UAAU,EAAE,CAAC;AACb,IAAA,SAAS,EAAE,CAAC;AACZ,IAAA,gBAAgB,EAAE,WAAW;AAC7B,IAAA,gBAAgB,EAAE,GAAG;AACrB,IAAA,aAAa,EAAE,CAAC;AAChB,IAAA,aAAa,EAAE,WAAW;AAC1B,IAAA,mBAAmB,EAAE,WAAW;AAChC,IAAA,mBAAmB,EAAE,GAAG;AACxB,IAAA,aAAa,EAAE,CAAC;AAChB,IAAA,cAAc,EAAE,GAAG;AACnB,IAAA,aAAa,EAAE,EAAE;;AAGN,MAAA,eAAe,GAAG;AAC7B,IAAA,gBAAgB,EAAE,MAAM;AACxB,IAAA,iBAAiB,EAAE,WAAW;AAC9B,IAAA,gBAAgB,EAAE,CAAC;AACnB,IAAA,iBAAiB,EAAE,GAAG;AACtB,IAAA,mBAAmB,EAAE,CAAC;AACtB,IAAA,mBAAmB,EAAE,CAAC;AACtB,IAAA,gBAAgB,EAAE,GAAG;AACrB,IAAA,gBAAgB,EAAE,EAAE;AACpB,IAAA,eAAe,EAAE,GAAG;AACpB,IAAA,eAAe,EAAE,GAAG;AACpB,IAAA,iBAAiB,EAAE,GAAG;AACtB,IAAA,iBAAiB,EAAE,CAAC;AACpB,IAAA,uBAAuB,EAAE,GAAG;AAC5B,IAAA,UAAU,EAAE,CAAC;AACb,IAAA,QAAQ,EAAE,CAAC;;;;;"}
1
+ {"version":3,"file":"settings.js","sources":["../../../../../src/module/GraphCanvas/constants/settings.ts"],"sourcesContent":["import type { LinkData, NodeData } from \"@/app/types\";\nimport { dragPlaceCoefficientGetter } from \"../lib\";\nimport type {\n ForceSettingsInterface,\n GraphSettingsInterface,\n LinkOptionsInterface,\n LinkSettingsInterface,\n NodeOptionsInterface,\n NodeSettingsInterface,\n} from \"../types\";\n\nexport const FORCE_SETTINGS: Required<\n ForceSettingsInterface<Record<string, unknown>, Record<string, unknown>>\n> = {\n forces: true,\n centerForce: true,\n chargeForce: true,\n linkForce: true,\n xForce: true,\n yForce: true,\n collideForce: true,\n centerPosition: {},\n centerStrength: 1,\n collideStrength: 0.1,\n collideAdditionalRadius: 4,\n collideIterations: 2,\n collideOffMax: { links: 0, nodes: 0 },\n chargeStrength: -40,\n chargeDistanceMax: Infinity,\n chargeDistanceMin: 1,\n xPosition: 0,\n xStrength: 0.1,\n yPosition: 0,\n yStrength: 0.1,\n linkDistance: 30,\n linkIterations: 1,\n linkStrength: 1,\n collideRadius: null,\n};\n\nexport const GRAPH_SETTINGS: Required<GraphSettingsInterface<Record<string, unknown>>> = {\n zoomExtent: [0.3, 10] as [number, number],\n translateExtent: [[], []],\n translateExtentEnable: true,\n translateExtentCoefficient: [3, 3],\n highlightUpFrames: 5,\n highlightDownFrames: 5,\n dragPlaceCoefficient: dragPlaceCoefficientGetter,\n zoomInitial: null,\n showDrawTime: true,\n showDrawTimeEveryTick: false,\n};\n\nexport const NODE_SETTINGS: Omit<\n Required<NodeSettingsInterface<NodeData, LinkData>>,\n \"options\" | \"idGetter\"\n> = {\n cache: true,\n highlightByNodeOnlyRoot: true,\n highlightByHoverNode: true,\n nodeRadiusFlexible: true,\n nodeSizeFlexible: true,\n textNodeDebug: true,\n highlightByNodeNodeFading: true,\n highlightByNodeNodeColor: false,\n highlightByNodeNodeSizing: true,\n highlightByNodeTextFading: true,\n highlightByNodeTextSizing: true,\n highlightByLinkNodeFading: false,\n highlightByLinkNodeColor: false,\n highlightByLinkNodeSizing: true,\n highlightByLinkTextFading: false,\n highlightByLinkTextSizing: true,\n nodeRadiusCoefficient: 5,\n nodeRadiusFactor: 1,\n nodeSizeCoefficient: 5,\n nodeSizeFactor: 0.1,\n highlightByNodeNodeSizingAdditional: 0.5,\n highlightByNodeNodeSizingAdditionalCoefficient: 0.35,\n highlightByNodeNodeColorFadingMin: 0.15,\n highlightByNodeTextShiftXAdditional: 0,\n highlightByNodeTextShiftYAdditional: 2,\n highlightByNodeTextSizingAdditional: 1,\n highlightByNodeTextWeightAdditional: 0,\n highlightByNodeTextWidthAdditional: 10,\n highlightByNodeNodeFadingMin: 0.21,\n highlightByNodeTextFadingMin: 0.21,\n highlightByLinkNodeSizingAdditional: 0.5,\n highlightByLinkNodeSizingAdditionalCoefficient: 0.35,\n highlightByLinkNodeColorFadingMin: 0.15,\n highlightByLinkTextShiftXAdditional: 0,\n highlightByLinkTextShiftYAdditional: 2,\n highlightByLinkTextSizingAdditional: 1,\n highlightByLinkTextWeightAdditional: 0,\n highlightByLinkTextWidthAdditional: 10,\n highlightByLinkNodeFadingMin: 0.21,\n highlightByLinkTextFadingMin: 0.21,\n};\n\nexport const NODE_OPTIONS: Omit<\n Required<NodeOptionsInterface<Record<string, unknown>, Record<string, unknown>>>,\n | \"color\"\n | \"text\"\n | \"textVisible\"\n | \"textSize\"\n | \"textShiftY\"\n | \"nodeDraw\"\n | \"nodeExtraDraw\"\n | \"textDraw\"\n | \"textExtraDraw\"\n> = {\n shape: \"text\",\n height: 10,\n width: 15,\n borderRadius: 0,\n radius: 4,\n alpha: 1,\n textNodeXPadding: 1,\n textNodeYPadding: 1,\n borderWidth: 0.1,\n borderColor: \"#000000FF\",\n textAlpha: 1,\n textWidth: 20,\n textShiftX: 0,\n textFont: \"Arial\",\n textAlign: \"center\" as CanvasTextAlign,\n textColor: \"#333\",\n textStyle: \"normal\",\n textWeight: 500,\n textGap: 0,\n};\n\nexport const LINK_SETTINGS: Omit<Required<LinkSettingsInterface<NodeData, LinkData>>, \"options\"> = {\n cache: true,\n particles: true,\n particleFlexSpeed: true,\n pretty: true,\n arrow: true,\n highlightByHoverLink: true,\n arrowByHighlight: true,\n highlightByNodeLinkFading: true,\n highlightByNodeArrowFading: true,\n highlightByLinkLinkFading: false,\n highlightByLinkArrowFading: false,\n particleFlexSpeedCoefficient: 4,\n hoverLinkThreshold: 2,\n highlightByNodeLinkFadingMin: 0.21,\n highlightByNodeArrowFadingMin: 0.21,\n highlightByLinkArrowFadingMin: 0.21,\n highlightByLinkLinkFadingMin: 0.21,\n};\n\nexport const LINK_OPTIONS: Omit<\n Required<LinkOptionsInterface<Record<string, unknown>, Record<string, unknown>>>,\n \"color\" | \"width\" | \"drawLink\" | \"drawExtraLink\" | \"arrowColor\"\n> = {\n alpha: 1,\n arrowAlpha: 1,\n arrowSize: 2,\n arrowBorderColor: \"#000000FF\",\n arrowBorderWidth: 0.1,\n particleAlpha: 1,\n particleColor: \"#000000FF\",\n particleBorderColor: \"#000000FF\",\n particleBorderWidth: 0.1,\n particleCount: 2,\n particleRadius: 0.5,\n particleSteps: 60,\n};\n\nexport const COMMON_SETTINGS = {\n linkColorZoomFar: \"#999\",\n linkColorZoomNear: \"#000000FF\",\n linkWidthZoomFar: 1,\n linkWidthZoomNear: 0.1,\n linkWidthZoomBorder: 1,\n linkColorZoomBorder: 1,\n nodeTextScaleMin: 1.5,\n nodeTextScaleMax: 20,\n nodeTextSizeMin: 1.5,\n nodeTextSizeMax: 3.5,\n nodeTextShiftYMin: 2.5,\n nodeTextShiftYMax: 4,\n nodeTextChangeStepCount: 200,\n nodeRadius: 5,\n nodeSize: 5,\n};\n"],"names":[],"mappings":";;;;AAWa,MAAA,cAAc,GAEvB;AACF,IAAA,MAAM,EAAE,IAAI;AACZ,IAAA,WAAW,EAAE,IAAI;AACjB,IAAA,WAAW,EAAE,IAAI;AACjB,IAAA,SAAS,EAAE,IAAI;AACf,IAAA,MAAM,EAAE,IAAI;AACZ,IAAA,MAAM,EAAE,IAAI;AACZ,IAAA,YAAY,EAAE,IAAI;AAClB,IAAA,cAAc,EAAE,EAAE;AAClB,IAAA,cAAc,EAAE,CAAC;A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BAAmB,EAAE,GAAG;AACxB,IAAA,aAAa,EAAE,CAAC;AAChB,IAAA,cAAc,EAAE,GAAG;AACnB,IAAA,aAAa,EAAE,EAAE;;AAGN,MAAA,eAAe,GAAG;AAC7B,IAAA,gBAAgB,EAAE,MAAM;AACxB,IAAA,iBAAiB,EAAE,WAAW;AAC9B,IAAA,gBAAgB,EAAE,CAAC;AACnB,IAAA,iBAAiB,EAAE,GAAG;AACtB,IAAA,mBAAmB,EAAE,CAAC;AACtB,IAAA,mBAAmB,EAAE,CAAC;AACtB,IAAA,gBAAgB,EAAE,GAAG;AACrB,IAAA,gBAAgB,EAAE,EAAE;AACpB,IAAA,eAAe,EAAE,GAAG;AACpB,IAAA,eAAe,EAAE,GAAG;AACpB,IAAA,iBAAiB,EAAE,GAAG;AACtB,IAAA,iBAAiB,EAAE,CAAC;AACpB,IAAA,uBAAuB,EAAE,GAAG;AAC5B,IAAA,UAAU,EAAE,CAAC;AACb,IAAA,QAAQ,EAAE,CAAC;;;;;"}
@@ -51,13 +51,15 @@ function nodeRadiusGetter({ radiusFlexible, radiusInitial, linkCount, radiusCoef
51
51
  return ((radiusFlexible && linkCount ? linkCount / radiusCoefficient : 0) * radiusFactor + radiusInitial);
52
52
  }
53
53
  function nodeSizeGetter({ heightInitial, linkCount, sizeCoefficient, sizeFactor, sizeFlexible, widthInitial, }) {
54
- let widthCoefficient = 1;
55
- let heightCoefficient = 1;
54
+ let additionalSizeCoefficient = 1;
56
55
  if (sizeFlexible && linkCount != undefined) {
57
- widthCoefficient += (linkCount / sizeCoefficient) * sizeFactor;
58
- heightCoefficient += (linkCount / sizeCoefficient) * sizeFactor;
56
+ additionalSizeCoefficient += (linkCount / sizeCoefficient) * sizeFactor;
59
57
  }
60
- return { width: widthInitial * widthCoefficient, height: heightInitial * heightCoefficient };
58
+ return {
59
+ width: widthInitial * additionalSizeCoefficient,
60
+ height: heightInitial * additionalSizeCoefficient,
61
+ additionalSizeCoefficient,
62
+ };
61
63
  }
62
64
  function nodeIdGetter(node) {
63
65
  return node.id;
@@ -1 +1 @@
1
- {"version":3,"file":"node-settings-getter.js","sources":["../../../../../../src/module/GraphCanvas/lib/settings/node-settings-getter.ts"],"sourcesContent":["import type { ZoomTransform } from \"d3-zoom\";\nimport { colorGetter } from \"@/lib\";\nimport type { NodeInterface } from \"@/types\";\nimport { COMMON_SETTINGS, NODE_OPTIONS, NODE_SETTINGS } from \"../../constants\";\nimport type { GraphState, NodeOptionsInterface, NodeSettingsInterface } from \"../../types\";\n\nexport function nodeSettingsGetter<\n NodeData extends Record<string, unknown>,\n LinkData extends Record<string, unknown>,\n>(\n settings: NodeSettingsInterface<NodeData, LinkData> | undefined,\n prevNodeSettings?: Required<Omit<NodeSettingsInterface<NodeData, LinkData>, \"options\">> &\n Pick<NodeSettingsInterface<NodeData, LinkData>, \"options\">,\n): Required<Omit<NodeSettingsInterface<NodeData, LinkData>, \"options\">> &\n Pick<NodeSettingsInterface<NodeData, LinkData>, \"options\"> {\n return {\n ...(prevNodeSettings ?? NODE_SETTINGS),\n idGetter: nodeIdGetter,\n ...settings,\n };\n}\n\nconst color = colorGetter();\n\nexport function nodeOptionsGetter<\n NodeData extends Record<string, unknown>,\n LinkData extends Record<string, unknown>,\n>(\n node: NodeInterface<NodeData>,\n _: number,\n __: NodeInterface<NodeData>[],\n state?: GraphState<NodeData, LinkData>,\n): Required<NodeOptionsInterface<NodeData, LinkData>> {\n const { textShiftY, textSize } = nodeTextSizeGetter(state?.areaTransform);\n\n return {\n ...NODE_OPTIONS,\n nodeDraw: null,\n nodeExtraDraw: null,\n textDraw: null,\n textExtraDraw: null,\n color: color(String(node.group ?? \"_DEFAULT\")),\n textVisible: Boolean(\n state?.areaTransform && state.areaTransform.k > COMMON_SETTINGS.nodeTextScaleMin,\n ),\n text: node.name ?? node.id.toString(),\n textShiftY,\n textSize,\n };\n}\n\nexport function nodeTextSizeGetter(transform: ZoomTransform | undefined) {\n let textSize: number = COMMON_SETTINGS.nodeTextSizeMax;\n let textShiftY: number = COMMON_SETTINGS.nodeTextShiftYMax;\n\n if (transform) {\n const scaleStepCoefficient =\n (COMMON_SETTINGS.nodeTextScaleMax - COMMON_SETTINGS.nodeTextScaleMin) /\n COMMON_SETTINGS.nodeTextChangeStepCount;\n const textStepCoefficient =\n (COMMON_SETTINGS.nodeTextSizeMax - COMMON_SETTINGS.nodeTextSizeMin) /\n COMMON_SETTINGS.nodeTextChangeStepCount;\n const shiftStepCoefficient =\n (COMMON_SETTINGS.nodeTextShiftYMax - COMMON_SETTINGS.nodeTextShiftYMin) /\n COMMON_SETTINGS.nodeTextChangeStepCount;\n\n if (transform.k >= COMMON_SETTINGS.nodeTextScaleMax) {\n textSize = COMMON_SETTINGS.nodeTextSizeMin;\n textShiftY = COMMON_SETTINGS.nodeTextShiftYMin;\n } else if (transform.k > COMMON_SETTINGS.nodeTextScaleMin) {\n const transformSteps =\n (transform.k - COMMON_SETTINGS.nodeTextScaleMin) / scaleStepCoefficient;\n\n textSize -= transformSteps * textStepCoefficient;\n textShiftY -= transformSteps * shiftStepCoefficient;\n }\n }\n\n return { textSize, textShiftY };\n}\n\nexport type NodeRadiusGetterOptions = {\n linkCount: number | undefined;\n radiusFlexible: boolean;\n radiusCoefficient: number;\n radiusFactor: number;\n radiusInitial: number;\n};\n\nexport function nodeRadiusGetter({\n radiusFlexible,\n radiusInitial,\n linkCount,\n radiusCoefficient,\n radiusFactor,\n}: NodeRadiusGetterOptions) {\n return (\n (radiusFlexible && linkCount ? linkCount / radiusCoefficient : 0) * radiusFactor + radiusInitial\n );\n}\n\nexport type NodeSizeGetterOptions = {\n linkCount: number | undefined;\n sizeFlexible: boolean;\n sizeCoefficient: number;\n sizeFactor: number;\n widthInitial: number;\n heightInitial: number;\n};\n\nexport function nodeSizeGetter({\n heightInitial,\n linkCount,\n sizeCoefficient,\n sizeFactor,\n sizeFlexible,\n widthInitial,\n}: NodeSizeGetterOptions) {\n let widthCoefficient = 1;\n let heightCoefficient = 1;\n if (sizeFlexible && linkCount != undefined) {\n widthCoefficient += (linkCount / sizeCoefficient) * sizeFactor;\n heightCoefficient += (linkCount / sizeCoefficient) * sizeFactor;\n }\n\n return { width: widthInitial * widthCoefficient, height: heightInitial * heightCoefficient };\n}\n\nexport function nodeIdGetter<NodeData extends Record<string, unknown>>(\n node: NodeInterface<NodeData>,\n) {\n return node.id;\n}\n"],"names":[],"mappings":";;;;AAMgB,SAAA,kBAAkB,CAIhC,QAA+D,EAC/D,gBAC4D,EAAA;IAG5D,OAAO;AACL,QAAA,IAAI,gBAAgB,IAAI,aAAa,CAAC;AACtC,QAAA,QAAQ,EAAE,YAAY;AACtB,QAAA,GAAG,QAAQ;KACZ;AACH;AAEA,MAAM,KAAK,GAAG,WAAW,EAAE;AAErB,SAAU,iBAAiB,CAI/B,IAA6B,EAC7B,CAAS,EACT,EAA6B,EAC7B,KAAsC,EAAA;AAEtC,IAAA,MAAM,EAAE,UAAU,EAAE,QAAQ,EAAE,GAAG,kBAAkB,CAAC,KAAK,EAAE,aAAa,CAAC;IAEzE,OAAO;AACL,QAAA,GAAG,YAAY;AACf,QAAA,QAAQ,EAAE,IAAI;AACd,QAAA,aAAa,EAAE,IAAI;AACnB,QAAA,QAAQ,EAAE,IAAI;AACd,QAAA,aAAa,EAAE,IAAI;QACnB,KAAK,EAAE,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,IAAI,UAAU,CAAC,CAAC;AAC9C,QAAA,WAAW,EAAE,OAAO,CAClB,KAAK,EAAE,aAAa,IAAI,KAAK,CAAC,aAAa,CAAC,CAAC,GAAG,eAAe,CAAC,gBAAgB,CACjF;QACD,IAAI,EAAE,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,EAAE,CAAC,QAAQ,EAAE;QACrC,UAAU;QACV,QAAQ;KACT;AACH;AAEM,SAAU,kBAAkB,CAAC,SAAoC,EAAA;AACrE,IAAA,IAAI,QAAQ,GAAW,eAAe,CAAC,eAAe;AACtD,IAAA,IAAI,UAAU,GA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IAAI,SAAS,EAAE;QAC1C,gBAAgB,IAAI,CAAC,SAAS,GAAG,eAAe,IAAI,UAAU;QAC9D,iBAAiB,IAAI,CAAC,SAAS,GAAG,eAAe,IAAI,UAAU;;AAGjE,IAAA,OAAO,EAAE,KAAK,EAAE,YAAY,GAAG,gBAAgB,EAAE,MAAM,EAAE,aAAa,GAAG,iBAAiB,EAAE;AAC9F;AAEM,SAAU,YAAY,CAC1B,IAA6B,EAAA;IAE7B,OAAO,IAAI,CAAC,EAAE;AAChB;;;;"}
1
+ {"version":3,"file":"node-settings-getter.js","sources":["../../../../../../src/module/GraphCanvas/lib/settings/node-settings-getter.ts"],"sourcesContent":["import type { ZoomTransform } from \"d3-zoom\";\nimport { colorGetter } from \"@/lib\";\nimport type { NodeInterface } from \"@/types\";\nimport { COMMON_SETTINGS, NODE_OPTIONS, NODE_SETTINGS } from \"../../constants\";\nimport type { GraphState, NodeOptionsInterface, NodeSettingsInterface } from \"../../types\";\n\nexport function nodeSettingsGetter<\n NodeData extends Record<string, unknown>,\n LinkData extends Record<string, unknown>,\n>(\n settings: NodeSettingsInterface<NodeData, LinkData> | undefined,\n prevNodeSettings?: Required<Omit<NodeSettingsInterface<NodeData, LinkData>, \"options\">> &\n Pick<NodeSettingsInterface<NodeData, LinkData>, \"options\">,\n): Required<Omit<NodeSettingsInterface<NodeData, LinkData>, \"options\">> &\n Pick<NodeSettingsInterface<NodeData, LinkData>, \"options\"> {\n return {\n ...(prevNodeSettings ?? NODE_SETTINGS),\n idGetter: nodeIdGetter,\n ...settings,\n };\n}\n\nconst color = colorGetter();\n\nexport function nodeOptionsGetter<\n NodeData extends Record<string, unknown>,\n LinkData extends Record<string, unknown>,\n>(\n node: NodeInterface<NodeData>,\n _: number,\n __: NodeInterface<NodeData>[],\n state?: GraphState<NodeData, LinkData>,\n): Required<NodeOptionsInterface<NodeData, LinkData>> {\n const { textShiftY, textSize } = nodeTextSizeGetter(state?.areaTransform);\n\n return {\n ...NODE_OPTIONS,\n nodeDraw: null,\n nodeExtraDraw: null,\n textDraw: null,\n textExtraDraw: null,\n color: color(String(node.group ?? \"_DEFAULT\")),\n textVisible: Boolean(\n state?.areaTransform && state.areaTransform.k > COMMON_SETTINGS.nodeTextScaleMin,\n ),\n text: node.name ?? node.id.toString(),\n textShiftY,\n textSize,\n };\n}\n\nexport function nodeTextSizeGetter(transform: ZoomTransform | undefined) {\n let textSize: number = COMMON_SETTINGS.nodeTextSizeMax;\n let textShiftY: number = COMMON_SETTINGS.nodeTextShiftYMax;\n\n if (transform) {\n const scaleStepCoefficient =\n (COMMON_SETTINGS.nodeTextScaleMax - COMMON_SETTINGS.nodeTextScaleMin) /\n COMMON_SETTINGS.nodeTextChangeStepCount;\n const textStepCoefficient =\n (COMMON_SETTINGS.nodeTextSizeMax - COMMON_SETTINGS.nodeTextSizeMin) /\n COMMON_SETTINGS.nodeTextChangeStepCount;\n const shiftStepCoefficient =\n (COMMON_SETTINGS.nodeTextShiftYMax - COMMON_SETTINGS.nodeTextShiftYMin) /\n COMMON_SETTINGS.nodeTextChangeStepCount;\n\n if (transform.k >= COMMON_SETTINGS.nodeTextScaleMax) {\n textSize = COMMON_SETTINGS.nodeTextSizeMin;\n textShiftY = COMMON_SETTINGS.nodeTextShiftYMin;\n } else if (transform.k > COMMON_SETTINGS.nodeTextScaleMin) {\n const transformSteps =\n (transform.k - COMMON_SETTINGS.nodeTextScaleMin) / scaleStepCoefficient;\n\n textSize -= transformSteps * textStepCoefficient;\n textShiftY -= transformSteps * shiftStepCoefficient;\n }\n }\n\n return { textSize, textShiftY };\n}\n\nexport type NodeRadiusGetterOptions = {\n linkCount: number | undefined;\n radiusFlexible: boolean;\n radiusCoefficient: number;\n radiusFactor: number;\n radiusInitial: number;\n};\n\nexport function nodeRadiusGetter({\n radiusFlexible,\n radiusInitial,\n linkCount,\n radiusCoefficient,\n radiusFactor,\n}: NodeRadiusGetterOptions) {\n return (\n (radiusFlexible && linkCount ? linkCount / radiusCoefficient : 0) * radiusFactor + radiusInitial\n );\n}\n\nexport type NodeSizeGetterOptions = {\n linkCount: number | undefined;\n sizeFlexible: boolean;\n sizeCoefficient: number;\n sizeFactor: number;\n widthInitial: number;\n heightInitial: number;\n};\n\nexport function nodeSizeGetter({\n heightInitial,\n linkCount,\n sizeCoefficient,\n sizeFactor,\n sizeFlexible,\n widthInitial,\n}: NodeSizeGetterOptions) {\n let additionalSizeCoefficient = 1;\n if (sizeFlexible && linkCount != undefined) {\n additionalSizeCoefficient += (linkCount / sizeCoefficient) * sizeFactor;\n }\n\n return {\n width: widthInitial * additionalSizeCoefficient,\n height: heightInitial * additionalSizeCoefficient,\n additionalSizeCoefficient,\n };\n}\n\nexport function nodeIdGetter<NodeData extends Record<string, unknown>>(\n node: NodeInterface<NodeData>,\n) {\n return node.id;\n}\n"],"names":[],"mappings":";;;;AAMgB,SAAA,kBAAkB,CAIhC,QAA+D,EAC/D,gBAC4D,EAAA;IAG5D,OAAO;AACL,QAAA,IAAI,gBAAgB,IAAI,aAAa,CAAC;AACtC,QAAA,QAAQ,EAAE,YAAY;AACtB,QAAA,GAAG,QAAQ;KACZ;AACH;AAEA,MAAM,KAAK,GAAG,WAAW,EAAE;AAErB,SAAU,iBAAiB,CAI/B,IAA6B,EAC7B,CAAS,EACT,EAA6B,EAC7B,KAAsC,EAAA;AAEtC,IAAA,MAAM,EAAE,UAAU,EAAE,QAAQ,EAAE,GAAG,kBAAkB,CAAC,KAAK,EAAE,aAAa,CAAC;IAEzE,OAAO;AACL,QAAA,GAAG,YAAY;AACf,QAAA,QAAQ,EAAE,IAAI;AACd,QAAA,aAAa,EAAE,IAAI;AACnB,QAAA,QAAQ,EAAE,IAAI;AACd,QAAA,aAAa,EAAE,IAAI;QACnB,KAAK,EAAE,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,IAAI,UAAU,CAAC,CAAC;AAC9C,QAAA,WAAW,EAAE,OAAO,CAClB,KAAK,EAAE,aAAa,IAAI,KAAK,CAAC,aAAa,C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,SAAS,GAAG,iBAAiB,GAAG,CAAC,IAAI,YAAY,GAAG,aAAa;AAEpG;AAWgB,SAAA,cAAc,CAAC,EAC7B,aAAa,EACb,SAAS,EACT,eAAe,EACf,UAAU,EACV,YAAY,EACZ,YAAY,GACU,EAAA;IACtB,IAAI,yBAAyB,GAAG,CAAC;AACjC,IAAA,IAAI,YAAY,IAAI,SAAS,IAAI,SAAS,EAAE;QAC1C,yBAAyB,IAAI,CAAC,SAAS,GAAG,eAAe,IAAI,UAAU;;IAGzE,OAAO;QACL,KAAK,EAAE,YAAY,GAAG,yBAAyB;QAC/C,MAAM,EAAE,aAAa,GAAG,yBAAyB;QACjD,yBAAyB;KAC1B;AACH;AAEM,SAAU,YAAY,CAC1B,IAA6B,EAAA;IAE7B,OAAO,IAAI,CAAC,EAAE;AAChB;;;;"}
@@ -44,6 +44,7 @@ function getDrawNode(nodeRenders, textRenders, state) {
44
44
  let textShiftY = nodeOptions.textShiftY;
45
45
  let textWeight = nodeOptions.textWeight;
46
46
  let textWidth = nodeOptions.textWidth;
47
+ let sizeCoefficient = 1;
47
48
  /** Node Highlight */
48
49
  if (this.highlightedNeighbors && this.highlightedNode) {
49
50
  /** Not highlighted */
@@ -75,12 +76,11 @@ function getDrawNode(nodeRenders, textRenders, state) {
75
76
  if (this.nodeSettings.highlightByNodeNodeSizing && nodeOptions.shape === "circle") {
76
77
  radiusInitial = animationByProgress(radiusInitial, this.nodeSettings.highlightByNodeNodeSizingAdditional, this.highlightProgress);
77
78
  }
78
- if (this.nodeSettings.highlightByLinkNodeSizing &&
79
+ if (this.nodeSettings.highlightByNodeNodeSizing &&
79
80
  (nodeOptions.shape === "square" || nodeOptions.shape === "text")) {
80
- const widthCoefficient = animationByProgress(1, this.nodeSettings.highlightByNodeNodeSizingAdditionalCoefficient, this.highlightProgress);
81
- const heightCoefficient = animationByProgress(1, this.nodeSettings.highlightByNodeNodeSizingAdditionalCoefficient, this.highlightProgress);
82
- widthInitial *= widthCoefficient;
83
- heightInitial *= heightCoefficient;
81
+ sizeCoefficient = animationByProgress(sizeCoefficient, this.nodeSettings.highlightByNodeNodeSizingAdditionalCoefficient, this.highlightProgress);
82
+ widthInitial *= sizeCoefficient;
83
+ heightInitial *= sizeCoefficient;
84
84
  }
85
85
  if (this.nodeSettings.highlightByNodeTextSizing) {
86
86
  textSize = animationByProgress(textSize, this.nodeSettings.highlightByNodeTextSizingAdditional, this.highlightProgress);
@@ -127,10 +127,9 @@ function getDrawNode(nodeRenders, textRenders, state) {
127
127
  (nodeOptions.shape === "square" ||
128
128
  nodeOptions.shape === "text" ||
129
129
  nodeOptions.shape === "icon")) {
130
- const widthCoefficient = animationByProgress(1, this.nodeSettings.highlightByLinkNodeSizingAdditionalCoefficient, this.highlightProgress);
131
- const heightCoefficient = animationByProgress(1, this.nodeSettings.highlightByLinkNodeSizingAdditionalCoefficient, this.highlightProgress);
132
- widthInitial *= widthCoefficient;
133
- heightInitial *= heightCoefficient;
130
+ sizeCoefficient = animationByProgress(sizeCoefficient, this.nodeSettings.highlightByNodeNodeSizingAdditionalCoefficient, this.highlightProgress);
131
+ widthInitial *= sizeCoefficient;
132
+ heightInitial *= sizeCoefficient;
134
133
  }
135
134
  if (this.nodeSettings.highlightByLinkTextSizing) {
136
135
  textSize = animationByProgress(textSize, this.nodeSettings.highlightByLinkTextSizingAdditional, this.highlightProgress);
@@ -154,7 +153,7 @@ function getDrawNode(nodeRenders, textRenders, state) {
154
153
  /** Flex size */
155
154
  let height = heightInitial;
156
155
  let width = widthInitial;
157
- if (nodeOptions.shape === "square" || nodeOptions.shape === "text") {
156
+ if (nodeOptions.shape === "square") {
158
157
  const size = nodeSizeGetter({
159
158
  heightInitial,
160
159
  widthInitial,
@@ -166,27 +165,53 @@ function getDrawNode(nodeRenders, textRenders, state) {
166
165
  width = size.width;
167
166
  height = size.height;
168
167
  }
168
+ if (nodeOptions.shape === "text") {
169
+ width = nodeOptions.width;
170
+ const size = nodeSizeGetter({
171
+ heightInitial,
172
+ widthInitial: width,
173
+ linkCount: node.linkCount,
174
+ sizeCoefficient: this.nodeSettings.nodeSizeCoefficient,
175
+ sizeFactor: this.nodeSettings.nodeSizeFactor,
176
+ sizeFlexible: this.nodeSettings.nodeSizeFlexible,
177
+ });
178
+ textSize *= size.additionalSizeCoefficient;
179
+ }
180
+ /** Size by text in textNode */
169
181
  if (nodeOptions.shape === "text" && nodeOptions.text) {
170
- const lines = this.cachedNodeText[node.id] ??
171
- getTextLines({
182
+ textWidth = width;
183
+ let lines;
184
+ let textNodeParameters;
185
+ const cachedLines = this.cachedNodeText[node.id];
186
+ const cachedTextNodeParameters = this.cachedTextNodeParameters[node.id];
187
+ if (cachedLines != undefined && cachedTextNodeParameters != undefined) {
188
+ lines = cachedLines;
189
+ textNodeParameters = cachedTextNodeParameters;
190
+ }
191
+ else {
192
+ const textInfo = getTextLines({
172
193
  context: this.context,
173
194
  text: nodeOptions.text,
174
195
  textAlign: nodeOptions.textAlign,
175
196
  textColor: nodeOptions.textColor,
176
197
  textFont: nodeOptions.textFont,
177
198
  textSize,
178
- maxWidth: width,
199
+ maxWidth: textWidth,
179
200
  textStyle: nodeOptions.textStyle,
180
201
  textWeight,
181
202
  });
182
- if (!this.cachedNodeText[node.id]) {
203
+ textNodeParameters = [textInfo.currentMaxSize, textSize];
204
+ lines = textInfo.lines;
183
205
  this.cachedNodeText[node.id] = lines;
206
+ this.cachedTextNodeParameters[node.id] = textNodeParameters;
184
207
  }
208
+ const textSizeCoefficient = textSize / textNodeParameters[1];
209
+ const maxSize = textNodeParameters[0] * textSizeCoefficient;
185
210
  height =
186
211
  lines.length * textSize +
187
212
  (lines.length - 1) * nodeOptions.textGap +
188
213
  nodeOptions.textNodeYPadding;
189
- width += nodeOptions.textNodeXPadding;
214
+ width = maxSize + nodeOptions.textNodeXPadding;
190
215
  }
191
216
  /** Node parameters */
192
217
  node._radius = radius;
@@ -243,7 +268,7 @@ function getDrawNode(nodeRenders, textRenders, state) {
243
268
  textSize,
244
269
  x: node.x,
245
270
  y: node.y + textSize / 4 - (lines.length - 1) * (textSize / 2),
246
- maxWidth: widthInitial,
271
+ maxWidth: textWidth,
247
272
  textStyle: nodeOptions.textStyle,
248
273
  textWeight,
249
274
  textGap: nodeOptions.textGap,
@@ -1 +1 @@
1
- {"version":3,"file":"draw-nodes.js","sources":["../../../../../src/module/GraphCanvas/slices/draw-nodes.ts"],"sourcesContent":["import { isNumber } from \"@krainovsd/js-helpers\";\nimport { colorToRgb, extractRgb, fadeRgb, rgbAnimationByProgress } from \"@/lib\";\nimport type { NodeInterface } from \"@/types\";\nimport type { GraphCanvas } from \"../GraphCanvas\";\nimport {\n animationByProgress,\n isNodeVisible,\n nodeIterationExtractor,\n nodeOptionsGetter,\n nodeRadiusGetter,\n nodeSizeGetter,\n} from \"../lib\";\nimport type { GraphState, NodeOptionsInterface } from \"../types\";\nimport { drawText, getTextLines } from \"./draw-text\";\n\nexport function getDrawNode<\n NodeData extends Record<string, unknown>,\n LinkData extends Record<string, unknown>,\n>(nodeRenders: (() => void)[], textRenders: (() => void)[], state: GraphState<NodeData, LinkData>) {\n return function drawNode(\n this: GraphCanvas<NodeData, LinkData>,\n node: NodeInterface<NodeData>,\n index: number,\n ) {\n if (!this.context || !node.x || !node.y) return;\n\n let nodeOptions: Required<NodeOptionsInterface<NodeData, LinkData>>;\n if (this.nodeSettings.cache && this.nodeOptionsCache[node.id]) {\n nodeOptions = this.nodeOptionsCache[node.id];\n } else {\n nodeOptions = nodeIterationExtractor(\n node,\n index,\n this.nodes,\n state,\n this.nodeSettings.options ?? {},\n nodeOptionsGetter,\n );\n if (this.nodeSettings.cache) {\n this.nodeOptionsCache[node.id] = nodeOptions;\n }\n }\n\n if (nodeOptions.nodeDraw && nodeOptions.textDraw) {\n nodeRenders.push(() => {\n nodeOptions?.nodeDraw?.(node, nodeOptions, state);\n });\n\n textRenders.push(() => {\n nodeOptions?.textDraw?.(node, nodeOptions, state);\n });\n\n return;\n }\n\n let alpha = nodeOptions.alpha;\n let color = nodeOptions.color;\n let radiusInitial = nodeOptions.radius;\n let widthInitial = nodeOptions.width;\n let heightInitial = nodeOptions.height;\n let textAlpha = nodeOptions.textAlpha;\n let textSize = nodeOptions.textSize;\n let textShiftX = nodeOptions.textShiftX;\n let textShiftY = nodeOptions.textShiftY;\n let textWeight = nodeOptions.textWeight;\n let textWidth = nodeOptions.textWidth;\n /** Node Highlight */\n if (this.highlightedNeighbors && this.highlightedNode) {\n /** Not highlighted */\n if (!this.highlightedNeighbors.has(node.id) && this.highlightedNode.id != node.id) {\n if (this.nodeSettings.highlightByNodeNodeFading) {\n const min =\n this.nodeSettings.highlightByNodeNodeFadingMin < alpha\n ? this.nodeSettings.highlightByNodeNodeFadingMin\n : alpha;\n alpha = animationByProgress(min, alpha - min, 1 - this.highlightProgress);\n }\n if (this.nodeSettings.highlightByNodeTextFading) {\n const min =\n this.nodeSettings.highlightByNodeTextFadingMin < textAlpha\n ? this.nodeSettings.highlightByNodeTextFadingMin\n : textAlpha;\n textAlpha = animationByProgress(min, textAlpha - min, 1 - this.highlightProgress);\n }\n if (this.nodeSettings.highlightByNodeNodeColor) {\n const colorRgb = extractRgb(colorToRgb(color));\n if (colorRgb) {\n const colorRgbFade = fadeRgb(\n colorRgb,\n this.nodeSettings.highlightByNodeNodeColorFadingMin,\n );\n const colorFadeAnimation = rgbAnimationByProgress(\n colorRgb,\n colorRgbFade,\n this.highlightProgress,\n );\n color = `rgb(${colorFadeAnimation.r}, ${colorFadeAnimation.g}, ${colorFadeAnimation.b})`;\n }\n }\n } else if (\n !this.nodeSettings.highlightByNodeOnlyRoot ||\n (this.nodeSettings.highlightByNodeOnlyRoot && this.highlightedNode.id === node.id)\n ) {\n /** Highlighted */\n\n if (this.nodeSettings.highlightByNodeNodeSizing && nodeOptions.shape === \"circle\") {\n radiusInitial = animationByProgress(\n radiusInitial,\n this.nodeSettings.highlightByNodeNodeSizingAdditional,\n this.highlightProgress,\n );\n }\n if (\n this.nodeSettings.highlightByLinkNodeSizing &&\n (nodeOptions.shape === \"square\" || nodeOptions.shape === \"text\")\n ) {\n const widthCoefficient = animationByProgress(\n 1,\n this.nodeSettings.highlightByNodeNodeSizingAdditionalCoefficient,\n this.highlightProgress,\n );\n const heightCoefficient = animationByProgress(\n 1,\n this.nodeSettings.highlightByNodeNodeSizingAdditionalCoefficient,\n this.highlightProgress,\n );\n widthInitial *= widthCoefficient;\n heightInitial *= heightCoefficient;\n }\n if (this.nodeSettings.highlightByNodeTextSizing) {\n textSize = animationByProgress(\n textSize,\n this.nodeSettings.highlightByNodeTextSizingAdditional,\n this.highlightProgress,\n );\n textShiftX = animationByProgress(\n textShiftX,\n this.nodeSettings.highlightByNodeTextShiftXAdditional,\n this.highlightProgress,\n );\n textShiftY = animationByProgress(\n textShiftY,\n this.nodeSettings.highlightByNodeTextShiftYAdditional,\n this.highlightProgress,\n );\n textWeight = animationByProgress(\n textWeight,\n this.nodeSettings.highlightByNodeTextWeightAdditional,\n this.highlightProgress,\n );\n textWidth = animationByProgress(\n textWidth,\n this.nodeSettings.highlightByNodeTextWidthAdditional,\n this.highlightProgress,\n );\n }\n }\n }\n /** LinkHighlight */\n if (this.highlightedNeighbors && this.highlightedLink) {\n /** Not highlighted */\n if (\n !this.highlightedNeighbors.has(node.id) &&\n this.highlightedLink.source !== node &&\n this.highlightedLink.target !== node\n ) {\n if (this.nodeSettings.highlightByLinkNodeFading) {\n const min =\n this.nodeSettings.highlightByLinkNodeFadingMin < alpha\n ? this.nodeSettings.highlightByLinkNodeFadingMin\n : alpha;\n alpha = animationByProgress(min, alpha - min, 1 - this.highlightProgress);\n }\n if (this.nodeSettings.highlightByLinkTextFading) {\n const min =\n this.nodeSettings.highlightByLinkTextFadingMin < textAlpha\n ? this.nodeSettings.highlightByLinkTextFadingMin\n : textAlpha;\n textAlpha = animationByProgress(min, textAlpha - min, 1 - this.highlightProgress);\n }\n if (this.nodeSettings.highlightByLinkNodeColor) {\n const colorRgb = extractRgb(colorToRgb(color));\n if (colorRgb) {\n const colorRgbFade = fadeRgb(\n colorRgb,\n this.nodeSettings.highlightByLinkNodeColorFadingMin,\n );\n const colorFadeAnimation = rgbAnimationByProgress(\n colorRgb,\n colorRgbFade,\n this.highlightProgress,\n );\n color = `rgb(${colorFadeAnimation.r}, ${colorFadeAnimation.g}, ${colorFadeAnimation.b})`;\n }\n }\n } else {\n /** Highlighted */\n\n if (this.nodeSettings.highlightByLinkNodeSizing && nodeOptions.shape === \"circle\") {\n radiusInitial = animationByProgress(\n radiusInitial,\n this.nodeSettings.highlightByLinkNodeSizingAdditional,\n this.highlightProgress,\n );\n }\n if (\n this.nodeSettings.highlightByLinkNodeSizing &&\n (nodeOptions.shape === \"square\" ||\n nodeOptions.shape === \"text\" ||\n nodeOptions.shape === \"icon\")\n ) {\n const widthCoefficient = animationByProgress(\n 1,\n this.nodeSettings.highlightByLinkNodeSizingAdditionalCoefficient,\n this.highlightProgress,\n );\n const heightCoefficient = animationByProgress(\n 1,\n this.nodeSettings.highlightByLinkNodeSizingAdditionalCoefficient,\n this.highlightProgress,\n );\n widthInitial *= widthCoefficient;\n heightInitial *= heightCoefficient;\n }\n if (this.nodeSettings.highlightByLinkTextSizing) {\n textSize = animationByProgress(\n textSize,\n this.nodeSettings.highlightByLinkTextSizingAdditional,\n this.highlightProgress,\n );\n textShiftX = animationByProgress(\n textShiftX,\n this.nodeSettings.highlightByLinkTextShiftXAdditional,\n this.highlightProgress,\n );\n textShiftY = animationByProgress(\n textShiftY,\n this.nodeSettings.highlightByLinkTextShiftYAdditional,\n this.highlightProgress,\n );\n textWeight = animationByProgress(\n textWeight,\n this.nodeSettings.highlightByLinkTextWeightAdditional,\n this.highlightProgress,\n );\n textWidth = animationByProgress(\n textWidth,\n this.nodeSettings.highlightByLinkTextWidthAdditional,\n this.highlightProgress,\n );\n }\n }\n }\n\n /** Flex radius */\n const radius =\n nodeOptions.shape === \"circle\"\n ? nodeRadiusGetter({\n radiusFlexible: this.nodeSettings.nodeRadiusFlexible,\n radiusInitial,\n radiusCoefficient: this.nodeSettings.nodeRadiusCoefficient,\n radiusFactor: this.nodeSettings.nodeRadiusFactor,\n linkCount: node.linkCount,\n })\n : radiusInitial;\n /** Flex size */\n let height: number = heightInitial;\n let width: number = widthInitial;\n if (nodeOptions.shape === \"square\" || nodeOptions.shape === \"text\") {\n const size = nodeSizeGetter({\n heightInitial,\n widthInitial,\n linkCount: node.linkCount,\n sizeCoefficient: this.nodeSettings.nodeSizeCoefficient,\n sizeFactor: this.nodeSettings.nodeSizeFactor,\n sizeFlexible: this.nodeSettings.nodeSizeFlexible,\n });\n width = size.width;\n height = size.height;\n }\n if (nodeOptions.shape === \"text\" && nodeOptions.text) {\n const lines =\n this.cachedNodeText[node.id] ??\n getTextLines({\n context: this.context,\n text: nodeOptions.text,\n textAlign: nodeOptions.textAlign,\n textColor: nodeOptions.textColor,\n textFont: nodeOptions.textFont,\n textSize,\n maxWidth: width,\n textStyle: nodeOptions.textStyle,\n textWeight,\n });\n\n if (!this.cachedNodeText[node.id]) {\n this.cachedNodeText[node.id] = lines;\n }\n\n height =\n lines.length * textSize +\n (lines.length - 1) * nodeOptions.textGap +\n nodeOptions.textNodeYPadding;\n width += nodeOptions.textNodeXPadding;\n }\n\n /** Node parameters */\n node._radius = radius;\n node._width = width;\n node._height = height;\n node._borderRadius =\n isNumber(nodeOptions.borderRadius) && nodeOptions.borderRadius > 0\n ? Math.min(nodeOptions.borderRadius, nodeOptions.width / 2, nodeOptions.height / 2)\n : 0;\n node._shape = nodeOptions.shape ?? \"circle\";\n\n /** Node Visibility */\n if (\n !isNodeVisible({\n height: this.height,\n width: this.width,\n transform: this.areaTransform,\n node,\n })\n ) {\n node._visible = false;\n\n return;\n }\n node._visible = true;\n\n /** Node draw */\n nodeRenders.push(() => {\n if (!this.context || !node.x || !node.y) return;\n\n this.context.beginPath();\n this.context.globalAlpha = alpha;\n this.context.lineWidth = nodeOptions.borderWidth;\n this.context.strokeStyle = nodeOptions.borderColor;\n this.context.fillStyle = color;\n\n switch (nodeOptions.shape) {\n case \"circle\": {\n this.context.arc(node.x, node.y, radius, 0, 2 * Math.PI);\n break;\n }\n case \"square\": {\n this.context.roundRect(\n node.x - width / 2,\n node.y - height / 2,\n width,\n height,\n node._borderRadius,\n );\n break;\n }\n case \"text\": {\n if (this.nodeSettings.textNodeDebug) {\n this.context.strokeRect(node.x - width / 2, node.y - height / 2, width, height);\n }\n\n const lines = this.cachedNodeText[node.id];\n if (nodeOptions.text && lines)\n drawText({\n id: node.id,\n cachedNodeText: this.cachedNodeText,\n context: this.context,\n text: nodeOptions.text,\n textAlign: nodeOptions.textAlign,\n textColor: nodeOptions.textColor,\n textFont: nodeOptions.textFont,\n textSize,\n x: node.x,\n y: node.y + textSize / 4 - (lines.length - 1) * (textSize / 2),\n maxWidth: widthInitial,\n textStyle: nodeOptions.textStyle,\n textWeight,\n textGap: nodeOptions.textGap,\n });\n break;\n }\n default: {\n this.context.arc(node.x, node.y, radius, 0, 2 * Math.PI);\n break;\n }\n }\n\n this.context.fill();\n this.context.stroke();\n });\n\n if (nodeOptions.nodeExtraDraw) {\n nodeRenders.push(() => {\n nodeOptions?.nodeExtraDraw?.(\n node,\n {\n ...nodeOptions,\n radius,\n alpha,\n color,\n textAlpha,\n textSize,\n textShiftX,\n textShiftY,\n textWeight,\n textWidth,\n },\n state,\n );\n });\n }\n\n /** Text draw */\n if (nodeOptions.textVisible && nodeOptions.text && nodeOptions.shape !== \"text\") {\n textRenders.push(() => {\n if (nodeOptions.textDraw) {\n nodeOptions.textDraw(\n node,\n {\n ...nodeOptions,\n radius,\n alpha,\n color,\n textAlpha,\n textSize,\n textShiftX,\n textShiftY,\n textWeight,\n textWidth,\n },\n state,\n );\n\n return;\n }\n\n if (!this.context || !node.x || !node.y || !nodeOptions.text) return;\n this.context.beginPath();\n this.context.globalAlpha = textAlpha;\n\n let y = node.y + textShiftY;\n if (nodeOptions.shape === \"circle\") {\n y += radius;\n }\n if (nodeOptions.shape === \"square\") {\n y += height / 2;\n }\n\n drawText({\n id: node.id,\n cachedNodeText: this.cachedNodeText,\n context: this.context,\n text: nodeOptions.text,\n textAlign: nodeOptions.textAlign,\n textColor: nodeOptions.textColor,\n textFont: nodeOptions.textFont,\n textSize,\n x: node.x + textShiftX,\n y,\n maxWidth: textWidth,\n textStyle: nodeOptions.textStyle,\n textWeight,\n textGap: nodeOptions.textGap,\n });\n\n if (nodeOptions.textExtraDraw) {\n nodeOptions.textExtraDraw(\n node,\n {\n ...nodeOptions,\n radius,\n alpha,\n color,\n textAlpha,\n textSize,\n textShiftX,\n textShiftY,\n textWeight,\n textWidth,\n },\n state,\n );\n }\n });\n }\n };\n}\n"],"names":[],"mappings":";;;;;;;;;;;;SAegB,WAAW,CAGzB,WAA2B,EAAE,WAA2B,EAAE,KAAqC,EAAA;AAC/F,IAAA,OAAO,SAAS,QAAQ,CAEtB,IAA6B,EAC7B,KAAa,EAAA;AAEb,QAAA,IAAI,CAAC,IAAI,CAAC,OAAO,IAAI,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YAAE;AAEzC,QAAA,IAAI,WAA+D;AACnE,QAAA,IAAI,IAAI,CAAC,YAAY,CAAC,KAAK,IAAI,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE;YAC7D,WAAW,GAAG,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,EAAE,CAAC;;aACvC;YACL,WAAW,GAAG,sBAAsB,CAClC,IAAI,EACJ,KAAK,EACL,IAAI,CAAC,KAAK,EACV,KAAK,EACL,IAAI,CAAC,YAAY,CAAC,OAAO,IAAI,EAAE,EAC/B,iBAAiB,CAClB;AACD,YAAA,IAAI,IAAI,CAAC,YAAY,CAAC,KAAK,EAAE;gBAC3B,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,EAAE,CAAC,GAAG,WAAW;;;QAIhD,IAAI,WAAW,CAAC,QAAQ,IAAI,WAAW,CAAC,QAAQ,EAAE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CAAC,CAAC,GAAG,UAAU;oBACtB,CAAC;AACD,oBAAA,QAAQ,EAAE,SAAS;oBACnB,SAAS,EAAE,WAAW,CAAC,SAAS;oBAChC,UAAU;oBACV,OAAO,EAAE,WAAW,CAAC,OAAO;AAC7B,iBAAA,CAAC;AAEF,gBAAA,IAAI,WAAW,CAAC,aAAa,EAAE;AAC7B,oBAAA,WAAW,CAAC,aAAa,CACvB,IAAI,EACJ;AACE,wBAAA,GAAG,WAAW;wBACd,MAAM;wBACN,KAAK;wBACL,KAAK;wBACL,SAAS;wBACT,QAAQ;wBACR,UAAU;wBACV,UAAU;wBACV,UAAU;wBACV,SAAS;qBACV,EACD,KAAK,CACN;;AAEL,aAAC,CAAC;;AAEN,KAAC;AACH;;;;"}
1
+ {"version":3,"file":"draw-nodes.js","sources":["../../../../../src/module/GraphCanvas/slices/draw-nodes.ts"],"sourcesContent":["import { isNumber } from \"@krainovsd/js-helpers\";\nimport { colorToRgb, extractRgb, fadeRgb, rgbAnimationByProgress } from \"@/lib\";\nimport type { CachedTextNodeParametersInterface, NodeInterface } from \"@/types\";\nimport type { GraphCanvas } from \"../GraphCanvas\";\nimport {\n animationByProgress,\n isNodeVisible,\n nodeIterationExtractor,\n nodeOptionsGetter,\n nodeRadiusGetter,\n nodeSizeGetter,\n} from \"../lib\";\nimport type { GraphState, NodeOptionsInterface } from \"../types\";\nimport { drawText, getTextLines } from \"./draw-text\";\n\nexport function getDrawNode<\n NodeData extends Record<string, unknown>,\n LinkData extends Record<string, unknown>,\n>(nodeRenders: (() => void)[], textRenders: (() => void)[], state: GraphState<NodeData, LinkData>) {\n return function drawNode(\n this: GraphCanvas<NodeData, LinkData>,\n node: NodeInterface<NodeData>,\n index: number,\n ) {\n if (!this.context || !node.x || !node.y) return;\n\n let nodeOptions: Required<NodeOptionsInterface<NodeData, LinkData>>;\n if (this.nodeSettings.cache && this.nodeOptionsCache[node.id]) {\n nodeOptions = this.nodeOptionsCache[node.id];\n } else {\n nodeOptions = nodeIterationExtractor(\n node,\n index,\n this.nodes,\n state,\n this.nodeSettings.options ?? {},\n nodeOptionsGetter,\n );\n if (this.nodeSettings.cache) {\n this.nodeOptionsCache[node.id] = nodeOptions;\n }\n }\n\n if (nodeOptions.nodeDraw && nodeOptions.textDraw) {\n nodeRenders.push(() => {\n nodeOptions?.nodeDraw?.(node, nodeOptions, state);\n });\n\n textRenders.push(() => {\n nodeOptions?.textDraw?.(node, nodeOptions, state);\n });\n\n return;\n }\n\n let alpha = nodeOptions.alpha;\n let color = nodeOptions.color;\n let radiusInitial = nodeOptions.radius;\n let widthInitial = nodeOptions.width;\n let heightInitial = nodeOptions.height;\n let textAlpha = nodeOptions.textAlpha;\n let textSize = nodeOptions.textSize;\n let textShiftX = nodeOptions.textShiftX;\n let textShiftY = nodeOptions.textShiftY;\n let textWeight = nodeOptions.textWeight;\n let textWidth = nodeOptions.textWidth;\n let sizeCoefficient = 1;\n /** Node Highlight */\n if (this.highlightedNeighbors && this.highlightedNode) {\n /** Not highlighted */\n if (!this.highlightedNeighbors.has(node.id) && this.highlightedNode.id != node.id) {\n if (this.nodeSettings.highlightByNodeNodeFading) {\n const min =\n this.nodeSettings.highlightByNodeNodeFadingMin < alpha\n ? this.nodeSettings.highlightByNodeNodeFadingMin\n : alpha;\n alpha = animationByProgress(min, alpha - min, 1 - this.highlightProgress);\n }\n if (this.nodeSettings.highlightByNodeTextFading) {\n const min =\n this.nodeSettings.highlightByNodeTextFadingMin < textAlpha\n ? this.nodeSettings.highlightByNodeTextFadingMin\n : textAlpha;\n textAlpha = animationByProgress(min, textAlpha - min, 1 - this.highlightProgress);\n }\n if (this.nodeSettings.highlightByNodeNodeColor) {\n const colorRgb = extractRgb(colorToRgb(color));\n if (colorRgb) {\n const colorRgbFade = fadeRgb(\n colorRgb,\n this.nodeSettings.highlightByNodeNodeColorFadingMin,\n );\n const colorFadeAnimation = rgbAnimationByProgress(\n colorRgb,\n colorRgbFade,\n this.highlightProgress,\n );\n color = `rgb(${colorFadeAnimation.r}, ${colorFadeAnimation.g}, ${colorFadeAnimation.b})`;\n }\n }\n } else if (\n !this.nodeSettings.highlightByNodeOnlyRoot ||\n (this.nodeSettings.highlightByNodeOnlyRoot && this.highlightedNode.id === node.id)\n ) {\n /** Highlighted */\n\n if (this.nodeSettings.highlightByNodeNodeSizing && nodeOptions.shape === \"circle\") {\n radiusInitial = animationByProgress(\n radiusInitial,\n this.nodeSettings.highlightByNodeNodeSizingAdditional,\n this.highlightProgress,\n );\n }\n if (\n this.nodeSettings.highlightByNodeNodeSizing &&\n (nodeOptions.shape === \"square\" || nodeOptions.shape === \"text\")\n ) {\n sizeCoefficient = animationByProgress(\n sizeCoefficient,\n this.nodeSettings.highlightByNodeNodeSizingAdditionalCoefficient,\n this.highlightProgress,\n );\n\n widthInitial *= sizeCoefficient;\n heightInitial *= sizeCoefficient;\n }\n if (this.nodeSettings.highlightByNodeTextSizing) {\n textSize = animationByProgress(\n textSize,\n this.nodeSettings.highlightByNodeTextSizingAdditional,\n this.highlightProgress,\n );\n textShiftX = animationByProgress(\n textShiftX,\n this.nodeSettings.highlightByNodeTextShiftXAdditional,\n this.highlightProgress,\n );\n textShiftY = animationByProgress(\n textShiftY,\n this.nodeSettings.highlightByNodeTextShiftYAdditional,\n this.highlightProgress,\n );\n textWeight = animationByProgress(\n textWeight,\n this.nodeSettings.highlightByNodeTextWeightAdditional,\n this.highlightProgress,\n );\n textWidth = animationByProgress(\n textWidth,\n this.nodeSettings.highlightByNodeTextWidthAdditional,\n this.highlightProgress,\n );\n }\n }\n }\n /** LinkHighlight */\n if (this.highlightedNeighbors && this.highlightedLink) {\n /** Not highlighted */\n if (\n !this.highlightedNeighbors.has(node.id) &&\n this.highlightedLink.source !== node &&\n this.highlightedLink.target !== node\n ) {\n if (this.nodeSettings.highlightByLinkNodeFading) {\n const min =\n this.nodeSettings.highlightByLinkNodeFadingMin < alpha\n ? this.nodeSettings.highlightByLinkNodeFadingMin\n : alpha;\n alpha = animationByProgress(min, alpha - min, 1 - this.highlightProgress);\n }\n if (this.nodeSettings.highlightByLinkTextFading) {\n const min =\n this.nodeSettings.highlightByLinkTextFadingMin < textAlpha\n ? this.nodeSettings.highlightByLinkTextFadingMin\n : textAlpha;\n textAlpha = animationByProgress(min, textAlpha - min, 1 - this.highlightProgress);\n }\n if (this.nodeSettings.highlightByLinkNodeColor) {\n const colorRgb = extractRgb(colorToRgb(color));\n if (colorRgb) {\n const colorRgbFade = fadeRgb(\n colorRgb,\n this.nodeSettings.highlightByLinkNodeColorFadingMin,\n );\n const colorFadeAnimation = rgbAnimationByProgress(\n colorRgb,\n colorRgbFade,\n this.highlightProgress,\n );\n color = `rgb(${colorFadeAnimation.r}, ${colorFadeAnimation.g}, ${colorFadeAnimation.b})`;\n }\n }\n } else {\n /** Highlighted */\n\n if (this.nodeSettings.highlightByLinkNodeSizing && nodeOptions.shape === \"circle\") {\n radiusInitial = animationByProgress(\n radiusInitial,\n this.nodeSettings.highlightByLinkNodeSizingAdditional,\n this.highlightProgress,\n );\n }\n if (\n this.nodeSettings.highlightByLinkNodeSizing &&\n (nodeOptions.shape === \"square\" ||\n nodeOptions.shape === \"text\" ||\n nodeOptions.shape === \"icon\")\n ) {\n sizeCoefficient = animationByProgress(\n sizeCoefficient,\n this.nodeSettings.highlightByNodeNodeSizingAdditionalCoefficient,\n this.highlightProgress,\n );\n\n widthInitial *= sizeCoefficient;\n heightInitial *= sizeCoefficient;\n }\n if (this.nodeSettings.highlightByLinkTextSizing) {\n textSize = animationByProgress(\n textSize,\n this.nodeSettings.highlightByLinkTextSizingAdditional,\n this.highlightProgress,\n );\n textShiftX = animationByProgress(\n textShiftX,\n this.nodeSettings.highlightByLinkTextShiftXAdditional,\n this.highlightProgress,\n );\n textShiftY = animationByProgress(\n textShiftY,\n this.nodeSettings.highlightByLinkTextShiftYAdditional,\n this.highlightProgress,\n );\n textWeight = animationByProgress(\n textWeight,\n this.nodeSettings.highlightByLinkTextWeightAdditional,\n this.highlightProgress,\n );\n textWidth = animationByProgress(\n textWidth,\n this.nodeSettings.highlightByLinkTextWidthAdditional,\n this.highlightProgress,\n );\n }\n }\n }\n\n /** Flex radius */\n const radius =\n nodeOptions.shape === \"circle\"\n ? nodeRadiusGetter({\n radiusFlexible: this.nodeSettings.nodeRadiusFlexible,\n radiusInitial,\n radiusCoefficient: this.nodeSettings.nodeRadiusCoefficient,\n radiusFactor: this.nodeSettings.nodeRadiusFactor,\n linkCount: node.linkCount,\n })\n : radiusInitial;\n /** Flex size */\n let height: number = heightInitial;\n let width: number = widthInitial;\n if (nodeOptions.shape === \"square\") {\n const size = nodeSizeGetter({\n heightInitial,\n widthInitial,\n linkCount: node.linkCount,\n sizeCoefficient: this.nodeSettings.nodeSizeCoefficient,\n sizeFactor: this.nodeSettings.nodeSizeFactor,\n sizeFlexible: this.nodeSettings.nodeSizeFlexible,\n });\n width = size.width;\n height = size.height;\n }\n if (nodeOptions.shape === \"text\") {\n width = nodeOptions.width;\n\n const size = nodeSizeGetter({\n heightInitial,\n widthInitial: width,\n linkCount: node.linkCount,\n sizeCoefficient: this.nodeSettings.nodeSizeCoefficient,\n sizeFactor: this.nodeSettings.nodeSizeFactor,\n sizeFlexible: this.nodeSettings.nodeSizeFlexible,\n });\n\n textSize *= size.additionalSizeCoefficient;\n }\n /** Size by text in textNode */\n if (nodeOptions.shape === \"text\" && nodeOptions.text) {\n textWidth = width;\n let lines: string[];\n\n let textNodeParameters: CachedTextNodeParametersInterface;\n\n const cachedLines = this.cachedNodeText[node.id];\n const cachedTextNodeParameters = this.cachedTextNodeParameters[node.id];\n if (cachedLines != undefined && cachedTextNodeParameters != undefined) {\n lines = cachedLines;\n textNodeParameters = cachedTextNodeParameters;\n } else {\n const textInfo = getTextLines({\n context: this.context,\n text: nodeOptions.text,\n textAlign: nodeOptions.textAlign,\n textColor: nodeOptions.textColor,\n textFont: nodeOptions.textFont,\n textSize,\n maxWidth: textWidth,\n textStyle: nodeOptions.textStyle,\n textWeight,\n });\n textNodeParameters = [textInfo.currentMaxSize, textSize];\n lines = textInfo.lines;\n this.cachedNodeText[node.id] = lines;\n this.cachedTextNodeParameters[node.id] = textNodeParameters;\n }\n\n const textSizeCoefficient = textSize / textNodeParameters[1];\n const maxSize = textNodeParameters[0] * textSizeCoefficient;\n\n height =\n lines.length * textSize +\n (lines.length - 1) * nodeOptions.textGap +\n nodeOptions.textNodeYPadding;\n\n width = maxSize + nodeOptions.textNodeXPadding;\n }\n\n /** Node parameters */\n node._radius = radius;\n node._width = width;\n node._height = height;\n node._borderRadius =\n isNumber(nodeOptions.borderRadius) && nodeOptions.borderRadius > 0\n ? Math.min(nodeOptions.borderRadius, nodeOptions.width / 2, nodeOptions.height / 2)\n : 0;\n node._shape = nodeOptions.shape ?? \"circle\";\n\n /** Node Visibility */\n if (\n !isNodeVisible({\n height: this.height,\n width: this.width,\n transform: this.areaTransform,\n node,\n })\n ) {\n node._visible = false;\n\n return;\n }\n node._visible = true;\n\n /** Node draw */\n nodeRenders.push(() => {\n if (!this.context || !node.x || !node.y) return;\n\n this.context.beginPath();\n this.context.globalAlpha = alpha;\n this.context.lineWidth = nodeOptions.borderWidth;\n this.context.strokeStyle = nodeOptions.borderColor;\n this.context.fillStyle = color;\n\n switch (nodeOptions.shape) {\n case \"circle\": {\n this.context.arc(node.x, node.y, radius, 0, 2 * Math.PI);\n break;\n }\n case \"square\": {\n this.context.roundRect(\n node.x - width / 2,\n node.y - height / 2,\n width,\n height,\n node._borderRadius,\n );\n break;\n }\n case \"text\": {\n if (this.nodeSettings.textNodeDebug) {\n this.context.strokeRect(node.x - width / 2, node.y - height / 2, width, height);\n }\n\n const lines = this.cachedNodeText[node.id];\n if (nodeOptions.text && lines)\n drawText({\n id: node.id,\n cachedNodeText: this.cachedNodeText,\n context: this.context,\n text: nodeOptions.text,\n textAlign: nodeOptions.textAlign,\n textColor: nodeOptions.textColor,\n textFont: nodeOptions.textFont,\n textSize,\n x: node.x,\n y: node.y + textSize / 4 - (lines.length - 1) * (textSize / 2),\n maxWidth: textWidth,\n textStyle: nodeOptions.textStyle,\n textWeight,\n textGap: nodeOptions.textGap,\n });\n break;\n }\n default: {\n this.context.arc(node.x, node.y, radius, 0, 2 * Math.PI);\n break;\n }\n }\n\n this.context.fill();\n this.context.stroke();\n });\n\n if (nodeOptions.nodeExtraDraw) {\n nodeRenders.push(() => {\n nodeOptions?.nodeExtraDraw?.(\n node,\n {\n ...nodeOptions,\n radius,\n alpha,\n color,\n textAlpha,\n textSize,\n textShiftX,\n textShiftY,\n textWeight,\n textWidth,\n },\n state,\n );\n });\n }\n\n /** Text draw */\n if (nodeOptions.textVisible && nodeOptions.text && nodeOptions.shape !== \"text\") {\n textRenders.push(() => {\n if (nodeOptions.textDraw) {\n nodeOptions.textDraw(\n node,\n {\n ...nodeOptions,\n radius,\n alpha,\n color,\n textAlpha,\n textSize,\n textShiftX,\n textShiftY,\n textWeight,\n textWidth,\n },\n state,\n );\n\n return;\n }\n\n if (!this.context || !node.x || !node.y || !nodeOptions.text) return;\n this.context.beginPath();\n this.context.globalAlpha = textAlpha;\n\n let y = node.y + textShiftY;\n if (nodeOptions.shape === \"circle\") {\n y += radius;\n }\n if (nodeOptions.shape === \"square\") {\n y += height / 2;\n }\n\n drawText({\n id: node.id,\n cachedNodeText: this.cachedNodeText,\n context: this.context,\n text: nodeOptions.text,\n textAlign: nodeOptions.textAlign,\n textColor: nodeOptions.textColor,\n textFont: nodeOptions.textFont,\n textSize,\n x: node.x + textShiftX,\n y,\n maxWidth: textWidth,\n textStyle: nodeOptions.textStyle,\n textWeight,\n textGap: nodeOptions.textGap,\n });\n\n if (nodeOptions.textExtraDraw) {\n nodeOptions.textExtraDraw(\n node,\n {\n ...nodeOptions,\n radius,\n alpha,\n color,\n textAlpha,\n textSize,\n textShiftX,\n textShiftY,\n textWeight,\n textWidth,\n },\n state,\n );\n }\n });\n }\n };\n}\n"],"names":[],"mappings":";;;;;;;;;;;;SAegB,WAAW,CAGzB,WAA2B,EAAE,WAA2B,E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Ac;oBACnC,OAAO,EAAE,IAAI,CAAC,OAAO;oBACrB,IAAI,EAAE,WAAW,CAAC,IAAI;oBACtB,SAAS,EAAE,WAAW,CAAC,SAAS;oBAChC,SAAS,EAAE,WAAW,CAAC,SAAS;oBAChC,QAAQ,EAAE,WAAW,CAAC,QAAQ;oBAC9B,QAAQ;AACR,oBAAA,CAAC,EAAE,IAAI,CAAC,CAAC,GAAG,UAAU;oBACtB,CAAC;AACD,oBAAA,QAAQ,EAAE,SAAS;oBACnB,SAAS,EAAE,WAAW,CAAC,SAAS;oBAChC,UAAU;oBACV,OAAO,EAAE,WAAW,CAAC,OAAO;AAC7B,iBAAA,CAAC;AAEF,gBAAA,IAAI,WAAW,CAAC,aAAa,EAAE;AAC7B,oBAAA,WAAW,CAAC,aAAa,CACvB,IAAI,EACJ;AACE,wBAAA,GAAG,WAAW;wBACd,MAAM;wBACN,KAAK;wBACL,KAAK;wBACL,SAAS;wBACT,QAAQ;wBACR,UAAU;wBACV,UAAU;wBACV,UAAU;wBACV,SAAS;qBACV,EACD,KAAK,CACN;;AAEL,aAAC,CAAC;;AAEN,KAAC;AACH;;;;"}
@@ -14,7 +14,7 @@ function drawText({ context, id, textAlign, textColor, textFont, textStyle, text
14
14
  context.fillText(text, x, y);
15
15
  return;
16
16
  }
17
- const lines = getTextLines({
17
+ const { lines } = getTextLines({
18
18
  context,
19
19
  maxWidth,
20
20
  text,
@@ -38,6 +38,7 @@ function getTextLines({ context, textAlign, textColor, textFont, textStyle, text
38
38
  const lines = [];
39
39
  let lineWidth = 0;
40
40
  let line = "";
41
+ let currentMaxSize = 0;
41
42
  for (const word of text.split(" ")) {
42
43
  const size = context.measureText(word).width;
43
44
  lineWidth += size + spaceWidth;
@@ -46,7 +47,10 @@ function getTextLines({ context, textAlign, textColor, textFont, textStyle, text
46
47
  continue;
47
48
  }
48
49
  if (lineWidth > maxWidth) {
49
- lineWidth = 0;
50
+ const initialSize = lineWidth - size - spaceWidth;
51
+ if (initialSize > currentMaxSize)
52
+ currentMaxSize = initialSize;
53
+ lineWidth = size;
50
54
  lines.push(line);
51
55
  line = word;
52
56
  }
@@ -57,7 +61,9 @@ function getTextLines({ context, textAlign, textColor, textFont, textStyle, text
57
61
  }
58
62
  if (line !== "")
59
63
  lines.push(line);
60
- return lines;
64
+ if (lineWidth > currentMaxSize)
65
+ currentMaxSize = lineWidth;
66
+ return { lines, currentMaxSize };
61
67
  }
62
68
 
63
69
  export { drawText, getTextLines };
@@ -1 +1 @@
1
- {"version":3,"file":"draw-text.js","sources":["../../../../../src/module/GraphCanvas/slices/draw-text.ts"],"sourcesContent":["import type { CachedNodeTextInterface } from \"@/types\";\nimport type { TextStyleEnum } from \"../types\";\n\nexport type DrawTextOptions = {\n id: string | number;\n x: number;\n y: number;\n text: string;\n textSize: number;\n textStyle: TextStyleEnum;\n textWeight: number;\n textFont: string;\n textColor: string;\n textGap: number;\n textAlign: CanvasTextAlign;\n context: CanvasRenderingContext2D;\n cachedNodeText: CachedNodeTextInterface;\n maxWidth?: number;\n};\n\nconst SPACE = \" \";\n\nexport function drawText({\n context,\n id,\n textAlign,\n textColor,\n textFont,\n textStyle,\n textGap,\n textWeight,\n textSize,\n text,\n x,\n y,\n cachedNodeText,\n maxWidth,\n}: DrawTextOptions) {\n context.font = `${textStyle} normal ${textWeight} ${textSize}px ${textFont}`;\n context.fillStyle = textColor;\n context.textAlign = textAlign;\n\n if (cachedNodeText[id] != undefined) {\n cachedNodeText[id].forEach((line, index) => {\n context.fillText(line, x, y + index * textSize + index * textGap);\n });\n\n return;\n }\n\n if (maxWidth == undefined || context.measureText(text).width <= maxWidth) {\n cachedNodeText[id] = [text];\n context.fillText(text, x, y);\n\n return;\n }\n\n const lines = getTextLines({\n context,\n maxWidth,\n text,\n textAlign,\n textColor,\n textFont,\n textSize,\n textStyle,\n textWeight,\n });\n\n cachedNodeText[id] = lines;\n lines.forEach((line, index) => {\n context.fillText(line, x, y + index * textSize + index * textGap);\n });\n}\n\nexport type GetTextLines = {\n text: string;\n textSize: number;\n textStyle: TextStyleEnum;\n textWeight: number;\n textFont: string;\n textColor: string;\n textAlign: CanvasTextAlign;\n context: CanvasRenderingContext2D;\n maxWidth: number;\n};\nexport function getTextLines({\n context,\n textAlign,\n textColor,\n textFont,\n textStyle,\n textWeight,\n textSize,\n text,\n maxWidth,\n}: GetTextLines) {\n context.font = `${textStyle} normal ${textWeight} ${textSize}px ${textFont}`;\n context.fillStyle = textColor;\n context.textAlign = textAlign;\n\n const spaceWidth = context.measureText(\" \").width;\n const lines: string[] = [];\n let lineWidth = 0;\n let line = \"\";\n\n for (const word of text.split(\" \")) {\n const size = context.measureText(word).width;\n lineWidth += size + spaceWidth;\n\n if (line === \"\") {\n line = word;\n\n continue;\n }\n if (lineWidth > maxWidth) {\n lineWidth = 0;\n lines.push(line);\n line = word;\n } else {\n lineWidth += spaceWidth;\n line += `${SPACE}${word}`;\n }\n }\n\n if (line !== \"\") lines.push(line);\n\n return lines;\n}\n"],"names":[],"mappings":"AAoBA,MAAM,KAAK,GAAG,GAAG;AAED,SAAA,QAAQ,CAAC,EACvB,OAAO,EACP,EAAE,EACF,SAAS,EACT,SAAS,EACT,QAAQ,EACR,SAAS,EACT,OAAO,EACP,UAAU,EACV,QAAQ,EACR,IAAI,EACJ,CAAC,EACD,CAAC,EACD,cAAc,EACd,QAAQ,GACQ,EAAA;AAChB,IAAA,OAAO,CAAC,IAAI,GAAG,CAAA,EAAG,SAAS,CAAA,QAAA,EAAW,UAAU,CAAA,CAAA,EAAI,QAAQ,CAAA,GAAA,EAAM,QAAQ,CAAA,CAAE;AAC5E,IAAA,OAAO,CAAC,SAAS,GAAG,SAAS;AAC7B,IAAA,OAAO,CAAC,SAAS,GAAG,SAAS;AAE7B,IAAA,IAAI,cAAc,CAAC,EAAE,CAAC,IAAI,SAAS,EAAE;QACnC,cAAc,CAAC,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,KAAK,KAAI;AACzC,YAAA,OAAO,C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jD,MAAM,KAAK,GAAa,EAAE;IAC1B,IAAI,SAAS,GAAG,CAAC;IACjB,IAAI,IAAI,GAAG,EAAE;IAEb,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE;QAClC,MAAM,IAAI,GAAG,OAAO,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,KAAK;AAC5C,QAAA,SAAS,IAAI,IAAI,GAAG,UAAU;AAE9B,QAAA,IAAI,IAAI,KAAK,EAAE,EAAE;YACf,IAAI,GAAG,IAAI;YAEX;;AAEF,QAAA,IAAI,SAAS,GAAG,QAAQ,EAAE;YACxB,SAAS,GAAG,CAAC;AACb,YAAA,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC;YAChB,IAAI,GAAG,IAAI;;aACN;YACL,SAAS,IAAI,UAAU;AACvB,YAAA,IAAI,IAAI,CAAG,EAAA,KAAK,CAAG,EAAA,IAAI,EAAE;;;IAI7B,IAAI,IAAI,KAAK,EAAE;AAAE,QAAA,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC;AAEjC,IAAA,OAAO,KAAK;AACd;;;;"}
1
+ {"version":3,"file":"draw-text.js","sources":["../../../../../src/module/GraphCanvas/slices/draw-text.ts"],"sourcesContent":["import type { CachedNodeTextInterface } from \"@/types\";\nimport type { TextStyleEnum } from \"../types\";\n\nexport type DrawTextOptions = {\n id: string | number;\n x: number;\n y: number;\n text: string;\n textSize: number;\n textStyle: TextStyleEnum;\n textWeight: number;\n textFont: string;\n textColor: string;\n textGap: number;\n textAlign: CanvasTextAlign;\n context: CanvasRenderingContext2D;\n cachedNodeText: CachedNodeTextInterface;\n maxWidth?: number;\n};\n\nconst SPACE = \" \";\n\nexport function drawText({\n context,\n id,\n textAlign,\n textColor,\n textFont,\n textStyle,\n textGap,\n textWeight,\n textSize,\n text,\n x,\n y,\n cachedNodeText,\n maxWidth,\n}: DrawTextOptions) {\n context.font = `${textStyle} normal ${textWeight} ${textSize}px ${textFont}`;\n context.fillStyle = textColor;\n context.textAlign = textAlign;\n\n if (cachedNodeText[id] != undefined) {\n cachedNodeText[id].forEach((line, index) => {\n context.fillText(line, x, y + index * textSize + index * textGap);\n });\n\n return;\n }\n\n if (maxWidth == undefined || context.measureText(text).width <= maxWidth) {\n cachedNodeText[id] = [text];\n context.fillText(text, x, y);\n\n return;\n }\n\n const { lines } = getTextLines({\n context,\n maxWidth,\n text,\n textAlign,\n textColor,\n textFont,\n textSize,\n textStyle,\n textWeight,\n });\n\n cachedNodeText[id] = lines;\n lines.forEach((line, index) => {\n context.fillText(line, x, y + index * textSize + index * textGap);\n });\n}\n\nexport type GetTextLines = {\n text: string;\n textSize: number;\n textStyle: TextStyleEnum;\n textWeight: number;\n textFont: string;\n textColor: string;\n textAlign: CanvasTextAlign;\n context: CanvasRenderingContext2D;\n maxWidth: number;\n};\nexport function getTextLines({\n context,\n textAlign,\n textColor,\n textFont,\n textStyle,\n textWeight,\n textSize,\n text,\n maxWidth,\n}: GetTextLines) {\n context.font = `${textStyle} normal ${textWeight} ${textSize}px ${textFont}`;\n context.fillStyle = textColor;\n context.textAlign = textAlign;\n\n const spaceWidth = context.measureText(\" \").width;\n const lines: string[] = [];\n let lineWidth = 0;\n let line = \"\";\n let currentMaxSize = 0;\n\n for (const word of text.split(\" \")) {\n const size = context.measureText(word).width;\n lineWidth += size + spaceWidth;\n\n if (line === \"\") {\n line = word;\n\n continue;\n }\n if (lineWidth > maxWidth) {\n const initialSize = lineWidth - size - spaceWidth;\n if (initialSize > currentMaxSize) currentMaxSize = initialSize;\n\n lineWidth = size;\n lines.push(line);\n line = word;\n } else {\n lineWidth += spaceWidth;\n line += `${SPACE}${word}`;\n }\n }\n\n if (line !== \"\") lines.push(line);\n if (lineWidth > currentMaxSize) currentMaxSize = lineWidth;\n\n return { lines, currentMaxSize };\n}\n"],"names":[],"mappings":"AAoBA,MAAM,KAAK,GAAG,GAAG;AAED,SAAA,QAAQ,CAAC,EACvB,OAAO,EACP,EAAE,EAC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