Skip to content

Fixed issue gh-11327: Plotly chart reset axes not working after reset#11498

Merged
lukasmasuch merged 17 commits intostreamlit:developfrom
sfc-gh-smohile:fix/plotly-reset-axes-after-fullscreen
Jun 5, 2025
Merged

Fixed issue gh-11327: Plotly chart reset axes not working after reset#11498
lukasmasuch merged 17 commits intostreamlit:developfrom
sfc-gh-smohile:fix/plotly-reset-axes-after-fullscreen

Conversation

@sfc-gh-smohile
Copy link
Copy Markdown
Contributor

Describe your changes

Fixed bug where Plotly Chart reset axes were not working after clicking full screen and going back.

GitHub Issue Link (if applicable)

#11327

Testing Plan

  • Explanation of why no additional tests are needed

  • Unit Tests (JS and/or Python)

  • E2E Tests: Added new E2E tests to verify that Plotly chart axes reset properly after entering and exiting fullscreen mode

  • Any manual testing needed?
    No


Contribution License Agreement

By submitting this pull request you agree that all contributions to this project are made under the Apache 2.0 license.

@snyk-io
Copy link
Copy Markdown
Contributor

snyk-io bot commented Jun 2, 2025

🎉 Snyk checks have passed. No issues have been found so far.

security/snyk check is complete. No issues have been found. (View Details)

license/snyk check is complete. No issues have been found. (View Details)

@sfc-gh-smohile sfc-gh-smohile self-assigned this Jun 2, 2025
@sfc-gh-smohile sfc-gh-smohile added change:bugfix PR contains bug fix implementation security-assessment-completed impact:users PR changes affect end users labels Jun 2, 2025
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Vega-lite snapshots in Firefox seem to be extremely flaky since today.... not sure why :(

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.

Thank god! I've been scratching my head for 3 hours wondering how did my plotly changes break vega lite 😢

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

yeah, my assumption is that there was some firefox patch update related playwright which causes some issues that prevents our theme changes to be applied to the charts. But I haven't looked deeper into this yet.

Copy link
Copy Markdown
Collaborator

@sfc-gh-lmasuch sfc-gh-lmasuch left a comment

Choose a reason for hiding this comment

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

LGTM 👍 but all the vega-lite snapshots need to be reverted to the original state.

Comment on lines 313 to 316
Copy link
Copy Markdown
Collaborator

@sfc-gh-lmasuch sfc-gh-lmasuch Jun 5, 2025

Choose a reason for hiding this comment

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

Just to confirm: the initialFigureSpec does not contain any height information we could use here? The 450px default is something that Plotly chooses in the frontend if no height is used?

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.

Yes, that is right. 450 is plotly's default height if no height is mentioned.

@sfc-gh-lmasuch sfc-gh-lmasuch requested a review from Copilot June 5, 2025 10:43
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Fixes the bug where Plotly chart axes did not reset correctly after exiting fullscreen by adding a default height fallback and an end-to-end test.

  • Added a fallback default height when initialFigureSpec.layout.height is undefined outside fullscreen.
  • Removed the dynamic key prop from the Plot component.
  • Introduced a new Playwright E2E test to verify axis reset after fullscreen zoom.

Reviewed Changes

Copilot reviewed 31 out of 31 changed files in this pull request and generated 3 comments.

File Description
frontend/lib/src/components/elements/PlotlyChart/PlotlyChart.tsx Adds default height fallback and removes the key prop on the Plot component
e2e_playwright/st_plotly_chart_test.py Adds test_plotly_fullscreen_reset_axis to verify axes reset after zooming in/out of fullscreen
Comments suppressed due to low confidence (1)

frontend/lib/src/components/elements/PlotlyChart/PlotlyChart.tsx:462

  • Removing the key prop may prevent the Plot component from fully remounting when toggling fullscreen, which can lead to stale internal state. Consider restoring a dynamic key or explicitly resetting Plotly's layout/state.
key={isFullScreen ? "fullscreen" : "original"}

Copy link

Copilot AI Jun 5, 2025

Choose a reason for hiding this comment

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

Use nth(index) instead of nth(0) to ensure the exit-fullscreen button targets the same chart instance you entered fullscreen on.

Suggested change
exit_fullscreen_button = app.locator('[data-title="Close fullscreen"]').nth(0)
exit_fullscreen_button = app.locator('[data-title="Close fullscreen"]').nth(index)

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

suggestion: This snapshot and the webkit snapshot for this same test need to be reverted.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

suggestion: +1 to @sfc-gh-lmasuch's review comment: all of the snapshots in this directory need to be reverted.

@sfc-gh-smohile sfc-gh-smohile force-pushed the fix/plotly-reset-axes-after-fullscreen branch from b509193 to 7e7085a Compare June 5, 2025 19:20
@lukasmasuch lukasmasuch enabled auto-merge (squash) June 5, 2025 22:35
@lukasmasuch lukasmasuch merged commit 20a7807 into streamlit:develop Jun 5, 2025
37 of 38 checks passed
@sfc-gh-smohile sfc-gh-smohile deleted the fix/plotly-reset-axes-after-fullscreen branch June 6, 2025 20:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

change:bugfix PR contains bug fix implementation impact:users PR changes affect end users

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants