Skip to content

Commit cb7ef43

Browse files
committed
improve interplay between vector and cone position attributes
- x/y/z always refers vector positions (their length should match u/v/w) - if nothing else provided, x/y/z correspond to the cone position also, - to set cone position, use `cones.(x|y|z)` for now - update attribute descriptions and trace meta info
1 parent a02dd11 commit cb7ef43

File tree

5 files changed

+87
-60
lines changed

5 files changed

+87
-60
lines changed

src/traces/cone/attributes.js

+39-22
Original file line numberDiff line numberDiff line change
@@ -22,29 +22,29 @@ var attrs = {
2222
role: 'info',
2323
editType: 'calc+clearAxisTypes',
2424
description: [
25-
'Sets the x positions of the cones.',
26-
'When `vx`, `vy`, `vz` are not set,',
27-
' these are also the x coordinates of the u/v/w vector field.'
25+
'Sets the x coordinates of the vector field',
26+
'If `cones` positions are not provided, this array',
27+
'corresponds to the x coordinates of the cones displayed as well.'
2828
].join(' ')
2929
},
3030
y: {
3131
valType: 'data_array',
3232
role: 'info',
3333
editType: 'calc+clearAxisTypes',
3434
description: [
35-
'Sets the y positions of the cones.',
36-
'When `vx`, `vy`, `vz` are not set,',
37-
' these are also the y coordinates of the u/v/w vector field.'
35+
'Sets the y coordinates of the vector field',
36+
'If `cones` positions are not provided, this array',
37+
'corresponds to the y coordinates of the cones displayed as well.'
3838
].join(' ')
3939
},
4040
z: {
4141
valType: 'data_array',
4242
role: 'info',
4343
editType: 'calc+clearAxisTypes',
4444
description: [
45-
'Sets the z positions of the cones.',
46-
'When `vx`, `vy`, `vz` are not set,',
47-
' these are also the z coordinates of the u/v/w vector field.'
45+
'Sets the z coordinates of the vector field',
46+
'If `cones` positions are not provided, this array',
47+
'corresponds to the z coordinates of the cones displayed as well.'
4848
].join(' ')
4949
},
5050

@@ -64,20 +64,37 @@ var attrs = {
6464
description: 'Sets the z components of the vector field.'
6565
},
6666

67-
vx: {
68-
valType: 'data_array',
69-
editType: 'calc',
70-
description: 'Sets the x coordinates of the vector field mesh.'
71-
},
72-
vy: {
73-
valType: 'data_array',
74-
editType: 'calc',
75-
description: 'Sets the y coordinates of the vector field mesh.'
76-
},
77-
vz: {
78-
valType: 'data_array',
67+
cones: {
68+
// potential attributes to add:
69+
//
70+
// - meshmode: 'cartesian-product', 'pts', 'grid'
71+
//
72+
// under `meshmode: 'grid'`
73+
// - (x|y|z)grid.start
74+
// - (x|y|z)grid.end
75+
// - (x|y|z)grid.size
76+
77+
x: {
78+
valType: 'data_array',
79+
editType: 'calc',
80+
description: 'Sets the x coordinates of the cones to be displayed.'
81+
},
82+
y: {
83+
valType: 'data_array',
84+
editType: 'calc',
85+
description: 'Sets the y coordinates of the cones to be displayed.'
86+
},
87+
z: {
88+
valType: 'data_array',
89+
editType: 'calc',
90+
description: 'Sets the z coordinates of the cones to be displayed.'
91+
},
92+
7993
editType: 'calc',
80-
description: 'Sets the z coordinates of the vector field mesh.'
94+
description: [
95+
'By setting `cones.x`, `cones.y` and `cones.z` to 1D arrays,',
96+
'plotly creates a mesh using the cartesian product of those 3 arrays.'
97+
].join(' ')
8198
},
8299

83100
sizemode: {

src/traces/cone/convert.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ var anchor2coneOffset = {tip: 1, tail: 0, cm: 0.25, center: 0.5};
7171
function convert(scene, trace) {
7272
var sceneLayout = scene.fullSceneLayout;
7373
var dataScale = scene.dataScale;
74+
var hasConesPos = trace.cones && trace.cones.x && trace.cones.y && trace.cones.z;
7475
var coneOpts = {};
7576

7677
function toDataCoords(arr, axisName) {
@@ -91,11 +92,11 @@ function convert(scene, trace) {
9192
toDataCoords(trace.z, 'zaxis')
9293
);
9394

94-
if(trace.vx && trace.vy && trace.vz) {
95+
if(hasConesPos) {
9596
coneOpts.meshgrid = [
96-
toDataCoords(trace.vx, 'xaxis'),
97-
toDataCoords(trace.vy, 'yaxis'),
98-
toDataCoords(trace.vz, 'zaxis')
97+
toDataCoords(trace.cones.x, 'xaxis'),
98+
toDataCoords(trace.cones.y, 'yaxis'),
99+
toDataCoords(trace.cones.z, 'zaxis')
99100
];
100101
}
101102

src/traces/cone/defaults.js

+4-6
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
3535
return;
3636
}
3737

38-
coerce('vx');
39-
coerce('vy');
40-
coerce('vz');
38+
coerce('cones.x');
39+
coerce('cones.y');
40+
coerce('cones.z');
4141

4242
coerce('sizeref');
4343
coerce('sizemode');
@@ -56,14 +56,12 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
5656
coerce('lightposition.y');
5757
coerce('lightposition.z');
5858

59-
// TODO should the default be viridis
60-
// ... and should we restrict cmin,cmax > 0 ???
6159
colorscaleDefaults(traceIn, traceOut, layout, coerce, {prefix: '', cLetter: 'c'});
6260

6361
coerce('text');
6462

6563
// disable 1D transforms
66-
// x/y/z should match lengths, u/v/w and vx/vy/vz should match as well, but
64+
// x/y/z and u/v/w should match lengths, cones.(x|y|z) should match as well, but
6765
// the two sets have different lengths so transforms wouldn't work.
6866
traceOut._length = null;
6967
};

src/traces/cone/index.js

+10-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,16 @@ module.exports = {
2222

2323
meta: {
2424
description: [
25-
'...'
25+
'Use cone traces to visualize vector fields.',
26+
'',
27+
'Specify a vector field using 6 1D arrays,',
28+
'3 position arrays `x`, `y` and `z`',
29+
'and 3 vector component arrays `u`, `v`, `w`.',
30+
'',
31+
'If nothing else is provided, the cones are drawn exactly at the positions given',
32+
'by `x`, `y` and `z`.',
33+
'To specify the cone positions manually, use arrays attributes',
34+
'`cones.x`, `cones.y` and `cones.z`.'
2635
].join(' ')
2736
}
2837
};

test/image/mocks/gl3d_cone-sparse.json

+29-27
Original file line numberDiff line numberDiff line change
@@ -5036,33 +5036,35 @@
50365036
0.021351568113512426,
50375037
0.611131516169977
50385038
],
5039-
"vx": [
5040-
0,
5041-
15,
5042-
30,
5043-
35,
5044-
40,
5045-
55,
5046-
70
5047-
],
5048-
"vy": [
5049-
0,
5050-
15,
5051-
30,
5052-
35,
5053-
40,
5054-
45,
5055-
50
5056-
],
5057-
"vz": [
5058-
0,
5059-
1,
5060-
2,
5061-
3,
5062-
30,
5063-
31,
5064-
50
5065-
]
5039+
"cones": {
5040+
"x": [
5041+
0,
5042+
15,
5043+
30,
5044+
35,
5045+
40,
5046+
55,
5047+
70
5048+
],
5049+
"y": [
5050+
0,
5051+
15,
5052+
30,
5053+
35,
5054+
40,
5055+
45,
5056+
50
5057+
],
5058+
"z": [
5059+
0,
5060+
1,
5061+
2,
5062+
3,
5063+
30,
5064+
31,
5065+
50
5066+
]
5067+
}
50665068
}
50675069
],
50685070
"layout": {

0 commit comments

Comments
 (0)