antvis / Graphin

🌌 A React toolkit for graph visualization based on G6.
https://github.com/antvis/graphin
MIT License
1.03k stars 266 forks source link

feat: upgrade to Graphin 3.0 #533

Closed yvonneyx closed 5 months ago

yvonneyx commented 5 months ago

类型定义

interface GraphinProps extends Pick<React.HTMLAttributes<HTMLDivElement>, 'id' | 'className' | 'style'> {
  onDestroy?: (graph: Graph) => void;
  onInit?: (graph: Graph) => void;
  onRender?: (graph: Graph) => void;
  options?: GraphOptions;
}

Example

const Demo: React.FC = () => {
  const [layout, setLayout] = useState<SingleLayoutOptions>(layouts[0]);

  return (
    <Graphin
      id="graphin-demo"
      className="graphin-container"
      style={{ width: '100%', height: '100%' }}
      options={{
        data,
        layout,
        behaviors: ['zoom-canvas', 'drag-canvas'],
      }}
    >
      <LayoutSelector
        onChange={value => setLayout(layouts.find(layout => layout.type === value)!)}
        options={layouts}
        value={layout.type}
      />
    </Graphin>
  );
};

效果截图

Kapture 2024-06-05 at 10 42 37