Skip to content

Commit 39c254e

Browse files
committed
cleanup streamtube/
- reuse cone colorbar - compute x/y/z bounds in calc - pass cmin/cmax to meshData.vertexIntensityBounds - rename starting position attributes cx/cy/cz -> startx/starty/startz - misc cleanup to bring streamtube closer to cone - add new TODOs
1 parent 583499f commit 39c254e

File tree

6 files changed

+217
-243
lines changed

6 files changed

+217
-243
lines changed

src/traces/streamtube/attributes.js

Lines changed: 37 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -19,95 +19,67 @@ var extendFlat = require('../../lib/extend').extendFlat;
1919
var attrs = {
2020
x: {
2121
valType: 'data_array',
22-
editType: 'calc',
23-
description: ''
22+
role: 'info',
23+
editType: 'calc+clearAxisTypes',
24+
description: 'Sets the x coordinates of the vector field'
2425
},
2526
y: {
2627
valType: 'data_array',
27-
editType: 'calc'
28+
role: 'info',
29+
editType: 'calc+clearAxisTypes',
30+
description: 'Sets the y coordinates of the vector field'
2831
},
2932
z: {
3033
valType: 'data_array',
31-
editType: 'calc'
34+
role: 'info',
35+
editType: 'calc+clearAxisTypes',
36+
description: 'Sets the z coordinates of the vector field'
3237
},
3338

3439
u: {
3540
valType: 'data_array',
3641
editType: 'calc',
37-
description: [
38-
].join(' ')
42+
description: 'Sets the x components of the vector field.'
3943
},
4044
v: {
4145
valType: 'data_array',
4246
editType: 'calc',
43-
description: [
44-
].join(' ')
45-
47+
description: 'Sets the y components of the vector field.'
4648
},
4749
w: {
4850
valType: 'data_array',
4951
editType: 'calc',
50-
description: [
51-
].join(' ')
52-
53-
},
54-
55-
cx: {
56-
valType: 'data_array',
57-
editType: 'calc+clearAxisTypes',
58-
description: [
59-
].join(' ')
60-
},
61-
cy: {
62-
valType: 'data_array',
63-
editType: 'calc+clearAxisTypes',
64-
description: [
65-
].join(' ')
66-
},
67-
cz: {
68-
valType: 'data_array',
69-
editType: 'calc+clearAxisTypes',
70-
description: [
71-
].join(' ')
52+
description: 'Sets the z components of the vector field.'
7253
},
7354

74-
bounds: {
55+
startx: {
7556
valType: 'data_array',
76-
editType: 'calc+clearAxisTypes',
77-
description: [
78-
].join(' ')
79-
},
80-
81-
colormap: {
82-
valType: 'string',
83-
role: 'style',
8457
editType: 'calc',
8558
description: [
59+
'Sets the x components of the starting position of the streamtubes',
60+
''
8661
].join(' ')
8762
},
88-
89-
maxLength: {
90-
valType: 'number',
91-
min: 1,
92-
dflt: 1000,
63+
starty: {
64+
valType: 'data_array',
9365
editType: 'calc',
9466
description: [
67+
'Sets the y components of the starting position of the streamtubes',
68+
''
9569
].join(' ')
9670
},
97-
98-
widthScale: {
99-
valType: 'number',
100-
role: 'style',
101-
min: 0,
102-
dflt: 100,
71+
startz: {
72+
valType: 'data_array',
10373
editType: 'calc',
10474
description: [
75+
'Sets the z components of the starting position of the streamtubes',
76+
''
10577
].join(' ')
10678
},
10779

10880
// TODO
109-
// sizemode: {},
110-
// sizescale: {},
81+
// maxLength
82+
// widthScale
11183

11284
text: {
11385
valType: 'string',
@@ -116,22 +88,29 @@ var attrs = {
11688
arrayOk: true,
11789
editType: 'calc',
11890
description: [
119-
91+
'Sets the text elements associated with the cones.',
92+
'If trace `hoverinfo` contains a *text* flag and *hovertext* is not set,',
93+
'these elements will be seen in the hover labels.'
12094
].join(' ')
12195
}
12296
};
12397

124-
extendFlat(attrs, colorAttrs('', 'calc', false), {
98+
extendFlat(attrs, colorAttrs('', 'calc', true), {
12599
showscale: colorscaleAttrs.showscale,
126100
colorbar: colorbarAttrs
127101
});
102+
delete attrs.color;
128103

129-
var fromMesh3d = ['opacity', 'flatshading', 'lightposition', 'lighting'];
130-
104+
var fromMesh3d = ['opacity', 'lightposition', 'lighting'];
131105
fromMesh3d.forEach(function(k) {
132106
attrs[k] = mesh3dAttrs[k];
133107
});
134108

135-
attrs.hoverinfo = extendFlat({}, baseAttrs.hoverinfo, {editType: 'calc'});
109+
// TODO maybe add divergence field?
110+
attrs.hoverinfo = extendFlat({}, baseAttrs.hoverinfo, {
111+
editType: 'calc',
112+
flags: ['x', 'y', 'z', 'u', 'v', 'w', 'norm', 'text', 'name'],
113+
dflt: 'x+y+z+norm+text+name'
114+
});
136115

137116
module.exports = attrs;

src/traces/streamtube/calc.js

Lines changed: 68 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,73 @@
1111
var colorscaleCalc = require('../../components/colorscale/calc');
1212

1313
module.exports = function calc(gd, trace) {
14-
if(trace.intensity) {
15-
colorscaleCalc(trace, trace.intensity, '', 'c');
14+
var i;
15+
16+
var u = trace.u;
17+
var v = trace.v;
18+
var w = trace.w;
19+
var vlen = Math.min(u.length, v.length, w.length);
20+
var normMax = -Infinity;
21+
var normMin = Infinity;
22+
23+
for(i = 0; i < vlen; i++) {
24+
var uu = u[i];
25+
var vv = v[i];
26+
var ww = w[i];
27+
var norm = Math.sqrt(uu * uu + vv * vv + ww * ww);
28+
29+
normMax = Math.max(normMax, norm);
30+
normMin = Math.min(normMin, norm);
31+
}
32+
33+
colorscaleCalc(trace, [normMin, normMax], '', 'c');
34+
35+
var xMax = -Infinity;
36+
var xMin = Infinity;
37+
var yMax = -Infinity;
38+
var yMin = Infinity;
39+
var zMax = -Infinity;
40+
var zMin = Infinity;
41+
42+
var x = trace.x;
43+
var y = trace.y;
44+
var z = trace.z;
45+
var plen = Math.min(x.length, y.length, z.length);
46+
47+
for(i = 0; i < plen; i++) {
48+
var xx = x[i];
49+
xMax = Math.max(xMax, xx);
50+
xMin = Math.min(xMin, xx);
51+
52+
var yy = y[i];
53+
yMax = Math.max(yMax, yy);
54+
yMin = Math.min(yMin, yy);
55+
56+
var zz = z[i];
57+
zMax = Math.max(zMax, zz);
58+
zMin = Math.min(zMin, zz);
59+
}
60+
61+
var startx = trace.startx;
62+
var starty = trace.starty;
63+
var startz = trace.startz;
64+
var slen = Math.min(startx.length, starty.length, startz.length);
65+
66+
for(i = 0; i < slen; i++) {
67+
var sx = startx[i];
68+
xMax = Math.max(xMax, sx);
69+
xMin = Math.min(xMin, sx);
70+
71+
var sy = starty[i];
72+
yMax = Math.max(yMax, sy);
73+
yMin = Math.min(yMin, sy);
74+
75+
var sz = startz[i];
76+
zMax = Math.max(zMax, sz);
77+
zMin = Math.min(zMin, sz);
1678
}
79+
80+
trace._xbnds = [xMin, xMax];
81+
trace._ybnds = [yMin, yMax];
82+
trace._zbnds = [zMin, zMax];
1783
};

src/traces/streamtube/colorbar.js

Lines changed: 0 additions & 48 deletions
This file was deleted.

0 commit comments

Comments
 (0)