@@ -28,6 +28,7 @@ const BarChartRace = ({ title, speed, colorPalette, timeUnit, barRaceData, isDow
2828 const [ dataset , setDataset ] = useState ( null ) ; // Processed data
2929 const [ currentKeyframeState , setCurrentKeyFrameState ] = useState ( 0 ) ; // Current keyframe state
3030 const [ downloadPercentage , setDownloadPercentage ] = useState ( null ) ;
31+ const [ graphicsPanelHeight , setGraphicsPanelHeight ] = useState ( getGraphicsPanelHeight ( ) ) ;
3132 const keyframesRef = useRef ( [ ] ) ; // Stores all keyframes
3233 const timeoutRef = useRef ( null ) ; // Handles animation timing
3334 const abortControllerRef = useRef ( null ) ;
@@ -72,7 +73,8 @@ const BarChartRace = ({ title, speed, colorPalette, timeUnit, barRaceData, isDow
7273 } ;
7374
7475 const width = container . clientWidth ;
75- const keyframes = initializeChart ( svgRef , dataset , width , title , colorPaletteArray , timeUnit , locale ) ;
76+ const maxHeight = graphicsPanelHeight ;
77+ const keyframes = initializeChart ( svgRef , dataset , width , maxHeight , title , colorPaletteArray , timeUnit , locale ) ;
7678 keyframesRef . current = keyframes ;
7779
7880 // Initialize chart with the first keyframe.
@@ -89,8 +91,20 @@ const BarChartRace = ({ title, speed, colorPalette, timeUnit, barRaceData, isDow
8991 currentSvg . remove ( ) ;
9092 }
9193 } ;
94+ } , [ dataset , timeUnit , title , colorPalette , locale , graphicsPanelHeight ] ) ;
9295
93- } , [ dataset , timeUnit , title , colorPalette , locale ] ) ;
96+ function getGraphicsPanelHeight ( ) {
97+ return document . getElementById ( "graphicsPanel" ) . clientHeight ;
98+ } ;
99+
100+ useEffect ( ( ) => {
101+ function handleResize ( ) {
102+ setGraphicsPanelHeight ( getGraphicsPanelHeight ( ) ) ;
103+ }
104+ window . addEventListener ( 'resize' , handleResize ) ;
105+ // cleanup:
106+ return ( ) => window . removeEventListener ( 'resize' , handleResize ) ;
107+ } , [ ] ) ;
94108
95109 const animationDelay = ( ) => {
96110 return 1000 / speed ;
@@ -255,7 +269,7 @@ const BarChartRace = ({ title, speed, colorPalette, timeUnit, barRaceData, isDow
255269 }
256270
257271 return (
258- < div id = "parent-container" className = "relative p-4" >
272+ < div id = "parent-container" className = "relative p-4" style = { { height : "90%" } } >
259273 < DownloadingAlert />
260274 < div id = "play-controls" className = "flex items-center" >
261275 < button
@@ -274,7 +288,7 @@ const BarChartRace = ({ title, speed, colorPalette, timeUnit, barRaceData, isDow
274288 onChange = { onRangeChange }
275289 />
276290 </ div >
277- < div id = "container" > </ div >
291+ < div id = "container" style = { { height : "95%" } } > </ div >
278292 </ div >
279293 ) ;
280294} ;
0 commit comments