@@ -6,6 +6,7 @@ import React, { Component } from 'react';
6
6
import PropTypes from 'prop-types' ;
7
7
import * as d3 from 'd3' ;
8
8
9
+
9
10
let root = { } ;
10
11
let duration = 750 ;
11
12
class Chart extends Component {
@@ -38,8 +39,8 @@ class Chart extends Component {
38
39
39
40
maked3Tree ( ) {
40
41
this . removed3Tree ( ) ;
41
- let width = 900 ;
42
- let height = 1000 ;
42
+ let width = 960 ;
43
+ let height = 1060 ;
43
44
let chartContainer = d3 . select ( this . chartRef . current )
44
45
. append ( 'svg' ) // chartContainer is now pointing to svg
45
46
. attr ( 'width' , width )
@@ -48,7 +49,7 @@ class Chart extends Component {
48
49
let g = chartContainer
49
50
. append ( "g" )
50
51
// this is changing where the graph is located physically
51
- . attr ( "transform" , `translate(${ width / 2.5 } , ${ height / 2 + 90 } )` ) ;
52
+ . attr ( "transform" , `translate(${ width / 2 + 4 } , ${ height / 2 + 2 } )` ) ;
52
53
53
54
// if we consider the container for our radial node graph as a box encapsulating, half of this container width is essentially the radius of our radial node graph
54
55
let radius = width / 2 ;
@@ -59,6 +60,7 @@ class Chart extends Component {
59
60
let tree = d3 . tree ( )
60
61
// this assigns width of tree to be 2pi
61
62
. size ( [ 2 * Math . PI , radius ] )
63
+ . separation ( function ( a , b ) { return ( a . parent == b . parent ? 1 : 2 ) / a . depth } ) ;
62
64
63
65
let d3root = tree ( hierarchy ) ;
64
66
@@ -77,6 +79,7 @@ class Chart extends Component {
77
79
. data ( d3root . descendants ( ) )
78
80
. enter ( )
79
81
. append ( "g" )
82
+ // assigning class to the node based on whether node has children or not
80
83
. attr ( "class" , function ( d ) {
81
84
return "node" + ( d . children ? " node--internal" : " node--leaf" )
82
85
} )
@@ -85,18 +88,19 @@ class Chart extends Component {
85
88
} ) ;
86
89
87
90
node . append ( "circle" )
88
- . attr ( "r" , 5 .5)
91
+ . attr ( "r" , 40 .5)
89
92
90
93
node
91
94
. append ( "text" )
92
95
. attr ( "dy" , "0.1em" )
93
96
. attr ( "x" , function ( d ) {
94
97
// this positions how far the text is from leaf nodes (ones without children)
95
- return d . x < Math . PI === ! d . children ? 10 : - 10 ;
98
+ // negative number before the colon moves the text of rightside nodes, positive number moves the text for the leftside nodes
99
+ return d . x < Math . PI === ! d . children ? - 20 : 20 ;
96
100
} )
97
101
. attr ( "text-anchor" , function ( d ) { return d . x < Math . PI === ! d . children ? "start" : "end" ; } )
98
102
// this arranges the angle of the text
99
- . attr ( "transform" , function ( d ) { return "rotate(" + ( d . x < Math . PI ? d . x - Math . PI / 2 : d . x + Math . PI / 2 ) * 180 / Math . PI + ")" ; } )
103
+ . attr ( "transform" , function ( d ) { return "rotate(" + ( d . x < Math . PI ? d . x - Math . PI / 2 : d . x + Math . PI / 2 ) * 1 / Math . PI + ")" ; } )
100
104
. text ( function ( d ) {
101
105
return "state" + d . data . index ;
102
106
} ) ;
0 commit comments