|
1 | 1 | import React, { useState } from 'react'; |
| 2 | +import { useDispatch, useSelector } from 'react-redux'; |
2 | 3 | import { Group } from '@visx/group'; |
3 | 4 | import { hierarchy, Tree } from '@visx/hierarchy'; |
4 | 5 | import { LinearGradient } from '@visx/gradient'; |
5 | 6 | import { pointRadial } from 'd3-shape'; |
6 | 7 | import { useTooltipInPortal } from '@visx/tooltip'; |
7 | 8 | import LinkControls from './axLinkControls'; |
8 | 9 | import getLinkComponent from './getAxLinkComponents'; |
| 10 | +import AxLegend from './axLegend'; |
| 11 | +import { renderAxLegend } from '../../../slices/AxSlices/axLegendSlice'; |
| 12 | +import type { RootState } from '../../../store'; |
9 | 13 |
|
10 | 14 | const theme = { |
11 | 15 | scheme: 'monokai', |
@@ -274,37 +278,41 @@ export default function AxTree(props) { |
274 | 278 | scroll: true, // when tooltip containers are scrolled, this will correctly update the Tooltip position |
275 | 279 | }); |
276 | 280 |
|
| 281 | + // ax Legend |
| 282 | + const { axLegendButtonClicked } = useSelector((state: RootState) => state.axLegend); |
| 283 | + const dispatch = useDispatch(); |
| 284 | + |
277 | 285 | return totalWidth < 10 ? null : ( |
278 | 286 | <div> |
279 | | - <LinkControls |
280 | | - layout={layout} |
281 | | - orientation={orientation} |
282 | | - linkType={linkType} |
283 | | - stepPercent={stepPercent} |
284 | | - setLayout={setLayout} |
285 | | - setOrientation={setOrientation} |
286 | | - setLinkType={setLinkType} |
287 | | - setStepPercent={setStepPercent} |
288 | | - /> |
| 287 | + <div id='axControls'> |
| 288 | + <LinkControls |
| 289 | + layout={layout} |
| 290 | + orientation={orientation} |
| 291 | + linkType={linkType} |
| 292 | + stepPercent={stepPercent} |
| 293 | + setLayout={setLayout} |
| 294 | + setOrientation={setOrientation} |
| 295 | + setLinkType={setLinkType} |
| 296 | + setStepPercent={setStepPercent} |
| 297 | + /> |
| 298 | + |
| 299 | + <button id='axLegendButton' onClick={() => dispatch(renderAxLegend())}> |
| 300 | + Generate Ax Tree Legend |
| 301 | + </button> |
| 302 | + </div> |
289 | 303 |
|
290 | 304 | {/* svg references purple background */} |
291 | | - <svg ref={containerRef} width={totalWidth} height={totalHeight + 0}> |
| 305 | + <svg ref={containerRef} width={totalWidth + 0.2*totalWidth} height={totalHeight}> |
292 | 306 | <LinearGradient id='root-gradient' from='#488689' to='#3c6e71' /> |
293 | 307 | <LinearGradient id='parent-gradient' from='#488689' to='#3c6e71' /> |
294 | | - <rect |
295 | | - className='componentMapContainer' |
296 | | - width={sizeWidth / aspect} |
297 | | - height={sizeHeight / aspect + 0} |
298 | | - rx={14} |
299 | | - /> |
300 | 308 | <Group transform={`scale(${aspect})`} top={margin.top} left={margin.left}> |
301 | 309 | <Tree |
302 | 310 | root={hierarchy(nodeAxArr[0], (d) => (d.isExpanded ? null : d.children))} |
303 | 311 | size={[sizeWidth / aspect, sizeHeight / aspect]} |
304 | 312 | separation={(a, b) => (a.parent === b.parent ? 0.5 : 0.5) / a.depth} |
305 | 313 | > |
306 | 314 | {(tree) => ( |
307 | | - <Group top={origin.y + 35} left={origin.x + 50 / aspect}> |
| 315 | + <Group top={origin.y + 35} left={origin.x + 110}> |
308 | 316 | {tree.links().map((link, i) => ( |
309 | 317 | <LinkComponent |
310 | 318 | key={i} |
@@ -477,6 +485,14 @@ export default function AxTree(props) { |
477 | 485 | </Tree> |
478 | 486 | </Group> |
479 | 487 | </svg> |
| 488 | + |
| 489 | + {/* ax Legend */} |
| 490 | + <div> |
| 491 | + { axLegendButtonClicked ? |
| 492 | + <AxLegend /> : '' |
| 493 | + } |
| 494 | + </div> |
| 495 | + |
480 | 496 | </div> |
481 | 497 | ); |
482 | 498 | } |
|
0 commit comments