Skip to content

Fix *auto* text of zero-length bar traces - #8078

Open
william-xue wants to merge 2 commits into
plotly:mainfrom
william-xue:bar-auto-text-zero-length
Open

william-xue wants to merge 2 commits into
plotly:mainfrom
william-xue:bar-auto-text-zero-length

Conversation

@william-xue

Copy link
Copy Markdown

Fixes #6474.

What changes

src/traces/bar/plot.js returned early for every blank bar when textposition was *auto* or *inside*, so a bar of zero length never drew its text. The early return now covers *inside* placement and bars that have no position at all (null values). Text with *auto* placement falls through to the existing fit check, which finds no room inside a zero-length bar and places the text outside.

*outside* text already drew for zero-length bars, so *auto* and *outside* now agree.

Validation

plotly-4.1.1.min.js from the CDN, loaded in headless Chrome. One page holds two figures; the .barlayer .bartext nodes come from the DOM after newPlot.

trace before after
y: [0, 5, 10], textposition: 'auto', text: ['ZERO', 'FIVE', 'TEN'] FIVE, TEN ZERO (bartext-outside, translate(96.66, 334)), FIVE, TEN
y: [null, 5, 10], textposition: 'auto', text: ['NULLPT', 'FIVE', 'TEN'] FIVE, TEN FIVE, TEN (unchanged)

The right column comes from the same page with the change applied to the bundle copy.

Tests

  • test/jasmine/tests/bar_test.js: new case inside the A bar plot describe, should draw *auto* text of zero-length bars outside. It fails before the change, because no ZERO node exists, and it asserts that a null value keeps its text hidden.
  • Baselines that move: test/image/baselines/bar_attrs_relative.png and test/image/baselines/round-bar_attrs_relative.png. Both mocks hold zero-length bars with textposition: 'auto' and text, so their baselines gain the outside label. The test-baselines job reports the diff.

I did not run the karma suites locally.

The draft log follows in a second commit, since its filename needs this PR number.

A zero-length bar kept its text hidden when textposition was
*auto*, while *outside* text was drawn. Only hide text for a bar
with no position or for *inside* placement.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bar chart: textposition='auto' not working for 0 values

1 participant