From 71bdd14643eb24db2cb359d6d75c2b96dd2cc5b2 Mon Sep 17 00:00:00 2001 From: william-xue <20151622+william-xue@users.noreply.github.com> Date: Fri, 25 Sep 2026 09:08:15 +0800 Subject: [PATCH 1/2] Fix *auto* text of zero-length bar traces 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. --- src/traces/bar/plot.js | 7 ++++++- test/jasmine/tests/bar_test.js | 24 ++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/src/traces/bar/plot.js b/src/traces/bar/plot.js index 60f7154cf73..61279648730 100644 --- a/src/traces/bar/plot.js +++ b/src/traces/bar/plot.js @@ -568,10 +568,15 @@ function appendBarText(gd, plotinfo, bar, cd, i, x0, x1, y0, y1, r, overhead, op var hasB = calcBar.hasB; var barIsRounded = r && r - overhead > TEXTPAD; + // A null value has no bar to place text inside of or next to. + // A zero-length bar keeps a position, so `auto` text can fall through to + // the outside placement below. + var isNullBar = !isNumeric(calcBar.s1); + if ( !text || textPosition === 'none' || - ((calcBar.isBlank || x0 === x1 || y0 === y1) && (textPosition === 'auto' || textPosition === 'inside')) + ((calcBar.isBlank || x0 === x1 || y0 === y1) && (textPosition === 'inside' || isNullBar)) ) { bar.select('text').remove(); return; diff --git a/test/jasmine/tests/bar_test.js b/test/jasmine/tests/bar_test.js index 55ee5f3ee75..a072cb03d83 100644 --- a/test/jasmine/tests/bar_test.js +++ b/test/jasmine/tests/bar_test.js @@ -2261,6 +2261,30 @@ describe('A bar plot', function() { .then(done, done.fail); }); + it('should draw *auto* text of zero-length bars outside', function(done) { + Plotly.newPlot(gd, { + data: [{ + type: 'bar', + x: ['a', 'b', 'c'], + y: [0, 5, null], + text: ['ZERO', 'FIVE', 'NULLPT'], + textposition: 'auto' + }], + layout: {width: 400, height: 400, margin: {l: 0, t: 0, r: 0, b: 0}} + }) + .then(function() { + var texts = []; + d3Select(gd).selectAll('.barlayer .bartext').each(function() { + texts.push(this.textContent); + }); + + expect(texts).toEqual(['ZERO', 'FIVE'], 'drawn bar text'); + expect(d3Select(gd).select('.barlayer .bartext').attr('class')) + .toBe('bartext bartext-outside', 'zero-length bar text placement'); + }) + .then(done, done.fail); + }); + describe('show narrow bars', function() { ['initial zoom', 'after zoom out'].forEach(function(zoomStr) { it(zoomStr, function(done) { From 29cab0878fc0f781ed17247cd82080b368a29b4d Mon Sep 17 00:00:00 2001 From: william-xue <20151622+william-xue@users.noreply.github.com> Date: Fri, 25 Sep 2026 09:09:13 +0800 Subject: [PATCH 2/2] Add draft log for the zero-length bar text fix --- draftlogs/8078_fix.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 draftlogs/8078_fix.md diff --git a/draftlogs/8078_fix.md b/draftlogs/8078_fix.md new file mode 100644 index 00000000000..4e8e33746c6 --- /dev/null +++ b/draftlogs/8078_fix.md @@ -0,0 +1 @@ + - Fix `textposition: 'auto'` text of zero-length `bar` traces [[#8078](https://github.com/plotly/plotly.js/pull/8078)]