11import React , { Component , useEffect , useState } from 'react' ;
22import * 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+ } ;
323
424/**
525 * @var colors: Colors array for the diffrerent node branches, each color is for a different branch
@@ -34,10 +54,17 @@ const filterHooks = (data: any[]) => {
3454 * @method maked3Tree :Creates a new D3 Tree
3555 */
3656
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+ ) ;
3965 let root = JSON . parse ( JSON . stringify ( hierarchy ) ) ;
4066 let isRecoil = false ;
67+ // console.log('before makedTree, hierarchy is, ', hierarchy);
4168 let HistoryRef = React . createRef ( root ) ; //React.createRef(root);
4269 useEffect ( ( ) => {
4370 maked3Tree ( ) ;
@@ -72,7 +99,7 @@ function History(props) {
7299 // d3.hierarchy constructs a root node from the specified hierarchical data
73100 // (our object titled dataset), which must be an object representing the root node
74101 const hierarchy = d3 . hierarchy ( root ) ;
75-
102+ // console.log('after maked3tree, hierarchy is now: ', hierarchy);
76103 const tree = d3
77104 . tree ( )
78105 . nodeSize ( [ width / 10 , height / 10 ] )
@@ -134,43 +161,24 @@ function History(props) {
134161 return 'translate(' + reinfeldTidierAlgo ( d . x , d . y ) + ')' ;
135162 } ) ;
136163
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+ //
137167 node
138168 . 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 ) ) ;
166177 } )
167- // eslint-disable-next-line no-unused-vars
168- // eslint-disable-next-line @typescript-eslint/no-unused-vars
169178 . 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 ) ;
173180 } ) ;
181+
174182 node
175183 . append ( 'text' )
176184 // adjusts the y coordinates for the node text
@@ -193,6 +201,7 @@ function History(props) {
193201 } )
194202 . text ( function ( d : { data : { name : number ; branch : number } } ) {
195203 // display the name of the specific patch
204+ // return `${d.data.name}.${d.data.branch}`;
196205 return `${ d . data . name } .${ d . data . branch } ` ;
197206 } ) ;
198207
@@ -201,7 +210,7 @@ function History(props) {
201210 svgContainer . call (
202211 zoom . transform ,
203212 // 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 )
205214 ) ;
206215 // allows the canvas to be zoom-able
207216 svgContainer . call (
@@ -250,10 +259,21 @@ function History(props) {
250259 return [ ( y = + y ) * Math . cos ( ( x -= Math . PI / 2 ) ) , y * Math . sin ( x ) ] ;
251260 }
252261 } ;
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
253265
254266 return (
255267 < >
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 >
257277 </ >
258278 ) ;
259279}
0 commit comments