11import React , { useState , useRef } from 'react' ;
2+ import { useDispatch , useSelector } from 'react-redux' ;
23import { Group } from '@visx/group' ;
34import { hierarchy , Tree } from '@visx/hierarchy' ;
45import { LinearGradient } from '@visx/gradient' ;
@@ -9,6 +10,9 @@ import { useTooltip, useTooltipInPortal, defaultStyles } from '@visx/tooltip';
910import ToolTipDataDisplay from './ToolTipDataDisplay' ;
1011import { ToolTipStyles } from '../../../FrontendTypes' ;
1112import { localPoint } from '@visx/event' ;
13+ import AxLegend from './axLegend' ;
14+ import { renderAxLegend } from '../../../slices/AxSlices/axLegendSlice' ;
15+ import type { RootState } from '../../../store' ;
1216
1317//still using below themes?
1418const theme = {
@@ -314,21 +318,39 @@ export default function AxTree(props) {
314318 populateNodeAxArr ( rootAxNode ) ;
315319 console . log ( 'nodeAxArr: ' , nodeAxArr ) ;
316320
321+ const {
322+ containerRef // Access to the container's bounding box. This will be empty on first render.
323+ } = useTooltipInPortal ( {
324+ // Visx hook
325+ detectBounds : true , // use TooltipWithBounds
326+ scroll : true , // when tooltip containers are scrolled, this will correctly update the Tooltip position
327+ } ) ;
328+
329+ // ax Legend
330+ const { axLegendButtonClicked } = useSelector ( ( state : RootState ) => state . axLegend ) ;
331+ const dispatch = useDispatch ( ) ;
332+
317333 return totalWidth < 10 ? null : (
318334 < div >
319- < LinkControls
320- layout = { layout }
321- orientation = { orientation }
322- linkType = { linkType }
323- stepPercent = { stepPercent }
324- setLayout = { setLayout }
325- setOrientation = { setOrientation }
326- setLinkType = { setLinkType }
327- setStepPercent = { setStepPercent }
328- />
335+ < div id = 'axControls' >
336+ < LinkControls
337+ layout = { layout }
338+ orientation = { orientation }
339+ linkType = { linkType }
340+ stepPercent = { stepPercent }
341+ setLayout = { setLayout }
342+ setOrientation = { setOrientation }
343+ setLinkType = { setLinkType }
344+ setStepPercent = { setStepPercent }
345+ />
346+
347+ < button id = 'axLegendButton' onClick = { ( ) => dispatch ( renderAxLegend ( ) ) } >
348+ Generate Ax Tree Legend
349+ </ button >
350+ </ div >
329351
330352 { /* svg references purple background */ }
331- < svg ref = { containerRef } width = { totalWidth } height = { totalHeight + 0 } >
353+ < svg ref = { containerRef } width = { totalWidth + 0.2 * totalWidth } height = { totalHeight } >
332354 < LinearGradient id = 'root-gradient' from = '#488689' to = '#3c6e71' />
333355 < LinearGradient id = 'parent-gradient' from = '#488689' to = '#3c6e71' />
334356 < rect
@@ -346,7 +368,7 @@ export default function AxTree(props) {
346368 separation = { ( a , b ) => ( a . parent === b . parent ? 0.5 : 0.5 ) / a . depth }
347369 >
348370 { ( tree ) => (
349- < Group top = { origin . y + 35 } left = { origin . x + 50 / aspect } >
371+ < Group top = { origin . y + 35 } left = { origin . x + 110 } >
350372 { tree . links ( ) . map ( ( link , i ) => (
351373 < LinkComponent
352374 key = { i }
@@ -598,6 +620,14 @@ export default function AxTree(props) {
598620 </ div >
599621 </ TooltipInPortal >
600622 ) }
623+
624+ { /* ax Legend */ }
625+ < div >
626+ { axLegendButtonClicked ?
627+ < AxLegend /> : ''
628+ }
629+ </ div >
630+
601631 </ div >
602632 ) ;
603633}
0 commit comments