diff --git a/src/traces/bar/plot.js b/src/traces/bar/plot.js index eaee3a1418c..c52bd16c976 100644 --- a/src/traces/bar/plot.js +++ b/src/traces/bar/plot.js @@ -242,7 +242,7 @@ function plot(gd, plotinfo, cdModule, traceLayer, opts, makeOnCompleteCallback) var sel = transition(Lib.ensureSingle(bar, 'path'), fullLayout, opts, makeOnCompleteCallback); sel .style('vector-effect', 'non-scaling-stroke') - .attr('d', isNaN((x1 - x0) * (y1 - y0)) ? 'M0,0Z' : 'M' + x0 + ',' + y0 + 'V' + y1 + 'H' + x1 + 'V' + y0 + 'Z') + .attr('d', (isNaN((x1 - x0) * (y1 - y0)) || (isBlank && gd._context.staticPlot)) ? 'M0,0Z' : 'M' + x0 + ',' + y0 + 'V' + y1 + 'H' + x1 + 'V' + y0 + 'Z') .call(Drawing.setClipUrl, plotinfo.layerClipId, gd); if(!fullLayout.uniformtext.mode && withTransition) { diff --git a/test/jasmine/tests/bar_test.js b/test/jasmine/tests/bar_test.js index a2cfe1cdfc7..44f237eeb7a 100644 --- a/test/jasmine/tests/bar_test.js +++ b/test/jasmine/tests/bar_test.js @@ -2119,6 +2119,21 @@ describe('A bar plot', function() { .then(done); }); + it('should display bar of zero-length as M0,0Z when staticPlot is true', function(done) { + // otherwise Chromium produces a PDF with visual artifacts in place of zero-length bar: https://github.com/plotly/orca/issues/345 + var mock = {data: [{type: 'bar', x: ['a', 'b'], y: [0, 5]}], config: {staticPlot: true}}; + + Plotly.newPlot(gd, mock) + .then(function() { + var nodes = gd.querySelectorAll('g.point > path'); + expect(nodes.length).toBe(2, '# of bars'); + var d = nodes[0].getAttribute('d'); + expect(d).toBe('M0,0Z'); + }) + .catch(failTest) + .then(done); + }); + describe('show narrow bars', function() { ['initial zoom', 'after zoom out'].forEach(function(zoomStr) { it(zoomStr, function(done) {