FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

fix bin size becomes 1 (very thin) when data changes with barmode: 'overlay' for histogram by Lexachoc · Pull Request #7507 · plotly/plotly.js · GitHub

fix bin size becomes 1 (very thin) when data changes with barmode: 'overlay' for histogram - #7507

Merged
camdecoster merged 6 commits into
plotly:masterfrom
Lexachoc:fix_autobin_size_overlay
Jul 13, 2026
Merged

fix bin size becomes 1 (very thin) when data changes with barmode: 'overlay' for histogram#7507
camdecoster merged 6 commits into
plotly:masterfrom
Lexachoc:fix_autobin_size_overlay

Conversation

Lexachoc commented Aug 3, 2025
edited
Loading

Copy link
Copy Markdown
Contributor

This PR fixes #7506

Description

When using Plotly.react to update the data of a histogram with barmode: 'overlay', if the traces contain single data points (one point per trace), the calculated bin.size could incorrectly set to 1. This results in the histogram bars becoming visually very thin after a data update.

This issue is particularly noticeable for react-plotly users, where data mutations are frequent.

Changes

This new logic ensures that auto-binning is correctly triggered when usingPlotly.react (for data mutations).

Before/After

See the fixed look in #7506 (comment).

Note on Plotly.react and layout object

This PR directly fixes the incorrect histogram auto-binning size calculation for single-point traces in overlay mode on data updates. However, it's worth noting that this issue is often triggered by a deeper behavior within Plotly.react concerning layout object reuse. See the Note in #7506.

I found that if the same layout object is reused in Plotly.react calls while the data's axis type (xaxis.type in layout) changes (e.g., from linear to category), the layout object can become "stuck" (stale) with the last-used axis type. For instance, after switching from numeric to string data, the axis type becomes category. When switching back to numeric data, the axis type incorrectly remains category, leading to rendering issues.

The long-term solution might involve changes to how Plotly.react handles the layout object. For now, the good practice for users might be: if your data update might change the axis type (i.e., change the layout), you should also provide a new layout object (or a deep copy) to Plotly.react to ensure correct rendering.

The test case added in this PR (histogram_test.js) intentionally uses data of the same type (linear, auto-detected by Plotly) to specifically test the auto-binning fix when data changes, without being affected by the separate layout reuse behavior.

gvwilson requested a review from camdecoster August 11, 2025 17:19
gvwilson added community community contribution P2 considered for next cycle fix fixes something broken labels Aug 11, 2025
camdecoster merged commit 55dfea3 into plotly:master Jul 13, 2026
162 of 164 checks passed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community community contribution fix fixes something broken P2 considered for next cycle

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bin size becomes 1 (very thin) when data changes with barmode: 'overlay' for histogram

3 participants


Back | FazBrowse Home | New Git URL