@@ -15,10 +15,15 @@ import React, { Component } from 'react';
15
15
import * as d3 from 'd3' ;
16
16
17
17
const colors = [ '#95B6B7' , '#475485' , '#519331' , '#AA5039' , '#8B2F5F' , '#C5B738' , '#858DFF' , '#FF8D02' , '#FFCD51' , '#ACDAE6' , '#FC997E' , '#CF93AD' , '#AA3939' , '#AA6C39' , '#226666' , '#2C4870' ] ;
18
+ interface ChartProps {
19
+ chartRef :any ;
20
+ maked3Tree : any ;
21
+ removed3Tree : any ;
22
+ }
18
23
19
24
let root = { } ;
20
25
class Chart extends Component {
21
- constructor ( props ) {
26
+ constructor ( props : ChartProps ) {
22
27
super ( props ) ;
23
28
this . chartRef = React . createRef ( ) ;
24
29
this . maked3Tree = this . maked3Tree . bind ( this ) ;
@@ -76,7 +81,7 @@ class Chart extends Component {
76
81
// .size([2 * Math.PI, radius / 1.3])
77
82
. nodeSize ( [ width / 10 , height / 10 ] )
78
83
// .separation(function (a, b) { return (a.parent == b.parent ? 1 : 2) / a.depth; });
79
- . separation ( function ( a , b ) { return ( a . parent == b . parent ? 2 : 2 ) ; } ) ;
84
+ . separation ( function ( a : { parent : object } , b : { parent : object } ) { return ( a . parent == b . parent ? 2 : 2 ) ; } ) ;
80
85
81
86
const d3root = tree ( hierarchy ) ;
82
87
@@ -90,15 +95,15 @@ class Chart extends Component {
90
95
. append ( 'path' )
91
96
. attr ( 'class' , 'link' )
92
97
. attr ( 'd' , d3 . linkRadial ( )
93
- . angle ( d => d . x )
94
- . radius ( d => d . y ) ) ;
98
+ . angle ( ( d : { x : number } ) => d . x )
99
+ . radius ( ( d : { y : number } ) => d . y ) ) ;
95
100
96
101
const node = g . selectAll ( '.node' )
97
102
// root.descendants gets an array of of all nodes
98
103
. data ( d3root . descendants ( ) )
99
104
. enter ( )
100
105
. append ( 'g' )
101
- . style ( 'fill' , function ( d ) {
106
+ . style ( 'fill' , function ( d : { data : { branch : number } } ) {
102
107
if ( d . data . branch < colors . length ) {
103
108
return colors [ d . data . branch ] ;
104
109
}
@@ -114,13 +119,13 @@ class Chart extends Component {
114
119
// .attr('class', function (d) {
115
120
// return 'node' + (d.children ? ' node--internal' : ' node--leaf');
116
121
// })
117
- . attr ( 'transform' , function ( d ) {
122
+ . attr ( 'transform' , function ( d : { x : number , y : number } ) {
118
123
return 'translate(' + reinfeldTidierAlgo ( d . x , d . y ) + ')' ;
119
124
} ) ;
120
125
121
126
node . append ( 'circle' )
122
127
. attr ( 'r' , 15 )
123
- . on ( 'mouseover' , function ( d ) {
128
+ . on ( 'mouseover' , function ( d : any ) {
124
129
d3 . select ( this )
125
130
. transition ( 100 )
126
131
. duration ( 20 )
@@ -135,7 +140,7 @@ class Chart extends Component {
135
140
. style ( 'top' , ( d3 . event . pageY - 65 ) + 'px' ) ;
136
141
} )
137
142
// eslint-disable-next-line no-unused-vars
138
- . on ( 'mouseout' , function ( d ) {
143
+ . on ( 'mouseout' , function ( d : any ) {
139
144
d3 . select ( this )
140
145
. transition ( )
141
146
. duration ( 300 )
@@ -149,16 +154,16 @@ class Chart extends Component {
149
154
. append ( 'text' )
150
155
// adjusts the y coordinates for the node text
151
156
. attr ( 'dy' , '0.5em' )
152
- . attr ( 'x' , function ( d ) {
157
+ . attr ( 'x' , function ( d : { x : number ; children ?: [ ] } ) {
153
158
// this positions how far the text is from leaf nodes (ones without children)
154
159
// negative number before the colon moves the text of rightside nodes,
155
160
// positive number moves the text for the leftside nodes
156
161
return d . x < Math . PI === ! d . children ? 0 : 0 ;
157
162
} )
158
163
. attr ( 'text-anchor' , 'middle' )
159
164
// this arranges the angle of the text
160
- . attr ( 'transform' , function ( d ) { return 'rotate(' + ( d . x < Math . PI ? d . x - Math . PI / 2 : d . x + Math . PI / 2 ) * 1 / Math . PI + ')' ; } )
161
- . text ( function ( d ) {
165
+ . attr ( 'transform' , function ( d : { x : number , y : number } ) { return 'rotate(' + ( d . x < Math . PI ? d . x - Math . PI / 2 : d . x + Math . PI / 2 ) * 1 / Math . PI + ')' ; } )
166
+ . text ( function ( d : { data : { name : number , branch : number } } ) {
162
167
// gabi and nate :: display the name of of specific patch
163
168
return `${ d . data . name } .${ d . data . branch } ` ;
164
169
} ) ;
@@ -179,7 +184,7 @@ class Chart extends Component {
179
184
g . attr ( 'cursor' , 'grabbing' ) ;
180
185
}
181
186
182
- function dragged ( d ) {
187
+ function dragged ( d : { x : number , y : number } ) {
183
188
d3 . select ( this ) . attr ( 'dx' , d . x = d3 . event . x ) . attr ( 'dy' , d . y = d3 . event . y ) ;
184
189
}
185
190
@@ -196,7 +201,7 @@ class Chart extends Component {
196
201
. attr ( 'class' , 'tooltip' )
197
202
. style ( 'opacity' , 0 ) ;
198
203
199
- function reinfeldTidierAlgo ( x , y ) {
204
+ function reinfeldTidierAlgo ( x : number , y : number ) {
200
205
return [ ( y = + y ) * Math . cos ( x -= Math . PI / 2 ) , y * Math . sin ( x ) ] ;
201
206
}
202
207
}
0 commit comments