@react-fabric/graph 1.0.0-beta.63 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/context/context.js +16 -0
- package/dist/cjs/graph/index.js +58 -381
- package/dist/cjs/index.js +25 -21
- package/dist/cjs/utils/edge.js +76 -0
- package/dist/cjs/utils/node.js +93 -0
- package/dist/cjs/utils/sdfFolder.js +107 -0
- package/dist/cjs/viewer/Graph.js +174 -0
- package/dist/esm/context/context.js +15 -0
- package/dist/esm/graph/index.js +59 -382
- package/dist/esm/index.js +24 -20
- package/dist/esm/utils/edge.js +75 -0
- package/dist/esm/utils/node.js +92 -0
- package/dist/esm/utils/sdfFolder.js +107 -0
- package/dist/esm/viewer/Graph.js +174 -0
- package/dist/types/context/context.d.ts +35 -0
- package/dist/types/graph/index.d.ts +47 -24
- package/dist/types/index.d.ts +28 -2
- package/dist/types/types/index.d.ts +124 -175
- package/dist/types/utils/edge.d.ts +28 -0
- package/dist/types/utils/node.d.ts +28 -0
- package/dist/types/utils/sdfFolder.d.ts +75 -0
- package/dist/types/viewer/Graph.d.ts +31 -0
- package/package.json +19 -25
- package/src/context/context.tsx +43 -0
- package/src/graph/index.ts +76 -399
- package/src/index.ts +24 -26
- package/src/types/index.ts +139 -185
- package/src/utils/edge.ts +65 -0
- package/src/utils/node.ts +105 -0
- package/src/utils/sdfFolder.ts +141 -0
- package/src/viewer/Graph.tsx +159 -0
- package/css/styles.css +0 -56
- package/dist/cjs/_virtual/_rollup-plugin-web-worker-loader__helper__auto__createBase64WorkerFactory.js +0 -14
- package/dist/cjs/_virtual/_rollup-plugin-web-worker-loader__helper__auto__isNodeJS.js +0 -9
- package/dist/cjs/_virtual/_rollup-plugin-web-worker-loader__helper__browser__createBase64WorkerFactory.js +0 -35
- package/dist/cjs/_virtual/_rollup-plugin-web-worker-loader__helper__node__WorkerClass.js +0 -11
- package/dist/cjs/_virtual/_rollup-plugin-web-worker-loader__helper__node__createBase64WorkerFactory.js +0 -20
- package/dist/cjs/_virtual/elk-worker.js +0 -8
- package/dist/cjs/components/ContextMenu.js +0 -133
- package/dist/cjs/components/Provider.js +0 -103
- package/dist/cjs/components/Tools.js +0 -205
- package/dist/cjs/components/Viewer.js +0 -59
- package/dist/cjs/components/context.js +0 -34
- package/dist/cjs/constants/index.js +0 -16
- package/dist/cjs/hooks/sigmaDragSelect.js +0 -169
- package/dist/cjs/hooks/sigmaHilighter.js +0 -83
- package/dist/cjs/hooks/sigmaMouseActions.js +0 -145
- package/dist/cjs/hooks/useGraphology.js +0 -41
- package/dist/cjs/hooks/useSigma.js +0 -112
- package/dist/cjs/programs/arrow-head/frag.glsl.js +0 -8
- package/dist/cjs/programs/arrow-head/index.js +0 -142
- package/dist/cjs/programs/arrow-head/vert.glsl.js +0 -8
- package/dist/cjs/programs/edge-curve/drawLabel.js +0 -136
- package/dist/cjs/programs/edge-curve/frag.glsl.js +0 -8
- package/dist/cjs/programs/edge-curve/index.js +0 -157
- package/dist/cjs/programs/edge-curve/vert.glsl.js +0 -8
- package/dist/cjs/programs/edge-line/drawLabel.js +0 -70
- package/dist/cjs/programs/edge-line/frag.glsl.js +0 -8
- package/dist/cjs/programs/edge-line/index.js +0 -166
- package/dist/cjs/programs/edge-line/vert.glsl.js +0 -8
- package/dist/cjs/programs/node-badge/factory.js +0 -250
- package/dist/cjs/programs/node-badge/frag.glsl.js +0 -8
- package/dist/cjs/programs/node-badge/index.js +0 -33
- package/dist/cjs/programs/node-badge/texture.js +0 -455
- package/dist/cjs/programs/node-badge/vert.glsl.js +0 -19
- package/dist/cjs/programs/node-circle/base/drawHover.js +0 -71
- package/dist/cjs/programs/node-circle/base/drawLabel.js +0 -113
- package/dist/cjs/programs/node-circle/base/frag.glsl.js +0 -8
- package/dist/cjs/programs/node-circle/base/index.js +0 -136
- package/dist/cjs/programs/node-circle/base/vert.glsl.js +0 -8
- package/dist/cjs/programs/node-circle/index.js +0 -15
- package/dist/cjs/programs/node-image/factory.js +0 -224
- package/dist/cjs/programs/node-image/frag.glsl.js +0 -8
- package/dist/cjs/programs/node-image/index.js +0 -14
- package/dist/cjs/programs/node-image/texture.js +0 -472
- package/dist/cjs/programs/node-image/vert.glsl.js +0 -8
- package/dist/cjs/programs/node-rect/base/drawHover.js +0 -68
- package/dist/cjs/programs/node-rect/base/drawLabel.js +0 -107
- package/dist/cjs/programs/node-rect/base/frag.glsl.js +0 -8
- package/dist/cjs/programs/node-rect/base/index.js +0 -135
- package/dist/cjs/programs/node-rect/base/vert.glsl.js +0 -8
- package/dist/cjs/programs/node-rect/index.js +0 -15
- package/dist/esm/_virtual/_rollup-plugin-web-worker-loader__helper__auto__createBase64WorkerFactory.js +0 -14
- package/dist/esm/_virtual/_rollup-plugin-web-worker-loader__helper__auto__isNodeJS.js +0 -9
- package/dist/esm/_virtual/_rollup-plugin-web-worker-loader__helper__browser__createBase64WorkerFactory.js +0 -34
- package/dist/esm/_virtual/_rollup-plugin-web-worker-loader__helper__node__WorkerClass.js +0 -13
- package/dist/esm/_virtual/_rollup-plugin-web-worker-loader__helper__node__createBase64WorkerFactory.js +0 -20
- package/dist/esm/_virtual/elk-worker.js +0 -8
- package/dist/esm/components/ContextMenu.js +0 -133
- package/dist/esm/components/Provider.js +0 -103
- package/dist/esm/components/Tools.js +0 -205
- package/dist/esm/components/Viewer.js +0 -59
- package/dist/esm/components/context.js +0 -33
- package/dist/esm/constants/index.js +0 -16
- package/dist/esm/hooks/sigmaDragSelect.js +0 -169
- package/dist/esm/hooks/sigmaHilighter.js +0 -83
- package/dist/esm/hooks/sigmaMouseActions.js +0 -145
- package/dist/esm/hooks/useGraphology.js +0 -41
- package/dist/esm/hooks/useSigma.js +0 -112
- package/dist/esm/programs/arrow-head/frag.glsl.js +0 -8
- package/dist/esm/programs/arrow-head/index.js +0 -141
- package/dist/esm/programs/arrow-head/vert.glsl.js +0 -8
- package/dist/esm/programs/edge-curve/drawLabel.js +0 -136
- package/dist/esm/programs/edge-curve/frag.glsl.js +0 -8
- package/dist/esm/programs/edge-curve/index.js +0 -156
- package/dist/esm/programs/edge-curve/vert.glsl.js +0 -8
- package/dist/esm/programs/edge-line/drawLabel.js +0 -70
- package/dist/esm/programs/edge-line/frag.glsl.js +0 -8
- package/dist/esm/programs/edge-line/index.js +0 -166
- package/dist/esm/programs/edge-line/vert.glsl.js +0 -8
- package/dist/esm/programs/node-badge/factory.js +0 -250
- package/dist/esm/programs/node-badge/frag.glsl.js +0 -8
- package/dist/esm/programs/node-badge/index.js +0 -32
- package/dist/esm/programs/node-badge/texture.js +0 -445
- package/dist/esm/programs/node-badge/vert.glsl.js +0 -19
- package/dist/esm/programs/node-circle/base/drawHover.js +0 -71
- package/dist/esm/programs/node-circle/base/drawLabel.js +0 -113
- package/dist/esm/programs/node-circle/base/frag.glsl.js +0 -8
- package/dist/esm/programs/node-circle/base/index.js +0 -136
- package/dist/esm/programs/node-circle/base/vert.glsl.js +0 -8
- package/dist/esm/programs/node-circle/index.js +0 -15
- package/dist/esm/programs/node-image/factory.js +0 -224
- package/dist/esm/programs/node-image/frag.glsl.js +0 -8
- package/dist/esm/programs/node-image/index.js +0 -13
- package/dist/esm/programs/node-image/texture.js +0 -462
- package/dist/esm/programs/node-image/vert.glsl.js +0 -8
- package/dist/esm/programs/node-rect/base/drawHover.js +0 -68
- package/dist/esm/programs/node-rect/base/drawLabel.js +0 -107
- package/dist/esm/programs/node-rect/base/frag.glsl.js +0 -8
- package/dist/esm/programs/node-rect/base/index.js +0 -135
- package/dist/esm/programs/node-rect/base/vert.glsl.js +0 -8
- package/dist/esm/programs/node-rect/index.js +0 -15
- package/dist/types/components/ContextMenu.d.ts +0 -1
- package/dist/types/components/Provider.d.ts +0 -3
- package/dist/types/components/Tools.d.ts +0 -1
- package/dist/types/components/Viewer.d.ts +0 -2
- package/dist/types/components/context.d.ts +0 -17
- package/dist/types/constants/index.d.ts +0 -12
- package/dist/types/graph/layout.worker.d.ts +0 -1
- package/dist/types/hooks/sigmaDragSelect.d.ts +0 -8
- package/dist/types/hooks/sigmaHilighter.d.ts +0 -3
- package/dist/types/hooks/sigmaMouseActions.d.ts +0 -3
- package/dist/types/hooks/useGraphology.d.ts +0 -6
- package/dist/types/hooks/useSigma.d.ts +0 -8
- package/dist/types/i18n/index.d.ts +0 -0
- package/dist/types/programs/arrow-head/frag.glsl.d.ts +0 -2
- package/dist/types/programs/arrow-head/index.d.ts +0 -9
- package/dist/types/programs/arrow-head/vert.glsl.d.ts +0 -2
- package/dist/types/programs/edge-curve/drawLabel.d.ts +0 -6
- package/dist/types/programs/edge-curve/frag.glsl.d.ts +0 -2
- package/dist/types/programs/edge-curve/index.d.ts +0 -43
- package/dist/types/programs/edge-curve/vert.glsl.d.ts +0 -2
- package/dist/types/programs/edge-line/drawLabel.d.ts +0 -5
- package/dist/types/programs/edge-line/frag.glsl.d.ts +0 -2
- package/dist/types/programs/edge-line/index.d.ts +0 -11
- package/dist/types/programs/edge-line/vert.glsl.d.ts +0 -2
- package/dist/types/programs/node-badge/factory.d.ts +0 -27
- package/dist/types/programs/node-badge/frag.glsl.d.ts +0 -2
- package/dist/types/programs/node-badge/index.d.ts +0 -5
- package/dist/types/programs/node-badge/texture.d.ts +0 -102
- package/dist/types/programs/node-badge/vert.glsl.d.ts +0 -2
- package/dist/types/programs/node-circle/base/drawHover.d.ts +0 -8
- package/dist/types/programs/node-circle/base/drawLabel.d.ts +0 -8
- package/dist/types/programs/node-circle/base/frag.glsl.d.ts +0 -2
- package/dist/types/programs/node-circle/base/index.d.ts +0 -37
- package/dist/types/programs/node-circle/base/vert.glsl.d.ts +0 -2
- package/dist/types/programs/node-circle/index.d.ts +0 -11
- package/dist/types/programs/node-image/factory.d.ts +0 -25
- package/dist/types/programs/node-image/frag.glsl.d.ts +0 -2
- package/dist/types/programs/node-image/index.d.ts +0 -5
- package/dist/types/programs/node-image/texture.d.ts +0 -102
- package/dist/types/programs/node-image/vert.glsl.d.ts +0 -2
- package/dist/types/programs/node-rect/base/drawHover.d.ts +0 -8
- package/dist/types/programs/node-rect/base/drawLabel.d.ts +0 -8
- package/dist/types/programs/node-rect/base/frag.glsl.d.ts +0 -2
- package/dist/types/programs/node-rect/base/index.d.ts +0 -34
- package/dist/types/programs/node-rect/base/vert.glsl.d.ts +0 -2
- package/dist/types/programs/node-rect/index.d.ts +0 -11
- package/src/components/ContextMenu.tsx +0 -138
- package/src/components/Provider.tsx +0 -116
- package/src/components/Tools.tsx +0 -68
- package/src/components/Viewer.tsx +0 -75
- package/src/components/context.ts +0 -43
- package/src/constants/index.ts +0 -22
- package/src/graph/layout.worker.ts +0 -42
- package/src/hooks/sigmaDragSelect.ts +0 -219
- package/src/hooks/sigmaHilighter.ts +0 -107
- package/src/hooks/sigmaMouseActions.ts +0 -153
- package/src/hooks/useGraphology.ts +0 -31
- package/src/hooks/useSigma.ts +0 -118
- package/src/i18n/index.ts +0 -0
- package/src/programs/arrow-head/frag.glsl.ts +0 -18
- package/src/programs/arrow-head/index.ts +0 -156
- package/src/programs/arrow-head/vert.glsl.ts +0 -75
- package/src/programs/edge-curve/drawLabel.ts +0 -166
- package/src/programs/edge-curve/frag.glsl.ts +0 -86
- package/src/programs/edge-curve/index.ts +0 -156
- package/src/programs/edge-curve/vert.glsl.ts +0 -110
- package/src/programs/edge-line/drawLabel.ts +0 -113
- package/src/programs/edge-line/frag.glsl.ts +0 -34
- package/src/programs/edge-line/index.ts +0 -163
- package/src/programs/edge-line/vert.glsl.ts +0 -104
- package/src/programs/node-badge/factory.ts +0 -325
- package/src/programs/node-badge/frag.glsl.ts +0 -79
- package/src/programs/node-badge/index.ts +0 -35
- package/src/programs/node-badge/texture.ts +0 -425
- package/src/programs/node-badge/vert.glsl.ts +0 -99
- package/src/programs/node-circle/base/drawHover.ts +0 -80
- package/src/programs/node-circle/base/drawLabel.ts +0 -145
- package/src/programs/node-circle/base/frag.glsl.ts +0 -72
- package/src/programs/node-circle/base/index.ts +0 -100
- package/src/programs/node-circle/base/vert.glsl.ts +0 -83
- package/src/programs/node-circle/index.ts +0 -19
- package/src/programs/node-image/factory.ts +0 -299
- package/src/programs/node-image/frag.glsl.ts +0 -97
- package/src/programs/node-image/index.ts +0 -7
- package/src/programs/node-image/texture.ts +0 -435
- package/src/programs/node-image/vert.glsl.ts +0 -60
- package/src/programs/node-rect/base/drawHover.ts +0 -77
- package/src/programs/node-rect/base/drawLabel.ts +0 -149
- package/src/programs/node-rect/base/frag.glsl.ts +0 -67
- package/src/programs/node-rect/base/index.ts +0 -107
- package/src/programs/node-rect/base/vert.glsl.ts +0 -87
- package/src/programs/node-rect/index.ts +0 -19
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { type Attributes } from "graphology-types";
|
|
2
|
-
import { type NodeHoverDrawingFunction, type NodeLabelDrawingFunction, type NodeProgramType } from "sigma/rendering";
|
|
3
|
-
import { type EdgeAttributes, type NodeAttributes } from "../../types";
|
|
4
|
-
import { type TextureManagerOptions } from "./texture";
|
|
5
|
-
interface CreateNodeImageProgramOptions<N extends Attributes, E extends Attributes, G extends Attributes> extends TextureManagerOptions {
|
|
6
|
-
drawingMode: "background" | "color";
|
|
7
|
-
keepWithinCircle: boolean;
|
|
8
|
-
drawLabel: NodeLabelDrawingFunction<N, E, G> | undefined;
|
|
9
|
-
drawHover: NodeHoverDrawingFunction<N, E, G> | undefined;
|
|
10
|
-
padding: number;
|
|
11
|
-
colorAttribute: string;
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* To share the texture between the program instances of the graph and the
|
|
15
|
-
* hovered nodes (to prevent some flickering, mostly), this program must be
|
|
16
|
-
* "built" for each sigma instance:
|
|
17
|
-
*/
|
|
18
|
-
export default function getNodeImageProgram(options?: Partial<CreateNodeImageProgramOptions<NodeAttributes & {
|
|
19
|
-
bg: string;
|
|
20
|
-
opacity: number;
|
|
21
|
-
}, EdgeAttributes, Attributes>>): NodeProgramType<NodeAttributes & {
|
|
22
|
-
bg: string;
|
|
23
|
-
opacity: number;
|
|
24
|
-
}, EdgeAttributes>;
|
|
25
|
-
export {};
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
export { default as createNodeImageProgram } from "./factory";
|
|
2
|
-
export declare const NodeImageProgram: (isCircle: boolean) => import("sigma/rendering").NodeProgramType<import("../..").NodeAttributes<KeyValue<any>> & {
|
|
3
|
-
bg: string;
|
|
4
|
-
opacity: number;
|
|
5
|
-
}, import("../..").EdgeAttributes<KeyValue<any>>>;
|
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
import { EventEmitter } from "events";
|
|
2
|
-
import { type Coordinates } from "sigma/types";
|
|
3
|
-
/**
|
|
4
|
-
* Useful types:
|
|
5
|
-
* *************
|
|
6
|
-
*/
|
|
7
|
-
export interface ImageLoading {
|
|
8
|
-
status: "loading";
|
|
9
|
-
}
|
|
10
|
-
export interface ImageError {
|
|
11
|
-
status: "error";
|
|
12
|
-
}
|
|
13
|
-
export interface ImageReady {
|
|
14
|
-
status: "ready";
|
|
15
|
-
image: HTMLImageElement;
|
|
16
|
-
sourceX: number;
|
|
17
|
-
sourceY: number;
|
|
18
|
-
sourceSize: number;
|
|
19
|
-
destinationSize: number;
|
|
20
|
-
}
|
|
21
|
-
export type ImageType = ImageLoading | ImageError | ImageReady;
|
|
22
|
-
export type Atlas = Record<string, Coordinates & {
|
|
23
|
-
size: number;
|
|
24
|
-
}>;
|
|
25
|
-
export interface TextureManagerOptions {
|
|
26
|
-
size: {
|
|
27
|
-
mode: "auto";
|
|
28
|
-
} | {
|
|
29
|
-
mode: "max";
|
|
30
|
-
value: number;
|
|
31
|
-
} | {
|
|
32
|
-
mode: "force";
|
|
33
|
-
value: number;
|
|
34
|
-
};
|
|
35
|
-
objectFit: "contain" | "cover" | "fill";
|
|
36
|
-
correctCentering: boolean;
|
|
37
|
-
}
|
|
38
|
-
export declare const DEFAULT_TEXTURE_MANAGER_OPTIONS: TextureManagerOptions;
|
|
39
|
-
export declare const DEBOUNCE_TIMEOUT = 100;
|
|
40
|
-
export declare const MARGIN_IN_TEXTURE = 1;
|
|
41
|
-
/**
|
|
42
|
-
* Helpers:
|
|
43
|
-
* ********
|
|
44
|
-
*/
|
|
45
|
-
/**
|
|
46
|
-
* This helper loads an image at a given URL, and returns an HTMLImageElement
|
|
47
|
-
* with it displayed once it's properly loaded, within a promise.
|
|
48
|
-
*/
|
|
49
|
-
export declare function loadRasterImage(imageSource: string): Promise<HTMLImageElement>;
|
|
50
|
-
export declare const makeSvg: (path?: string) => string;
|
|
51
|
-
/**
|
|
52
|
-
* This helper loads an SVG image at a given URL, adjusts its size to a given
|
|
53
|
-
* size, and returns an HTMLImageElement with it displayed once it's properly
|
|
54
|
-
* loaded, within a promise.
|
|
55
|
-
*/
|
|
56
|
-
export declare function loadSVGImage(imageSource: string, { size }?: {
|
|
57
|
-
size?: number;
|
|
58
|
-
}): Promise<HTMLImageElement>;
|
|
59
|
-
/**
|
|
60
|
-
* This helper loads an image using the proper function.
|
|
61
|
-
*/
|
|
62
|
-
export declare function loadImage(imageSource: string, { size }?: {
|
|
63
|
-
size?: number;
|
|
64
|
-
}): Promise<HTMLImageElement>;
|
|
65
|
-
/**
|
|
66
|
-
* This helper computes exact coordinates to draw an image onto a texture.
|
|
67
|
-
*/
|
|
68
|
-
export declare function refineImage(image: HTMLImageElement, corrector: PictogramCenteringCorrector, { objectFit, size, correctCentering }: TextureManagerOptions): Omit<ImageReady, "status" | "image">;
|
|
69
|
-
/**
|
|
70
|
-
* This helper takes a collection of image states and a context, draw all the
|
|
71
|
-
* images in the context, and returns an atlas to get where each image is drawn
|
|
72
|
-
* on the texture.
|
|
73
|
-
*/
|
|
74
|
-
export declare function drawTexture(ctx: CanvasRenderingContext2D, images: Record<string, ImageType>): Atlas;
|
|
75
|
-
/**
|
|
76
|
-
* This class helps to "correct" the centering of an SVG pictogram by finding
|
|
77
|
-
* the "true" visually correct center through the barycenter of the pictogram's
|
|
78
|
-
* alpha layer in x and y dimension.
|
|
79
|
-
*/
|
|
80
|
-
export declare class PictogramCenteringCorrector {
|
|
81
|
-
canvas: HTMLCanvasElement;
|
|
82
|
-
context: CanvasRenderingContext2D;
|
|
83
|
-
constructor();
|
|
84
|
-
getCorrectionOffset(image: HTMLImageElement, size: number): Coordinates;
|
|
85
|
-
}
|
|
86
|
-
export declare class TextureManager extends EventEmitter {
|
|
87
|
-
static NEW_TEXTURE_EVENT: string;
|
|
88
|
-
private readonly options;
|
|
89
|
-
private readonly canvas;
|
|
90
|
-
private readonly ctx;
|
|
91
|
-
private frameId?;
|
|
92
|
-
private readonly corrector;
|
|
93
|
-
private imageStates;
|
|
94
|
-
private texture;
|
|
95
|
-
private atlas;
|
|
96
|
-
constructor(options?: Partial<TextureManagerOptions>);
|
|
97
|
-
private scheduleGenerateTexture;
|
|
98
|
-
private generateTexture;
|
|
99
|
-
registerImage(source: string): Promise<void>;
|
|
100
|
-
getAtlas(): Atlas;
|
|
101
|
-
getTexture(): ImageData;
|
|
102
|
-
}
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
declare const VERTEX_SHADER_SOURCE = "\nattribute vec4 a_id;\nattribute vec4 a_fill;\nattribute vec4 a_color;\nattribute vec2 a_position;\nattribute float a_size;\nattribute float a_angle;\nattribute float a_colorMode;\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;\nvarying float v_colorMode;\n\nconst float bias = 255.0 / 254.0;\nconst float marginRatio = 1.05;\n\nvoid main() {\n float size = 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 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 = vec4(0.0, 0.0, 0.0, 0.0);\n v_color = vec4(a_color.rgb, a_opacity * bias);\n v_opacity = a_opacity;\n v_colorMode = a_colorMode;\n // Pass the texture coordinates:\n v_texture = a_texture;\n #endif\n\n v_color.a *= bias;\n}\n";
|
|
2
|
-
export default VERTEX_SHADER_SOURCE;
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { type Settings } from "sigma/settings";
|
|
2
|
-
import { type EdgeAttributes, type NodeAttributes } from "../../../types";
|
|
3
|
-
export declare function drawNodeHover(context: CanvasRenderingContext2D, data: NodeAttributes & {
|
|
4
|
-
opacity: number;
|
|
5
|
-
x: number;
|
|
6
|
-
y: number;
|
|
7
|
-
size: number;
|
|
8
|
-
}, settings: Settings<NodeAttributes, EdgeAttributes>): void;
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { type Settings } from "sigma/settings";
|
|
2
|
-
import { type EdgeAttributes, type InternalNodeAttributes, type NodeAttributes } from "../../../types";
|
|
3
|
-
export declare function drawNodeLabel(context: CanvasRenderingContext2D, data: InternalNodeAttributes & {
|
|
4
|
-
opacity: number;
|
|
5
|
-
x: number;
|
|
6
|
-
y: number;
|
|
7
|
-
size: number;
|
|
8
|
-
}, settings: Settings<NodeAttributes<any>, EdgeAttributes<any>>): void;
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { NodeProgram, type ProgramInfo } from "sigma/rendering";
|
|
2
|
-
import { type NodeDisplayData, type RenderParams } from "sigma/types";
|
|
3
|
-
import { type NodeAttributes } from "../../../types";
|
|
4
|
-
declare const UNIFORMS: readonly ["u_sizeRatio", "u_correctionRatio", "u_cameraAngle", "u_matrix"];
|
|
5
|
-
export declare class NodeRectBase extends NodeProgram<(typeof UNIFORMS)[number], NodeAttributes> {
|
|
6
|
-
getDefinition(): {
|
|
7
|
-
VERTICES: number;
|
|
8
|
-
VERTEX_SHADER_SOURCE: string;
|
|
9
|
-
FRAGMENT_SHADER_SOURCE: string;
|
|
10
|
-
METHOD: 4;
|
|
11
|
-
UNIFORMS: readonly ["u_sizeRatio", "u_correctionRatio", "u_cameraAngle", "u_matrix"];
|
|
12
|
-
ATTRIBUTES: ({
|
|
13
|
-
name: string;
|
|
14
|
-
size: number;
|
|
15
|
-
type: 5121;
|
|
16
|
-
normalized: boolean;
|
|
17
|
-
} | {
|
|
18
|
-
name: string;
|
|
19
|
-
size: number;
|
|
20
|
-
type: 5126;
|
|
21
|
-
})[];
|
|
22
|
-
CONSTANT_ATTRIBUTES: {
|
|
23
|
-
name: string;
|
|
24
|
-
size: number;
|
|
25
|
-
type: 5126;
|
|
26
|
-
}[];
|
|
27
|
-
CONSTANT_DATA: number[][];
|
|
28
|
-
};
|
|
29
|
-
processVisibleItem(nodeIndex: number, startIndex: number, data: NodeDisplayData & NodeAttributes & {
|
|
30
|
-
opacity: number;
|
|
31
|
-
}): void;
|
|
32
|
-
setUniforms(params: RenderParams, { gl, uniformLocations }: ProgramInfo): void;
|
|
33
|
-
}
|
|
34
|
-
export {};
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { type NodeAttributes } from "../../types";
|
|
2
|
-
export declare const NodeRectProgram: {
|
|
3
|
-
new (_gl: WebGLRenderingContext, _pickingBuffer: WebGLFramebuffer | null, _renderer: import("sigma").default<NodeAttributes<any>, import("graphology-types").Attributes, import("graphology-types").Attributes>): {
|
|
4
|
-
drawLabel: import("sigma/rendering").NodeLabelDrawingFunction<NodeAttributes<any>, import("graphology-types").Attributes, import("graphology-types").Attributes> | undefined;
|
|
5
|
-
drawHover: import("sigma/rendering").NodeHoverDrawingFunction<NodeAttributes<any>, import("graphology-types").Attributes, import("graphology-types").Attributes> | undefined;
|
|
6
|
-
kill(): void;
|
|
7
|
-
reallocate(_capacity: number): void;
|
|
8
|
-
process(_nodeIndex: number, _offset: number, _data: import("sigma/types").NodeDisplayData): void;
|
|
9
|
-
render(_params: import("sigma/types").RenderParams): void;
|
|
10
|
-
};
|
|
11
|
-
};
|
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* React Fabric
|
|
3
|
-
* @version: 1.0.0
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* The MIT License (MIT)
|
|
7
|
-
* Copyright (c) 2025 Adarsh Pastakia
|
|
8
|
-
*
|
|
9
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software
|
|
10
|
-
* and associated documentation files (the "Software"), to deal in the Software without restriction,
|
|
11
|
-
* including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
12
|
-
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
|
|
13
|
-
* subject to the following conditions:
|
|
14
|
-
*
|
|
15
|
-
* The above copyright notice and this permission notice shall be included in all copies or substantial
|
|
16
|
-
* portions of the Software.
|
|
17
|
-
*
|
|
18
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
|
|
19
|
-
* TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
20
|
-
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
21
|
-
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
22
|
-
*/
|
|
23
|
-
|
|
24
|
-
import {
|
|
25
|
-
autoUpdate,
|
|
26
|
-
flip,
|
|
27
|
-
FloatingPortal,
|
|
28
|
-
offset,
|
|
29
|
-
useClick,
|
|
30
|
-
useDismiss,
|
|
31
|
-
useFloating,
|
|
32
|
-
useFloatingNodeId,
|
|
33
|
-
useInteractions,
|
|
34
|
-
} from "@floating-ui/react";
|
|
35
|
-
import { Divider, Menu, MenuItem } from "@react-fabric/core";
|
|
36
|
-
import { cloneElement, useEffect, useRef, useState } from "react";
|
|
37
|
-
import { type SigmaEdgeEventPayload, type SigmaNodeEventPayload, type SigmaStageEventPayload } from "sigma/types";
|
|
38
|
-
import { ICONS } from "../constants";
|
|
39
|
-
import { useGraph } from "./context";
|
|
40
|
-
|
|
41
|
-
export const GraphContextMenu = () => {
|
|
42
|
-
const [isOpen, setIsOpen] = useState(false);
|
|
43
|
-
const nodeId = useFloatingNodeId();
|
|
44
|
-
const { sigma } = useGraph();
|
|
45
|
-
const [menu, setMenu] = useState<Array<React.ReactElement<typeof MenuItem>>>([]);
|
|
46
|
-
|
|
47
|
-
const { refs, floatingStyles, context } = useFloating({
|
|
48
|
-
open: isOpen,
|
|
49
|
-
nodeId,
|
|
50
|
-
onOpenChange: (open, evt, reason) => {
|
|
51
|
-
const target = evt?.target as HTMLElement;
|
|
52
|
-
if (!target?.closest(".menu-list")) setIsOpen(open);
|
|
53
|
-
},
|
|
54
|
-
strategy: "absolute",
|
|
55
|
-
placement: "bottom-start",
|
|
56
|
-
whileElementsMounted: autoUpdate,
|
|
57
|
-
middleware: [offset(8), flip()],
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
const click = useClick(context, {
|
|
61
|
-
toggle: true,
|
|
62
|
-
ignoreMouse: true,
|
|
63
|
-
});
|
|
64
|
-
const dismiss = useDismiss(context, { bubbles: true });
|
|
65
|
-
|
|
66
|
-
const { getFloatingProps } = useInteractions([dismiss, click]);
|
|
67
|
-
|
|
68
|
-
const tryClosing = useRef((e: React.MouseEvent) => {
|
|
69
|
-
if ((e.target as HTMLElement)?.closest("[data-dropdown-dismiss='true']")) setTimeout(() => setIsOpen(false), 50);
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
useEffect(() => {
|
|
73
|
-
const handleContextMenu = (e: SigmaNodeEventPayload | SigmaEdgeEventPayload | SigmaStageEventPayload) => {
|
|
74
|
-
if ("node" in e) {
|
|
75
|
-
setMenu([
|
|
76
|
-
<MenuItem key="0.0" label="Select neighbors" />,
|
|
77
|
-
<Divider key="0.1" />,
|
|
78
|
-
<MenuItem key="0.2" label="Delete node(s)" color="danger" icon={ICONS.delete} />,
|
|
79
|
-
<MenuItem key="0.3" label="Clear graph" color="danger" icon={ICONS.clear} />,
|
|
80
|
-
]);
|
|
81
|
-
} else if ("edge" in e) {
|
|
82
|
-
setMenu([
|
|
83
|
-
<MenuItem key="1.0" label="Select neighbors" />,
|
|
84
|
-
<Divider key="1.1" />,
|
|
85
|
-
<MenuItem key="1.2" label="Clear graph" color="danger" icon={ICONS.clear} />,
|
|
86
|
-
]);
|
|
87
|
-
} else {
|
|
88
|
-
setMenu([<MenuItem key="2.0" label="Clear graph" color="danger" icon={ICONS.clear} />]);
|
|
89
|
-
}
|
|
90
|
-
const virtual = {
|
|
91
|
-
getBoundingClientRect() {
|
|
92
|
-
return {
|
|
93
|
-
width: 0,
|
|
94
|
-
height: 0,
|
|
95
|
-
x: e.event.x,
|
|
96
|
-
y: e.event.y,
|
|
97
|
-
top: e.event.y,
|
|
98
|
-
left: e.event.x,
|
|
99
|
-
right: e.event.x,
|
|
100
|
-
bottom: e.event.y,
|
|
101
|
-
};
|
|
102
|
-
},
|
|
103
|
-
};
|
|
104
|
-
setIsOpen(true);
|
|
105
|
-
refs.setReference(virtual);
|
|
106
|
-
e.event.original.preventDefault();
|
|
107
|
-
return false;
|
|
108
|
-
};
|
|
109
|
-
sigma.instance?.on("rightClickNode", handleContextMenu);
|
|
110
|
-
sigma.instance?.on("rightClickEdge", handleContextMenu);
|
|
111
|
-
sigma.instance?.on("rightClickStage", handleContextMenu);
|
|
112
|
-
|
|
113
|
-
return () => {
|
|
114
|
-
sigma.instance?.off("rightClickNode", handleContextMenu);
|
|
115
|
-
sigma.instance?.off("rightClickEdge", handleContextMenu);
|
|
116
|
-
sigma.instance?.off("rightClickStage", handleContextMenu);
|
|
117
|
-
};
|
|
118
|
-
}, [sigma]);
|
|
119
|
-
|
|
120
|
-
return (
|
|
121
|
-
isOpen && (
|
|
122
|
-
<FloatingPortal root={refs.domReference.current?.closest<HTMLElement>(".theme-base") ?? undefined}>
|
|
123
|
-
{cloneElement((<Menu>{menu}</Menu>) as AnyObject, {
|
|
124
|
-
...getFloatingProps(),
|
|
125
|
-
style: {
|
|
126
|
-
...floatingStyles,
|
|
127
|
-
borderRadius: "var(--rounding)",
|
|
128
|
-
zIndex: "var(--z-popover)",
|
|
129
|
-
fontSize: "0.75rem",
|
|
130
|
-
},
|
|
131
|
-
className: "bg-default outline rounded-capped shadow-lg",
|
|
132
|
-
ref: refs.setFloating,
|
|
133
|
-
onMouseUp: tryClosing.current,
|
|
134
|
-
})}
|
|
135
|
-
</FloatingPortal>
|
|
136
|
-
)
|
|
137
|
-
);
|
|
138
|
-
};
|
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
import { Icon } from "@react-fabric/core";
|
|
2
|
-
import { fitViewportToNodes } from "@sigma/utils";
|
|
3
|
-
import { type PropsWithChildren, useEffect, useImperativeHandle, useState } from "react";
|
|
4
|
-
import { type SigmaNodeEventPayload } from "sigma/types";
|
|
5
|
-
import { useDragSelection } from "../hooks/sigmaDragSelect";
|
|
6
|
-
import { useGraphology } from "../hooks/useGraphology";
|
|
7
|
-
import { useSigma } from "../hooks/useSigma";
|
|
8
|
-
import { type GraphProps } from "../types";
|
|
9
|
-
import { GraphContext } from "./context";
|
|
10
|
-
|
|
11
|
-
export const GraphProvider = <N = KeyValue, E = KeyValue>({
|
|
12
|
-
ref,
|
|
13
|
-
data,
|
|
14
|
-
children,
|
|
15
|
-
nodeReducer,
|
|
16
|
-
edgeReducer,
|
|
17
|
-
onSelectChange,
|
|
18
|
-
onNodeDoubleClick,
|
|
19
|
-
onContextMenu,
|
|
20
|
-
}: PropsWithChildren<GraphProps<N, E>>) => {
|
|
21
|
-
const { graph, selected } = useGraphology<N, E>(data);
|
|
22
|
-
const sigma = useSigma<N, E>(graph, nodeReducer, edgeReducer);
|
|
23
|
-
|
|
24
|
-
const dragSelector = useDragSelection(sigma.instance);
|
|
25
|
-
|
|
26
|
-
const [layoutRunning, setLayoutRunning] = useState(false);
|
|
27
|
-
|
|
28
|
-
const resetViewport = () => {
|
|
29
|
-
if (graph.size === 0) return;
|
|
30
|
-
void (
|
|
31
|
-
sigma.instance &&
|
|
32
|
-
fitViewportToNodes(sigma.instance, graph.nodes(), {
|
|
33
|
-
animate: true,
|
|
34
|
-
})
|
|
35
|
-
);
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
const zoomIn = () => {
|
|
39
|
-
if (graph.size === 0) return;
|
|
40
|
-
void sigma.instance?.getCamera().animatedZoom();
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
const zoomOut = () => {
|
|
44
|
-
if (graph.size === 0) return;
|
|
45
|
-
void sigma.instance?.getCamera().animatedUnzoom();
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
useEffect(() => {
|
|
49
|
-
const resetHandler = () => {
|
|
50
|
-
void (
|
|
51
|
-
sigma.instance &&
|
|
52
|
-
fitViewportToNodes(sigma.instance, graph.nodes(), {
|
|
53
|
-
animate: true,
|
|
54
|
-
})
|
|
55
|
-
);
|
|
56
|
-
};
|
|
57
|
-
graph.on("layoutRunning", setLayoutRunning);
|
|
58
|
-
graph.on("layoutDone", resetHandler);
|
|
59
|
-
onSelectChange && graph.on("nodesSelected", onSelectChange);
|
|
60
|
-
|
|
61
|
-
return () => {
|
|
62
|
-
graph.off("layoutDone", resetHandler);
|
|
63
|
-
graph.off("layoutRunning", setLayoutRunning);
|
|
64
|
-
onSelectChange && graph.off("nodesSelected", onSelectChange);
|
|
65
|
-
};
|
|
66
|
-
}, [graph, sigma, onSelectChange]);
|
|
67
|
-
|
|
68
|
-
useEffect(() => {
|
|
69
|
-
const handleClick = (e: SigmaNodeEventPayload) => {
|
|
70
|
-
onNodeDoubleClick?.(e.node, graph.getNodeAttributes(e.node));
|
|
71
|
-
e.event.original.preventDefault();
|
|
72
|
-
e.event.preventSigmaDefault();
|
|
73
|
-
e.preventSigmaDefault();
|
|
74
|
-
return false;
|
|
75
|
-
};
|
|
76
|
-
sigma.instance?.on("doubleClickNode", handleClick);
|
|
77
|
-
|
|
78
|
-
return () => {
|
|
79
|
-
sigma.instance?.off("doubleClickNode", handleClick);
|
|
80
|
-
};
|
|
81
|
-
}, [sigma, graph, onNodeDoubleClick]);
|
|
82
|
-
|
|
83
|
-
useImperativeHandle(
|
|
84
|
-
ref,
|
|
85
|
-
() => ({
|
|
86
|
-
graph,
|
|
87
|
-
sigma,
|
|
88
|
-
}),
|
|
89
|
-
[graph, sigma],
|
|
90
|
-
);
|
|
91
|
-
|
|
92
|
-
return (
|
|
93
|
-
<GraphContext.Provider
|
|
94
|
-
value={
|
|
95
|
-
{
|
|
96
|
-
sigma,
|
|
97
|
-
graph,
|
|
98
|
-
selected,
|
|
99
|
-
dragSelector,
|
|
100
|
-
layoutRunning,
|
|
101
|
-
resetViewport,
|
|
102
|
-
zoomIn,
|
|
103
|
-
zoomOut,
|
|
104
|
-
} as AnyObject
|
|
105
|
-
}
|
|
106
|
-
>
|
|
107
|
-
{children}
|
|
108
|
-
|
|
109
|
-
{layoutRunning && (
|
|
110
|
-
<div className="absolute top-0 end-0 p-1">
|
|
111
|
-
<Icon icon="icon-[svg-spinners--eclipse]" />
|
|
112
|
-
</div>
|
|
113
|
-
)}
|
|
114
|
-
</GraphContext.Provider>
|
|
115
|
-
);
|
|
116
|
-
};
|
package/src/components/Tools.tsx
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import { Button, ButtonGroup, Dropdown, Menu, MenuItem } from "@react-fabric/core";
|
|
2
|
-
import { ICONS } from "../constants";
|
|
3
|
-
import { useGraph } from "./context";
|
|
4
|
-
|
|
5
|
-
export const Tools = () => {
|
|
6
|
-
const { dragSelector, graph, selected, resetViewport, zoomIn, zoomOut } = useGraph();
|
|
7
|
-
|
|
8
|
-
return (
|
|
9
|
-
<div className="flex flex-nowrap outline absolute top-0 start-0 p-0 z-1 bg-default">
|
|
10
|
-
<ButtonGroup variant="link">
|
|
11
|
-
<Button aria-label="Home" icon={ICONS.focus} onClick={resetViewport} />
|
|
12
|
-
<Button aria-label="Zoomin" icon={ICONS.zoomIn} onClick={zoomIn} />
|
|
13
|
-
<Button aria-label="Zoomout" icon={ICONS.zoomOut} onClick={zoomOut} />
|
|
14
|
-
</ButtonGroup>
|
|
15
|
-
<ButtonGroup variant="link">
|
|
16
|
-
{dragSelector.selectionMode !== "lasso" && (
|
|
17
|
-
<Button
|
|
18
|
-
aria-label="lasso"
|
|
19
|
-
icon={ICONS.lasso}
|
|
20
|
-
disabled={!!dragSelector.selectionMode}
|
|
21
|
-
onClick={() => dragSelector.startLassoSelection()}
|
|
22
|
-
/>
|
|
23
|
-
)}
|
|
24
|
-
{dragSelector.selectionMode && (
|
|
25
|
-
<Button color="danger" aria-label="cancel" icon={ICONS.cancel} onClick={() => dragSelector.cancelSelection()} />
|
|
26
|
-
)}
|
|
27
|
-
{dragSelector.selectionMode !== "rectangle" && (
|
|
28
|
-
<Button
|
|
29
|
-
aria-label="rectselect"
|
|
30
|
-
icon={ICONS.select}
|
|
31
|
-
disabled={!!dragSelector.selectionMode}
|
|
32
|
-
onClick={() => dragSelector.startRectangleSelection()}
|
|
33
|
-
/>
|
|
34
|
-
)}
|
|
35
|
-
</ButtonGroup>
|
|
36
|
-
<ButtonGroup variant="link">
|
|
37
|
-
<Dropdown>
|
|
38
|
-
<Button
|
|
39
|
-
aria-label="force"
|
|
40
|
-
variant="link"
|
|
41
|
-
icon={
|
|
42
|
-
"M19.5 17C19.37 17 19.24 17 19.11 17.04L17.5 13.79C17.95 13.34 18.25 12.71 18.25 12C18.25 10.62 17.13 9.5 15.75 9.5C15.62 9.5 15.5 9.5 15.36 9.54L13.73 6.29C14.21 5.84 14.5 5.21 14.5 4.5C14.5 3.12 13.38 2 12 2S9.5 3.12 9.5 4.5C9.5 5.21 9.79 5.84 10.26 6.29L8.64 9.54C8.5 9.5 8.38 9.5 8.25 9.5C6.87 9.5 5.75 10.62 5.75 12C5.75 12.71 6.05 13.34 6.5 13.79L4.89 17.04C4.76 17 4.63 17 4.5 17C3.12 17 2 18.12 2 19.5C2 20.88 3.12 22 4.5 22S7 20.88 7 19.5C7 18.8 6.71 18.16 6.24 17.71L7.86 14.46C8 14.5 8.12 14.5 8.25 14.5C8.38 14.5 8.5 14.5 8.64 14.46L10.27 17.71C9.8 18.16 9.5 18.8 9.5 19.5C9.5 20.88 10.62 22 12 22S14.5 20.88 14.5 19.5C14.5 18.12 13.38 17 12 17C11.87 17 11.74 17 11.61 17.04L10 13.79C10.46 13.34 10.75 12.71 10.75 12S10.46 10.66 10 10.21L11.61 6.96C11.74 7 11.87 7 12 7S12.26 7 12.39 6.96L14 10.21C13.55 10.66 13.25 11.3 13.25 12C13.25 13.38 14.37 14.5 15.75 14.5C15.88 14.5 16 14.5 16.14 14.46L17.77 17.71C17.3 18.16 17 18.8 17 19.5C17 20.88 18.12 22 19.5 22S22 20.88 22 19.5C22 18.12 20.88 17 19.5 17Z"
|
|
43
|
-
}
|
|
44
|
-
/>
|
|
45
|
-
<Menu className="text-sm">
|
|
46
|
-
<MenuItem label="box" onClick={async () => await graph.elkLayout("box")} />
|
|
47
|
-
<MenuItem label="force" onClick={async () => await graph.elkLayout("force")} />
|
|
48
|
-
<MenuItem label="layered" onClick={async () => await graph.elkLayout("layered")} />
|
|
49
|
-
<MenuItem label="stress" onClick={async () => await graph.elkLayout("stress")} />
|
|
50
|
-
<MenuItem label="radial" onClick={async () => await graph.elkLayout("radial")} />
|
|
51
|
-
<MenuItem label="sporeOverlap" onClick={async () => await graph.elkLayout("sporeOverlap")} />
|
|
52
|
-
<MenuItem label="sporeCompaction" onClick={async () => await graph.elkLayout("sporeCompaction")} />
|
|
53
|
-
</Menu>
|
|
54
|
-
</Dropdown>
|
|
55
|
-
</ButtonGroup>
|
|
56
|
-
<ButtonGroup variant="link">
|
|
57
|
-
<Button
|
|
58
|
-
aria-label="delete"
|
|
59
|
-
color="danger"
|
|
60
|
-
icon={ICONS.delete}
|
|
61
|
-
disabled={!selected.length}
|
|
62
|
-
onClick={() => graph.dropNodes(selected)}
|
|
63
|
-
/>
|
|
64
|
-
<Button aria-label="clear" color="danger" icon={ICONS.clear} onClick={() => graph.clear()} />
|
|
65
|
-
</ButtonGroup>
|
|
66
|
-
</div>
|
|
67
|
-
);
|
|
68
|
-
};
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* React Fabric
|
|
3
|
-
* @version: 1.0.0
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* The MIT License (MIT)
|
|
7
|
-
* Copyright (c) 2025 Adarsh Pastakia
|
|
8
|
-
*
|
|
9
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software
|
|
10
|
-
* and associated documentation files (the "Software"), to deal in the Software without restriction,
|
|
11
|
-
* including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
12
|
-
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
|
|
13
|
-
* subject to the following conditions:
|
|
14
|
-
*
|
|
15
|
-
* The above copyright notice and this permission notice shall be included in all copies or substantial
|
|
16
|
-
* portions of the Software.
|
|
17
|
-
*
|
|
18
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
|
|
19
|
-
* TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
20
|
-
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
21
|
-
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
22
|
-
*/
|
|
23
|
-
|
|
24
|
-
import { Section } from "@react-fabric/core";
|
|
25
|
-
import { useEffect, useRef } from "react";
|
|
26
|
-
import { type GraphProps } from "../types";
|
|
27
|
-
import { GraphContextMenu } from "./ContextMenu";
|
|
28
|
-
import { GraphProvider } from "./Provider";
|
|
29
|
-
import { Tools } from "./Tools";
|
|
30
|
-
import { useGraph } from "./context";
|
|
31
|
-
|
|
32
|
-
const Graph = () => {
|
|
33
|
-
const { sigma, graph } = useGraph();
|
|
34
|
-
const handlesRef = useRef<HTMLDivElement>(null);
|
|
35
|
-
|
|
36
|
-
useEffect(() => {
|
|
37
|
-
// remove group handle if group node is dropped
|
|
38
|
-
const handler = ({ key }: KeyValue) => {
|
|
39
|
-
const handle = handlesRef.current?.querySelector(`[data-id="${key}"]`);
|
|
40
|
-
handle?.remove();
|
|
41
|
-
};
|
|
42
|
-
graph.on("nodeDropped", handler);
|
|
43
|
-
return () => {
|
|
44
|
-
graph.off("nodeDropped", handler);
|
|
45
|
-
};
|
|
46
|
-
}, [graph]);
|
|
47
|
-
|
|
48
|
-
return (
|
|
49
|
-
<div className="area-content relative bg-default graph-viewer">
|
|
50
|
-
<div dir="ltr" ref={sigma.containerRef} className="absolute inset-0" />
|
|
51
|
-
<div
|
|
52
|
-
role="none"
|
|
53
|
-
ref={handlesRef}
|
|
54
|
-
dir="ltr"
|
|
55
|
-
onClick={(e) => {
|
|
56
|
-
const key = (e.target as any).dataset.id;
|
|
57
|
-
key && graph.toggleExpanded(key);
|
|
58
|
-
}}
|
|
59
|
-
className="absolute inset-0 overflow-hidden pointer-events-none sigma-groupHandles"
|
|
60
|
-
/>
|
|
61
|
-
</div>
|
|
62
|
-
);
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
export const SigmaGraph = <N = KeyValue, E = KeyValue>(props: GraphProps<N, E>) => {
|
|
66
|
-
return (
|
|
67
|
-
<Section className="relative">
|
|
68
|
-
<GraphProvider {...props}>
|
|
69
|
-
<Tools />
|
|
70
|
-
<Graph />
|
|
71
|
-
<GraphContextMenu />
|
|
72
|
-
</GraphProvider>
|
|
73
|
-
</Section>
|
|
74
|
-
);
|
|
75
|
-
};
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* React Fabric
|
|
3
|
-
* @version: 1.0.0
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* The MIT License (MIT)
|
|
7
|
-
* Copyright (c) 2026 Adarsh Pastakia
|
|
8
|
-
*
|
|
9
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software
|
|
10
|
-
* and associated documentation files (the "Software"), to deal in the Software without restriction,
|
|
11
|
-
* including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
12
|
-
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
|
|
13
|
-
* subject to the following conditions:
|
|
14
|
-
*
|
|
15
|
-
* The above copyright notice and this permission notice shall be included in all copies or substantial
|
|
16
|
-
* portions of the Software.
|
|
17
|
-
*
|
|
18
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
|
|
19
|
-
* TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
20
|
-
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
21
|
-
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
22
|
-
*/
|
|
23
|
-
|
|
24
|
-
import { createContext, useContext } from "react";
|
|
25
|
-
import { Graph } from "../graph";
|
|
26
|
-
import { useDragSelection } from "../hooks/sigmaDragSelect";
|
|
27
|
-
import { useSigma } from "../hooks/useSigma";
|
|
28
|
-
import { EdgeAttributes, NodeAttributes } from "../types";
|
|
29
|
-
|
|
30
|
-
interface Context<N = KeyValue, E = KeyValue> {
|
|
31
|
-
sigma: ReturnType<typeof useSigma>;
|
|
32
|
-
graph: Graph<NodeAttributes<N>, EdgeAttributes<E>>;
|
|
33
|
-
selected: string[];
|
|
34
|
-
layoutRunning: boolean;
|
|
35
|
-
dragSelector: ReturnType<typeof useDragSelection>;
|
|
36
|
-
resetViewport: () => void;
|
|
37
|
-
zoomIn: () => void;
|
|
38
|
-
zoomOut: () => void;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export const GraphContext = createContext<Context>({} as Context);
|
|
42
|
-
|
|
43
|
-
export const useGraph = <N = KeyValue, E = KeyValue>() => useContext(GraphContext) as Context<N, E>;
|