@@ -30,27 +30,26 @@ const filterHooks = (data: any[]) => {
30
30
return JSON . stringify ( data [ 0 ] . state ) ;
31
31
} ;
32
32
33
- interface ChartProps {
33
+ interface HistoryProps {
34
34
hierarchy : Record < string , unknown > ;
35
35
}
36
36
37
37
let root = { } ;
38
- class Chart extends Component {
38
+ class History extends Component {
39
39
/**
40
40
* @method maked3Tree :Creates a new D3 Tree
41
41
*/
42
- constructor ( props : ChartProps ) {
42
+ constructor ( props : HistoryProps ) {
43
43
super ( props ) ;
44
44
// what React.createRef() is doing.
45
- this . chartRef = React . createRef ( ) ;
45
+ this . HistoryRef = React . createRef ( ) ;
46
46
this . maked3Tree = this . maked3Tree . bind ( this ) ;
47
47
this . removed3Tree = this . removed3Tree . bind ( this ) ;
48
48
this . isRecoil = false ;
49
49
}
50
50
51
51
componentDidMount ( ) {
52
52
const { hierarchy } = this . props ;
53
- console . log ( 'HIERARCHYYYYY' , hierarchy ) ;
54
53
root = JSON . parse ( JSON . stringify ( hierarchy ) ) ;
55
54
this . maked3Tree ( ) ;
56
55
}
@@ -62,23 +61,23 @@ class Chart extends Component {
62
61
}
63
62
64
63
removed3Tree ( ) {
65
- const { current } = this . chartRef ;
64
+ const { current } = this . HistoryRef ;
66
65
while ( current . hasChildNodes ( ) ) {
67
66
current . removeChild ( current . lastChild ) ;
68
67
}
69
68
}
70
69
71
70
/**
72
- * @method maked3Tree Creates a new Tree Chart
71
+ * @method maked3Tree Creates a new Tree History
73
72
* @var
74
73
*/
75
74
maked3Tree ( ) : void {
76
75
this . removed3Tree ( ) ;
77
-
78
- const width = 800 ;
79
- const height = 600 ;
76
+
77
+ const width = 800 ;
78
+ const height = 600 ;
80
79
const svgContainer = d3
81
- . select ( this . chartRef . current )
80
+ . select ( this . HistoryRef . current )
82
81
. append ( 'svg' ) // svgContainer is now pointing to svg
83
82
. attr ( 'width' , width )
84
83
. attr ( 'height' , height ) ;
@@ -88,19 +87,13 @@ class Chart extends Component {
88
87
// this is changing where the graph is located physically
89
88
. attr ( 'transform' , `translate(${ width / 2 + 4 } , ${ height / 2 + 2 } )` ) ;
90
89
91
- // if we consider the container for our radial node graph as a box encapsulating
92
- // half of this container width is essentially the radius of our radial node graph
93
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
94
- const radius = width / 2 ;
95
-
96
90
// d3.hierarchy constructs a root node from the specified hierarchical data
97
91
// (our object titled dataset), which must be an object representing the root node
98
92
const hierarchy = d3 . hierarchy ( root ) ;
99
93
100
94
const tree = d3
101
95
. tree ( )
102
- // this assigns width of tree to be 2pi
103
- // .size([2 * Math.PI, radius / 1.3])
96
+
104
97
. nodeSize ( [ width / 10 , height / 10 ] )
105
98
// .separation(function (a, b) { return (a.parent == b.parent ? 1 : 2) / a.depth; });
106
99
. separation ( function ( a : { parent : object } , b : { parent : object } ) {
@@ -227,21 +220,12 @@ class Chart extends Component {
227
220
return `${ d . data . name } .${ d . data . branch } ` ;
228
221
} ) ;
229
222
230
- // allows svg to be dragged around
231
- node . call (
232
- d3
233
- . drag ( )
234
- . on ( 'start' , dragstarted )
235
- . on ( 'drag' , dragged )
236
- . on ( 'end' , dragended )
237
- ) ;
238
-
239
- // d3 zoom functionality
223
+ // Zoom Functions
240
224
let zoom = d3 . zoom ( ) . on ( 'zoom' , zoomed ) ;
241
225
svgContainer . call (
242
226
zoom . transform ,
243
227
// Changes the initial view, (left, top)
244
- d3 . zoomIdentity . translate ( width / 2 , height / 2 ) . scale ( 1 )
228
+ d3 . zoomIdentity . translate ( width / 2 , height / 2 ) . scale ( 1 )
245
229
) ;
246
230
// allows the canvas to be zoom-able
247
231
svgContainer . call (
@@ -255,7 +239,15 @@ class Chart extends Component {
255
239
g . attr ( 'transform' , d3 . event . transform ) ;
256
240
}
257
241
258
- // Drag
242
+ // DRAG FUNCTIONS
243
+ node . call (
244
+ d3
245
+ . drag ( )
246
+ . on ( 'start' , dragstarted )
247
+ . on ( 'drag' , dragged )
248
+ . on ( 'end' , dragended )
249
+ ) ;
250
+
259
251
function dragstarted ( ) {
260
252
d3 . select ( this ) . raise ( ) ;
261
253
g . attr ( 'cursor' , 'grabbing' ) ;
@@ -286,10 +278,10 @@ class Chart extends Component {
286
278
render ( ) {
287
279
return (
288
280
< div className = "history-d3-container" >
289
- < div ref = { this . chartRef } className = "history-d3-div" />
281
+ < div ref = { this . HistoryRef } className = "history-d3-div" />
290
282
</ div >
291
283
) ;
292
284
}
293
285
}
294
286
295
- export default Chart ;
287
+ export default History ;
0 commit comments