@react-fabric/graph 1.0.0-beta.59 → 1.0.0-beta.61

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (73) hide show
  1. package/dist/cjs/components/Context.js +7 -8
  2. package/dist/cjs/components/ContextMenu.js +8 -9
  3. package/dist/cjs/components/Tools.js +102 -24
  4. package/dist/cjs/components/Viewer.js +1 -0
  5. package/dist/cjs/graph/index.js +73 -66
  6. package/dist/cjs/hooks/useSigma.js +5 -5
  7. package/dist/cjs/programs/arrow-head/frag.glsl.js +1 -1
  8. package/dist/cjs/programs/arrow-head/index.js +1 -1
  9. package/dist/cjs/programs/arrow-head/vert.glsl.js +1 -1
  10. package/dist/cjs/programs/edge-curve/index.js +2 -2
  11. package/dist/cjs/programs/edge-line/index.js +2 -2
  12. package/dist/cjs/programs/node-badge/vert.glsl.js +1 -1
  13. package/dist/cjs/programs/node-circle/base/drawHover.js +2 -1
  14. package/dist/cjs/programs/node-circle/base/drawLabel.js +2 -1
  15. package/dist/cjs/programs/node-rect/base/drawHover.js +2 -1
  16. package/dist/cjs/programs/node-rect/base/drawLabel.js +2 -1
  17. package/dist/esm/components/Context.js +8 -9
  18. package/dist/esm/components/ContextMenu.js +8 -9
  19. package/dist/esm/components/Tools.js +102 -24
  20. package/dist/esm/components/Viewer.js +1 -0
  21. package/dist/esm/graph/index.js +74 -67
  22. package/dist/esm/hooks/useSigma.js +5 -5
  23. package/dist/esm/programs/arrow-head/frag.glsl.js +1 -1
  24. package/dist/esm/programs/arrow-head/index.js +1 -1
  25. package/dist/esm/programs/arrow-head/vert.glsl.js +1 -1
  26. package/dist/esm/programs/edge-curve/index.js +2 -2
  27. package/dist/esm/programs/edge-line/index.js +2 -2
  28. package/dist/esm/programs/node-badge/vert.glsl.js +1 -1
  29. package/dist/esm/programs/node-circle/base/drawHover.js +2 -1
  30. package/dist/esm/programs/node-circle/base/drawLabel.js +2 -1
  31. package/dist/esm/programs/node-rect/base/drawHover.js +2 -1
  32. package/dist/esm/programs/node-rect/base/drawLabel.js +2 -1
  33. package/dist/types/components/Context.d.ts +3 -3
  34. package/dist/types/components/Viewer.d.ts +1 -1
  35. package/dist/types/graph/index.d.ts +9 -4
  36. package/dist/types/hooks/sigmaHilighter.d.ts +1 -1
  37. package/dist/types/hooks/sigmaMouseActions.d.ts +1 -1
  38. package/dist/types/hooks/useGraphology.d.ts +1 -1
  39. package/dist/types/hooks/useSigma.d.ts +2 -2
  40. package/dist/types/programs/arrow-head/index.d.ts +4 -4
  41. package/dist/types/programs/edge-curve/index.d.ts +1 -1
  42. package/dist/types/programs/node-circle/base/drawHover.d.ts +1 -1
  43. package/dist/types/programs/node-circle/base/drawLabel.d.ts +1 -1
  44. package/dist/types/programs/node-circle/index.d.ts +1 -1
  45. package/dist/types/programs/node-rect/base/drawHover.d.ts +1 -1
  46. package/dist/types/programs/node-rect/base/drawLabel.d.ts +1 -1
  47. package/dist/types/programs/node-rect/index.d.ts +1 -1
  48. package/dist/types/types/index.d.ts +7 -7
  49. package/package.json +4 -4
  50. package/src/components/Context.tsx +20 -12
  51. package/src/components/ContextMenu.tsx +32 -14
  52. package/src/components/Tools.tsx +15 -16
  53. package/src/components/Viewer.tsx +2 -1
  54. package/src/graph/index.ts +68 -63
  55. package/src/graph/layout.worker.ts +1 -1
  56. package/src/hooks/sigmaHilighter.ts +2 -2
  57. package/src/hooks/sigmaMouseActions.ts +1 -1
  58. package/src/hooks/useGraphology.ts +1 -1
  59. package/src/hooks/useSigma.ts +8 -8
  60. package/src/programs/arrow-head/frag.glsl.ts +1 -1
  61. package/src/programs/arrow-head/index.ts +17 -8
  62. package/src/programs/arrow-head/vert.glsl.ts +1 -1
  63. package/src/programs/edge-curve/index.ts +2 -2
  64. package/src/programs/edge-line/index.ts +2 -2
  65. package/src/programs/node-badge/factory.ts +3 -3
  66. package/src/programs/node-badge/vert.glsl.ts +4 -4
  67. package/src/programs/node-circle/base/drawHover.ts +2 -2
  68. package/src/programs/node-circle/base/drawLabel.ts +6 -6
  69. package/src/programs/node-circle/index.ts +1 -1
  70. package/src/programs/node-rect/base/drawHover.ts +2 -2
  71. package/src/programs/node-rect/base/drawLabel.ts +6 -6
  72. package/src/programs/node-rect/index.ts +1 -1
  73. package/src/types/index.ts +6 -6
@@ -3,18 +3,22 @@ import {
3
3
  DEFAULT_EDGE_CURVATURE,
4
4
  indexParallelEdgesIndex,
5
5
  } from "@sigma/edge-curve";
6
- import ElkConstructor, { ELK } from "elkjs/lib/elk.bundled";
7
- // @ts-expect-error ignore
8
- import ElkWorker from "../../../../node_modules/elkjs/lib/elk-worker?worker";
6
+ import ElkConstructor, { type ELK } from "elkjs/lib/elk.bundled";
9
7
  import Graphology from "graphology";
10
- import { random } from "graphology-layout";
11
- import { GraphEvents, GraphOptions } from "graphology-types";
8
+ import { circular } from "graphology-layout";
9
+ import forceAtlas2, {
10
+ type ForceAtlas2Settings,
11
+ } from "graphology-layout-forceatlas2";
12
+ import ForceAtlas2Worker from "graphology-layout-forceatlas2/worker";
13
+ import { type GraphEvents, type GraphOptions } from "graphology-types";
12
14
  import { animateNodes } from "sigma/utils";
15
+ // @ts-expect-error ignore
16
+ import ElkWorker from "../../../../node_modules/elkjs/lib/elk-worker?worker";
13
17
  import {
14
- EdgeAttributes,
15
- InternalNodeAttributes,
16
- NodeAttributes,
17
- RawGraph,
18
+ type EdgeAttributes,
19
+ type InternalNodeAttributes,
20
+ type NodeAttributes,
21
+ type RawGraph,
18
22
  } from "../types";
19
23
 
20
24
  interface ExtendedEvents extends GraphEvents {
@@ -78,13 +82,13 @@ export class Graph<N = KeyValue, E = KeyValue> extends Graphology<
78
82
  nodes: string[],
79
83
  attributesOrNodeReducer?:
80
84
  | NodeAttributes<N>
81
- | ((attributes: NodeAttributes<N>[]) => NodeAttributes<N>),
85
+ | ((attributes: Array<NodeAttributes<N>>) => NodeAttributes<N>),
82
86
  edgeReducer?: (edges: RawGraph<N, E>["edges"]) => RawGraph<N, E>["edges"],
83
87
  ) {
84
88
  if (!nodes.length) return;
85
89
  let newNodeAttributes: NodeAttributes<N> = {};
86
90
  let edgeList: RawGraph<N, E>["edges"] = [];
87
- const attributeList: NodeAttributes<N>[] = [];
91
+ const attributeList: Array<NodeAttributes<N>> = [];
88
92
  nodes.forEach((n) => {
89
93
  const atts = this.getNodeAttributes(n);
90
94
  if (atts) {
@@ -133,7 +137,7 @@ export class Graph<N = KeyValue, E = KeyValue> extends Graphology<
133
137
  nodes: string[],
134
138
  attributesOrNodeReducer?:
135
139
  | NodeAttributes<N>
136
- | ((attributes: NodeAttributes<N>[]) => NodeAttributes<N>),
140
+ | ((attributes: Array<NodeAttributes<N>>) => NodeAttributes<N>),
137
141
  edgeReducer?: (edges: RawGraph<N, E>["edges"]) => RawGraph<N, E>["edges"],
138
142
  ) {
139
143
  if (!nodes.length) return;
@@ -144,7 +148,7 @@ export class Graph<N = KeyValue, E = KeyValue> extends Graphology<
144
148
  } as any;
145
149
  let edgeList: RawGraph<N, E>["edges"] = [];
146
150
  const movedEdges: RawGraph<N, E>["edges"] = [];
147
- const attributeList: NodeAttributes<N>[] = [];
151
+ const attributeList: Array<NodeAttributes<N>> = [];
148
152
  nodes.forEach((n) => {
149
153
  const atts = this.getNodeAttributes(n);
150
154
  if (atts) {
@@ -213,7 +217,7 @@ export class Graph<N = KeyValue, E = KeyValue> extends Graphology<
213
217
  ungroupNode(node: string) {
214
218
  const atts = this.getNodeAttributes(node);
215
219
  if (!atts || !atts.isGroup) return;
216
- const nodes = atts.nodeList || [];
220
+ const nodes = atts.nodeList ?? [];
217
221
  nodes.forEach((n: string) => {
218
222
  const originalEdges = this.getNodeAttribute(n, "originalEdges");
219
223
  if (originalEdges && Array.isArray(originalEdges)) {
@@ -250,7 +254,25 @@ export class Graph<N = KeyValue, E = KeyValue> extends Graphology<
250
254
  // fire events for nodes added
251
255
  this.emit("nodesLoaded", newNodes);
252
256
  // apply random positions for nodes
253
- const positions = random(this as any);
257
+ // const positions = random(this as any);
258
+ // animateNodes(
259
+ // this as any,
260
+ // positions,
261
+ // {
262
+ // duration: 200,
263
+ // },
264
+ // () => {
265
+ // // fire layout done event
266
+ // this.emit("layoutDone");
267
+ // },
268
+ // );
269
+ void this.elkLayout("force");
270
+ return this;
271
+ }
272
+
273
+ circularLayout() {
274
+ if (this.size === 0) return this;
275
+ const positions = circular(this as any);
254
276
  animateNodes(
255
277
  this as any,
256
278
  positions,
@@ -258,58 +280,41 @@ export class Graph<N = KeyValue, E = KeyValue> extends Graphology<
258
280
  duration: 200,
259
281
  },
260
282
  () => {
261
- // fire layout done event
262
283
  this.emit("layoutDone");
263
284
  },
264
285
  );
265
286
  return this;
266
287
  }
267
288
 
268
- // circularLayout() {
269
- // if (this.size === 0) return this;
270
- // const positions = circular(this as any);
271
- // animateNodes(
272
- // this as any,
273
- // positions,
274
- // {
275
- // duration: 200,
276
- // },
277
- // () => {
278
- // this.emit("layoutDone");
279
- // },
280
- // );
281
- // return this;
282
- // }
283
-
284
- // private _timer: any;
285
- // private _worker?: forceAtlas2Worker;
286
- // forceLayout(settings: ForceAtlas2Settings = {}) {
287
- // if (this.size === 0) return this;
288
- // const sensibleSettings = forceAtlas2.inferSettings(this as any);
289
- // if (this._worker?.isRunning()) {
290
- // clearTimeout(this._timer);
291
- // }
292
- // this._worker?.kill();
293
- // this._worker = new forceAtlas2Worker(this as any, {
294
- // settings: {
295
- // ...sensibleSettings,
296
- // ...settings,
297
- // },
298
- // });
299
- // this.emit("layoutRunning", true);
300
- // this._worker.start();
301
- // this._timer = setTimeout(
302
- // () => {
303
- // this._worker?.stop();
304
- // this._worker?.kill();
305
- // this.emit("layoutRunning", false);
306
- // this.emit("layoutDone");
307
- // },
308
- // // @ts-expect-error ignore
309
- // this.nodes().length * window.__GRAPH_LAYOUT_DURATION_MULTIPLIER__,
310
- // );
311
- // return this;
312
- // }
289
+ private _timer: any;
290
+ private _worker?: ForceAtlas2Worker;
291
+ forceLayout(settings: ForceAtlas2Settings = {}) {
292
+ if (this.size === 0) return this;
293
+ const sensibleSettings = forceAtlas2.inferSettings(this as any);
294
+ if (this._worker?.isRunning()) {
295
+ clearTimeout(this._timer);
296
+ }
297
+ this._worker?.kill();
298
+ this._worker = new ForceAtlas2Worker(this as any, {
299
+ settings: {
300
+ ...sensibleSettings,
301
+ ...settings,
302
+ },
303
+ });
304
+ this.emit("layoutRunning", true);
305
+ this._worker.start();
306
+ this._timer = setTimeout(
307
+ () => {
308
+ this._worker?.stop();
309
+ this._worker?.kill();
310
+ this.emit("layoutRunning", false);
311
+ this.emit("layoutDone");
312
+ },
313
+ // @ts-expect-error ignore
314
+ this.nodes().length * window.__GRAPH_LAYOUT_DURATION_MULTIPLIER__,
315
+ );
316
+ return this;
317
+ }
313
318
 
314
319
  // @ts-expect-error ignore
315
320
  private elk: ELK;
@@ -325,8 +330,8 @@ export class Graph<N = KeyValue, E = KeyValue> extends Graphology<
325
330
  .layout(
326
331
  {
327
332
  id: "root",
328
- width: 1600,
329
- height: 900,
333
+ // width: 1600,
334
+ // height: 900,
330
335
  children: this.mapNodes((node, atts) => ({
331
336
  id: node,
332
337
  width: atts.size ?? Math.max(16, (atts.weight ?? 0) * 3),
@@ -1,5 +1,5 @@
1
1
  import ElkConstructor from "elkjs/lib/elk-api";
2
- // @ts-ignore
2
+ // @ts-expect-error ignore
3
3
  import ElkWorker from "elkjs/lib/elk-worker?worker";
4
4
 
5
5
  function layoutRunner({ type, nodes, edges }: KeyValue) {
@@ -1,8 +1,8 @@
1
1
  import { debounce } from "@react-fabric/utilities";
2
2
  import type Graph from "graphology";
3
3
  import type Sigma from "sigma";
4
- import { SigmaEdgeEventPayload, SigmaNodeEventPayload } from "sigma/types";
5
- import { EdgeAttributes, NodeAttributes } from "../types";
4
+ import { type SigmaEdgeEventPayload, type SigmaNodeEventPayload } from "sigma/types";
5
+ import { type EdgeAttributes, type NodeAttributes } from "../types";
6
6
 
7
7
  export const attachHighlighter = (
8
8
  renderer: Sigma<NodeAttributes<any>, EdgeAttributes<any>>,
@@ -1,7 +1,7 @@
1
1
  import type Graph from "graphology";
2
2
  import type Sigma from "sigma";
3
3
  import { type MouseCoords } from "sigma/types";
4
- import { EdgeAttributes, NodeAttributes } from "../types";
4
+ import { type EdgeAttributes, type NodeAttributes } from "../types";
5
5
 
6
6
  export const attachMouseActions = (
7
7
  renderer: Sigma<NodeAttributes<any>, EdgeAttributes<any>>,
@@ -1,6 +1,6 @@
1
1
  import { useEffect, useState } from "react";
2
2
  import { Graph } from "../graph";
3
- import { GraphProps } from "../types";
3
+ import { type GraphProps } from "../types";
4
4
 
5
5
  export const useGraphology = <N, E>(data: GraphProps<N, E>["data"]) => {
6
6
  const [graph, setGraph] = useState(new Graph<N, E>({ multi: true }));
@@ -1,16 +1,16 @@
1
1
  import { useIsDark } from "@react-fabric/core";
2
2
  import { useEffect, useState } from "react";
3
3
  import Sigma from "sigma";
4
- import { Graph } from "../graph";
4
+ import { type Graph } from "../graph";
5
5
  import { EdgeCurveProgram } from "../programs/edge-curve";
6
6
  import { EdgeLineProgram } from "../programs/edge-line";
7
7
  import { NodeCircleProgram } from "../programs/node-circle";
8
8
  import { NodeRectProgram } from "../programs/node-rect";
9
9
  import {
10
- EdgeAttributes,
11
- InternalEdgeAttributes,
12
- InternalNodeAttributes,
13
- NodeAttributes,
10
+ type EdgeAttributes,
11
+ type InternalEdgeAttributes,
12
+ type InternalNodeAttributes,
13
+ type NodeAttributes,
14
14
  } from "../types";
15
15
  import { attachHighlighter } from "./sigmaHilighter";
16
16
  import { attachMouseActions } from "./sigmaMouseActions";
@@ -55,7 +55,7 @@ export const useSigma = <N, E>(
55
55
  },
56
56
  nodeReducer(key, data) {
57
57
  const nodeData: InternalNodeAttributes<N> =
58
- nodeReducer?.(data) || data;
58
+ nodeReducer?.(data) ?? data;
59
59
  // Ensure node size is at least 16 for visibility
60
60
  if (!nodeData.size && nodeData.weight) {
61
61
  nodeData.size = Math.max(16, nodeData.weight * 3);
@@ -65,13 +65,13 @@ export const useSigma = <N, E>(
65
65
  }
66
66
 
67
67
  // ensure node label renderer is called in order to render selected border
68
- nodeData.label = nodeData.label || "";
68
+ nodeData.label = nodeData.label ?? "";
69
69
  nodeData.id = key;
70
70
  return nodeData;
71
71
  },
72
72
  edgeReducer(key, data) {
73
73
  const edgeData: InternalEdgeAttributes<E> =
74
- edgeReducer?.(data) || data;
74
+ edgeReducer?.(data) ?? data;
75
75
  // Ensure edge size is at least 0.5 for visibility
76
76
  if (!edgeData.size && edgeData.weight) {
77
77
  edgeData.size = Math.max(0.5, edgeData.weight * 6);
@@ -1,7 +1,7 @@
1
1
  /* istanbul ignore file */
2
2
 
3
3
  // language=GLSL
4
- const SHADER_SOURCE = /*glsl*/ `
4
+ const SHADER_SOURCE = /* glsl */ `
5
5
  precision mediump float;
6
6
 
7
7
  varying vec4 v_color;
@@ -1,9 +1,18 @@
1
- import { Attributes } from "graphology-types";
2
-
3
- import { EdgeProgram, EdgeProgramType, ProgramInfo } from "sigma/rendering";
4
- import { EdgeDisplayData, NodeDisplayData, RenderParams } from "sigma/types";
1
+ /* eslint-disable @typescript-eslint/naming-convention */
2
+ import { type Attributes } from "graphology-types";
3
+
4
+ import {
5
+ EdgeProgram,
6
+ type EdgeProgramType,
7
+ type ProgramInfo,
8
+ } from "sigma/rendering";
9
+ import {
10
+ type EdgeDisplayData,
11
+ type NodeDisplayData,
12
+ type RenderParams,
13
+ } from "sigma/types";
5
14
  import { floatColor } from "sigma/utils";
6
- import { InternalEdgeAttributes } from "../../types";
15
+ import { type InternalEdgeAttributes } from "../../types";
7
16
  import FRAGMENT_SHADER_SOURCE from "./frag.glsl";
8
17
  import VERTEX_SHADER_SOURCE from "./vert.glsl";
9
18
 
@@ -18,11 +27,11 @@ const UNIFORMS = [
18
27
  "u_widenessToThicknessRatio",
19
28
  ] as const;
20
29
 
21
- export type CreateEdgeArrowHeadProgramOptions = {
30
+ export interface CreateEdgeArrowHeadProgramOptions {
22
31
  extremity: "source" | "target";
23
32
  lengthToThicknessRatio: number;
24
33
  widenessToThicknessRatio: number;
25
- };
34
+ }
26
35
 
27
36
  export const DEFAULT_EDGE_ARROW_HEAD_PROGRAM_OPTIONS: CreateEdgeArrowHeadProgramOptions =
28
37
  {
@@ -40,7 +49,7 @@ export function createEdgeArrowHeadProgram<
40
49
  ): EdgeProgramType<N, E, G> {
41
50
  const options = {
42
51
  ...DEFAULT_EDGE_ARROW_HEAD_PROGRAM_OPTIONS,
43
- ...(inputOptions || {}),
52
+ ...(inputOptions ?? {}),
44
53
  };
45
54
 
46
55
  return class EdgeArrowHeadProgram<
@@ -1,7 +1,7 @@
1
1
  /* istanbul ignore file */
2
2
 
3
3
  // language=GLSL
4
- const SHADER_SOURCE = /*glsl*/ `
4
+ const SHADER_SOURCE = /* glsl */ `
5
5
  attribute vec2 a_position;
6
6
  attribute vec2 a_normal;
7
7
  attribute float a_radius;
@@ -13,7 +13,7 @@ import {
13
13
  type RenderParams,
14
14
  } from "sigma/types";
15
15
  import { floatColor } from "sigma/utils";
16
- import { InternalEdgeAttributes } from "../../types";
16
+ import { type InternalEdgeAttributes } from "../../types";
17
17
  import { createDrawCurvedEdgeLabel } from "./drawLabel";
18
18
  import FRAGMENT_SHADER_SOURCE from "./frag.glsl";
19
19
  import VERTEX_SHADER_SOURCE from "./vert.glsl";
@@ -84,7 +84,7 @@ export class EdgeCurveProgramBase<
84
84
 
85
85
  const thickness =
86
86
  Math.min(data.size || 1, 0.5) *
87
- (data.selected || data.highlight ? 16 : 8);
87
+ (data.selected ?? data.highlight ? 16 : 8);
88
88
  const x1 = sourceData.x;
89
89
  const y1 = sourceData.y;
90
90
  const x2 = targetData.x;
@@ -12,7 +12,7 @@ import {
12
12
  type RenderParams,
13
13
  } from "sigma/types";
14
14
  import { floatColor } from "sigma/utils";
15
- import { InternalEdgeAttributes } from "../../types";
15
+ import { type InternalEdgeAttributes } from "../../types";
16
16
  import { createEdgeArrowHeadProgram } from "../arrow-head";
17
17
  import { drawLineLabel } from "./drawLabel";
18
18
  import FRAGMENT_SHADER_SOURCE from "./frag.glsl";
@@ -86,7 +86,7 @@ class EdgeLineProgramBase<
86
86
  if (data.highlight) color = "#F54A4A";
87
87
 
88
88
  const thickness =
89
- Math.min(data.size || 1, 0.5) * (data.selected || data.highlight ? 8 : 4);
89
+ Math.min(data.size || 1, 0.5) * (data.selected ?? data.highlight ? 8 : 4);
90
90
  const x1 = sourceData.x;
91
91
  const y1 = sourceData.y;
92
92
  const x2 = targetData.x;
@@ -259,14 +259,14 @@ export default function getNodeImageProgram(
259
259
 
260
260
  const badge = data.badge?.find((b) => b.position === badgePosition);
261
261
 
262
- let fill = floatColor(badge?.color ?? "#00000000");
263
- let color = floatColor(
262
+ const fill = floatColor(badge?.color ?? "#00000000");
263
+ const color = floatColor(
264
264
  badge?.iconColor ??
265
265
  this.renderer.getSetting("labelColor").color ??
266
266
  "#000",
267
267
  );
268
268
 
269
- let imageSource = badge
269
+ const imageSource = badge
270
270
  ? ICON_MAP[badge.type as any] ?? badge.path
271
271
  : undefined;
272
272
 
@@ -61,16 +61,16 @@ void main() {
61
61
  position.x += originalSize / divisor;
62
62
  position.y -= originalSize / divisor;
63
63
  }
64
- if(a_placement == ${POSITION["top"]}) {
64
+ if(a_placement == ${POSITION.top}) {
65
65
  position.y += originalSize / 2.0;
66
66
  }
67
- if(a_placement == ${POSITION["bottom"]}) {
67
+ if(a_placement == ${POSITION.bottom}) {
68
68
  position.y -= originalSize / 2.0;
69
69
  }
70
- if(a_placement == ${POSITION["left"]}) {
70
+ if(a_placement == ${POSITION.left}) {
71
71
  position.x -= originalSize / 2.0;
72
72
  }
73
- if(a_placement == ${POSITION["right"]}) {
73
+ if(a_placement == ${POSITION.right}) {
74
74
  position.x += originalSize / 2.0;
75
75
  }
76
76
  gl_Position = vec4(
@@ -1,5 +1,5 @@
1
1
  import { type Settings } from "sigma/settings";
2
- import { EdgeAttributes, NodeAttributes } from "../../../types";
2
+ import { type EdgeAttributes, type NodeAttributes } from "../../../types";
3
3
  import { drawNodeLabel } from "./drawLabel";
4
4
 
5
5
  /* istanbul ignore file */
@@ -21,7 +21,7 @@ export function drawNodeHover(
21
21
  // use node color or default node color
22
22
  const bg = settings.defaultNodeColor || "#fff";
23
23
  // use label color or default label color
24
- const color = data.labelColor || settings.labelColor.color || "#000";
24
+ const color = data.labelColor ?? settings.labelColor.color ?? "#000";
25
25
 
26
26
  context.font = `${weight} ${size}px ${font}`;
27
27
 
@@ -1,8 +1,8 @@
1
1
  import { type Settings } from "sigma/settings";
2
2
  import {
3
- EdgeAttributes,
4
- InternalNodeAttributes,
5
- NodeAttributes,
3
+ type EdgeAttributes,
4
+ type InternalNodeAttributes,
5
+ type NodeAttributes,
6
6
  } from "../../../types";
7
7
 
8
8
  /* istanbul ignore file */
@@ -24,7 +24,7 @@ export function drawNodeLabel(
24
24
  // use node color or default node color
25
25
  const bg = settings.defaultNodeColor || "#fff";
26
26
  // use label color or default label color
27
- const color = data.labelColor || settings.labelColor.color || "#000";
27
+ const color = data.labelColor ?? settings.labelColor.color ?? "#000";
28
28
 
29
29
  if (data.highlight) {
30
30
  // Then we draw the label background
@@ -108,10 +108,10 @@ export function drawNodeLabel(
108
108
  const container =
109
109
  context.canvas.parentElement?.parentElement?.querySelector(
110
110
  ".sigma-groupHandles",
111
- ) as HTMLDivElement;
111
+ ) as unknown as HTMLElement;
112
112
  let handle = container.querySelector(
113
113
  `[data-id="${data.id}"]`,
114
- ) as HTMLDivElement;
114
+ ) as unknown as HTMLElement;
115
115
  if (!handle) {
116
116
  handle = document.createElement("div");
117
117
  handle.className = "sigma-groupHandle";
@@ -1,5 +1,5 @@
1
1
  import { createNodeCompoundProgram } from "sigma/rendering";
2
- import { NodeAttributes } from "../../types";
2
+ import { type NodeAttributes } from "../../types";
3
3
  import { NodeBadgeProgram } from "../node-badge";
4
4
  import { NodeImageProgram } from "../node-image";
5
5
  import { NodeCircleBase } from "./base";
@@ -1,5 +1,5 @@
1
1
  import { type Settings } from "sigma/settings";
2
- import { EdgeAttributes, NodeAttributes } from "../../../types";
2
+ import { type EdgeAttributes, type NodeAttributes } from "../../../types";
3
3
  import { drawNodeLabel } from "./drawLabel";
4
4
 
5
5
  /* istanbul ignore file */
@@ -21,7 +21,7 @@ export function drawNodeHover(
21
21
  // use node color or default node color
22
22
  const bg = settings.defaultNodeColor || "#fff";
23
23
  // use label color or default label color
24
- const color = data.labelColor || settings.labelColor.color || "#000";
24
+ const color = data.labelColor ?? settings.labelColor.color ?? "#000";
25
25
 
26
26
  context.font = `${weight} ${size}px ${font}`;
27
27
 
@@ -1,8 +1,8 @@
1
1
  import { type Settings } from "sigma/settings";
2
2
  import {
3
- EdgeAttributes,
4
- InternalNodeAttributes,
5
- NodeAttributes,
3
+ type EdgeAttributes,
4
+ type InternalNodeAttributes,
5
+ type NodeAttributes,
6
6
  } from "../../../types";
7
7
 
8
8
  /* istanbul ignore file */
@@ -24,7 +24,7 @@ export function drawNodeLabel(
24
24
  // use node color or default node color
25
25
  const bg = settings.defaultNodeColor || "#fff";
26
26
  // use label color or default label color
27
- const color = data.labelColor || settings.labelColor.color || "#000";
27
+ const color = data.labelColor ?? settings.labelColor.color ?? "#000";
28
28
 
29
29
  if (data.highlight) {
30
30
  // Then we draw the label background
@@ -112,10 +112,10 @@ export function drawNodeLabel(
112
112
  const container =
113
113
  context.canvas.parentElement?.parentElement?.querySelector(
114
114
  ".sigma-groupHandles",
115
- ) as HTMLDivElement;
115
+ ) as unknown as HTMLElement;
116
116
  let handle = container.querySelector(
117
117
  `[data-id="${data.id}"]`,
118
- ) as HTMLDivElement;
118
+ ) as unknown as HTMLElement;
119
119
  if (!handle) {
120
120
  handle = document.createElement("div");
121
121
  handle.className = "sigma-groupHandle";
@@ -1,5 +1,5 @@
1
1
  import { createNodeCompoundProgram } from "sigma/rendering";
2
- import { NodeAttributes } from "../../types";
2
+ import { type NodeAttributes } from "../../types";
3
3
  import { NodeBadgeProgram } from "../node-badge";
4
4
  import { NodeImageProgram } from "../node-image";
5
5
  import { NodeRectBase } from "./base";
@@ -1,6 +1,6 @@
1
- import { GraphOptions } from "graphology-types";
2
- import { RefObject } from "react";
3
- import { Graph } from "../graph";
1
+ import { type GraphOptions } from "graphology-types";
2
+ import { type RefObject } from "react";
3
+ import { type Graph } from "../graph";
4
4
 
5
5
  interface NodeBadge {
6
6
  position:
@@ -179,13 +179,13 @@ export interface InternalEdgeAttributes<E = KeyValue>
179
179
  }
180
180
 
181
181
  export interface RawGraph<N = KeyValue, E = KeyValue> {
182
- nodes: { key: string; attributes?: NodeAttributes<N> }[];
183
- edges: {
182
+ nodes: Array<{ key: string; attributes?: NodeAttributes<N> }>;
183
+ edges: Array<{
184
184
  key: string;
185
185
  source: string;
186
186
  target: string;
187
187
  attributes?: EdgeAttributes<E>;
188
- }[];
188
+ }>;
189
189
  attributes?: KeyValue;
190
190
  options?: GraphOptions;
191
191
  }