-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathForceTree1.js
More file actions
49 lines (41 loc) · 1.5 KB
/
Copy pathForceTree1.js
File metadata and controls
49 lines (41 loc) · 1.5 KB
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
39
40
41
42
43
44
45
46
47
48
49
// source: https://github.com/vasturiano/react-force-graph/blob/master/example/tree/index.html
import React, {useEffect, useRef } from 'react' // useState
import { ForceGraph2D } from 'react-force-graph'
import * as d3 from 'd3'
//const useForceUpdate = () => {
// const setToggle = useState(false)[1]
// return () => setToggle(b => !b)
//}
const ForceTree = ({ data }) => {
const fgRef = useRef()
//const [controls] = useState({ 'DAG Orientation': 'td'});
//const forceUpdate = useForceUpdate()
//useEffect(() => {
// // add controls GUI
// const gui = new dat.GUI()
// gui.add(controls, 'DAG Orientation', ['td', 'bu', 'lr', 'rl', 'radialout', 'radialin', null])
// .onChange(forceUpdate)
//}, [])
useEffect(() => {
// add collision force
fgRef.current.d3Force('collision', d3.forceCollide(node => Math.sqrt(100 / (node.level + 1))));
}, [])
console.log("GRAPH DATA", data)
return <ForceGraph2D width={900} height={550}
ref={fgRef}
graphData={data}
dagMode="td" // dagMode={controls['DAG Orientation']}
dagLevelDistance={300}
backgroundColor="#101020"
linkColor={() => 'rgba(255,255,255,0.2)'}
nodeRelSize={1}
nodeId="path"
nodeVal={node => 100 / (node.level + 1)}
nodeLabel="path"
nodeAutoColorBy="module"
linkDirectionalParticles={2}
linkDirectionalParticleWidth={2}
d3VelocityDecay={0.3}
/>
}
export default ForceTree