From 37debb6af27302312724592f1b378b53e40c55a9 Mon Sep 17 00:00:00 2001 From: archmoj Date: Thu, 12 Mar 2020 12:55:58 -0400 Subject: [PATCH 1/2] fix issue 4631 - bypass NaN positions --- src/traces/bar/plot.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/traces/bar/plot.js b/src/traces/bar/plot.js index 11b72020351..eaee3a1418c 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', 'M' + x0 + ',' + y0 + 'V' + y1 + 'H' + x1 + 'V' + y0 + 'Z') + .attr('d', isNaN((x1 - x0) * (y1 - y0)) ? 'M0,0Z' : 'M' + x0 + ',' + y0 + 'V' + y1 + 'H' + x1 + 'V' + y0 + 'Z') .call(Drawing.setClipUrl, plotinfo.layerClipId, gd); if(!fullLayout.uniformtext.mode && withTransition) { From bf5973a91df002bd10e9fdea0eade2246c1545a9 Mon Sep 17 00:00:00 2001 From: archmoj Date: Thu, 12 Mar 2020 13:23:44 -0400 Subject: [PATCH 2/2] add jasmine test --- test/jasmine/tests/bar_test.js | 83 +++++++++++++++++++++++++++++++++- 1 file changed, 82 insertions(+), 1 deletion(-) diff --git a/test/jasmine/tests/bar_test.js b/test/jasmine/tests/bar_test.js index f9951e2ddd8..39cc38d4d04 100644 --- a/test/jasmine/tests/bar_test.js +++ b/test/jasmine/tests/bar_test.js @@ -2876,7 +2876,7 @@ describe('bar tweening', function() { data: [{ type: 'bar', x: ['A', 'B', 'C'], - y: [null, 5, 3], + y: [null, 5, 3, 4], marker: { line: { width: 10 @@ -2931,6 +2931,87 @@ describe('bar tweening', function() { .catch(failTest) .then(done); }); + + it('handle NaN positions on vertical bars', function(done) { + var y1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; + var y2 = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]; + var mockCopy = { + data: [ + { + type: 'bar', + x: [ + 0, + 1, + '', + 'NaN', + NaN, + Infinity, + -Infinity, + undefined, + null, + 9 + ], + y: y1 + } + ], + layout: { + width: 400, + height: 300 + } + }; + + var tests = [ + [0, '.point path', 'attr', 'd', ['M2,120V109H22V120Z', 'M26,120V97H46V120Z', 'M0,0Z', 'M0,0Z', 'M0,0Z', 'M0,0Z', 'M0,0Z', 'M0,0Z', 'M0,0Z', 'M218,120V6H238V120Z']], + [300, '.point path', 'attr', 'd', ['M2,120V47H22V120Z', 'M26,120V49H46V120Z', 'M0,0Z', 'M0,0Z', 'M0,0Z', 'M0,0Z', 'M0,0Z', 'M0,0Z', 'M0,0Z', 'M218,120V68H238V120Z']], + [600, '.point path', 'attr', 'd', ['M2,120V6H22V120Z', 'M26,120V17H46V120Z', 'M0,0Z', 'M0,0Z', 'M0,0Z', 'M0,0Z', 'M0,0Z', 'M0,0Z', 'M0,0Z', 'M218,120V109H238V120Z']] + ]; + var animateOpts = {data: [{y: y2}]}; + + checkTransition(gd, mockCopy, animateOpts, transitionOpts, tests) + .catch(failTest) + .then(done); + }); + + it('handle NaN positions on horizontal bars', function(done) { + var x1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; + var x2 = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]; + var mockCopy = { + data: [ + { + type: 'bar', + orientation: 'h', + y: [ + 0, + 1, + '', + 'NaN', + NaN, + Infinity, + -Infinity, + undefined, + null, + 9 + ], + x: x1 + } + ], + layout: { + width: 400, + height: 300 + } + }; + + var tests = [ + [0, '.point path', 'attr', 'd', ['M0,119V109H23V119Z', 'M0,107V97H46V107Z', 'M0,0Z', 'M0,0Z', 'M0,0Z', 'M0,0Z', 'M0,0Z', 'M0,0Z', 'M0,0Z', 'M0,11V1H228V11Z']], + [300, '.point path', 'attr', 'd', ['M0,119V109H146V119Z', 'M0,107V97H141V107Z', 'M0,0Z', 'M0,0Z', 'M0,0Z', 'M0,0Z', 'M0,0Z', 'M0,0Z', 'M0,0Z', 'M0,11V1H105V11Z']], + [600, '.point path', 'attr', 'd', ['M0,119V109H228V119Z', 'M0,107V97H205V107Z', 'M0,0Z', 'M0,0Z', 'M0,0Z', 'M0,0Z', 'M0,0Z', 'M0,0Z', 'M0,0Z', 'M0,11V1H23V11Z']] + ]; + var animateOpts = {data: [{x: x2}]}; + + checkTransition(gd, mockCopy, animateOpts, transitionOpts, tests) + .catch(failTest) + .then(done); + }); }); describe('bar uniformtext', function() {