File size: 868 Bytes
ab2ded1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import { useEffect, useRef } from 'react';
import { ForceGraph2D } from 'react-force-graph';
import { graphData } from './constant';

const Next = () => {
  const graphRef = useRef<ForceGraph2D>();

  useEffect(() => {
    graphRef.current.d3Force('cluster');
  }, []);

  return (
    <div>
      <ForceGraph2D
        ref={graphRef}
        graphData={graphData}
        nodeAutoColorBy={'type'}
        nodeLabel={(node) => {
          return node.id;
        }}
        // nodeVal={(node) => {
        //   return <div>xxx</div>;
        // }}
        // nodeVal={(node) => 100 / (node.level + 1)}
        linkAutoColorBy={'type'}
        nodeCanvasObjectMode={() => 'after'}
        nodeCanvasObject={(node, ctx) => {
          console.info(ctx);
          return ctx.canvas;
        }}
        // nodeVal={'id'}
      />
    </div>
  );
};

export default Next;