1
1
import React , { useRef , useEffect , useContext } from "react" ;
2
2
import { select , hierarchy , tree , linkHorizontal } from "d3" ;
3
3
import { stateContext } from '../context/context' ;
4
+
5
+ // i don't think this does what i need it to do
4
6
import useResizeObserver from "./useResizeObserver" ;
5
7
6
8
function usePrevious ( value ) {
@@ -15,6 +17,8 @@ function TreeChart({ data }) {
15
17
const [ state , dispatch ] = useContext ( stateContext ) ;
16
18
const svgRef = useRef ( ) ;
17
19
const wrapperRef = useRef ( ) ;
20
+
21
+ // this needs to be modified
18
22
const dimensions = useResizeObserver ( wrapperRef ) ;
19
23
console . log ( 'dimensions' , dimensions ) ;
20
24
@@ -33,11 +37,12 @@ function TreeChart({ data }) {
33
37
34
38
console . log ( 'width' , width ) ;
35
39
console . log ( 'height' , height ) ;
40
+
36
41
// transform hierarchical data
37
42
const root = hierarchy ( data [ 0 ] ) ;
38
43
const treeLayout = tree ( ) . size ( [ height , width ] ) ;
39
44
40
- // Returns a new link generator with horizontal tangents .
45
+ // Returns a new link generator with horizontal display .
41
46
// To visualize links in a tree diagram rooted on the left edge of the display
42
47
const linkGenerator = linkHorizontal ( )
43
48
. x ( link => link . y )
@@ -46,7 +51,7 @@ function TreeChart({ data }) {
46
51
// insert our data into the tree layout
47
52
treeLayout ( root ) ;
48
53
49
- // nodes - each element in the tree
54
+ // node - each element in the tree
50
55
svg
51
56
. selectAll ( ".node" )
52
57
. data ( root . descendants ( ) )
@@ -62,7 +67,7 @@ function TreeChart({ data }) {
62
67
. attr ( "r" , 4 ) // radius of circle
63
68
. attr ( "opacity" , 1 ) ;
64
69
65
- // links - lines that connect the nodes
70
+ // link - lines that connect the nodes
66
71
const enteringAndUpdatingLinks = svg
67
72
. selectAll ( ".link" )
68
73
. data ( root . links ( ) )
0 commit comments