Fix bogus colorbar size rescale when restyling to the mode the colorbar already uses - #8015
Draft
LeonxLJX wants to merge 1 commit into
Draft
Fix bogus colorbar size rescale when restyling to the mode the colorbar already uses#8015LeonxLJX wants to merge 1 commit into
LeonxLJX wants to merge 1 commit into
Conversation
When restyling 'colorbar.thicknessmode' (or 'lenmode') on a colorbar that was created without an explicit value, the "keep the rendered size" conversion in plot_api rescaled innerContFull.thickness as if it were a fraction, even though its units are given by innerContFull.thicknessmode - whose default is 'pixels'. This wrote thickness values like 30 * gs.w back into the user trace and collapsed the layout (most visibly for splom, see plotly#8012). Only rescale when the units actually change, and read the colorbar orientation from the real attribute ('orientation' is 'v'/'h'; the old 'orient' top/bottom read was always undefined, so horizontal colorbars normalized thickness against gs.w instead of gs.h). Add regression tests in colorbar_test.js.
This was referenced Sep 3, 2026
Author
|
Hi @emilykl — bumping for review when you have a moment. The PR is a one-line guard in |
Contributor
|
Hi @LeonxLJX, please see my comment on the linked issue. Please be patient, we have many PRs to review and this is a relatively niche bug. |
emilykl
marked this pull request as draft
September 4, 2026 14:40
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
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.
Problem
Plotly.restyle(gd, {'marker.colorbar.thicknessmode': 'pixels'})on a trace whose colorbar was created without an explicitthicknessmode/thicknesssilently writes a huge pixel value back into the user trace and collapses the layout — most dramatically forsplom, where the whole grid squeezes into a strip (#8012, also reported from plotly.py as plotly/plotly.py#5615). Setting the exact same value atnewPlottime renders fine.Headless repro (jsdom + min bundle, 3.5.0), generic across trace types — not splom-specific:
Root cause
The "keep the rendered size when switching size modes" branch in
src/plot_api/plot_api.js:Two defects:
oldVal !== newVal, and when the user never set the attributeoldValisundefined. ButinnerContFull.thicknessis expressed in the units ofinnerContFull.thicknessmode— whose default is'pixels'— so restyling an unset colorbar to'pixels'multiplies an already-pixelthickness(30) by the plot width and writes30 * gs.winto the user data. Restyling an unset colorbar to'fraction'divides in the same bogus way.orientread. The colorbar attribute isorientation('v'/'h'), soinnerContFull.orientis alwaysundefinedandtopOrBottomis alwaysfalse: horizontal colorbars normalizethicknessagainstgs.winstead ofgs.h(andlenagainstgs.hinstead ofgs.w), disagreeing with the normalizer used at draw time (isVertical ? gs.w : gs.hinsrc/components/colorbar/draw.js).Fix
innerContFull.thicknessmode !== newVal(resp.lenmode) — the full container's mode is the authoritative statement of the unitsinnerContFull.thicknessis in, regardless of what the user previously set. Also skip when the value is missing instead of propagatingNaN.innerContFull.orientation === 'h', matchingdraw.js.Behavior on legitimate switches is unchanged: verified headlessly that an explicitly-set
thicknessmode: 'fraction', thickness: 0.1restyled to'pixels'still converts to0.1 * gs.w(= 59 px at gs.w = 590), and the existingchanged size modestest case keeps itsthickPx / 400/lenFrac * 400expectations (guarded conversion still fires when the full mode differs from the new value).Alternatives considered
oldValinstead of the full mode:oldValcan beundefined/nulland says nothing about the units of the coerced value, so every combination needs special-casing; the full mode already encodes it.colorbar_test.jsdepends on.Tests
Three regression tests in
test/jasmine/tests/colorbar_test.js:colorbarrestyled to'pixels'keepsthicknessat the 30 px default (rootcolorbar, and the reportedsplommarker.colorbarshape);thicknessrescales against the plot height (fails on master, wheretopOrBottomis alwaysfalse).Closes #8012.