Skip to content

Commit 4af4984

Browse files
committed
simplify get direction function in streamtube calc and improve jasmine test for random input
1 parent 608dc1a commit 4af4984

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

src/traces/streamtube/calc.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ module.exports = function calc(gd, trace) {
118118

119119
var getArray = function(c) { return c === 'x' ? x : c === 'y' ? y : z; };
120120
var getVals = function(c) { return c === 'x' ? Xs : c === 'y' ? Ys : Zs; };
121-
var getDir = function(c) { return (+(c[len - 1] - c[0])) * 2 + 1; };
121+
var getDir = function(c) { return (c[len - 1] < c[0]) ? -1 : 1; };
122122

123123
var arrK = getArray(gridFill[1]);
124124
var arrJ = getArray(gridFill[3]);

test/jasmine/tests/streamtube_test.js

+11-11
Original file line numberDiff line numberDiff line change
@@ -305,17 +305,13 @@ describe('Test streamtube interactions', function() {
305305
var v = [];
306306
var w = [];
307307

308-
for(var i = 0; i < 3; i++) {
309-
for(var j = i; j < 4; j++) {
310-
for(var k = j; k < 5; k++) {
311-
x.push(i);
312-
y.push(j);
313-
z.push(k);
314-
u.push(1);
315-
v.push(1);
316-
w.push(1);
317-
}
318-
}
308+
for(var n = 0; n < 1000; n++) {
309+
x.push((10 * Math.random()) | 0);
310+
y.push((10 * Math.random()) | 0);
311+
z.push((10 * Math.random()) | 0);
312+
u.push(1);
313+
v.push(1);
314+
w.push(1);
319315
}
320316

321317
var fig = {
@@ -338,11 +334,15 @@ describe('Test streamtube interactions', function() {
338334
expect(exp.cellsLength).toBe(objs[0].cells.length, 'cells length - ' + msg);
339335
}
340336

337+
spyOn(Lib, 'warn');
338+
341339
Plotly.plot(gd, fig).then(function() {
342340
_assert('arbitrary coordinates', {
343341
positionsLength: 0,
344342
cellsLength: 0
345343
});
344+
}).then(function() {
345+
expect(Lib.warn).toHaveBeenCalledWith('Encountered arbitrary coordinates! Unable to input data grid.');
346346
})
347347
.catch(failTest)
348348
.then(done);

0 commit comments

Comments
 (0)