Skip to content

Commit 273292d

Browse files
committed
make startx/starty/startz optional
1 parent 80bcd84 commit 273292d

File tree

5 files changed

+40
-15
lines changed

5 files changed

+40
-15
lines changed

src/traces/streamtube/calc.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ module.exports = function calc(gd, trace) {
2121
var z = trace.z;
2222
var len = Math.min(x.length, y.length, z.length, u.length, v.length, w.length);
2323

24-
var startx = trace.startx;
25-
var starty = trace.starty;
26-
var startz = trace.startz;
24+
var startx = trace.startx || [];
25+
var starty = trace.starty || [];
26+
var startz = trace.startz || [];
2727
var slen = Math.min(startx.length, starty.length, startz.length);
2828

2929
var normMax = 0;
@@ -76,6 +76,7 @@ module.exports = function calc(gd, trace) {
7676
}
7777

7878
trace._len = len;
79+
trace._slen = slen;
7980
trace._normMax = normMax;
8081
trace._xbnds = [xMin, xMax];
8182
trace._ybnds = [yMin, yMax];

src/traces/streamtube/convert.js

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -103,13 +103,42 @@ function convert(scene, trace) {
103103

104104
tubeOpts.meshgrid = [meshx, meshy, meshz];
105105

106-
// TODO make this optional?
107-
// Default to in-between x/y/z mesh
108-
tubeOpts.startingPositions = zip3(
109-
toDataCoords(trace.startx, 'xaxis'),
110-
toDataCoords(trace.starty, 'yaxis'),
111-
toDataCoords(trace.startz, 'zaxis')
112-
);
106+
if(trace.startx && trace.starty && trace.startz) {
107+
var slen = trace._slen;
108+
tubeOpts.startingPositions = zip3(
109+
toDataCoords(trace.startx.slice(0, slen), 'xaxis'),
110+
toDataCoords(trace.starty.slice(0, slen), 'yaxis'),
111+
toDataCoords(trace.startz.slice(0, slen), 'zaxis')
112+
);
113+
} else {
114+
// Default starting positions: cut xz plane at min-y,
115+
// takes all x/y/z pts on that plane except those on the edges
116+
// to generate "well-defined" tubes
117+
var sy0 = sceneLayout.yaxis.d2l(trace._ybnds[0]) * dataScale[1];
118+
var sx, sz;
119+
if(valsx.length > 2 && valsz.length > 2) {
120+
sx = valsx.slice(1, valsx.length - 1);
121+
sz = valsz.slice(1, valsy.length - 1);
122+
} else {
123+
// use all pts on 2x2 and 1x1 planes
124+
sx = valsx.slice();
125+
sz = valsz.slice();
126+
}
127+
128+
var startingPositions = new Array(sx.length * sz.length);
129+
var m = 0;
130+
131+
for(var i = 0; i < sx.length; i++) {
132+
for(var k = 0; k < sz.length; k++) {
133+
startingPositions[m++] = [
134+
sceneLayout.xaxis.d2l(sx[i]) * dataScale[0],
135+
sy0,
136+
sceneLayout.zaxis.d2l(sz[k]) * dataScale[2]
137+
];
138+
}
139+
}
140+
tubeOpts.startingPositions = startingPositions;
141+
}
113142

114143
tubeOpts.colormap = parseColorScale(trace.colorscale);
115144

src/traces/streamtube/defaults.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
* LICENSE file in the root directory of this source tree.
77
*/
88

9-
109
'use strict';
1110

1211
var Lib = require('../../lib');
@@ -35,7 +34,6 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
3534
return;
3635
}
3736

38-
// TODO optional or required for v1 ??
3937
coerce('startx');
4038
coerce('starty');
4139
coerce('startz');
-9.56 KB
Loading

test/image/mocks/gl3d_streamtube-simple.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,6 @@
9292
0.08865606199840186,
9393
0.1693927420185106
9494
],
95-
"startx": [0, 0, 0, 0, 0, 0, 0, 0, 0],
96-
"starty": [0, 0, 0, 1, 1, 1, 2, 2, 2],
97-
"startz": [0, 1, 2, 0, 1, 2, 0, 1, 2],
9895
"sizeref": 0.5,
9996
"cmin": 0,
10097
"cmax": 3

0 commit comments

Comments
 (0)