14
14
import React , { Component } from 'react' ;
15
15
import * as d3 from 'd3' ;
16
16
17
- const colors = [ '#2C4870' , '#519331' , '#AA5039' , '#8B2F5F' , '#C5B738' , '#858DFF' , '#FF8D02' , '#FFCD51' , '#ACDAE6' , '#FC997E' , '#CF93AD' , '#AA3939' , '#AA6C39' , '#226666' , ]
17
+ const colors = [ '#2C4870' , '#519331' , '#AA5039' , '#8B2F5F' , '#C5B738' , '#858DFF' , '#FF8D02' , '#FFCD51' , '#ACDAE6' , '#FC997E' , '#CF93AD' , '#AA3939' , '#AA6C39' , '#226666' ] ;
18
18
19
19
let root = { } ;
20
20
class Chart extends Component {
@@ -34,7 +34,7 @@ class Chart extends Component {
34
34
componentDidUpdate ( ) {
35
35
const { hierarchy } = this . props ;
36
36
root = JSON . parse ( JSON . stringify ( hierarchy ) ) ;
37
- console . log ( " Chart -> componentDidUpdate -> hierarchy" , hierarchy ) ;
37
+ console . log ( ' Chart -> componentDidUpdate -> hierarchy' , hierarchy ) ;
38
38
this . maked3Tree ( ) ;
39
39
}
40
40
@@ -46,7 +46,6 @@ class Chart extends Component {
46
46
}
47
47
48
48
maked3Tree ( ) {
49
-
50
49
this . removed3Tree ( ) ;
51
50
// const margin = {
52
51
// top: 0,
@@ -76,9 +75,9 @@ class Chart extends Component {
76
75
const tree = d3 . tree ( )
77
76
// this assigns width of tree to be 2pi
78
77
// .size([2 * Math.PI, radius / 1.3])
79
- . nodeSize ( [ width / 10 , height / 10 ] )
78
+ . nodeSize ( [ width / 10 , height / 10 ] )
80
79
// .separation(function (a, b) { return (a.parent == b.parent ? 1 : 2) / a.depth; });
81
- . separation ( function ( a , b ) { return ( a . parent == b . parent ? 2 : 2 ) } ) ;
80
+ . separation ( function ( a , b ) { return ( a . parent == b . parent ? 2 : 2 ) ; } ) ;
82
81
83
82
const d3root = tree ( hierarchy ) ;
84
83
@@ -92,9 +91,7 @@ class Chart extends Component {
92
91
. append ( 'path' )
93
92
. attr ( 'class' , 'link' )
94
93
. attr ( 'd' , d3 . linkRadial ( )
95
- . angle ( d => {
96
- return d . x
97
- } )
94
+ . angle ( d => d . x )
98
95
. radius ( d => d . y ) ) ;
99
96
100
97
const node = g . selectAll ( '.node' )
@@ -103,15 +100,14 @@ class Chart extends Component {
103
100
. enter ( )
104
101
. append ( 'g' )
105
102
. style ( 'fill' , function ( d ) {
106
- if ( d . data . branch < colors . length ) {
107
- return colors [ d . data . branch ]
108
- } else {
109
- let indexColors = d . data . branch - colors . length ;
110
- while ( indexColors > colors . length ) {
111
- indexColors = indexColors - colors . length ;
112
- }
113
- return colors [ indexColors ]
103
+ if ( d . data . branch < colors . length ) {
104
+ return colors [ d . data . branch ] ;
105
+ }
106
+ let indexColors = d . data . branch - colors . length ;
107
+ while ( indexColors > colors . length ) {
108
+ indexColors -= colors . length ;
114
109
}
110
+ return colors [ indexColors ] ;
115
111
} )
116
112
. attr ( 'class' , 'node--internal' )
117
113
// })
@@ -176,7 +172,7 @@ class Chart extends Component {
176
172
177
173
chartContainer . call ( d3 . zoom ( )
178
174
. extent ( [ [ 0 , 0 ] , [ width , height ] ] )
179
- . scaleExtent ( [ 0 , 8 ] ) //scaleExtent([minimum scale factor, maximum scale factor])
175
+ . scaleExtent ( [ 0 , 8 ] ) // scaleExtent([minimum scale factor, maximum scale factor])
180
176
. on ( 'zoom' , zoomed ) ) ;
181
177
182
178
function dragstarted ( ) {
0 commit comments