Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cone sizeref fixes #2715

Merged
merged 9 commits into from
Jun 11, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions src/traces/cone/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,20 +112,26 @@ var attrs = {
editType: 'calc',
dflt: 'scaled',
description: [
'Sets the mode by which the cones are sized.',
'If *scaled*, `sizeref` scales such that the reference cone size',
'for the maximum vector magnitude is 1.',
'If *absolute*, `sizeref` scales such that the reference cone size',
'for vector magnitude 1 is one grid unit.'
'Determines whether `sizeref` is set as a *scaled* (i.e unitless) scalar',
'(normalized by the max u/v/w norm in the vector field) or as',
'*absolute* value (in unit of velocity).'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't use the word "velocity" here - you can show many other quantities as vector fields (electric fields, as just one common example). Just say "in the same units as the vector field" or some such.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh right, good call!

].join(' ')
},
sizeref: {
valType: 'number',
role: 'info',
editType: 'calc',
min: 0,
dflt: 1,
description: 'Sets the cone size reference value.'
description: [
'Adjusts the cone size scaling.',
'The size of the cones is determined by their u/v/w norm multiplied a factor and `sizeref`.',
'This factor (computed internally) corresponds to the minimum "time" to travel across two',
'two successive x/y/z positions at the average velocity of those two successive positions',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

two twos is one two too many

'All cones in a given trace use the same factor.',
'With `sizemode` set to *scaled*, `sizeref` is unitless, its default value is *0.5*',
'With `sizemode` set to *absolute*, `sizeref` has units of velocity, its the default value is',
'half the sample\'s maximum vector norm.'
].join(' ')
},

anchor: {
Expand Down
18 changes: 11 additions & 7 deletions src/traces/cone/convert.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ function zip3(x, y, z) {
}

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

Expand Down Expand Up @@ -88,15 +87,21 @@ function convert(scene, trace) {

coneOpts.colormap = parseColorScale(trace.colorscale);
coneOpts.vertexIntensityBounds = [trace.cmin / trace._normMax, trace.cmax / trace._normMax];

coneOpts[sizeMode2sizeKey[trace.sizemode]] = trace.sizeref;
coneOpts.coneOffset = anchor2coneOffset[trace.anchor];

var meshData = conePlot(coneOpts);
if(trace.sizemode === 'scaled') {
// unitless sizeref
coneOpts.coneSize = trace.sizeref || 0.5;
} else {
// sizeref here has unit of velocity
coneOpts.coneSize = (trace.sizeref / trace._normMax) || 0.5;
Copy link
Contributor Author

@etpinard etpinard Jun 11, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previously, coneSize under sizemode: 'absolute' was scaled using the max norm of the "scaled" u/v/w vectors (that same dataScale than in #2646). This made sizeref under sizemode: 'absolute' had little meaning.

Now, sizeref under sizemode: 'absolute' is scaled by the "input" u/v/w max norm should make this thing a little less confusing.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! Two questions:

  • When is the || 0.5 (in either case) necessary?
  • What if the field is uniformly zero? then _normMax will be 0 and coneSize will be Infinity... which I suppose is OK if the end result is no errors and nothing drawn.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if the field is uniformly zero?

Oh right, Infinity is truthy. Good call!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When is the || 0.5 (in either case) necessary?

Currently, the sizeref attribute declaration does not set a dflt field. In practice I guess it does have a hard default of 0.5. But technically under the sizemode: 'absolute', the sizemode default is 0.5 * trace._normMax.

}

var meshData = conePlot(coneOpts);

// pass gl-mesh3d lighting attributes
meshData.lightPosition = [trace.lightposition.x, trace.lightposition.y, trace.lightposition.z];
var lp = trace.lightposition;
meshData.lightPosition = [lp.x, lp.y, lp.z];
meshData.ambient = trace.lighting.ambient;
meshData.diffuse = trace.lighting.diffuse;
meshData.specular = trace.lighting.specular;
Expand All @@ -105,8 +110,7 @@ function convert(scene, trace) {
meshData.opacity = trace.opacity;

// stash autorange pad value
trace._pad = anchor2coneSpan[trace.anchor] * meshData.vectorScale * trace.sizeref;
if(trace.sizemode === 'scaled') trace._pad *= trace._normMax;
trace._pad = anchor2coneSpan[trace.anchor] * meshData.vectorScale * meshData.coneScale * trace._normMax;

return meshData;
}
Expand Down