Skip to content

Commit 9fa5ece

Browse files
committed
add 'len' argument to zip3
- to not have to .slice input array twice
1 parent 5c2ddfc commit 9fa5ece

File tree

4 files changed

+18
-9
lines changed

4 files changed

+18
-9
lines changed

src/plots/gl3d/zip3.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
'use strict';
1010

1111
module.exports = function zip3(x, y, z, len) {
12-
var result = new Array(x.length);
12+
len = len || x.length;
13+
14+
var result = new Array(len);
1315
for(var i = 0; i < len; i++) {
1416
result[i] = [x[i], y[i], z[i]];
1517
}

src/traces/cone/calc.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@ module.exports = function calc(gd, trace) {
1414
var u = trace.u;
1515
var v = trace.v;
1616
var w = trace.w;
17-
var len = Math.min(u.length, v.length, w.length);
17+
var len = Math.min(
18+
trace.x.length, trace.y.length, trace.z.length,
19+
u.length, v.length, w.length
20+
);
1821
var normMax = -Infinity;
1922
var normMin = Infinity;
2023

@@ -28,6 +31,7 @@ module.exports = function calc(gd, trace) {
2831
normMin = Math.min(normMin, norm);
2932
}
3033

34+
trace._len = len;
3135
trace._normMax = normMax;
3236

3337
colorscaleCalc(trace, [normMin, normMax], '', 'c');

src/traces/cone/convert.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,15 @@ function convert(scene, trace) {
6969
coneOpts.vectors = zip3(
7070
toDataCoords(trace.u, 'xaxis'),
7171
toDataCoords(trace.v, 'yaxis'),
72-
toDataCoords(trace.w, 'zaxis')
72+
toDataCoords(trace.w, 'zaxis'),
73+
trace._len
7374
);
7475

7576
coneOpts.positions = zip3(
7677
toDataCoords(trace.x, 'xaxis'),
7778
toDataCoords(trace.y, 'yaxis'),
78-
toDataCoords(trace.z, 'zaxis')
79+
toDataCoords(trace.z, 'zaxis'),
80+
trace._len
7981
);
8082

8183
coneOpts.colormap = parseColorScale(trace.colorscale);

src/traces/streamtube/convert.js

+6-5
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,12 @@ function convert(scene, trace) {
8686
return Lib.simpleMap(arr, function(v) { return ax.d2l(v) * scale; });
8787
}
8888

89-
var u = toDataCoords(trace.u.slice(0, len), 'xaxis');
90-
var v = toDataCoords(trace.v.slice(0, len), 'yaxis');
91-
var w = toDataCoords(trace.w.slice(0, len), 'zaxis');
92-
93-
tubeOpts.vectors = zip3(u, v, w);
89+
tubeOpts.vectors = zip3(
90+
toDataCoords(trace.u, 'xaxis'),
91+
toDataCoords(trace.v, 'yaxis'),
92+
toDataCoords(trace.w, 'zaxis'),
93+
len
94+
);
9495

9596
var valsx = distinctVals(trace.x.slice(0, len));
9697
var valsy = distinctVals(trace.y.slice(0, len));

0 commit comments

Comments
 (0)