@gravity-ui/graph
v0.0.3
Published
Modern graph editor component
Downloads
827
Readme
@gravity-ui/graph ·
High performance graph renderer with scale-aware detalization
Install and setup
npm install @gravity-ui/graph
Examples
- Basic storybook example
- Large Basic storybook example
- Custom blocks view
- Bezier connection
- Customization connection
import { GraphCanvas, GraphState, TRenderBlockFn, useGraph } from "@gravity-ui/graph";
import React from "react";
const config = {};
export function GraphEditor() {
const { graph, setEntities, start } = useGraph(config);
useEffect(() => {
setEntities({
blocks: [
{
is: "block-action",
id: "action_1",
x: -100,
y: -450,
width: 126,
height: 126,
selected: true,
name: "Block #1",
anchors: [],
},
{
id: "action_2",
is: "block-action",
x: 253,
y: 176,
width: 126,
height: 126,
selected: false,
name: "Block #2",
anchors: [],
}
],
connections: [
{
sourceBlockId: "action_1",
targetBlockId: "action_2",
}
]
})
})
const renderBlock = (graph, block) => {
return <HTMLBlockView graph={graph} block={block} />;
};
return (
<GraphCanvas
graph={graph}
renderBlock={renderBlockFn}
onStateChanged={({ state }) => {
if (state === GraphState.ATTACHED) {
start();
graph.zoomTo("center", { padding: 300 });
}
}}
/>
);
}