Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork2k
fix bin size becomes 1 (very thin) when data changes with barmode: 'overlay' for histogram#7507
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Open
Lexachoc wants to merge3 commits intoplotly:masterChoose a base branch fromLexachoc:fix_autobin_size_overlay
base:master
Could not load branches
Branch not found:{{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline, and old review comments may become outdated.
Uh oh!
There was an error while loading.Please reload this page.
Conversation
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 freeto join this conversation on GitHub. Already have an account?Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading.Please reload this page.
This PRfixes#7506
Description
When using
Plotly.reactto update the data of a histogram withbarmode: 'overlay', if the traces contain single data points (one point per trace), the calculatedbin.sizecould incorrectly set to1. 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 using
Plotly.react(for data mutations).Before/After
See the fixed look in#7506 (comment).
Note on
Plotly.reactandlayoutobjectThis PR directly fixes the incorrect histogram auto-binning size calculation for single-point traces in
overlaymode on data updates. However, it's worth noting that this issue is often triggered by a deeper behavior withinPlotly.reactconcerning layout object reuse. See the Note in#7506.I found that if the same
layoutobject is reused inPlotly.reactcalls while the data's axis type (xaxis.typeinlayout) changes (e.g., fromlineartocategory), 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 becomescategory. When switching back to numeric data, the axis type incorrectly remainscategory, leading to rendering issues.The long-term solution might involve changes to how
Plotly.reacthandles 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) toPlotly.reactto 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 theauto-binningfix when data changes, without being affected by the separate layout reuse behavior.