@@ -29,6 +29,14 @@ const defaultMargin: DefaultMargin = {
2929 bottom : 70 ,
3030} ;
3131
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+
3240export default function ComponentMap ( {
3341 // imported props to be used to display the dendrogram
3442 width : totalWidth ,
@@ -127,7 +135,7 @@ export default function ComponentMap({
127135 } ;
128136
129137 const formatRenderTime : string = ( time : number ) : string => {
130- const renderTime = time . toFixed ( 3 ) ;
138+ const renderTime = parseFloat ( time ) . toFixed ( 3 ) ;
131139 return `${ renderTime } ms ` ;
132140 } ;
133141
@@ -189,21 +197,25 @@ export default function ComponentMap({
189197 setSelectedNode = { setSelectedNode }
190198 />
191199
192- < svg ref = { containerRef } width = { totalWidth } height = { totalHeight } >
200+ < svg
201+ ref = { containerRef }
202+ width = { totalWidth / aspect }
203+ height = { ( totalHeight + stepHeight ) / aspect }
204+ >
193205 < LinearGradient id = 'links-gradient' from = '#e75e62' to = '#f00008' />
194206 < rect
195207 onClick = { ( ) => {
196208 hideTooltip ( ) ;
197209 } }
198- width = { totalWidth }
199- height = { totalHeight }
210+ width = { totalWidth / aspect }
211+ height = { ( totalHeight + stepHeight ) / aspect }
200212 rx = { 14 }
201213 fill = '#242529'
202214 />
203- < Group top = { margin . top } left = { margin . left } >
215+ < Group transform = { `scale( ${ aspect } )` } top = { margin . top } left = { margin . left } >
204216 < Tree
205217 root = { hierarchy ( startNode , ( d ) => ( d . isExpanded ? d . children : null ) ) }
206- size = { [ sizeWidth , sizeHeight ] }
218+ size = { [ sizeWidth / aspect , ( sizeHeight + stepHeight ) / aspect ] }
207219 separation = { ( a , b ) => ( a . parent === b . parent ? 1 : 0.5 ) / a . depth }
208220 >
209221 { ( tree ) => (
@@ -213,7 +225,7 @@ export default function ComponentMap({
213225 key = { i }
214226 data = { link }
215227 percent = { stepPercent }
216- stroke = '#F00008 '
228+ stroke = '#FFFFFF '
217229 strokeWidth = '1'
218230 fill = 'none'
219231 />
@@ -245,19 +257,87 @@ export default function ComponentMap({
245257 left = node . y ;
246258 }
247259
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+
248328 // 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+ // };
261341
262342 return (
263343 < Group top = { top } left = { left } key = { key } className = 'rect' >
@@ -344,6 +424,7 @@ export default function ComponentMap({
344424 </ Group >
345425 ) ;
346426 } ) }
427+ { console . log ( nodeCoords ) }
347428 </ Group >
348429 ) }
349430 </ Tree >
0 commit comments