Skip to content

Fix Chart.js resize for charts in hidden tab panels#81

Merged
tomtom215 merged 1 commit into
mainfrom
claude/fix-screenshot-dimensions-JAofT
Apr 2, 2026
Merged

Fix Chart.js resize for charts in hidden tab panels#81
tomtom215 merged 1 commit into
mainfrom
claude/fix-screenshot-dimensions-JAofT

Conversation

@tomtom215
Copy link
Copy Markdown
Owner

Summary

This PR fixes an issue where Chart.js charts created in hidden tab panels were not properly resizing when their containing tab became visible. The fix ensures charts are resized after the DOM layout reflow occurs when switching tabs.

Changes

  • Added requestAnimationFrame callback to the tab switching function that triggers Chart.js resize for all canvas elements in the newly visible panel
  • Applied the fix to both the benchmark dashboard template and the reference documentation
  • The resize is deferred to the next animation frame to allow the browser to complete the layout reflow before Chart.js recalculates dimensions

Implementation Details

When a tab panel transitions from hidden to visible, Chart.js charts within that panel need to be explicitly resized since they were rendered while their container had display: none or similar hidden state. The fix:

  1. Waits for the next animation frame using requestAnimationFrame to ensure the layout has reflowed
  2. Queries all canvas elements in the newly active panel
  3. Retrieves the Chart.js instance for each canvas and calls its resize() method if it exists

This ensures charts display with correct dimensions immediately after tab activation.

https://claude.ai/code/session_01JMApLxRnxbdgtrCjcQwFTH

Charts created in hidden tab panels (display:none) have zero dimensions.
When a tab is activated, use requestAnimationFrame + Chart.getChart().resize()
to ensure charts render at correct dimensions after layout reflow.

https://claude.ai/code/session_01JMApLxRnxbdgtrCjcQwFTH
@tomtom215 tomtom215 merged commit dce3fda into main Apr 2, 2026
40 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