Skip to content

Commit 1721ab7

Browse files
committed
fix waterfall connectors - not to draw lines between null amounts - using BADNUM
1 parent f3a071e commit 1721ab7

File tree

5 files changed

+23
-4
lines changed

5 files changed

+23
-4
lines changed

src/traces/waterfall/calc.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
var Axes = require('../../plots/cartesian/axes');
1212
var mergeArray = require('../../lib').mergeArray;
1313
var calcSelection = require('../scatter/calc_selection');
14+
var BADNUM = require('../../constants/numerical').BADNUM;
1415

1516
function isAbsolute(a) {
1617
return (a === 'a' || a === 'absolute');
@@ -44,13 +45,22 @@ module.exports = function calc(gd, trace) {
4445
var hasTotals = false;
4546

4647
for(var i = 0; i < serieslen; i++) {
48+
4749
var amount = size[i] || 0;
4850

51+
var connectToNext = false;
52+
if(size[i] !== BADNUM || isTotal(trace.measure[i]) || isAbsolute(trace.measure[i])) {
53+
if(i + 1 < serieslen && (size[i + 1] !== BADNUM || isTotal(trace.measure[i + 1]) || isAbsolute(trace.measure[i + 1]))) {
54+
connectToNext = true;
55+
}
56+
}
57+
4958
var cdi = cd[i] = {
5059
i: i,
5160
p: pos[i],
5261
s: amount,
53-
rawS: amount
62+
rawS: amount,
63+
cNext: connectToNext
5464
};
5565

5666
if(isAbsolute(trace.measure[i])) {

src/traces/waterfall/plot.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,12 @@ function plotConnectors(gd, plotinfo, cdModule, traceLayer) {
4646

4747
connectors.exit().remove();
4848

49-
var len = connectors[0].length;
49+
var len = connectors.size();
5050

5151
connectors.each(function(di, i) {
52+
// don't draw lines between nulls
53+
if(i !== len - 1 && !di.cNext) return;
54+
5255
var connector = d3.select(this);
5356
var shape = '';
5457

-707 Bytes
Loading

test/image/mocks/waterfall_nonnumeric_sizes.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,17 @@
55
"a",
66
"b",
77
"c",
8-
"d"
8+
"d",
9+
"e",
10+
"f"
911
],
1012
"y": [
1113
1,
1214
null,
1315
"nonsense",
14-
15
16+
14,
17+
0,
18+
1
1519
],
1620
"type": "waterfall"
1721
}

test/jasmine/tests/waterfall_test.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ describe('waterfall calc / crossTraceCalc', function() {
231231
assertPointField(cd, 'isSum', [[false, false, false], [true, false, true, false, true]]);
232232
assertPointField(cd, 'rawS', [[2, 1, 2], [3, 1, 0, 2, 0]]);
233233
assertPointField(cd, 'dir', [['increasing', 'increasing', 'increasing'], ['totals', 'increasing', 'totals', 'increasing', 'totals']]);
234+
assertPointField(cd, 'cNext', [[true, true, false], [true, true, true, true, false]]);
234235
assertPointField(cd, 'hasTotals', [[false, undefined, undefined], [true, undefined, undefined, undefined, undefined]]);
235236
assertTraceField(cd, 't.barwidth', [0.8, 0.8]);
236237
assertTraceField(cd, 't.poffset', [-0.4, -0.4]);
@@ -263,6 +264,7 @@ describe('waterfall calc / crossTraceCalc', function() {
263264
assertPointField(cd, 'isSum', [[false, false, false], [true, false, true, false, true]]);
264265
assertPointField(cd, 'rawS', [[2, 1, 2], [3, 1, 0, 2, 0]]);
265266
assertPointField(cd, 'dir', [['increasing', 'increasing', 'increasing'], ['totals', 'increasing', 'totals', 'increasing', 'totals']]);
267+
assertPointField(cd, 'cNext', [[true, true, false], [true, true, true, true, false]]);
266268
assertPointField(cd, 'hasTotals', [[false, undefined, undefined], [true, undefined, undefined, undefined, undefined]]);
267269
assertTraceField(cd, 't.barwidth', [0.36, 0.36]);
268270
assertTraceField(cd, 't.poffset', [-0.38, 0.02]);

0 commit comments

Comments
 (0)