图书馆 / Graph

Graph

具有动态比例感知细节的高性能图形渲染器

@gravity-ui/graph · npm package Release storybook

具有比例感知细节的高性能图形渲染器

Storybook

安装和设置

npm install @gravity-ui/graph

示例

import {GraphCanvas, GraphState, TRenderBlockFn, GraphBlock, 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 renderBlockFn = (graph, block) => {
    return (
      <GraphBlock graph={graph} block={block}>
        {block.id}
      </GraphBlock>
    );
  };

  return (
    <GraphCanvas
      graph={graph}
      renderBlock={renderBlockFn}
      onStateChanged={({state}) => {
        if (state === GraphState.ATTACHED) {
          start();
          graph.zoomTo('center', {padding: 300});
        }
      }}
    />
  );
}

文档

关于图书馆
明星
30
版本
1.0.1
上次更新
27.06.2025
存储库
github.com/gravity-ui/graph
执照
MIT License
维护者
贡献者