@@ -12,27 +12,26 @@ const Map = (props) => {
12
12
const { snapshot, snapshots } = props ;
13
13
const lastSnap = snapshots . length - 1 ;
14
14
15
- let width = 1800 ;
16
- let height = 900 ;
17
- let margin = { top : 10 , right : 120 , bottom : 10 , left : 120 } ;
18
- let dy = 100 ;
19
- let dx = 76 ;
20
- let data = snapshots [ lastSnap ] ;
21
- let tree = d3 . tree ( ) . nodeSize ( [ dx , dy ] ) ;
22
- let diagonal = d3
15
+ const width = 2000 ;
16
+ const height = 600 ;
17
+ const margin = { top : 10 , right : 120 , bottom : 10 , left : 120 } ;
18
+ const dy = 100 ;
19
+ const dx = 76 ;
20
+ const data = snapshots [ lastSnap ] ;
21
+ const tree = d3 . tree ( ) . nodeSize ( [ dx , dy ] ) ;
22
+ const diagonal = d3
23
23
. linkHorizontal ( )
24
24
. x ( ( d ) => d . y )
25
25
. y ( ( d ) => d . x ) ;
26
26
27
27
28
28
29
29
useEffect ( ( ) => {
30
-
30
+ document . getElementById ( 'canvas' ) . innerHTML = '_' ;
31
31
return makeChart ( ) ;
32
32
} ) ;
33
33
34
34
const makeChart = ( ) => {
35
- document . getElementById ( 'canvas' ) . innerHTML = '' ;
36
35
37
36
const root = d3 . hierarchy ( data ) ;
38
37
@@ -41,23 +40,13 @@ const Map = (props) => {
41
40
root . descendants ( ) . forEach ( ( d , i ) => {
42
41
d . id = i ;
43
42
d . _children = d . children ;
44
- // if (d.depth && d.data.name.length !== 7 ) d.children = null;
43
+ if ( d . depth === 9 ) d . children = null ;
45
44
} ) ;
46
45
47
46
console . log ( "root" , root )
48
- // const svgContainer: any = d3
49
- // .select('#canvas')
50
- // .attr('width', width)
51
- // .attr('height', height);
52
-
53
- // const svg = d3
54
- // .create('svg')
55
- // .attr('viewBox', [-margin.left, -margin.top, width, dx])
56
- // .style('font', '10px sans-serif')
57
- // .style('user-select', 'none');
58
-
47
+
59
48
const svg = d3
60
- . select ( '#canvas' )
49
+ . select ( '#canvas' )
61
50
. attr ( 'width' , width )
62
51
. attr ( 'height' , height )
63
52
// .attr('viewBox', [-margin.left, -margin.top, width, dx])
@@ -68,7 +57,7 @@ const Map = (props) => {
68
57
. append ( 'g' )
69
58
. attr ( 'fill' , 'none' )
70
59
. attr ( 'stroke' , '#555' )
71
- . attr ( 'stroke-opacity' , 0.4 )
60
+ . attr ( 'stroke-opacity' , 0.9 )
72
61
. attr ( 'stroke-width' , 1.5 ) ;
73
62
74
63
const gNode = svg
@@ -92,7 +81,7 @@ const Map = (props) => {
92
81
if ( node . x > right . x ) right = node ;
93
82
} ) ;
94
83
95
- const height = right . x - left . x + margin . top + margin . bottom ;
84
+ const height = right . x - left . x + margin . top + margin . bottom ;
96
85
97
86
const transition = svg
98
87
. transition ( )
@@ -109,7 +98,7 @@ const Map = (props) => {
109
98
. append ( 'g' )
110
99
. attr ( 'transform' , ( d ) => `translate(${ source . y0 } ,${ source . x0 } )` )
111
100
. attr ( 'fill-opacity' , 0 )
112
- . attr ( 'stroke-linejoin' , 'round' )
101
+ // .attr('stroke-linejoin', 'round')
113
102
. attr ( 'stroke-opacity' , 1 )
114
103
. on ( 'click' , ( d ) => {
115
104
d . children = d . children ? null : d . _children ;
@@ -118,10 +107,11 @@ const Map = (props) => {
118
107
119
108
nodeEnter
120
109
. append ( 'circle' )
121
- . attr ( 'r' , 15 )
110
+ . attr ( 'r' , 10 )
122
111
. attr ( 'fill' , ( d ) => ( d . _children ? '#46edf2' : '#95B6B7' ) )
123
- . attr ( 'stroke-linejoin' , 'round' )
124
- . attr ( 'stroke-width' , 10 ) ;
112
+ //.attr('stroke-linejoin', 'round')
113
+ . attr ( 'stroke-width' , 10 )
114
+ . attr ( 'stroke-opacity' , 1 ) ;
125
115
126
116
127
117
nodeEnter
@@ -130,15 +120,15 @@ const Map = (props) => {
130
120
. attr ( 'x' , ( d : any ) => ( d . children ? - 50 : 50 ) )
131
121
. attr ( 'text-anchor' , ( d : any ) => ( d . children ? 'end' : 'start' ) )
132
122
. text ( ( d : any ) => d . data . name )
133
- . style ( 'font-size' , `1rem ` )
123
+ . style ( 'font-size' , `.8rem ` )
134
124
. style ( 'fill' , 'white' )
135
125
. clone ( true )
136
126
. lower ( )
127
+ . attr ( "stroke-linejoin" , "round" )
137
128
. attr ( 'stroke' , '#646464' )
138
129
. attr ( 'stroke-width' , 2 ) ;
139
130
140
131
141
- console . log ( "119" )
142
132
// Transition nodes to their new position.
143
133
const nodeUpdate = node
144
134
. merge ( nodeEnter )
@@ -163,7 +153,7 @@ const Map = (props) => {
163
153
const linkEnter = link
164
154
. enter ( )
165
155
. append ( 'path' )
166
- . selectAll ( 'path' )
156
+ // .selectAll('path')
167
157
. attr ( 'd' , ( d ) => {
168
158
const o = { x : source . x0 , y : source . y0 } ;
169
159
return diagonal ( { source : o , target : o } ) ;
@@ -187,6 +177,9 @@ const Map = (props) => {
187
177
d . x0 = d . x ;
188
178
d . y0 = d . y ;
189
179
} ) ;
180
+
181
+ }
182
+
190
183
//______________ZOOM______________\\
191
184
192
185
// Sets starting zoom but breaks keeping currents zoom on state change
@@ -198,20 +191,19 @@ const Map = (props) => {
198
191
// d3.zoomIdentity.translate(150, 250).scale(0.2)
199
192
// );
200
193
201
- // allows the canvas to be zoom-able
194
+ // allows the canvas to be zoom-able
202
195
svg . call (
203
196
d3
204
197
. zoom ( )
205
- . scaleExtent ( [ 0.05 , 0.9 ] ) // [zoomOut, zoomIn]
198
+ . scaleExtent ( [ 0.15 , 1.5 ] ) // [zoomOut, zoomIn]
206
199
. on ( 'zoom' , zoomed )
207
200
) ;
208
201
function zoomed ( d : any ) {
209
202
svg . attr ( 'transform' , d3 . event . transform ) ;
210
203
}
211
204
212
- //_____________DRAG_____________\\
213
- // allows the canvas to be draggable
214
- svg . call (
205
+ // allows the canvas to be draggable
206
+ svg . call (
215
207
d3
216
208
. drag ( )
217
209
. on ( 'start' , dragStarted )
@@ -221,7 +213,7 @@ const Map = (props) => {
221
213
222
214
function dragStarted ( ) : any {
223
215
d3 . select ( this ) . raise ( ) ;
224
- svg . attr ( 'cursor' , 'grabbing' ) ;
216
+ svg . attr ( 'cursor' , 'grabbing' ) ;
225
217
}
226
218
function dragged ( d : any ) : any {
227
219
d3 . select ( this )
@@ -231,8 +223,8 @@ const Map = (props) => {
231
223
function dragEnded ( ) : any {
232
224
svg . attr ( 'cursor' , 'grab' ) ;
233
225
}
234
- }
235
-
226
+
227
+
236
228
237
229
update ( root ) ;
238
230
} ;
@@ -390,12 +382,10 @@ const Map = (props) => {
390
382
// }
391
383
// });
392
384
393
- console . log ( "Return" )
394
385
return (
395
386
< div data-testid = "canvas" >
396
387
397
388
< svg id = "canvas" > </ svg >
398
- hi
399
389
</ div >
400
390
401
391
) ;
0 commit comments