Skip to content

Commit 8021478

Browse files
committed
referencing defaultMargins correctly based on updated prop drilling, fixes multiple NaN issues
1 parent 1ccf620 commit 8021478

File tree

1 file changed

+30
-17
lines changed
  • src/app/components/StateRoute/AxMap

1 file changed

+30
-17
lines changed

src/app/components/StateRoute/AxMap/Ax.tsx

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,8 @@ const dataArray = [
128128
}
129129
]
130130

131+
const startNode: TreeNode = dataArray[0];
132+
131133
const defaultMargin = {
132134
top: 30,
133135
left: 30,
@@ -148,18 +150,23 @@ export type LinkTypesProps = {
148150
margin?: { top: number; right: number; bottom: number; left: number };
149151
};
150152

151-
export default function AxTree(props, {
152-
width: totalWidth,
153-
height: totalHeight,
154-
margin = defaultMargin,
155-
}: LinkTypesProps) {
153+
export default function AxTree(props) {
154+
const {
155+
currLocation,
156+
axSnapshots,
157+
width,
158+
height
159+
} = props;
160+
161+
let margin = defaultMargin;
162+
let totalWidth = width;
163+
let totalHeight = height;
164+
156165
const [layout, setLayout] = useState('cartesian');
157166
const [orientation, setOrientation] = useState('horizontal');
158167
const [linkType, setLinkType] = useState('diagonal');
159168
const [stepPercent, setStepPercent] = useState(0.5);
160169

161-
console.log('total height access: ', totalHeight);
162-
163170
const innerWidth: number = totalWidth - margin.left - margin.right;
164171
const innerHeight: number = totalHeight - margin.top - margin.bottom - 60;
165172

@@ -185,12 +192,9 @@ export default function AxTree(props, {
185192
}
186193
}
187194

188-
const LinkComponent = getLinkComponent({ layout, linkType, orientation });
195+
console.log('size width height ax: ', sizeWidth, sizeHeight);
189196

190-
const {
191-
currLocation,
192-
axSnapshots
193-
} = props;
197+
const LinkComponent = getLinkComponent({ layout, linkType, orientation });
194198

195199
const currAxSnapshot = JSON.parse(JSON.stringify(axSnapshots[currLocation.index]));
196200

@@ -282,12 +286,20 @@ export default function AxTree(props, {
282286
setLinkType={setLinkType}
283287
setStepPercent={setStepPercent}
284288
/>
289+
290+
{/* svg references purple background */}
285291
<svg width={totalWidth} height={totalHeight + 0}>
286-
<LinearGradient id="links-gradient" from="#fd9b93" to="#fe6e9e" />
287-
<rect width={totalWidth} height={totalHeight} rx={14} fill="#272b4d" />
288-
<Group top={margin.top} left={margin.left}>
292+
<LinearGradient id='root-gradient' from='#488689' to='#3c6e71' />
293+
<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+
<Group transform={`scale(${aspect})`} top={margin.top} left={margin.left}>
289301
<Tree
290-
root={hierarchy(data, (d) => (d.isExpanded ? null : d.children))}
302+
root={hierarchy(startNode, (d) => (d.isExpanded ? null : d.children))}
291303
size={[sizeWidth / aspect, sizeHeight / aspect]}
292304
separation={(a, b) => (a.parent === b.parent ? 0.5 : 0.5) / a.depth}
293305
>
@@ -305,7 +317,6 @@ export default function AxTree(props, {
305317

306318
// code relating to each node in tree
307319
{tree.descendants().map((node, key) => {
308-
console.log('node.data: ', node.data);
309320
const widthFunc = (name): number => {
310321
//returns a number that is related to the length of the name. Used for determining the node width.
311322
const nodeLength = name.length;
@@ -322,6 +333,8 @@ export default function AxTree(props, {
322333

323334
if (layout === 'polar') {
324335
const [radialX, radialY] = pointRadial(node.x, node.y);
336+
console.log('ax tree, radial x y', radialX, radialY);
337+
console.log('ax tree node.x, node.y:', node.x, node.y);
325338
top = radialY;
326339
left = radialX;
327340
} else if (orientation === 'vertical') {

0 commit comments

Comments
 (0)