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

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 +6 -6
  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 +6 -6
  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 +18 -10
  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
@@ -14,6 +14,6 @@ var POSITION = {
14
14
  };
15
15
 
16
16
  // language=GLSL
17
- var VERTEX_SHADER_SOURCE = /* glsl */"\nattribute vec4 a_id;\nattribute vec4 a_fill;\nattribute vec4 a_color;\nattribute vec2 a_position;\nattribute float a_circle;\nattribute float a_placement;\nattribute float a_size;\nattribute float a_angle;\nattribute float a_opacity;\nattribute vec4 a_texture;\n\nuniform mat3 u_matrix;\nuniform float u_sizeRatio;\nuniform float u_correctionRatio;\n\nvarying vec4 v_fill;\nvarying vec4 v_color;\nvarying vec2 v_diffVector;\nvarying float v_radius;\nvarying float v_opacity;\nvarying vec4 v_texture;\n\nconst float bias = 255.0 / 254.0;\nconst float marginRatio = 1.1;\nconst vec4 transparent = vec4(0.0, 0.0, 0.0, 0.0);\n\nvoid main() {\n float size = (a_size / 4.0) * u_correctionRatio / u_sizeRatio * 4.0;\n float originalSize = a_size * u_correctionRatio / u_sizeRatio * 4.0;\n vec2 diffVector = size * vec2(cos(a_angle), sin(a_angle));\n vec2 position = a_position + diffVector * marginRatio;\n float divisor = a_circle == 1.0 ? 2.5 : 2.0;\n if(a_placement == ".concat(POSITION["top-left"], ") {\n position.x -= originalSize / divisor;\n position.y += originalSize / divisor;\n }\n if(a_placement == ").concat(POSITION["top-right"], ") {\n position.x += originalSize / divisor;\n position.y += originalSize / divisor;\n }\n if(a_placement == ").concat(POSITION["bottom-left"], ") {\n position.x -= originalSize / divisor;\n position.y -= originalSize / divisor;\n }\n if(a_placement == ").concat(POSITION["bottom-right"], ") {\n position.x += originalSize / divisor;\n position.y -= originalSize / divisor;\n }\n if(a_placement == ").concat(POSITION["top"], ") {\n position.y += originalSize / 2.0;\n }\n if(a_placement == ").concat(POSITION["bottom"], ") {\n position.y -= originalSize / 2.0;\n }\n if(a_placement == ").concat(POSITION["left"], ") {\n position.x -= originalSize / 2.0;\n }\n if(a_placement == ").concat(POSITION["right"], ") {\n position.x += originalSize / 2.0;\n }\n gl_Position = vec4(\n (u_matrix * vec3(position, 1)).xy,\n 0,\n 1\n );\n\n v_diffVector = diffVector;\n v_radius = size / 2.0 / marginRatio;\n\n #ifdef PICKING_MODE\n // For picking mode, we use the ID as the color:\n v_color = a_id;\n #else\n // For normal mode, we use the color:\n v_fill = mix(transparent, a_fill, a_opacity * bias);\n v_color = vec4(a_color.rgb, a_opacity * bias);\n v_opacity = a_opacity;\n // Pass the texture coordinates:\n v_texture = a_texture;\n #endif\n}\n");
17
+ var VERTEX_SHADER_SOURCE = /* glsl */"\nattribute vec4 a_id;\nattribute vec4 a_fill;\nattribute vec4 a_color;\nattribute vec2 a_position;\nattribute float a_circle;\nattribute float a_placement;\nattribute float a_size;\nattribute float a_angle;\nattribute float a_opacity;\nattribute vec4 a_texture;\n\nuniform mat3 u_matrix;\nuniform float u_sizeRatio;\nuniform float u_correctionRatio;\n\nvarying vec4 v_fill;\nvarying vec4 v_color;\nvarying vec2 v_diffVector;\nvarying float v_radius;\nvarying float v_opacity;\nvarying vec4 v_texture;\n\nconst float bias = 255.0 / 254.0;\nconst float marginRatio = 1.1;\nconst vec4 transparent = vec4(0.0, 0.0, 0.0, 0.0);\n\nvoid main() {\n float size = (a_size / 4.0) * u_correctionRatio / u_sizeRatio * 4.0;\n float originalSize = a_size * u_correctionRatio / u_sizeRatio * 4.0;\n vec2 diffVector = size * vec2(cos(a_angle), sin(a_angle));\n vec2 position = a_position + diffVector * marginRatio;\n float divisor = a_circle == 1.0 ? 2.5 : 2.0;\n if(a_placement == ".concat(POSITION["top-left"], ") {\n position.x -= originalSize / divisor;\n position.y += originalSize / divisor;\n }\n if(a_placement == ").concat(POSITION["top-right"], ") {\n position.x += originalSize / divisor;\n position.y += originalSize / divisor;\n }\n if(a_placement == ").concat(POSITION["bottom-left"], ") {\n position.x -= originalSize / divisor;\n position.y -= originalSize / divisor;\n }\n if(a_placement == ").concat(POSITION["bottom-right"], ") {\n position.x += originalSize / divisor;\n position.y -= originalSize / divisor;\n }\n if(a_placement == ").concat(POSITION.top, ") {\n position.y += originalSize / 2.0;\n }\n if(a_placement == ").concat(POSITION.bottom, ") {\n position.y -= originalSize / 2.0;\n }\n if(a_placement == ").concat(POSITION.left, ") {\n position.x -= originalSize / 2.0;\n }\n if(a_placement == ").concat(POSITION.right, ") {\n position.x += originalSize / 2.0;\n }\n gl_Position = vec4(\n (u_matrix * vec3(position, 1)).xy,\n 0,\n 1\n );\n\n v_diffVector = diffVector;\n v_radius = size / 2.0 / marginRatio;\n\n #ifdef PICKING_MODE\n // For picking mode, we use the ID as the color:\n v_color = a_id;\n #else\n // For normal mode, we use the color:\n v_fill = mix(transparent, a_fill, a_opacity * bias);\n v_color = vec4(a_color.rgb, a_opacity * bias);\n v_opacity = a_opacity;\n // Pass the texture coordinates:\n v_texture = a_texture;\n #endif\n}\n");
18
18
 
19
19
  export { VERTEX_SHADER_SOURCE as default };
@@ -5,6 +5,7 @@ import { drawNodeLabel } from './drawLabel.js';
5
5
  /* istanbul ignore file */
6
6
 
7
7
  function drawNodeHover(context, data, settings) {
8
+ var _ref, _data$labelColor;
8
9
  var nodeSize = data.size;
9
10
  var size = settings.labelSize;
10
11
  var font = settings.labelFont;
@@ -12,7 +13,7 @@ function drawNodeHover(context, data, settings) {
12
13
  // use node color or default node color
13
14
  var bg = settings.defaultNodeColor || "#fff";
14
15
  // use label color or default label color
15
- var color = data.labelColor || settings.labelColor.color || "#000";
16
+ var color = (_ref = (_data$labelColor = data.labelColor) !== null && _data$labelColor !== void 0 ? _data$labelColor : settings.labelColor.color) !== null && _ref !== void 0 ? _ref : "#000";
16
17
  context.font = "".concat(weight, " ").concat(size, "px ").concat(font);
17
18
 
18
19
  // Then we draw the label background
@@ -3,6 +3,7 @@
3
3
  /* istanbul ignore file */
4
4
 
5
5
  function drawNodeLabel(context, data, settings) {
6
+ var _ref, _data$labelColor;
6
7
  var nodeSize = data.size;
7
8
  var size = settings.labelSize;
8
9
  var font = settings.labelFont;
@@ -10,7 +11,7 @@ function drawNodeLabel(context, data, settings) {
10
11
  // use node color or default node color
11
12
  var bg = settings.defaultNodeColor || "#fff";
12
13
  // use label color or default label color
13
- var color = data.labelColor || settings.labelColor.color || "#000";
14
+ var color = (_ref = (_data$labelColor = data.labelColor) !== null && _data$labelColor !== void 0 ? _data$labelColor : settings.labelColor.color) !== null && _ref !== void 0 ? _ref : "#000";
14
15
  if (data.highlight) {
15
16
  var _data$highlightColor, _data$highlightColor2;
16
17
  // Then we draw the label background
@@ -5,6 +5,7 @@ import { drawNodeLabel } from './drawLabel.js';
5
5
  /* istanbul ignore file */
6
6
 
7
7
  function drawNodeHover(context, data, settings) {
8
+ var _ref, _data$labelColor;
8
9
  var nodeSize = data.size;
9
10
  var size = settings.labelSize;
10
11
  var font = settings.labelFont;
@@ -12,7 +13,7 @@ function drawNodeHover(context, data, settings) {
12
13
  // use node color or default node color
13
14
  var bg = settings.defaultNodeColor || "#fff";
14
15
  // use label color or default label color
15
- var color = data.labelColor || settings.labelColor.color || "#000";
16
+ var color = (_ref = (_data$labelColor = data.labelColor) !== null && _data$labelColor !== void 0 ? _data$labelColor : settings.labelColor.color) !== null && _ref !== void 0 ? _ref : "#000";
16
17
  context.font = "".concat(weight, " ").concat(size, "px ").concat(font);
17
18
 
18
19
  // Then we draw the label background
@@ -3,6 +3,7 @@
3
3
  /* istanbul ignore file */
4
4
 
5
5
  function drawNodeLabel(context, data, settings) {
6
+ var _ref, _data$labelColor;
6
7
  var nodeSize = data.size;
7
8
  var size = settings.labelSize;
8
9
  var font = settings.labelFont;
@@ -10,7 +11,7 @@ function drawNodeLabel(context, data, settings) {
10
11
  // use node color or default node color
11
12
  var bg = settings.defaultNodeColor || "#fff";
12
13
  // use label color or default label color
13
- var color = data.labelColor || settings.labelColor.color || "#000";
14
+ var color = (_ref = (_data$labelColor = data.labelColor) !== null && _data$labelColor !== void 0 ? _data$labelColor : settings.labelColor.color) !== null && _ref !== void 0 ? _ref : "#000";
14
15
  if (data.highlight) {
15
16
  var _data$highlightColor, _data$color;
16
17
  // Then we draw the label background
@@ -1,8 +1,8 @@
1
- import { PropsWithChildren } from "react";
2
- import { Graph } from "../graph";
1
+ import { type PropsWithChildren } from "react";
2
+ import { type Graph } from "../graph";
3
3
  import { useDragSelection } from "../hooks/sigmaDragSelect";
4
4
  import { useSigma } from "../hooks/useSigma";
5
- import { EdgeAttributes, GraphProps, NodeAttributes } from "../types";
5
+ import { type EdgeAttributes, type GraphProps, type NodeAttributes } from "../types";
6
6
  interface Context<N = KeyValue, E = KeyValue> {
7
7
  sigma: ReturnType<typeof useSigma>;
8
8
  graph: Graph<NodeAttributes<N>, EdgeAttributes<E>>;
@@ -1,2 +1,2 @@
1
- import { GraphProps } from "../types";
1
+ import { type GraphProps } from "../types";
2
2
  export declare const SigmaGraph: <N = KeyValue, E = KeyValue>(props: GraphProps<N, E>) => import("react/jsx-runtime").JSX.Element;
@@ -1,6 +1,7 @@
1
1
  import Graphology from "graphology";
2
- import { GraphEvents, GraphOptions } from "graphology-types";
3
- import { EdgeAttributes, InternalNodeAttributes, NodeAttributes, RawGraph } from "../types";
2
+ import { type ForceAtlas2Settings } from "graphology-layout-forceatlas2";
3
+ import { type GraphEvents, type GraphOptions } from "graphology-types";
4
+ import { type EdgeAttributes, type InternalNodeAttributes, type NodeAttributes, type RawGraph } from "../types";
4
5
  interface ExtendedEvents extends GraphEvents {
5
6
  nodesLoaded: (nodes: string[]) => void;
6
7
  nodesDropped: (nodes: string[]) => void;
@@ -13,11 +14,15 @@ export declare class Graph<N = KeyValue, E = KeyValue> extends Graphology<Intern
13
14
  on<Event extends keyof ExtendedEvents>(type: Event, listener: ExtendedEvents[Event]): this;
14
15
  off<Event extends keyof ExtendedEvents>(type: Event, listener: ExtendedEvents[Event]): this;
15
16
  emit<Event extends keyof ExtendedEvents>(type: Event, ...args: Parameters<ExtendedEvents[Event]>): boolean;
16
- mergeNodes(key: string, nodes: string[], attributesOrNodeReducer?: NodeAttributes<N> | ((attributes: NodeAttributes<N>[]) => NodeAttributes<N>), edgeReducer?: (edges: RawGraph<N, E>["edges"]) => RawGraph<N, E>["edges"]): this | undefined;
17
- groupNodes(key: string, nodes: string[], attributesOrNodeReducer?: NodeAttributes<N> | ((attributes: NodeAttributes<N>[]) => NodeAttributes<N>), edgeReducer?: (edges: RawGraph<N, E>["edges"]) => RawGraph<N, E>["edges"]): this | undefined;
17
+ mergeNodes(key: string, nodes: string[], attributesOrNodeReducer?: NodeAttributes<N> | ((attributes: Array<NodeAttributes<N>>) => NodeAttributes<N>), edgeReducer?: (edges: RawGraph<N, E>["edges"]) => RawGraph<N, E>["edges"]): this | undefined;
18
+ groupNodes(key: string, nodes: string[], attributesOrNodeReducer?: NodeAttributes<N> | ((attributes: Array<NodeAttributes<N>>) => NodeAttributes<N>), edgeReducer?: (edges: RawGraph<N, E>["edges"]) => RawGraph<N, E>["edges"]): this | undefined;
18
19
  ungroupNode(node: string): this | undefined;
19
20
  toggleExpanded(node: string, force?: boolean): this;
20
21
  import(data: RawGraph<N, E> | Graph<N, E>, merge?: boolean): this;
22
+ circularLayout(): this;
23
+ private _timer;
24
+ private _worker?;
25
+ forceLayout(settings?: ForceAtlas2Settings): this;
21
26
  private elk;
22
27
  elkLayout(type: string): Promise<void>;
23
28
  dropNodes(nodes: string[]): void;
@@ -1,3 +1,3 @@
1
1
  import type Sigma from "sigma";
2
- import { EdgeAttributes, NodeAttributes } from "../types";
2
+ import { type EdgeAttributes, type NodeAttributes } from "../types";
3
3
  export declare const attachHighlighter: (renderer: Sigma<NodeAttributes<any>, EdgeAttributes<any>>) => void;
@@ -1,3 +1,3 @@
1
1
  import type Sigma from "sigma";
2
- import { EdgeAttributes, NodeAttributes } from "../types";
2
+ import { type EdgeAttributes, type NodeAttributes } from "../types";
3
3
  export declare const attachMouseActions: (renderer: Sigma<NodeAttributes<any>, EdgeAttributes<any>>) => void;
@@ -1,5 +1,5 @@
1
1
  import { Graph } from "../graph";
2
- import { GraphProps } from "../types";
2
+ import { type GraphProps } from "../types";
3
3
  export declare const useGraphology: <N, E>(data: GraphProps<N, E>["data"]) => {
4
4
  graph: Graph<N, E>;
5
5
  selected: string[];
@@ -1,6 +1,6 @@
1
1
  import Sigma from "sigma";
2
- import { Graph } from "../graph";
3
- import { EdgeAttributes, NodeAttributes } from "../types";
2
+ import { type Graph } from "../graph";
3
+ import { type EdgeAttributes, type NodeAttributes } from "../types";
4
4
  export declare const useSigma: <N, E>(graph: Graph<N, E>, nodeReducer?: (node: NodeAttributes<N>) => NodeAttributes<N>, edgeReducer?: (edge: EdgeAttributes<E>) => EdgeAttributes<E>) => {
5
5
  instance: Sigma<NodeAttributes<N>, EdgeAttributes<E>, import("graphology-types").Attributes> | undefined;
6
6
  containerRef: import("react").Dispatch<import("react").SetStateAction<HTMLDivElement | null>>;
@@ -1,9 +1,9 @@
1
- import { Attributes } from "graphology-types";
2
- import { EdgeProgramType } from "sigma/rendering";
3
- export type CreateEdgeArrowHeadProgramOptions = {
1
+ import { type Attributes } from "graphology-types";
2
+ import { type EdgeProgramType } from "sigma/rendering";
3
+ export interface CreateEdgeArrowHeadProgramOptions {
4
4
  extremity: "source" | "target";
5
5
  lengthToThicknessRatio: number;
6
6
  widenessToThicknessRatio: number;
7
- };
7
+ }
8
8
  export declare const DEFAULT_EDGE_ARROW_HEAD_PROGRAM_OPTIONS: CreateEdgeArrowHeadProgramOptions;
9
9
  export declare function createEdgeArrowHeadProgram<N extends Attributes = Attributes, E extends Attributes = Attributes, G extends Attributes = Attributes>(inputOptions?: Partial<CreateEdgeArrowHeadProgramOptions>): EdgeProgramType<N, E, G>;
@@ -1,7 +1,7 @@
1
1
  import { type Attributes } from "graphology-types";
2
2
  import { EdgeProgram, type ProgramInfo } from "sigma/rendering";
3
3
  import { type EdgeDisplayData, type NodeDisplayData, type RenderParams } from "sigma/types";
4
- import { InternalEdgeAttributes } from "../../types";
4
+ import { type InternalEdgeAttributes } from "../../types";
5
5
  declare const UNIFORMS: readonly ["u_matrix", "u_sizeRatio", "u_dimensions", "u_pixelRatio", "u_feather", "u_minEdgeThickness", "u_lengthToThicknessRatio", "u_widenessToThicknessRatio"];
6
6
  export declare class EdgeCurveProgramBase<N extends Attributes = Attributes, E extends Attributes = Attributes, G extends Attributes = Attributes> extends EdgeProgram<(typeof UNIFORMS)[number], N, E, G> {
7
7
  getDefinition(): {
@@ -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
  export declare function drawNodeHover(context: CanvasRenderingContext2D, data: NodeAttributes & {
4
4
  opacity: number;
5
5
  x: number;
@@ -1,5 +1,5 @@
1
1
  import { type Settings } from "sigma/settings";
2
- import { EdgeAttributes, InternalNodeAttributes, NodeAttributes } from "../../../types";
2
+ import { type EdgeAttributes, type InternalNodeAttributes, type NodeAttributes } from "../../../types";
3
3
  export declare function drawNodeLabel(context: CanvasRenderingContext2D, data: InternalNodeAttributes & {
4
4
  opacity: number;
5
5
  x: number;
@@ -1,4 +1,4 @@
1
- import { NodeAttributes } from "../../types";
1
+ import { type NodeAttributes } from "../../types";
2
2
  export declare const NodeCircleProgram: {
3
3
  new (_gl: WebGLRenderingContext, _pickingBuffer: WebGLFramebuffer | null, _renderer: import("sigma").default<NodeAttributes<any>, import("graphology-types").Attributes, import("graphology-types").Attributes>): {
4
4
  drawLabel: import("sigma/rendering").NodeLabelDrawingFunction<NodeAttributes<any>, import("graphology-types").Attributes, import("graphology-types").Attributes> | undefined;
@@ -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
  export declare function drawNodeHover(context: CanvasRenderingContext2D, data: NodeAttributes & {
4
4
  opacity: number;
5
5
  x: number;
@@ -1,5 +1,5 @@
1
1
  import { type Settings } from "sigma/settings";
2
- import { EdgeAttributes, InternalNodeAttributes, NodeAttributes } from "../../../types";
2
+ import { type EdgeAttributes, type InternalNodeAttributes, type NodeAttributes } from "../../../types";
3
3
  export declare function drawNodeLabel(context: CanvasRenderingContext2D, data: InternalNodeAttributes & {
4
4
  opacity: number;
5
5
  x: number;
@@ -1,4 +1,4 @@
1
- import { NodeAttributes } from "../../types";
1
+ import { type NodeAttributes } from "../../types";
2
2
  export declare const NodeRectProgram: {
3
3
  new (_gl: WebGLRenderingContext, _pickingBuffer: WebGLFramebuffer | null, _renderer: import("sigma").default<NodeAttributes<any>, import("graphology-types").Attributes, import("graphology-types").Attributes>): {
4
4
  drawLabel: import("sigma/rendering").NodeLabelDrawingFunction<NodeAttributes<any>, import("graphology-types").Attributes, import("graphology-types").Attributes> | undefined;
@@ -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
  interface NodeBadge {
5
5
  position: "top-left" | "top-right" | "bottom-left" | "bottom-right" | "top" | "left" | "right";
6
6
  type?: "star" | "exclaim" | "thumbUp" | "thumbDown";
@@ -161,16 +161,16 @@ export interface InternalEdgeAttributes<E = KeyValue> extends EdgeAttributes<E>
161
161
  id?: string;
162
162
  }
163
163
  export interface RawGraph<N = KeyValue, E = KeyValue> {
164
- nodes: {
164
+ nodes: Array<{
165
165
  key: string;
166
166
  attributes?: NodeAttributes<N>;
167
- }[];
168
- edges: {
167
+ }>;
168
+ edges: Array<{
169
169
  key: string;
170
170
  source: string;
171
171
  target: string;
172
172
  attributes?: EdgeAttributes<E>;
173
- }[];
173
+ }>;
174
174
  attributes?: KeyValue;
175
175
  options?: GraphOptions;
176
176
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-fabric/graph",
3
- "version": "1.0.0-beta.59",
3
+ "version": "1.0.0-beta.60",
4
4
  "description": "RUF: SigmaJS link analysis graph",
5
5
  "author": "Adarsh Pastakia <adarshpastakia@outlook.com>",
6
6
  "license": "MIT",
@@ -36,8 +36,8 @@
36
36
  },
37
37
  "dependencies": {
38
38
  "@floating-ui/react": "~0.27.16",
39
- "@react-fabric/core": "^1.0.0-beta.59",
40
- "@react-fabric/utilities": "^1.0.0-beta.59",
39
+ "@react-fabric/core": "^1.0.0-beta.60",
40
+ "@react-fabric/utilities": "^1.0.0-beta.60",
41
41
  "@sigma/edge-curve": "~3.1.0",
42
42
  "@sigma/utils": "~3.0.0",
43
43
  "classnames": "~2.5.1",
@@ -65,5 +65,5 @@
65
65
  "node": ">=18.12.0",
66
66
  "npm": ">=8.19.0"
67
67
  },
68
- "gitHead": "74efd06c9c5ac629b6ef5cdc6d53ecb1c356f2eb"
68
+ "gitHead": "a79f053ee7e13422c06d7d9c35d4f0c2610cdf5d"
69
69
  }
@@ -2,18 +2,22 @@ import { CoreIcons, Icon } from "@react-fabric/core";
2
2
  import { fitViewportToNodes } from "@sigma/utils";
3
3
  import {
4
4
  createContext,
5
- PropsWithChildren,
5
+ type PropsWithChildren,
6
6
  useContext,
7
7
  useEffect,
8
8
  useImperativeHandle,
9
9
  useState,
10
10
  } from "react";
11
- import { SigmaNodeEventPayload } from "sigma/types";
12
- import { Graph } from "../graph";
11
+ import { type SigmaNodeEventPayload } from "sigma/types";
12
+ import { type Graph } from "../graph";
13
13
  import { useDragSelection } from "../hooks/sigmaDragSelect";
14
14
  import { useGraphology } from "../hooks/useGraphology";
15
15
  import { useSigma } from "../hooks/useSigma";
16
- import { EdgeAttributes, GraphProps, NodeAttributes } from "../types";
16
+ import {
17
+ type EdgeAttributes,
18
+ type GraphProps,
19
+ type NodeAttributes,
20
+ } from "../types";
17
21
 
18
22
  interface Context<N = KeyValue, E = KeyValue> {
19
23
  sigma: ReturnType<typeof useSigma>;
@@ -50,28 +54,32 @@ export const GraphProvider = <N = KeyValue, E = KeyValue>({
50
54
 
51
55
  const resetViewport = () => {
52
56
  if (graph.size === 0) return;
53
- sigma.instance &&
57
+ void (
58
+ sigma.instance &&
54
59
  fitViewportToNodes(sigma.instance, graph.nodes(), {
55
60
  animate: true,
56
- });
61
+ })
62
+ );
57
63
  };
58
64
 
59
65
  const zoomIn = () => {
60
66
  if (graph.size === 0) return;
61
- sigma.instance?.getCamera().animatedZoom();
67
+ void sigma.instance?.getCamera().animatedZoom();
62
68
  };
63
69
 
64
70
  const zoomOut = () => {
65
71
  if (graph.size === 0) return;
66
- sigma.instance?.getCamera().animatedUnzoom();
72
+ void sigma.instance?.getCamera().animatedUnzoom();
67
73
  };
68
74
 
69
75
  useEffect(() => {
70
76
  const resetHandler = () => {
71
- sigma.instance &&
77
+ void (
78
+ sigma.instance &&
72
79
  fitViewportToNodes(sigma.instance, graph.nodes(), {
73
80
  animate: true,
74
- });
81
+ })
82
+ );
75
83
  };
76
84
  graph.on("layoutRunning", setLayoutRunning);
77
85
  graph.on("layoutDone", resetHandler);
@@ -32,21 +32,23 @@ import {
32
32
  useFloatingNodeId,
33
33
  useInteractions,
34
34
  } from "@floating-ui/react";
35
+ import { Divider, Menu, MenuItem } from "@react-fabric/core";
35
36
  import { cloneElement, useEffect, useRef, useState } from "react";
36
37
  import {
37
- SigmaEdgeEventPayload,
38
- SigmaNodeEventPayload,
39
- SigmaStageEventPayload,
38
+ type SigmaEdgeEventPayload,
39
+ type SigmaNodeEventPayload,
40
+ type SigmaStageEventPayload,
40
41
  } from "sigma/types";
41
- import { useGraph } from "./Context";
42
- import { Divider, Menu, MenuItem } from "@react-fabric/core";
43
42
  import { ICONS } from "../constants";
43
+ import { useGraph } from "./Context";
44
44
 
45
45
  export const GraphContextMenu = () => {
46
46
  const [isOpen, setIsOpen] = useState(false);
47
47
  const nodeId = useFloatingNodeId();
48
- const { sigma, graph } = useGraph();
49
- const [menu, setMenu] = useState<React.ReactElement<typeof MenuItem>[]>([]);
48
+ const { sigma } = useGraph();
49
+ const [menu, setMenu] = useState<Array<React.ReactElement<typeof MenuItem>>>(
50
+ [],
51
+ );
50
52
 
51
53
  const { refs, floatingStyles, context } = useFloating({
52
54
  open: isOpen,
@@ -80,24 +82,40 @@ export const GraphContextMenu = () => {
80
82
  ) => {
81
83
  if ("node" in e) {
82
84
  setMenu([
83
- <MenuItem label="Select neighbors" />,
84
- <Divider />,
85
+ <MenuItem key="0.0" label="Select neighbors" />,
86
+ <Divider key="0.1" />,
85
87
  <MenuItem
88
+ key="0.2"
86
89
  label="Delete node(s)"
87
90
  color="danger"
88
91
  icon={ICONS.delete}
89
92
  />,
90
- <MenuItem label="Clear graph" color="danger" icon={ICONS.clear} />,
93
+ <MenuItem
94
+ key="0.3"
95
+ label="Clear graph"
96
+ color="danger"
97
+ icon={ICONS.clear}
98
+ />,
91
99
  ]);
92
100
  } else if ("edge" in e) {
93
101
  setMenu([
94
- <MenuItem label="Select neighbors" />,
95
- <Divider />,
96
- <MenuItem label="Clear graph" color="danger" icon={ICONS.clear} />,
102
+ <MenuItem key="1.0" label="Select neighbors" />,
103
+ <Divider key="1.1" />,
104
+ <MenuItem
105
+ key="1.2"
106
+ label="Clear graph"
107
+ color="danger"
108
+ icon={ICONS.clear}
109
+ />,
97
110
  ]);
98
111
  } else {
99
112
  setMenu([
100
- <MenuItem label="Clear graph" color="danger" icon={ICONS.clear} />,
113
+ <MenuItem
114
+ key="2.0"
115
+ label="Clear graph"
116
+ color="danger"
117
+ icon={ICONS.clear}
118
+ />,
101
119
  ]);
102
120
  }
103
121
  const virtual = {
@@ -9,15 +9,8 @@ import { ICONS } from "../constants";
9
9
  import { useGraph } from "./Context";
10
10
 
11
11
  export const Tools = () => {
12
- const {
13
- dragSelector,
14
- graph,
15
- selected,
16
- layoutRunning,
17
- resetViewport,
18
- zoomIn,
19
- zoomOut,
20
- } = useGraph();
12
+ const { dragSelector, graph, selected, resetViewport, zoomIn, zoomOut } =
13
+ useGraph();
21
14
 
22
15
  return (
23
16
  <div className="flex flex-nowrap outline absolute top-0 start-0 p-0 z-1 bg-base">
@@ -62,27 +55,33 @@ export const Tools = () => {
62
55
  }
63
56
  />
64
57
  <Menu className="text-sm">
65
- <MenuItem label="box" onClick={() => graph.elkLayout("box")} />
66
- <MenuItem label="force" onClick={() => graph.elkLayout("force")} />
58
+ <MenuItem
59
+ label="box"
60
+ onClick={async () => await graph.elkLayout("box")}
61
+ />
62
+ <MenuItem
63
+ label="force"
64
+ onClick={async () => await graph.elkLayout("force")}
65
+ />
67
66
  <MenuItem
68
67
  label="layered"
69
- onClick={() => graph.elkLayout("layered")}
68
+ onClick={async () => await graph.elkLayout("layered")}
70
69
  />
71
70
  <MenuItem
72
71
  label="stress"
73
- onClick={() => graph.elkLayout("stress")}
72
+ onClick={async () => await graph.elkLayout("stress")}
74
73
  />
75
74
  <MenuItem
76
75
  label="radial"
77
- onClick={() => graph.elkLayout("radial")}
76
+ onClick={async () => await graph.elkLayout("radial")}
78
77
  />
79
78
  <MenuItem
80
79
  label="sporeOverlap"
81
- onClick={() => graph.elkLayout("sporeOverlap")}
80
+ onClick={async () => await graph.elkLayout("sporeOverlap")}
82
81
  />
83
82
  <MenuItem
84
83
  label="sporeCompaction"
85
- onClick={() => graph.elkLayout("sporeCompaction")}
84
+ onClick={async () => await graph.elkLayout("sporeCompaction")}
86
85
  />
87
86
  </Menu>
88
87
  </Dropdown>
@@ -22,7 +22,7 @@
22
22
  */
23
23
 
24
24
  import { Section } from "@react-fabric/core";
25
- import { GraphProps } from "../types";
25
+ import { type GraphProps } from "../types";
26
26
  import { GraphProvider, useGraph } from "./Context";
27
27
  import { Tools } from "./Tools";
28
28
  import { useEffect, useRef } from "react";
@@ -48,6 +48,7 @@ const Graph = () => {
48
48
  <div className="area-content relative bg-base graph-viewer">
49
49
  <div dir="ltr" ref={sigma.containerRef} className="absolute inset-0" />
50
50
  <div
51
+ role="none"
51
52
  ref={handlesRef}
52
53
  dir="ltr"
53
54
  onClick={(e) => {