Skip to content

Commit 39b9840

Browse files
committed
add jasmine tests to guard against negative sizes during calc step
1 parent e584f80 commit 39b9840

File tree

3 files changed

+94
-0
lines changed

3 files changed

+94
-0
lines changed

test/jasmine/tests/bar_test.js

+14
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,20 @@ describe('Bar.calc', function() {
407407
assertPointField(cd, 'x', [[1, NaN, NaN, 15]]);
408408
assertPointField(cd, 'y', [[1, 2, 10, 30]]);
409409
});
410+
411+
it('should guard against negative marker.line.width values', function() {
412+
var gd = mockBarPlot([{
413+
marker: {
414+
line: {
415+
width: [2, 1, 0, -1, false, true, null, [], -Infinity, Infinity, NaN, {}]
416+
}
417+
},
418+
y: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
419+
}], {});
420+
421+
var cd = gd.calcdata;
422+
assertPointField(cd, 'mlw', [[2, 1, 0, 0, 0, 1, 0, 0, 0, Infinity, NaN, NaN]]);
423+
});
410424
});
411425

412426
describe('Bar.crossTraceCalc (formerly known as setPositions)', function() {

test/jasmine/tests/funnel_test.js

+28
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,34 @@ describe('Funnel.calc', function() {
351351
assertPointField(cd, 'y', [[1, NaN, NaN, 15]]);
352352
assertPointField(cd, 'x', [[0.5, 1, 5, 15]]);
353353
});
354+
355+
it('should guard against negative marker.line.width values', function() {
356+
var gd = mockFunnelPlot([{
357+
marker: {
358+
line: {
359+
width: [2, 1, 0, -1, false, true, null, [], -Infinity, Infinity, NaN, {}]
360+
}
361+
},
362+
y: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
363+
}], {});
364+
365+
var cd = gd.calcdata;
366+
assertPointField(cd, 'mlw', [[2, 1, 0, 0, 0, 1, 0, 0, 0, Infinity, NaN, NaN]]);
367+
});
368+
369+
it('should guard against negative marker.line.width values', function() {
370+
var gd = mockFunnelPlot([{
371+
marker: {
372+
line: {
373+
width: [2, 1, 0, -1, false, true, null, [], -Infinity, Infinity, NaN, {}]
374+
}
375+
},
376+
y: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
377+
}], {});
378+
379+
var cd = gd.calcdata;
380+
assertPointField(cd, 'mlw', [[2, 1, 0, 0, 0, 1, 0, 0, 0, Infinity, NaN, NaN]]);
381+
});
354382
});
355383

356384
describe('Funnel.crossTraceCalc', function() {

test/jasmine/tests/scatter_test.js

+52
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ var Scatter = require('@src/traces/scatter');
33
var makeBubbleSizeFn = require('@src/traces/scatter/make_bubble_size_func');
44
var linePoints = require('@src/traces/scatter/line_points');
55
var Lib = require('@src/lib');
6+
var Plots = require('@src/plots/plots');
67

78
var Plotly = require('@lib/index');
89
var createGraphDiv = require('../assets/create_graph_div');
@@ -18,6 +19,8 @@ var assertMultiNodeOrder = customAssertions.assertMultiNodeOrder;
1819
var checkEventData = require('../assets/check_event_data');
1920
var constants = require('@src/traces/scatter/constants');
2021

22+
var supplyAllDefaults = require('../assets/supply_defaults');
23+
2124
var getOpacity = function(node) { return Number(node.style.opacity); };
2225
var getFillOpacity = function(node) { return Number(node.style['fill-opacity']); };
2326
var getColor = function(node) { return node.style.fill; };
@@ -273,6 +276,55 @@ describe('Test scatter', function() {
273276
});
274277
});
275278

279+
describe('calc', function() {
280+
function assertPointField(calcData, prop, expectation) {
281+
var values = [];
282+
283+
calcData.forEach(function(calcTrace) {
284+
var vals = calcTrace.map(function(pt) {
285+
return Lib.nestedProperty(pt, prop).get();
286+
});
287+
288+
values.push(vals);
289+
});
290+
291+
expect(values).toBeCloseTo2DArray(expectation, undefined, '(field ' + prop + ')');
292+
}
293+
294+
it('should guard against negative size values', function() {
295+
var gd = {
296+
data: [{
297+
type: 'scatter',
298+
mode: 'markers+text',
299+
marker: {
300+
line: {
301+
width: [2, 1, 0, -1, false, true, null, [], -Infinity, Infinity, NaN, {}]
302+
},
303+
opacity: [2, 1, 0, -1, false, true, null, [], -Infinity, Infinity, NaN, {}],
304+
size: [2, 1, 0, -1, false, true, null, [], -Infinity, Infinity, NaN, {}]
305+
},
306+
textfont: {
307+
size: [2, 1, 0, -1, false, true, null, [], -Infinity, Infinity, NaN, {}]
308+
},
309+
text: ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12'],
310+
y: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
311+
}],
312+
layout: {},
313+
calcdata: [],
314+
_context: {locale: 'en', locales: {}}
315+
};
316+
317+
supplyAllDefaults(gd);
318+
Plots.doCalcdata(gd);
319+
320+
var cd = gd.calcdata;
321+
assertPointField(cd, 'mlw', [[2, 1, 0, 0, 0, 1, 0, 0, 0, Infinity, NaN, NaN]]);
322+
assertPointField(cd, 'mo', [[2, 1, 0, 0, 0, 1, 0, 0, 0, Infinity, NaN, NaN]]);
323+
assertPointField(cd, 'ms', [[2, 1, 0, 0, 0, 1, 0, 0, 0, Infinity, NaN, NaN]]);
324+
assertPointField(cd, 'ts', [[2, 1, 0, 0, 0, 1, 0, 0, 0, Infinity, NaN, NaN]]);
325+
});
326+
});
327+
276328
describe('isBubble', function() {
277329
it('should return true when marker.size is an Array', function() {
278330
var trace = {

0 commit comments

Comments
 (0)