GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Increase axis autorange when bars have outside text labels by emilykl · Pull Request #7675 · plotly/plotly.js

Conversation

@emilykl

@emilykl emilykl commented Dec 16, 2025 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Closes #2001

Adds a step during bar calc to add extra padding to axis range if bar has outside text labels.

Note: The first commit in this PR is just formatting changes. Use this diff to skip the first commit and see only the meaningful changes.

Codepen here! https://codepen.io/emilykl-code/pen/JoXQqLL

This is a stopgap fix for the fact that text labels are not taken into account during autorange calculations (see #2000).

Unfortunately, as discussed in that issue, modifying autorange to account for text labels is a significant amount of work, so I've opted for a more limited fix to address the issue identified in #2001.

Changes in this PR:

  • Add a function which computes an estimate for the amount of additional axis space (in pixels) required by bar text labels
    • This estimate is equal to the number of lines in the bar text (the maximum of the whole array), times the font size, plus the padding between text and bar
    • This many pixels are then added to the axis range on the relevant side of the bar plot
    • The extra padding is ONLY applied when all of the following are true: textposition is 'outside', orientation is vertical, and text or texttemplate is provided and non-falsy, and textangle is 0 or 'auto'
      • These exclusions are to avoid cases where the text is not parallel with the top of the bar, which are significantly harder to estimate due to needing to estimate the text width rather than the height
      • The goal is to improve the current situation by adding padding in the most common cases where needed, while avoiding adding too much padding to the extent possible (even if this means excluding some cases where padding is needed)
      • I am aware of one edge case where too much padding is added; this is when bars have different numbers of lines of text, but the most lines are not aligned with the longest bar. I'm willing to accept that tradeoff, but open to feedback.
  • Update image baselines which show visual differences caused by this change
  • Remove "cliponaxis": "false" from the hist_stacked image mock, to demonstrate the effect of the changes in this PR (see below)

Screenshots

Before:
Screenshot 2025-12-17 at 11 30 09 AM

After:
Screenshot 2025-12-17 at 11 29 37 AM

hist_stacked mock (with cliponaxis: false removed) Before:
Screenshot 2025-12-17 at 3 11 04 PM

hist_stacked mock (with cliponaxis: false removed) After:
Screenshot 2025-12-17 at 3 11 56 PM

Steps for testing

Use the following mock:

{
    "data": [
        {
            "type": "bar",
            "orientation": "v",
            "x": ["A", "B", "C"],
            "y": [100, 250, -95],
            "base": [100, 100, 100],
            "texttemplate": "%{y}<br>units",
            "textposition": "outside",
        },
    ],
    "layout": {
    }
}

Verify that it looks like the "before" picture on master and the "after" picture on this branch.

Other variations to test:

  • Setting layout.yaxis.autorange to "reversed"
  • Using the bar.text property instead of bar.texttemplate
  • Adding a second bar trace and setting layout.barmode to "stack"

You can also load the hist_stacked mock in the devtools as another test case.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@emilykl
run formatter
5cb0bcd
@emilykl
emilykl force-pushed the cutoff-bar-labels branch from 55cb0eb to 1264314 Compare December 16, 2025 21:23
@emilykl
add extra axis padding when bars have outside text labels
a437597
@emilykl
emilykl force-pushed the cutoff-bar-labels branch from 1264314 to a437597 Compare December 16, 2025 21:35
emilykl added 3 commits December 16, 2025 19:07
@emilykl
handle multi-line labels, and pad only one side of axis
17cbffe
@emilykl
change naming, return object in 0 case
f044df3
@emilykl
fix bug with non-string values
3cb2f47
@emilykl
emilykl force-pushed the cutoff-bar-labels branch from e090b3a to 3cb2f47 Compare December 17, 2025 02:23
emilykl added 2 commits December 16, 2025 21:56
@emilykl
fix bug when text attr is a string
a416665
@emilykl
update baselines
1405769
@emilykl
emilykl marked this pull request as ready for review December 17, 2025 16:28
@emilykl
emilykl requested a review from camdecoster December 17, 2025 16:28
@robertclaus robertclaus assigned camdecoster Dec 17, 2025
@emilykl emilykl changed the title DRAFT: Fix for cut-off bar labels Increase axis autorange when bars have outside text labels Dec 17, 2025
@emilykl emilykl mentioned this pull request Dec 17, 2025
[BUG] Text is cut off on bars where textposition=outside #2001
Closed
@emilykl
remove 'cliponaxis: false' from hist_stacked mock to test bar label c…
ea934c3
…lipping
camdecoster
camdecoster approved these changes Dec 18, 2025
View reviewed changes

@camdecoster camdecoster left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

I left some syntax and refactoring comments, but this looks good.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

emilykl reacted with hooray emoji
All reactions
  • 🎉 1 reaction
Comment thread src/traces/bar/cross_trace_calc.js Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread src/traces/bar/cross_trace_calc.js Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread src/traces/bar/cross_trace_calc.js Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread src/traces/bar/cross_trace_calc.js Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread src/traces/bar/cross_trace_calc.js Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread src/traces/bar/cross_trace_calc.js Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread src/traces/bar/cross_trace_calc.js Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread src/traces/bar/cross_trace_calc.js Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread src/traces/bar/cross_trace_calc.js Resolved

Uh oh!

There was an error while loading. Please reload this page.

emilykl added 2 commits December 18, 2025 18:13
@emilykl
account for line spacing
b1e8fff
@emilykl
update baselines following prev commit which fixed line spacing calc
2294dbd
@emilykl
emilykl force-pushed the cutoff-bar-labels branch 2 times, most recently from 1ef511f to acf38e1 Compare December 19, 2025 20:20
@emilykl @camdecoster
Update src/traces/bar/cross_trace_calc.js
e0ab211
Co-authored-by: Cameron DeCoster <[email protected]>
@emilykl
emilykl force-pushed the cutoff-bar-labels branch from acf38e1 to e0ab211 Compare December 19, 2025 23:03
@emilykl
emilykl merged commit e0c2df7 into master Dec 19, 2025
6 of 7 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@emilykl
emilykl deleted the cutoff-bar-labels branch December 19, 2025 23:13
@emilykl emilykl mentioned this pull request Dec 23, 2025
Set cliponaxis: false by default for bar traces with text and textposition: 'auto' or 'outside' #7558
Closed
emilykl added a commit that referenced this pull request Dec 23, 2025
@emilykl
add draftlog for PR #7675
23b0d0e
emilykl added a commit that referenced this pull request Dec 23, 2025
@emilykl
Merge pull request #7677 from plotly/draftlog-7675
e661a4c
Add draftlog for PR #7675
@archmoj archmoj mentioned this pull request Jan 27, 2026
Set default layout.axis.tickmode to 'sync' when axis is overlaying #7684
Merged
@archmoj

archmoj commented Feb 4, 2026

Copy link
Copy Markdown
Contributor

@emilykl Whereas this is potentially a breaking change for users, I'm wondering if you are going to revert this PR and introduce this change in v4?
cc: @alexcjohnson

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@alexcjohnson

alexcjohnson commented Feb 4, 2026

Copy link
Copy Markdown
Collaborator

IMO the previous behavior was a bug, and it's unlikely anyone depends on it, so I think including it now is the right call.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@emilykl emilykl mentioned this pull request Jul 15, 2026
[BUG]: Bar labels overlap with top/right axis labels with textposition=outside #7822
Closed
@emilykl emilykl mentioned this pull request Aug 31, 2026
Auto-scaling of the go.Bar does not respect labels plotly/plotly.py#2788
Closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@camdecoster camdecoster camdecoster approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@camdecoster camdecoster

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

[BUG] Text is cut off on bars where textposition=outside

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@emilykl @archmoj @alexcjohnson @camdecoster
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.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.