@@ -29,6 +29,14 @@ const defaultMargin: DefaultMargin = {
29
29
bottom : 70 ,
30
30
} ;
31
31
32
+ let stepHeight : number = 0 ;
33
+ const nodeCoords : object = { } ;
34
+ let count : number = 0 ;
35
+ let aspect : number = 1 ;
36
+ let nodeCoordTier = 0 ;
37
+ let nodeOneLeft = 0 ;
38
+ let nodeTwoLeft = 2 ;
39
+
32
40
export default function ComponentMap ( {
33
41
// imported props to be used to display the dendrogram
34
42
width : totalWidth ,
@@ -127,7 +135,7 @@ export default function ComponentMap({
127
135
} ;
128
136
129
137
const formatRenderTime : string = ( time : number ) : string => {
130
- const renderTime = time . toFixed ( 3 ) ;
138
+ const renderTime = parseFloat ( time ) . toFixed ( 3 ) ;
131
139
return `${ renderTime } ms ` ;
132
140
} ;
133
141
@@ -189,21 +197,25 @@ export default function ComponentMap({
189
197
setSelectedNode = { setSelectedNode }
190
198
/>
191
199
192
- < svg ref = { containerRef } width = { totalWidth } height = { totalHeight } >
200
+ < svg
201
+ ref = { containerRef }
202
+ width = { totalWidth / aspect }
203
+ height = { ( totalHeight + stepHeight ) / aspect }
204
+ >
193
205
< LinearGradient id = 'links-gradient' from = '#e75e62' to = '#f00008' />
194
206
< rect
195
207
onClick = { ( ) => {
196
208
hideTooltip ( ) ;
197
209
} }
198
- width = { totalWidth }
199
- height = { totalHeight }
210
+ width = { totalWidth / aspect }
211
+ height = { ( totalHeight + stepHeight ) / aspect }
200
212
rx = { 14 }
201
213
fill = '#242529'
202
214
/>
203
- < Group top = { margin . top } left = { margin . left } >
215
+ < Group transform = { `scale( ${ aspect } )` } top = { margin . top } left = { margin . left } >
204
216
< Tree
205
217
root = { hierarchy ( startNode , ( d ) => ( d . isExpanded ? d . children : null ) ) }
206
- size = { [ sizeWidth , sizeHeight ] }
218
+ size = { [ sizeWidth / aspect , ( sizeHeight + stepHeight ) / aspect ] }
207
219
separation = { ( a , b ) => ( a . parent === b . parent ? 1 : 0.5 ) / a . depth }
208
220
>
209
221
{ ( tree ) => (
@@ -213,7 +225,7 @@ export default function ComponentMap({
213
225
key = { i }
214
226
data = { link }
215
227
percent = { stepPercent }
216
- stroke = '#F00008 '
228
+ stroke = '#FFFFFF '
217
229
strokeWidth = '1'
218
230
fill = 'none'
219
231
/>
@@ -245,19 +257,87 @@ export default function ComponentMap({
245
257
left = node . y ;
246
258
}
247
259
260
+ count < nodeList . length
261
+ ? ! nodeCoords [ top ]
262
+ ? ( nodeCoords [ top ] = [ left - width / 2 , left + width / 2 ] )
263
+ : nodeCoords [ top ] . push ( left - width / 2 , left + width / 2 )
264
+ : null ;
265
+ count ++ ;
266
+
267
+ //check if the node coordinate object has been constructed
268
+ if ( count === nodeList . length ) {
269
+ //check if there is still a tier of the node tree to collision check
270
+ while ( Object . values ( nodeCoords ) [ nodeCoordTier ] ) {
271
+ //check if there are atleast two nodes on the current tier
272
+ if (
273
+ Object . values ( nodeCoords ) [ nodeCoordTier ] [ nodeOneLeft ] &&
274
+ Object . values ( nodeCoords ) [ nodeCoordTier ] [ nodeTwoLeft ]
275
+ ) {
276
+ //check if the left side of the righthand node is to the right of the right side of the lefthand node (i.e. collision)
277
+ if (
278
+ Object . values ( nodeCoords ) [ nodeCoordTier ] [ nodeTwoLeft ] <
279
+ Object . values ( nodeCoords ) [ nodeCoordTier ] [ nodeOneLeft + 1 ]
280
+ ) {
281
+ //check if the visible percentage of the left hand node is less than the current lowest (this will be used to resize and rescale the map)
282
+ if (
283
+ Math . abs (
284
+ Object . values ( nodeCoords ) [ nodeCoordTier ] [ nodeTwoLeft ] -
285
+ Object . values ( nodeCoords ) [ nodeCoordTier ] [ nodeOneLeft ] ,
286
+ ) /
287
+ Math . abs (
288
+ Object . values ( nodeCoords ) [ nodeCoordTier ] [ nodeOneLeft + 1 ] -
289
+ Object . values ( nodeCoords ) [ nodeCoordTier ] [ nodeOneLeft ] ,
290
+ ) <
291
+ aspect
292
+ ) {
293
+ console . log ( aspect ) ;
294
+ //assign a new lowest percentage if one is found
295
+ aspect =
296
+ Math . abs (
297
+ Object . values ( nodeCoords ) [ nodeCoordTier ] [ nodeTwoLeft ] -
298
+ Object . values ( nodeCoords ) [ nodeCoordTier ] [ nodeOneLeft ] ,
299
+ ) /
300
+ Math . abs (
301
+ Object . values ( nodeCoords ) [ nodeCoordTier ] [ nodeOneLeft + 1 ] -
302
+ Object . values ( nodeCoords ) [ nodeCoordTier ] [ nodeOneLeft ] ,
303
+ ) ;
304
+ }
305
+ //move the node pointers down the list after checking the current overlap percentage
306
+ else {
307
+ nodeOneLeft += 2 ;
308
+ nodeTwoLeft += 2 ;
309
+ }
310
+ }
311
+ //move the node pointers if no collision is found
312
+ else {
313
+ nodeOneLeft += 2 ;
314
+ nodeTwoLeft += 2 ;
315
+ }
316
+ }
317
+ //move to the next tier of the node tree if done checking the current one
318
+ else {
319
+ nodeOneLeft = 0 ;
320
+ nodeTwoLeft = 2 ;
321
+ nodeCoordTier ++ ;
322
+ }
323
+ }
324
+ } else {
325
+ null ;
326
+ }
327
+
248
328
// mousing controls & Tooltip display logic
249
- const handleMouseAndClickOver : void = ( event ) => {
250
- const coords = localPoint ( event . target . ownerSVGElement , event ) ;
251
- const tooltipObj = { ...node . data } ;
252
-
253
- showTooltip ( {
254
- tooltipLeft : coords . x ,
255
- tooltipTop : coords . y ,
256
- tooltipData : tooltipObj ,
257
- // this is where the data for state and render time is displayed
258
- // but does not show props functions and etc
259
- } ) ;
260
- } ;
329
+ // const handleMouseAndClickOver: void = (event) => {
330
+ // const coords = localPoint(event.target.ownerSVGElement, event);
331
+ // const tooltipObj = { ...node.data };
332
+
333
+ // showTooltip({
334
+ // tooltipLeft: coords.x,
335
+ // tooltipTop: coords.y,
336
+ // tooltipData: tooltipObj,
337
+ // // this is where the data for state and render time is displayed
338
+ // // but does not show props functions and etc
339
+ // });
340
+ // };
261
341
262
342
return (
263
343
< Group top = { top } left = { left } key = { key } className = 'rect' >
@@ -344,6 +424,7 @@ export default function ComponentMap({
344
424
</ Group >
345
425
) ;
346
426
} ) }
427
+ { console . log ( nodeCoords ) }
347
428
</ Group >
348
429
) }
349
430
</ Tree >
0 commit comments