Skip to content

fix: optimises initial chart rendering when using bottom legend#223

Merged
pan-kot merged 1 commit into
cloudscape-design:mainfrom
ryugaraj:fix/fit-height-bottom-legend-visibility
May 11, 2026
Merged

fix: optimises initial chart rendering when using bottom legend#223
pan-kot merged 1 commit into
cloudscape-design:mainfrom
ryugaraj:fix/fit-height-bottom-legend-visibility

Conversation

@ryugaraj
Copy link
Copy Markdown
Contributor

When fitHeight is enabled with a bottom legend, the chart must wait for the footer measurement before computing the correct height. Previously the chart would render at full height then visibly shrink once the legend measured in. Now the chart-plot-wrapper is hidden with visibility:hidden until the footer measurement completes.

Also adds a unit test for getChartPlotWrapperStyles and updates the many-series dev page to use fitHeight for easier reproduction.

Description

Fixes a rendering issue where the chart would display with incorrect height
when fitHeight is enabled with a bottom legend position. The chart now
remains hidden (via CSS visibility) until the footer measurements complete,
preventing visual glitches during the measurement phase.

How has this been tested?

Tested with page 01-cartesian-chart/many-series with CPU throttling between 6-20 times to see the legend used to cause the chart to resize but now it renders simultaneously.

Also added some basic unit test to help identify breaking changes in future.

Before

Screen.Recording.2026-05-11.at.12.52.35.mov

After

Screen.Recording.2026-05-11.at.12.52.03.mov

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@ryugaraj ryugaraj changed the title fix: hide chart during footer measurement when using bottom legend fix: Optimises initial chart rendering when using bottom legend May 11, 2026
@ryugaraj ryugaraj marked this pull request as ready for review May 11, 2026 12:51
@ryugaraj ryugaraj requested a review from a team as a code owner May 11, 2026 12:51
@ryugaraj ryugaraj requested review from jperals and removed request for a team May 11, 2026 12:51
@ryugaraj ryugaraj changed the title fix: Optimises initial chart rendering when using bottom legend fix: optimises initial chart rendering when using bottom legend May 11, 2026
Comment thread src/core/chart-container.tsx Outdated
expect(wrapper.findByClassName(testClasses["chart-plot-wrapper"])!.getElement().style.minInlineSize).toBe("333px");
});

test("hides chart plot wrapper while waiting for footer measurement with fitHeight and bottom legend", async () => {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be possible to test this on the chart container instead by checking for the presence of the visibility: hidden style? Then the test would ensure the function does not just work correctly, but is also correctly integrated with the component.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, updating the tests.

@ryugaraj ryugaraj force-pushed the fix/fit-height-bottom-legend-visibility branch 2 times, most recently from 06beb34 to 530a3d0 Compare May 11, 2026 14:38
Comment thread src/core/__tests__/chart-core-fit-size.test.tsx Outdated
Comment thread src/core/__tests__/chart-core-fit-size.test.tsx Outdated
When fitHeight is enabled with a bottom legend, the chart height depends
on the footer measurement. Without this fix, the chart briefly renders at
full container height then visibly shrinks once the legend is measured,
causing a layout shift. The chart-plot-wrapper is now hidden with
visibility:hidden until the footer measurement completes.
@ryugaraj ryugaraj force-pushed the fix/fit-height-bottom-legend-visibility branch from 530a3d0 to 76eee22 Compare May 11, 2026 14:55
@pan-kot pan-kot enabled auto-merge May 11, 2026 15:49
@pan-kot pan-kot added this pull request to the merge queue May 11, 2026
Merged via the queue into cloudscape-design:main with commit 40086fb May 11, 2026
42 of 44 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants