Skip to content

Commit c5173e1

Browse files
authored
Merge pull request #4634 from plotly/fix4631-bar-handle-nan
Fix4631 - handle NaN cases to allow breaks on bar-like traces
2 parents 9a611b3 + bf5973a commit c5173e1

File tree

2 files changed

+83
-2
lines changed

2 files changed

+83
-2
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', 'M' + x0 + ',' + y0 + 'V' + y1 + 'H' + x1 + 'V' + y0 + 'Z')
245+
.attr('d', isNaN((x1 - x0) * (y1 - y0)) ? '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

+82-1
Original file line numberDiff line numberDiff line change
@@ -2876,7 +2876,7 @@ describe('bar tweening', function() {
28762876
data: [{
28772877
type: 'bar',
28782878
x: ['A', 'B', 'C'],
2879-
y: [null, 5, 3],
2879+
y: [null, 5, 3, 4],
28802880
marker: {
28812881
line: {
28822882
width: 10
@@ -2931,6 +2931,87 @@ describe('bar tweening', function() {
29312931
.catch(failTest)
29322932
.then(done);
29332933
});
2934+
2935+
it('handle NaN positions on vertical bars', function(done) {
2936+
var y1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
2937+
var y2 = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1];
2938+
var mockCopy = {
2939+
data: [
2940+
{
2941+
type: 'bar',
2942+
x: [
2943+
0,
2944+
1,
2945+
'',
2946+
'NaN',
2947+
NaN,
2948+
Infinity,
2949+
-Infinity,
2950+
undefined,
2951+
null,
2952+
9
2953+
],
2954+
y: y1
2955+
}
2956+
],
2957+
layout: {
2958+
width: 400,
2959+
height: 300
2960+
}
2961+
};
2962+
2963+
var tests = [
2964+
[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']],
2965+
[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']],
2966+
[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']]
2967+
];
2968+
var animateOpts = {data: [{y: y2}]};
2969+
2970+
checkTransition(gd, mockCopy, animateOpts, transitionOpts, tests)
2971+
.catch(failTest)
2972+
.then(done);
2973+
});
2974+
2975+
it('handle NaN positions on horizontal bars', function(done) {
2976+
var x1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
2977+
var x2 = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1];
2978+
var mockCopy = {
2979+
data: [
2980+
{
2981+
type: 'bar',
2982+
orientation: 'h',
2983+
y: [
2984+
0,
2985+
1,
2986+
'',
2987+
'NaN',
2988+
NaN,
2989+
Infinity,
2990+
-Infinity,
2991+
undefined,
2992+
null,
2993+
9
2994+
],
2995+
x: x1
2996+
}
2997+
],
2998+
layout: {
2999+
width: 400,
3000+
height: 300
3001+
}
3002+
};
3003+
3004+
var tests = [
3005+
[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']],
3006+
[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']],
3007+
[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']]
3008+
];
3009+
var animateOpts = {data: [{x: x2}]};
3010+
3011+
checkTransition(gd, mockCopy, animateOpts, transitionOpts, tests)
3012+
.catch(failTest)
3013+
.then(done);
3014+
});
29343015
});
29353016

29363017
describe('bar uniformtext', function() {

0 commit comments

Comments
 (0)