Skip to content

Commit 5279f99

Browse files
committed
set bar size in main serieslen loop
- so that item with non-numeric (x,y) are excluded from the calcdata.
1 parent b62529d commit 5279f99

File tree

2 files changed

+32
-11
lines changed

2 files changed

+32
-11
lines changed

src/traces/bar/calc.js

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,21 @@ module.exports = function calc(gd, trace) {
5151
var serieslen = Math.min(pos.length, size.length),
5252
cd = [];
5353

54-
// set position
54+
// set position and size
5555
for(i = 0; i < serieslen; i++) {
56+
var p = pos[i];
57+
var s = size[i];
5658

5759
// add bars with non-numeric sizes to calcdata
5860
// so that ensure that traces with gaps are
5961
// plotted in the correct order
6062

61-
if(isNumeric(pos[i])) {
62-
cd.push({p: pos[i]});
63+
if(isNumeric(p)) {
64+
if(isNumeric(s)) {
65+
cd.push({ p: p, s: s });
66+
} else {
67+
cd.push({ p: p });
68+
}
6369
}
6470
}
6571

@@ -84,13 +90,6 @@ module.exports = function calc(gd, trace) {
8490
}
8591
}
8692

87-
// set size
88-
for(i = 0; i < cd.length; i++) {
89-
if(isNumeric(size[i])) {
90-
cd[i].s = size[i];
91-
}
92-
}
93-
9493
// auto-z and autocolorscale if applicable
9594
if(hasColorscale(trace, 'marker')) {
9695
colorscaleCalc(trace, trace.marker.color, 'marker', 'c');

test/jasmine/tests/bar_test.js

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,28 @@ describe('Bar.calc', function() {
283283
var cd = gd.calcdata;
284284
assertPointField(cd, 'b', [[0, 1, 2], [0, 1, 0], [0, 0]]);
285285
});
286+
287+
it('should exclude items with non-numeric x/y from calcdata', function() {
288+
var gd = mockBarPlot([{
289+
x: [5, NaN, 15, 20, null, 21],
290+
y: [20, NaN, 23, 25, null, 26]
291+
}]);
292+
293+
var cd = gd.calcdata;
294+
assertPointField(cd, 'x', [[5, 15, 20, 21]]);
295+
assertPointField(cd, 'y', [[20, 23, 25, 26]]);
296+
});
297+
298+
it('should not exclude items with non-numeric y from calcdata (to plots gaps correctly)', function() {
299+
var gd = mockBarPlot([{
300+
x: ['a', 'b', 'c', 'd'],
301+
y: [1, null, 'nonsense', 15]
302+
}]);
303+
304+
var cd = gd.calcdata;
305+
assertPointField(cd, 'x', [[0, 1, 2, 3]]);
306+
assertPointField(cd, 'y', [[1, NaN, NaN, 15]]);
307+
});
286308
});
287309

288310
describe('Bar.setPositions', function() {
@@ -1285,7 +1307,7 @@ function mockBarPlot(dataWithoutTraceType, layout) {
12851307

12861308
var gd = {
12871309
data: dataWithTraceType,
1288-
layout: layout,
1310+
layout: layout || {},
12891311
calcdata: []
12901312
};
12911313

0 commit comments

Comments
 (0)