Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Increase axis autorange when bars have outside text labels#7675

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

Merged
emilykl merged 11 commits intomasterfromcutoff-bar-labels
Dec 19, 2025

Conversation

@emilykl
Copy link
Contributor

@emilyklemilykl commentedDec 16, 2025
edited
Loading

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. Usethis 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, andtext ortexttemplate is provided and non-falsy, andtextangle is0 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 textwidth rather than theheight
      • The goal is to improve the current situation by adding padding in the most common cases where needed, while avoiding addingtoo much padding to the extent possible (even if this means excluding some cases where padding is needed)
      • I am aware ofone 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 thehist_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 (withcliponaxis: false removed) Before:
Screenshot 2025-12-17 at 3 11 04 PM

hist_stacked mock (withcliponaxis: 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 onmaster and the "after" picture on this branch.

Other variations to test:

  • Settinglayout.yaxis.autorange to"reversed"
  • Using thebar.text property instead ofbar.texttemplate
  • Adding a second bar trace and settinglayout.barmode to"stack"

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

@emilyklemilykl marked this pull request as ready for reviewDecember 17, 2025 16:28
@emilyklemilykl changed the titleDRAFT: Fix for cut-off bar labelsIncrease axis autorange when bars have outside text labelsDec 17, 2025
Copy link
Contributor

@camdecostercamdecoster left a 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.

emilykl reacted with hooray emoji
@emilyklemilyklforce-pushed thecutoff-bar-labels branch 2 times, most recently from1ef511f toacf38e1CompareDecember 19, 2025 20:20
Co-authored-by: Cameron DeCoster <cameron.decoster@gmail.com>
@emilyklemilykl merged commite0c2df7 intomasterDec 19, 2025
6 of 7 checks passed
@emilyklemilykl deleted the cutoff-bar-labels branchDecember 19, 2025 23:13
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@camdecostercamdecostercamdecoster approved these changes

Assignees

@camdecostercamdecoster

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

3 participants

@emilykl@camdecoster

[8]ページ先頭

©2009-2025 Movatter.jp