Skip to content

Commit

Permalink
fix: Prevent charts from jumping when updating alignment during windo…
Browse files Browse the repository at this point in the history
…w resize event
  • Loading branch information
bprusinowski committed Feb 1, 2024
1 parent 58b390e commit 170989b
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion app/components/chart-helpers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ export const AlignChartElementsProvider = ({
export const useChartHeaderMarginBottom = () => {
const alignChartElements = useAlignChartElements();
const headerRef = React.useRef<HTMLDivElement>(null);
const oldMargin = React.useRef(0);

React.useEffect(() => {
if (headerRef.current) {
Expand All @@ -84,7 +85,13 @@ export const useChartHeaderMarginBottom = () => {
const headerMarginBottom = React.useMemo(() => {
if (headerRef.current) {
const { height } = headerRef.current.getBoundingClientRect();
return alignChartElements.maxHeaderHeight - height;
const newMargin =
alignChartElements.maxHeaderHeight === 0
? oldMargin.current
: alignChartElements.maxHeaderHeight - height;
oldMargin.current = newMargin;

return newMargin;
}

return 0;
Expand Down

0 comments on commit 170989b

Please sign in to comment.