Clamp colorbar axis domain to prevent inversion errors#7908
Open
zeehio wants to merge 2 commits into
Open
Conversation
Vertical colorbars could end up with ax.domain[1] < ax.domain[0], producing a negative axis length and throwing "Something went wrong with axis scaling" during draw. This happened in two spots: - the initial domain assignment, when the colorbar's available height (len * plot height) is smaller than 2 * ypad - the title-height adjustment, when the title (top or bottom side) is taller than the colorbar's domain All three assignments are now clamped so domain[1] can never drop below domain[0] (or domain[0] rise above domain[1]). Fixes plotly#6499 Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011XRrkTKVes3TEaB8FNDrea
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011XRrkTKVes3TEaB8FNDrea
zeehio
force-pushed
the
claude/plotly-issue-6499-repro-6k2s7e
branch
from
July 16, 2026 17:55
8e526a4 to
4d427c7
Compare
zeehio
marked this pull request as ready for review
July 16, 2026 17:56
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.
Fixes #6499 (
axisDraw: Hitting ax.domain[1] < ax.domain[0]).Claude assisted. I do understand the code though
Vertical colorbars could end up with
ax.domain[1] < ax.domain[0], producing a negative axis length and throwingSomething went wrong with axis scalingduring draw. This happened insrc/components/colorbar/draw.jsin two places:len * plot height) is smaller than2 * ypad. This is the one actually hit by the real-world report in the issue (a plot with two legends/guides squeezing the colorbar's available space) — it fires before any title logic even runs.top-side branch; the symmetricbottom/right-side branch had the identical bug and is fixed here too.All three domain assignments are now clamped with
Math.max/Math.minsodomain[1]can never drop belowdomain[0](or vice versa), instead of throwing. In the extreme-squeeze case the colorbar collapses to zero height rather than crashing — a defensive fix, not a full relayout, but it eliminates the exception.Repro/verification notes (from investigating the issue): the crash reproduces end-to-end via
ggplot2→ggplotly()→ plotly.js when a colorbar's available space is tight relative to its title/padding, confirmed with a realhtmlwidgets::saveWidget()output rendered in headless Chromium at short container heights (≲80px) — consistent with the issue's note that reproduction depends on the window size. It also depends on the legend size.Added 3 regression tests to
test/jasmine/tests/colorbar_test.js, one per fixed code path — verified each fails with the exact reported error on the pre-fix code and passes after the fix.