1
1
import React , { Component , useEffect , useState } from 'react' ;
2
2
import * as d3 from 'd3' ;
3
+ import LegendKey from './legend' ;
4
+ import { changeView , changeSlider } from '../actions/actions' ;
5
+ // import { useStoreContext } from '../store';
6
+ // import { string } from 'prop-types';
7
+ import { Zoom } from '@visx/zoom' ;
8
+ import { localPoint } from '@visx/event' ;
9
+ import { RectClipPath } from '@visx/clip-path' ;
10
+ // import ZoomI from './zoomFt';
11
+
12
+ // const colorScale = scaleLinear<number>({ range: [0, 1], domain: [0, 1000] });
13
+ // const sizeScale = scaleLinear<number>({ domain: [0, 600], range: [0.5, 8] });
14
+
15
+ const initialTransform = {
16
+ scaleX : 1.27 ,
17
+ scaleY : 1.27 ,
18
+ translateX : - 211.62 ,
19
+ translateY : 162.59 ,
20
+ skewX : 0 ,
21
+ skewY : 0 ,
22
+ } ;
3
23
4
24
/**
5
25
* @var colors: Colors array for the diffrerent node branches, each color is for a different branch
@@ -34,10 +54,17 @@ const filterHooks = (data: any[]) => {
34
54
* @method maked3Tree :Creates a new D3 Tree
35
55
*/
36
56
37
- function History ( props ) {
38
- let { hierarchy } = props ;
57
+ function History ( props : any ) {
58
+ //visx zoom first
59
+ const [ showMiniMap , setShowMiniMap ] = useState < boolean > ( true ) ;
60
+
61
+ const { width, height, hierarchy, dispatch, sliderIndex, viewIndex } = props ;
62
+ console . log (
63
+ `inside History tab -> width is ${ width } and height is ${ height } `
64
+ ) ;
39
65
let root = JSON . parse ( JSON . stringify ( hierarchy ) ) ;
40
66
let isRecoil = false ;
67
+ // console.log('before makedTree, hierarchy is, ', hierarchy);
41
68
let HistoryRef = React . createRef ( root ) ; //React.createRef(root);
42
69
useEffect ( ( ) => {
43
70
maked3Tree ( ) ;
@@ -72,7 +99,7 @@ function History(props) {
72
99
// d3.hierarchy constructs a root node from the specified hierarchical data
73
100
// (our object titled dataset), which must be an object representing the root node
74
101
const hierarchy = d3 . hierarchy ( root ) ;
75
-
102
+ // console.log('after maked3tree, hierarchy is now: ', hierarchy);
76
103
const tree = d3
77
104
. tree ( )
78
105
. nodeSize ( [ width / 10 , height / 10 ] )
@@ -134,43 +161,24 @@ function History(props) {
134
161
return 'translate(' + reinfeldTidierAlgo ( d . x , d . y ) + ')' ;
135
162
} ) ;
136
163
164
+ // here we the node circle is created and given a radius size, we are also giving it a mouseover and onClick functionality
165
+ // mouseover will highlight the node while onClick will dispatch changeSlider and changeView actions. This will act as a timeJump request.
166
+ //
137
167
node
138
168
. append ( 'circle' )
139
- . attr ( 'r' , 15 )
140
- . on ( 'mouseover' , function ( d : any ) {
141
- d3 . select ( this ) . transition ( 100 ) . duration ( 20 ) . attr ( 'r' , 25 ) ;
142
-
143
- tooltipDiv . transition ( ) . duration ( 50 ) . style ( 'opacity' , 0.9 ) ;
144
-
145
- if ( d . data . stateSnapshot . children [ 0 ] . name === 'RecoilRoot' ) {
146
- isRecoil = true ;
147
- }
148
- if ( ! isRecoil ) {
149
- tooltipDiv
150
- . html ( filterHooks ( d . data . stateSnapshot . children ) , this )
151
- . style ( 'left' , d3 . event . pageX - 90 + 'px' )
152
- . style ( 'top' , d3 . event . pageY - 65 + 'px' ) ;
153
- } else {
154
- tooltipDiv
155
- . html (
156
- 'Load Time : ' +
157
- JSON . stringify (
158
- d . data . stateSnapshot . children [ 0 ] . componentData . actualDuration
159
- ) . substring ( 0 , 5 ) +
160
- ' ms' ,
161
- this
162
- )
163
- . style ( 'left' , d3 . event . pageX - 90 + 'px' )
164
- . style ( 'top' , d3 . event . pageY - 65 + 'px' ) ;
165
- }
169
+ . attr ( 'r' , 13 )
170
+ . on ( 'mouseover' , function ( d : `Record<string, unknown>`) {
171
+ d3 . select ( this ) . transition ( 100 ) . duration ( 20 ) . attr ( 'r' , 20 ) ;
172
+ } )
173
+ . on ( 'click' , function ( d : `Record<string, unknown>`) {
174
+ const index = parseInt ( `${ d . data . name } .${ d . data . branch } ` ) ;
175
+ dispatch ( changeSlider ( index ) ) ;
176
+ dispatch ( changeView ( index ) ) ;
166
177
} )
167
- // eslint-disable-next-line no-unused-vars
168
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
169
178
. on ( 'mouseout' , function ( d : any ) {
170
- d3 . select ( this ) . transition ( ) . duration ( 300 ) . attr ( 'r' , 15 ) ;
171
-
172
- tooltipDiv . transition ( ) . duration ( 400 ) . style ( 'opacity' , 0 ) ;
179
+ d3 . select ( this ) . transition ( ) . duration ( 300 ) . attr ( 'r' , 13 ) ;
173
180
} ) ;
181
+
174
182
node
175
183
. append ( 'text' )
176
184
// adjusts the y coordinates for the node text
@@ -193,6 +201,7 @@ function History(props) {
193
201
} )
194
202
. text ( function ( d : { data : { name : number ; branch : number } } ) {
195
203
// display the name of the specific patch
204
+ // return `${d.data.name}.${d.data.branch}`;
196
205
return `${ d . data . name } .${ d . data . branch } ` ;
197
206
} ) ;
198
207
@@ -201,7 +210,7 @@ function History(props) {
201
210
svgContainer . call (
202
211
zoom . transform ,
203
212
// Changes the initial view, (left, top)
204
- d3 . zoomIdentity . translate ( width / 2 , height / 2 ) . scale ( 1 )
213
+ d3 . zoomIdentity . translate ( width / 3 , height / 4 ) . scale ( 1 )
205
214
) ;
206
215
// allows the canvas to be zoom-able
207
216
svgContainer . call (
@@ -250,10 +259,21 @@ function History(props) {
250
259
return [ ( y = + y ) * Math . cos ( ( x -= Math . PI / 2 ) ) , y * Math . sin ( x ) ] ;
251
260
}
252
261
} ;
262
+ // console.log('have we hit maked3dtree');
263
+ // below we are rendering the LegendKey component and passing hierarchy as props
264
+ // then rendering each node in History tab to render using D3
253
265
254
266
return (
255
267
< >
256
- < div ref = { HistoryRef } className = "history-d3-div" id = "historyContainer" />
268
+ < div >
269
+ < LegendKey hierarchy = { hierarchy } />
270
+ < div
271
+ ref = { HistoryRef }
272
+ className = "history-d3-div"
273
+ id = "historyContainer"
274
+ // position="absolute"
275
+ />
276
+ </ div >
257
277
</ >
258
278
) ;
259
279
}
0 commit comments