Skip to content

Commit f4b836c

Browse files
authored
Merge pull request #2715 from plotly/cone-sizeref-fixes
Cone sizeref fixes
2 parents 69a1004 + a1ba953 commit f4b836c

15 files changed

+12865
-65
lines changed

package-lock.json

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
"es6-promise": "^3.0.2",
7070
"fast-isnumeric": "^1.1.1",
7171
"font-atlas-sdf": "^1.3.3",
72-
"gl-cone3d": "^v1.0.1",
72+
"gl-cone3d": "^1.1.0",
7373
"gl-contour2d": "^1.1.4",
7474
"gl-error3d": "^1.0.7",
7575
"gl-heatmap2d": "^1.0.4",

src/traces/cone/attributes.js

+13-7
Original file line numberDiff line numberDiff line change
@@ -112,20 +112,26 @@ var attrs = {
112112
editType: 'calc',
113113
dflt: 'scaled',
114114
description: [
115-
'Sets the mode by which the cones are sized.',
116-
'If *scaled*, `sizeref` scales such that the reference cone size',
117-
'for the maximum vector magnitude is 1.',
118-
'If *absolute*, `sizeref` scales such that the reference cone size',
119-
'for vector magnitude 1 is one grid unit.'
115+
'Determines whether `sizeref` is set as a *scaled* (i.e unitless) scalar',
116+
'(normalized by the max u/v/w norm in the vector field) or as',
117+
'*absolute* value (in the same units as the vector field).'
120118
].join(' ')
121119
},
122120
sizeref: {
123121
valType: 'number',
124122
role: 'info',
125123
editType: 'calc',
126124
min: 0,
127-
dflt: 1,
128-
description: 'Sets the cone size reference value.'
125+
description: [
126+
'Adjusts the cone size scaling.',
127+
'The size of the cones is determined by their u/v/w norm multiplied a factor and `sizeref`.',
128+
'This factor (computed internally) corresponds to the minimum "time" to travel across',
129+
'two successive x/y/z positions at the average velocity of those two successive positions.',
130+
'All cones in a given trace use the same factor.',
131+
'With `sizemode` set to *scaled*, `sizeref` is unitless, its default value is *0.5*',
132+
'With `sizemode` set to *absolute*, `sizeref` has the same units as the u/v/w vector field,',
133+
'its the default value is half the sample\'s maximum vector norm.'
134+
].join(' ')
129135
},
130136

131137
anchor: {

src/traces/cone/convert.js

+14-26
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
'use strict';
1010

11-
var createScatterPlot = require('gl-scatter3d');
1211
var conePlot = require('gl-cone3d');
1312
var createConeMesh = require('gl-cone3d').createConeMesh;
1413

@@ -19,14 +18,13 @@ function Cone(scene, uid) {
1918
this.scene = scene;
2019
this.uid = uid;
2120
this.mesh = null;
22-
this.pts = null;
2321
this.data = null;
2422
}
2523

2624
var proto = Cone.prototype;
2725

2826
proto.handlePick = function(selection) {
29-
if(selection.object === this.pts) {
27+
if(selection.object === this.mesh) {
3028
var selectIndex = selection.index = selection.data.index;
3129
var xx = this.data.x[selectIndex];
3230
var yy = this.data.y[selectIndex];
@@ -61,7 +59,6 @@ function zip3(x, y, z) {
6159
}
6260

6361
var axisName2scaleIndex = {xaxis: 0, yaxis: 1, zaxis: 2};
64-
var sizeMode2sizeKey = {scaled: 'coneSize', absolute: 'absoluteConeSize'};
6562
var anchor2coneOffset = {tip: 1, tail: 0, cm: 0.25, center: 0.5};
6663
var anchor2coneSpan = {tip: 1, tail: 1, cm: 0.75, center: 0.5};
6764

@@ -90,17 +87,23 @@ function convert(scene, trace) {
9087

9188
coneOpts.colormap = parseColorScale(trace.colorscale);
9289
coneOpts.vertexIntensityBounds = [trace.cmin / trace._normMax, trace.cmax / trace._normMax];
93-
94-
coneOpts[sizeMode2sizeKey[trace.sizemode]] = trace.sizeref;
9590
coneOpts.coneOffset = anchor2coneOffset[trace.anchor];
9691

97-
var meshData = conePlot(coneOpts);
92+
if(trace.sizemode === 'scaled') {
93+
// unitless sizeref
94+
coneOpts.coneSize = trace.sizeref || 0.5;
95+
} else {
96+
// sizeref here has unit of velocity
97+
coneOpts.coneSize = trace.sizeref && trace._normMax ?
98+
trace.sizeref / trace._normMax :
99+
0.5;
100+
}
98101

99-
// stash positions for gl-scatter3d 'hover' trace
100-
meshData._pts = coneOpts.positions;
102+
var meshData = conePlot(coneOpts);
101103

102104
// pass gl-mesh3d lighting attributes
103-
meshData.lightPosition = [trace.lightposition.x, trace.lightposition.y, trace.lightposition.z];
105+
var lp = trace.lightposition;
106+
meshData.lightPosition = [lp.x, lp.y, lp.z];
104107
meshData.ambient = trace.lighting.ambient;
105108
meshData.diffuse = trace.lighting.diffuse;
106109
meshData.specular = trace.lighting.specular;
@@ -109,8 +112,7 @@ function convert(scene, trace) {
109112
meshData.opacity = trace.opacity;
110113

111114
// stash autorange pad value
112-
trace._pad = anchor2coneSpan[trace.anchor] * meshData.vectorScale * trace.sizeref;
113-
if(trace.sizemode === 'scaled') trace._pad *= trace._normMax;
115+
trace._pad = anchor2coneSpan[trace.anchor] * meshData.vectorScale * meshData.coneScale * trace._normMax;
114116

115117
return meshData;
116118
}
@@ -119,14 +121,10 @@ proto.update = function(data) {
119121
this.data = data;
120122

121123
var meshData = convert(this.scene, data);
122-
123124
this.mesh.update(meshData);
124-
this.pts.update({position: meshData._pts});
125125
};
126126

127127
proto.dispose = function() {
128-
this.scene.glplot.remove(this.pts);
129-
this.pts.dispose();
130128
this.scene.glplot.remove(this.mesh);
131129
this.mesh.dispose();
132130
};
@@ -137,21 +135,11 @@ function createConeTrace(scene, data) {
137135
var meshData = convert(scene, data);
138136
var mesh = createConeMesh(gl, meshData);
139137

140-
var pts = createScatterPlot({
141-
gl: gl,
142-
position: meshData._pts,
143-
project: false,
144-
opacity: 0
145-
});
146-
147138
var cone = new Cone(scene, data.uid);
148139
cone.mesh = mesh;
149-
cone.pts = pts;
150140
cone.data = data;
151141
mesh._trace = cone;
152-
pts._trace = cone;
153142

154-
scene.glplot.add(pts);
155143
scene.glplot.add(mesh);
156144

157145
return cone;
159 KB
Loading
1.12 KB
Loading
-5.27 KB
Loading
60.4 KB
Loading
6.5 KB
Loading
6.88 KB
Loading
-1.91 KB
Loading

0 commit comments

Comments
 (0)