1
+ /* eslint-disable react-hooks/exhaustive-deps */
1
2
// @ts -nocheck
2
3
import React , { Component , useEffect , useState } from 'react' ;
3
4
import * as d3 from 'd3' ;
@@ -7,10 +8,10 @@ import { changeView, changeSlider } from '../actions/actions';
7
8
* @var colors: Colors array for the diffrerent node branches, each color is for a different branch
8
9
*/
9
10
const colors = [
10
- '#eb4d70' ,
11
- '#f19938' ,
12
- '#6ce18b' ,
13
- '#78f6ef' ,
11
+ '#eb4d70' ,
12
+ '#f19938' ,
13
+ '#6ce18b' ,
14
+ '#78f6ef' ,
14
15
'#9096f8' ,
15
16
'#C5B738' ,
16
17
'#858DFF' ,
@@ -39,17 +40,19 @@ const filterHooks = (data: any[]) => {
39
40
// main function exported to StateRoute
40
41
// below we destructure the props
41
42
function History ( props : Record < string , unknown > ) {
42
- const { width, height, hierarchy, dispatch, sliderIndex, viewIndex } = props ;
43
+ const {
44
+ width, height, hierarchy, dispatch, sliderIndex, viewIndex,
45
+ } = props ;
43
46
44
- let root = JSON . parse ( JSON . stringify ( hierarchy ) ) ;
45
- let isRecoil = false ;
47
+ const root = JSON . parse ( JSON . stringify ( hierarchy ) ) ;
48
+ const isRecoil = false ;
46
49
47
- let HistoryRef = React . createRef ( root ) ;
50
+ const HistoryRef = React . createRef ( root ) ;
48
51
useEffect ( ( ) => {
49
52
maked3Tree ( ) ;
50
- } , [ root ] ) ;
53
+ } , [ maked3Tree , root ] ) ;
51
54
52
- let removed3Tree = function ( ) {
55
+ const removed3Tree = function ( ) {
53
56
const { current } = HistoryRef ;
54
57
while ( current . hasChildNodes ( ) ) {
55
58
current . removeChild ( current . lastChild ) ;
@@ -62,8 +65,8 @@ function History(props: Record<string, unknown>) {
62
65
*/
63
66
let maked3Tree = function ( ) {
64
67
removed3Tree ( ) ;
65
- const width : number = 800 ;
66
- const height : number = 600 ;
68
+ const width = 800 ;
69
+ const height = 600 ;
67
70
const svgContainer = d3
68
71
. select ( HistoryRef . current )
69
72
. append ( 'svg' ) // svgContainer is now pointing to svg
@@ -81,9 +84,7 @@ function History(props: Record<string, unknown>) {
81
84
const tree = d3
82
85
. tree ( )
83
86
. nodeSize ( [ width / 10 , height / 10 ] )
84
- . separation ( function ( a : { parent : object } , b : { parent : object } ) {
85
- return a . parent == b . parent ? 2 : 2 ;
86
- } ) ;
87
+ . separation ( ( a : { parent : object } , b : { parent : object } ) => ( a . parent == b . parent ? 2 : 2 ) ) ;
87
88
88
89
const d3root = tree ( hierarchy ) ;
89
90
@@ -101,7 +102,7 @@ function History(props: Record<string, unknown>) {
101
102
d3
102
103
. linkRadial ( )
103
104
. angle ( ( d : { x : number } ) => d . x )
104
- . radius ( ( d : { y : number } ) => d . y )
105
+ . radius ( ( d : { y : number } ) => d . y ) ,
105
106
) ;
106
107
107
108
const node = g
@@ -110,11 +111,10 @@ function History(props: Record<string, unknown>) {
110
111
. data ( d3root . descendants ( ) )
111
112
. enter ( )
112
113
. append ( 'g' )
113
- . style ( 'fill' , function ( d ) {
114
+ . style ( 'fill' , d => {
114
115
let loadTime ;
115
116
if ( d . data . stateSnapshot . children [ 0 ] . componentData . actualDuration ) {
116
- loadTime =
117
- d . data . stateSnapshot . children [ 0 ] . componentData . actualDuration ;
117
+ loadTime = d . data . stateSnapshot . children [ 0 ] . componentData . actualDuration ;
118
118
} else {
119
119
loadTime = 1 ;
120
120
}
@@ -135,9 +135,7 @@ function History(props: Record<string, unknown>) {
135
135
return colors [ indexColors ] ;
136
136
} )
137
137
. attr ( 'class' , 'node--internal' )
138
- . attr ( 'transform' , function ( d : { x : number ; y : number } ) {
139
- return 'translate(' + reinfeldTidierAlgo ( d . x , d . y ) + ')' ;
140
- } ) ;
138
+ . attr ( 'transform' , ( d : { x : number ; y : number } ) => `translate(${ reinfeldTidierAlgo ( d . x , d . y ) } )` ) ;
141
139
142
140
// here we the node circle is created and given a radius size, we are also giving it a mouseover and onClick functionality
143
141
// mouseover will highlight the node
@@ -146,10 +144,10 @@ function History(props: Record<string, unknown>) {
146
144
node
147
145
. append ( 'circle' )
148
146
. attr ( 'r' , 14 )
149
- . on ( 'mouseover' , function ( d : ` Record<string, unknown>` ) {
147
+ . on ( 'mouseover' , function ( d : ' Record<string, unknown>' ) {
150
148
d3 . select ( this ) . transition ( 90 ) . duration ( 18 ) . attr ( 'r' , 21 ) ;
151
149
} )
152
- . on ( 'click' , function ( d : ` Record<string, unknown>` ) {
150
+ . on ( 'click' , ( d : ' Record<string, unknown>' ) => {
153
151
const index = parseInt ( `${ d . data . name } .${ d . data . branch } ` ) ;
154
152
dispatch ( changeSlider ( index ) ) ;
155
153
dispatch ( changeView ( index ) ) ;
@@ -163,41 +161,37 @@ function History(props: Record<string, unknown>) {
163
161
. append ( 'text' )
164
162
// adjusts the y coordinates for the node text
165
163
. attr ( 'dy' , '0.5em' )
166
- . attr ( 'x' , function ( d : { x : number ; children ?: [ ] } ) {
164
+ . attr ( 'x' , ( d : { x : number ; children ?: [ ] } ) =>
167
165
// this positions how far the text is from leaf nodes (ones without children)
168
166
// negative number before the colon moves the text of rightside nodes,
169
167
// positive number moves the text for the leftside nodes
170
- return d . x < Math . PI === ! d . children ? 0 : 0 ;
171
- } )
168
+ ( d . x < Math . PI === ! d . children ? 0 : 0 ) )
172
169
. attr ( 'text-anchor' , 'middle' )
173
170
// this arranges the angle of the text
174
- . attr ( 'transform' , function ( d : { x : number ; y : number } ) {
175
- return (
176
- 'rotate(' +
177
- ( ( d . x < Math . PI ? d . x - Math . PI / 2 : d . x + Math . PI / 2 ) * 1 ) /
178
- Math . PI +
179
- ')'
180
- ) ;
181
- } )
182
- . text ( function ( d : { data : { name : number ; branch : number } } ) {
171
+ . attr ( 'transform' , ( d : { x : number ; y : number } ) => (
172
+ `rotate(${
173
+ ( ( d . x < Math . PI ? d . x - Math . PI / 2 : d . x + Math . PI / 2 ) * 1 )
174
+ / Math . PI
175
+ } )`
176
+ ) )
177
+ . text ( ( d : { data : { name : number ; branch : number } } ) =>
183
178
// display the name of the specific patch
184
179
// return `${d.data.name}.${d.data.branch}`;
185
- return `${ d . data . name } .${ d . data . branch } ` ;
186
- } ) ;
180
+ `${ d . data . name } .${ d . data . branch } ` ) ;
187
181
188
182
// Zoom Functions
189
- let zoom = d3 . zoom ( ) . on ( 'zoom' , zoomed ) ;
183
+ const zoom = d3 . zoom ( ) . on ( 'zoom' , zoomed ) ;
190
184
svgContainer . call (
191
185
zoom . transform ,
192
186
// Changes the initial view, (left, top)
193
- d3 . zoomIdentity . translate ( width / 3 , height / 4 ) . scale ( 1 )
187
+ d3 . zoomIdentity . translate ( width / 3 , height / 4 ) . scale ( 1 ) ,
194
188
) ;
195
189
// allows the canvas to be zoom-able
196
190
svgContainer . call (
197
191
d3
198
192
. zoom ( )
199
193
. scaleExtent ( [ 0 , 0.9 ] ) // [zoomOut, zoomIn]
200
- . on ( 'zoom' , zoomed )
194
+ . on ( 'zoom' , zoomed ) ,
201
195
) ;
202
196
// helper function that allows for zooming ( think about how I can convert this any to typescript)
203
197
function zoomed ( d : any ) {
@@ -210,7 +204,7 @@ function History(props: Record<string, unknown>) {
210
204
. drag ( )
211
205
. on ( 'start' , dragstarted )
212
206
. on ( 'drag' , dragged )
213
- . on ( 'end' , dragended )
207
+ . on ( 'end' , dragended ) ,
214
208
) ;
215
209
216
210
function dragstarted ( ) {
0 commit comments