Skip to content

Commit

Permalink
cast bad size values to zero instead of NaN - fixup scattergeo jasmin…
Browse files Browse the repository at this point in the history
…e test
  • Loading branch information
archmoj committed Jul 23, 2019
1 parent 39b9840 commit f9db523
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 32 deletions.
2 changes: 1 addition & 1 deletion src/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ lib.mergeArray = function(traceAttr, cd, cdAttr, fn) {
lib.mergeArrayCastPositive = function(traceAttr, cd, cdAttr) {
return lib.mergeArray(traceAttr, cd, cdAttr, function(v) {
var w = +v;
return isNaN(w) ? NaN : w > 0 ? w : 0;
return !isFinite(w) ? 0 : w > 0 ? w : 0;
});
};

Expand Down
6 changes: 3 additions & 3 deletions test/jasmine/tests/bar_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -412,14 +412,14 @@ describe('Bar.calc', function() {
var gd = mockBarPlot([{
marker: {
line: {
width: [2, 1, 0, -1, false, true, null, [], -Infinity, Infinity, NaN, {}]
width: [2, 1, 0, -1, false, true, null, [], -Infinity, Infinity, NaN, {}, '12+1', '1e1']
}
},
y: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
y: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]
}], {});

var cd = gd.calcdata;
assertPointField(cd, 'mlw', [[2, 1, 0, 0, 0, 1, 0, 0, 0, Infinity, NaN, NaN]]);
assertPointField(cd, 'mlw', [[2, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 10]]);
});
});

Expand Down
20 changes: 3 additions & 17 deletions test/jasmine/tests/funnel_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -356,28 +356,14 @@ describe('Funnel.calc', function() {
var gd = mockFunnelPlot([{
marker: {
line: {
width: [2, 1, 0, -1, false, true, null, [], -Infinity, Infinity, NaN, {}]
width: [2, 1, 0, -1, false, true, null, [], -Infinity, Infinity, NaN, {}, '12+1', '1e1']
}
},
y: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
y: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]
}], {});

var cd = gd.calcdata;
assertPointField(cd, 'mlw', [[2, 1, 0, 0, 0, 1, 0, 0, 0, Infinity, NaN, NaN]]);
});

it('should guard against negative marker.line.width values', function() {
var gd = mockFunnelPlot([{
marker: {
line: {
width: [2, 1, 0, -1, false, true, null, [], -Infinity, Infinity, NaN, {}]
}
},
y: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
}], {});

var cd = gd.calcdata;
assertPointField(cd, 'mlw', [[2, 1, 0, 0, 0, 1, 0, 0, 0, Infinity, NaN, NaN]]);
assertPointField(cd, 'mlw', [[2, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 10]]);
});
});

Expand Down
20 changes: 10 additions & 10 deletions test/jasmine/tests/scatter_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -298,16 +298,16 @@ describe('Test scatter', function() {
mode: 'markers+text',
marker: {
line: {
width: [2, 1, 0, -1, false, true, null, [], -Infinity, Infinity, NaN, {}]
width: [2, 1, 0, -1, false, true, null, [], -Infinity, Infinity, NaN, {}, '12+1', '1e1']
},
opacity: [2, 1, 0, -1, false, true, null, [], -Infinity, Infinity, NaN, {}],
size: [2, 1, 0, -1, false, true, null, [], -Infinity, Infinity, NaN, {}]
opacity: [2, 1, 0, -1, false, true, null, [], -Infinity, Infinity, NaN, {}, '12+1', '1e1'],
size: [2, 1, 0, -1, false, true, null, [], -Infinity, Infinity, NaN, {}, '12+1', '1e1']
},
textfont: {
size: [2, 1, 0, -1, false, true, null, [], -Infinity, Infinity, NaN, {}]
size: [2, 1, 0, -1, false, true, null, [], -Infinity, Infinity, NaN, {}, '12+1', '1e1']
},
text: ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12'],
y: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
text: ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14'],
y: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]
}],
layout: {},
calcdata: [],
Expand All @@ -318,10 +318,10 @@ describe('Test scatter', function() {
Plots.doCalcdata(gd);

var cd = gd.calcdata;
assertPointField(cd, 'mlw', [[2, 1, 0, 0, 0, 1, 0, 0, 0, Infinity, NaN, NaN]]);
assertPointField(cd, 'mo', [[2, 1, 0, 0, 0, 1, 0, 0, 0, Infinity, NaN, NaN]]);
assertPointField(cd, 'ms', [[2, 1, 0, 0, 0, 1, 0, 0, 0, Infinity, NaN, NaN]]);
assertPointField(cd, 'ts', [[2, 1, 0, 0, 0, 1, 0, 0, 0, Infinity, NaN, NaN]]);
assertPointField(cd, 'mlw', [[2, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 10]]);
assertPointField(cd, 'mo', [[2, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 10]]);
assertPointField(cd, 'ms', [[2, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 10]]);
assertPointField(cd, 'ts', [[2, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 10]]);
});
});

Expand Down
2 changes: 1 addition & 1 deletion test/jasmine/tests/scattergeo_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ describe('Test scattergeo calc', function() {

expect(calcTrace).toEqual([
{ lonlat: [10, 20], mc: 0, ms: 10 },
{ lonlat: [20, 30], mc: null, ms: NaN },
{ lonlat: [20, 30], mc: null, ms: 0 },
{ lonlat: [BADNUM, BADNUM], mc: 5, ms: 8 },
{ lonlat: [30, 10], mc: 10, ms: 10 }
]);
Expand Down

0 comments on commit f9db523

Please sign in to comment.