@@ -2,24 +2,6 @@ import React, { Component, useEffect, useState } from 'react';
22import * as d3 from 'd3' ;
33import LegendKey from './legend' ;
44import { 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- } ;
235
246/**
257 * @var colors: Colors array for the diffrerent node branches, each color is for a different branch
@@ -54,17 +36,14 @@ const filterHooks = (data: any[]) => {
5436 * @method maked3Tree :Creates a new D3 Tree
5537 */
5638
57- function History ( props : any ) {
58- //visx zoom first
59- const [ showMiniMap , setShowMiniMap ] = useState < boolean > ( true ) ;
60-
39+ // main function exported to StateRoute
40+ // below we destructure the props
41+ function History ( props : Record < string , unknown > ) {
6142 const { width, height, hierarchy, dispatch, sliderIndex, viewIndex } = props ;
62- console . log (
63- `inside History tab -> width is ${ width } and height is ${ height } `
64- ) ;
43+
6544 let root = JSON . parse ( JSON . stringify ( hierarchy ) ) ;
6645 let isRecoil = false ;
67- // console.log('before makedTree, hierarchy is, ', hierarchy);
46+
6847 let HistoryRef = React . createRef ( root ) ; //React.createRef(root);
6948 useEffect ( ( ) => {
7049 maked3Tree ( ) ;
@@ -83,8 +62,8 @@ function History(props: any) {
8362 */
8463 let maked3Tree = function ( ) {
8564 removed3Tree ( ) ;
86- const width : any = 800 ;
87- const height : any = 600 ;
65+ const width : number = 800 ;
66+ const height : number = 600 ;
8867 const svgContainer = d3
8968 . select ( HistoryRef . current )
9069 . append ( 'svg' ) // svgContainer is now pointing to svg
@@ -99,7 +78,6 @@ function History(props: any) {
9978 // d3.hierarchy constructs a root node from the specified hierarchical data
10079 // (our object titled dataset), which must be an object representing the root node
10180 const hierarchy = d3 . hierarchy ( root ) ;
102- // console.log('after maked3tree, hierarchy is now: ', hierarchy);
10381 const tree = d3
10482 . tree ( )
10583 . nodeSize ( [ width / 10 , height / 10 ] )
@@ -162,21 +140,23 @@ function History(props: any) {
162140 } ) ;
163141
164142 // 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- //
143+ // mouseover will highlight the node
144+ // the onCLick of a selected node will dispatch changeSlider and changeView actions. This will act as a timeJump request.
145+ // further optimization would improve the onclick feature, onclick seems to only register on the lower half of the node
167146 node
168147 . append ( 'circle' )
169- . attr ( 'r' , 13 )
148+ . attr ( 'r' , 14 )
170149 . on ( 'mouseover' , function ( d : `Record<string, unknown>`) {
171- d3 . select ( this ) . transition ( 100 ) . duration ( 20 ) . attr ( 'r' , 20 ) ;
150+ d3 . select ( this ) . transition ( 90 ) . duration ( 18 ) . attr ( 'r' , 21 ) ;
172151 } )
173152 . on ( 'click' , function ( d : `Record<string, unknown>`) {
174153 const index = parseInt ( `${ d . data . name } .${ d . data . branch } ` ) ;
175154 dispatch ( changeSlider ( index ) ) ;
176155 dispatch ( changeView ( index ) ) ;
177156 } )
157+ // think about how I can convert this any to typescript
178158 . on ( 'mouseout' , function ( d : any ) {
179- d3 . select ( this ) . transition ( ) . duration ( 300 ) . attr ( 'r' , 13 ) ;
159+ d3 . select ( this ) . transition ( ) . duration ( 300 ) . attr ( 'r' , 14 ) ;
180160 } ) ;
181161
182162 node
@@ -219,7 +199,7 @@ function History(props: any) {
219199 . scaleExtent ( [ 0 , 0.9 ] ) // [zoomOut, zoomIn]
220200 . on ( 'zoom' , zoomed )
221201 ) ;
222- // helper function that allows for zooming
202+ // helper function that allows for zooming ( think about how I can convert this any to typescript)
223203 function zoomed ( d : any ) {
224204 g . attr ( 'transform' , d3 . event . transform ) ;
225205 }
@@ -259,10 +239,9 @@ function History(props: any) {
259239 return [ ( y = + y ) * Math . cos ( ( x -= Math . PI / 2 ) ) , y * Math . sin ( x ) ] ;
260240 }
261241 } ;
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
265242
243+ // below we are rendering the LegendKey component and passing hierarchy as props
244+ // then rendering each node in History tab to render using D3, which will share area with LegendKey
266245 return (
267246 < >
268247 < div >
0 commit comments