Skip to content

Commit 6a0ecd2

Browse files
authored
Merge pull request #5294 from plotly/remove-zero-length-bar-static-plot
In staticPlot, do not draw-zero length bars
2 parents aa6f442 + b1632b7 commit 6a0ecd2

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/traces/bar/plot.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ function plot(gd, plotinfo, cdModule, traceLayer, opts, makeOnCompleteCallback)
242242
var sel = transition(Lib.ensureSingle(bar, 'path'), fullLayout, opts, makeOnCompleteCallback);
243243
sel
244244
.style('vector-effect', 'non-scaling-stroke')
245-
.attr('d', isNaN((x1 - x0) * (y1 - y0)) ? 'M0,0Z' : 'M' + x0 + ',' + y0 + 'V' + y1 + 'H' + x1 + 'V' + y0 + 'Z')
245+
.attr('d', (isNaN((x1 - x0) * (y1 - y0)) || (isBlank && gd._context.staticPlot)) ? 'M0,0Z' : 'M' + x0 + ',' + y0 + 'V' + y1 + 'H' + x1 + 'V' + y0 + 'Z')
246246
.call(Drawing.setClipUrl, plotinfo.layerClipId, gd);
247247

248248
if(!fullLayout.uniformtext.mode && withTransition) {

test/jasmine/tests/bar_test.js

+15
Original file line numberDiff line numberDiff line change
@@ -2119,6 +2119,21 @@ describe('A bar plot', function() {
21192119
.then(done);
21202120
});
21212121

2122+
it('should display bar of zero-length as M0,0Z when staticPlot is true', function(done) {
2123+
// otherwise Chromium produces a PDF with visual artifacts in place of zero-length bar: https://github.com/plotly/orca/issues/345
2124+
var mock = {data: [{type: 'bar', x: ['a', 'b'], y: [0, 5]}], config: {staticPlot: true}};
2125+
2126+
Plotly.newPlot(gd, mock)
2127+
.then(function() {
2128+
var nodes = gd.querySelectorAll('g.point > path');
2129+
expect(nodes.length).toBe(2, '# of bars');
2130+
var d = nodes[0].getAttribute('d');
2131+
expect(d).toBe('M0,0Z');
2132+
})
2133+
.catch(failTest)
2134+
.then(done);
2135+
});
2136+
21222137
describe('show narrow bars', function() {
21232138
['initial zoom', 'after zoom out'].forEach(function(zoomStr) {
21242139
it(zoomStr, function(done) {

0 commit comments

Comments
 (0)