Skip to content

Commit 04ddaab

Browse files
committed
fixed aspect ratio for initial loading of app
1 parent 6824840 commit 04ddaab

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/app/components/StateRoute/ComponentMap/ComponentMap.tsx

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ const defaultMargin: DefaultMargin = {
3838

3939
const nodeCoords: object = {};
4040
let count: number = 0;
41-
let aspect: number = 1; // aspect resizes the component map container to accommodate large node trees on complex sites
41+
let aspect: number = 1;
4242
let nodeCoordTier = 0;
4343
let nodeOneLeft = 0;
4444
let nodeTwoLeft = 2;
@@ -54,6 +54,8 @@ export default function ComponentMap({
5454
const [linkType, setLinkType] = useState('step'); // We create a local state "linkType" and set it to a string 'step'.
5555
const [stepPercent, setStepPercent] = useState(0.0); // We create a local state "stepPercent" and set it to a number '0.0'. This will be used to scale the Map component's link: Step to 0%
5656
const [selectedNode, setSelectedNode] = useState('root'); // We create a local state "selectedNode" and set it to a string 'root'.
57+
const [forceUpdate, setForceUpdate] = useState(false);
58+
5759
const dispatch = useDispatch();
5860

5961
const toolTipTimeoutID = useRef(null); //useRef stores stateful data that’s not needed for rendering.
@@ -62,6 +64,14 @@ export default function ComponentMap({
6264
dispatch(setCurrentTabInApp('map')); // dispatch sent at initial page load allowing changing "immer's" draft.currentTabInApp to 'map' to facilitate render.
6365
}, [dispatch]);
6466

67+
// force app to re-render to accurately calculate aspect ratio upon initial load
68+
useEffect(() => {
69+
const timer = setTimeout(() => {
70+
setForceUpdate((prev) => !prev);
71+
}, 100);
72+
return () => clearTimeout(timer);
73+
}, []);
74+
6575
// setting the margins for the Map to render in the tab window.
6676
const innerWidth: number = totalWidth - margin.left - margin.right;
6777
const innerHeight: number = totalHeight - margin.top - margin.bottom - 60;
@@ -231,7 +241,6 @@ export default function ComponentMap({
231241
/>
232242

233243
<svg ref={containerRef} width={totalWidth} height={totalHeight + 0}>
234-
{/* <LinearGradient id='root-gradient' from='#e75e62' to='#f00008' /> */}
235244
<LinearGradient id='root-gradient' from='#488689' to='#3c6e71' />
236245
<LinearGradient id='parent-gradient' from='#488689' to='#3c6e71' />
237246
<rect
@@ -387,7 +396,7 @@ export default function ComponentMap({
387396
}
388397
}
389398
} else {
390-
aspect = Math.max(aspect, 0.2);
399+
aspect = Math.max(aspect, 1);
391400
}
392401

393402
// mousing controls & Tooltip display logic

0 commit comments

Comments
 (0)