You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
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)
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.
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:
textpositionis'outside',orientationis vertical, andtextortexttemplateis provided and non-falsy, andtextangleis0or'auto'"cliponaxis": "false"from thehist_stackedimage mock, to demonstrate the effect of the changes in this PR (see below)Screenshots
Before:

After:

hist_stackedmock (withcliponaxis: falseremoved) Before:hist_stackedmock (withcliponaxis: falseremoved) After:Steps for testing
Use the following mock:
Verify that it looks like the "before" picture on
masterand the "after" picture on this branch.Other variations to test:
layout.yaxis.autorangeto"reversed"bar.textproperty instead ofbar.texttemplatelayout.barmodeto"stack"You can also load the
hist_stackedmock in the devtools as another test case.