Skip to content

3D cone traces #2641

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

Merged
merged 32 commits into from
May 18, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
ec64895
scaffold cone
etpinard Apr 16, 2018
5736290
move 3d parseColorScale to gl_format_color
etpinard May 16, 2018
cb7cb7f
get cone colorbar and vx/vy/vz mesh grid to work
etpinard May 16, 2018
89eaf11
add three cone mocks
etpinard May 16, 2018
863b0da
implement 'sizemode' and 'sizeref'
etpinard May 16, 2018
fa32a74
add lib/cone.js + add cone to gl3d bundle
etpinard May 16, 2018
71e46af
hook in hover labels for cones
etpinard May 16, 2018
a2c3694
clean up scene computeTraceBounds
etpinard May 17, 2018
a2db567
find min/max u/v/w norm in calc directly
etpinard May 17, 2018
db8222b
add "pad" using max u/v/w norm around cone bounds
etpinard May 17, 2018
55700b8
add 'anchor' to mimic gl-cone3d's coneOffset
etpinard May 17, 2018
e4a2035
add cone-specific hoverinfo flags
etpinard May 17, 2018
a02dd11
fixup cmin/cmax -> vertexIntensityBounds
etpinard May 17, 2018
cb7ef43
improve interplay between vector and cone position attributes
etpinard May 17, 2018
e718c66
fixup hover gl-scatter3d trace for cone with set `cones.(x|y|z)`
etpinard May 17, 2018
f651eec
use stashed gl-cone3d field as hover x/y/z u/v/w fields
etpinard May 17, 2018
3f3bfac
rename image-exporter -> orca
etpinard May 17, 2018
aaf7249
mv gl3d_cone-* out of `npm run test-image` into noci_test.sh
etpinard May 17, 2018
d5d6f33
add some cone tests
etpinard May 17, 2018
b7465fb
add hover label test for cones
etpinard May 17, 2018
5a42de0
comment out cones.(x|y|z) attributes for now
etpinard May 17, 2018
04d3d91
better pad value for autoranged cones
etpinard May 18, 2018
2a45dae
revert to current gl-cone3d master
etpinard May 18, 2018
8dca9ae
factor out `visible: false` converse test
etpinard May 18, 2018
3d26d47
fixup cone autorange pad computation
etpinard May 18, 2018
5a59bc7
fixup pad autorange (again)
etpinard May 18, 2018
3dd6cf5
pass gl-mesh3d lighting params
etpinard May 18, 2018
fb2ec1e
use gl-cone2d "vectorScale" to get better autorange pad value
etpinard May 18, 2018
74ecbf8
scaled pad value by normMax only under sizemode: 'scaled'
etpinard May 18, 2018
abb11e0
sub in npm version for gl-cone3d
etpinard May 18, 2018
8e8f5d6
fixup tests post 74ecbf8
etpinard May 18, 2018
2c08357
add autorange test case for "scaled up the x/y/z arrays"
etpinard May 18, 2018
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
25 changes: 22 additions & 3 deletions src/traces/cone/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,28 @@ var attrs = {
description: 'Sets the z coordinates of the vector field mesh.'
},

// TODO
// sizemode: {},
// sizeref: {},
sizemode: {
valType: 'enumerated',
values: ['scaled', 'absolute'],
role: 'info',
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.'
Copy link
Collaborator

Choose a reason for hiding this comment

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

What do you mean by a grid unit here? Is it one unit of the (x, y, z) positions or the spacing between adjacent cones?

Almost always the vectors have different units from the position space they're displayed in - so I'd think if you specify nothing at all about the cone sizing, they should end up scaled so the largest one is about as big as the smallest spacing between adjacent cones.

There's definitely a use case for 'absolute' - the user has pre-calculated everything and they want each cone to go from one precise (x, y, z) to another precise (x, y, z). I'm not sure there's a use case though for scaling to one unit in position, I'd think 'scaled' should refer to the minimum adjacent cone distance.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

@kig kig May 17, 2018

Choose a reason for hiding this comment

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

I'll have a new look at the cone sizing parameters. Pre-meshgrid they were based on the position space units and scaled so that two cones with maximum norm, pointing to the same direction, would have their tip and base touch. Like <|<|. That would be with coneSize 2. With coneSize 1, you'd get no overlapping cones even when they're |><|.

The absolute sizing ditched the automatic cone scaling and used the cone vector norm to figure out the size of the cone model, so that a norm of 1 with absolute size factor 1 results in a cone that's one unit tall in the position unit space. Absolute size factor 2 => 2 unit tall cone, etc.

With the meshgrid sampling (and the realization that the cone positions may not be on a nice regular grid), I changed the automatic cone sizing to scale based on the smallest distance between two adjacent cone positions (adjacent in the sense that they've got successive indices in the positions array). This is not the right thing to do though, doing a smallest distance between any two cone positions would be, but that's O(n^2) with a naive algo.

Another idea floated on the sizing was to have pixel-based sizing as well, which'd probably work like "invert the projection, view and model transform matrices for cone model, scale cone model according to viewport size" but would result in ortho camera cones which might be confusing. (And it sounds like a bit of a pain to implement.)

Copy link
Collaborator

Choose a reason for hiding this comment

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

@kig that all sounds great. I guess we only need to worry about the smallest-distance calculation when using the (x, y, z) data to position the cones; With the cartesian product of x/y/z interpolation grids each dimension should be pretty compact, even if the values are out of order. But I guarantee at some point we'll see a data set where the closest points are not successive. I don't know if there's a JS implementation already available but it's possible to do it in O(n log(n)^2) http://www.cs.ucsb.edu/~suri/cs235/ClosestPair.pdf

Lets not worry about pixel-based sizing, at least not for now. I guess I can see using this if we also do automatic grid spacing, ie when you zoom in and the cone spacing gets larger, at some point we decrease the grid size so we draw more cones between the existing ones. That's definitely not a v1 feature 😅

].join(' ')
},
sizeref: {
valType: 'number',
role: 'info',
editType: 'calc',
min: 0,
dflt: 1,
description: 'Sets the cone size reference value.'
},

text: {
valType: 'string',
Expand Down
5 changes: 4 additions & 1 deletion src/traces/cone/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
coerce('vy');
coerce('vz');

coerce('text');
coerce('sizeref');
coerce('sizemode');

// TODO do these attributes work?
coerce('lighting.ambient');
Expand All @@ -57,6 +58,8 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
// ... and should we restrict cmin,cmax > 0 ???
colorscaleDefaults(traceIn, traceOut, layout, coerce, {prefix: '', cLetter: 'c'});

coerce('text');

// disable 1D transforms
// x/y/z should match lengths, u/v/w and vx/vy/vz should match as well, but
// the two sets have different lengths so transforms wouldn't work.
Expand Down
5 changes: 2 additions & 3 deletions src/traces/cone/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ function zip3(x, y, z) {
}

var axisName2scaleIndex = {xaxis: 0, yaxis: 1, zaxis: 2};
var sizeMode2sizeKey = {scaled: 'coneSize', absolute: 'absoluteConeSize'};

exports.cone2mesh = function cone2mesh(trace, sceneLayout, dataScale) {
var coneOpts = {};
Expand Down Expand Up @@ -61,9 +62,7 @@ exports.cone2mesh = function cone2mesh(trace, sceneLayout, dataScale) {
coneOpts.colormap = parseColorScale(trace.colorscale);
coneOpts.vertexIntensityBounds = [trace.cmin, trace.cmax];

// sizemode:
// sizeref,
coneOpts.coneSize = 2;
coneOpts[sizeMode2sizeKey[trace.sizemode]] = trace.sizeref;

return conePlot(coneOpts);
};
Binary file modified test/image/baselines/gl3d_cone-simple.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/image/baselines/gl3d_cone-sparse.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 9 additions & 7 deletions test/image/mocks/gl3d_cone-simple.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
{
"data": [
{
"type": "scatter3d",
"mode": "markers",
{
"type": "scatter3d",
"mode": "markers",
"x": [1, 2, 3],
"y": [1, 2, 3],
"z": [1, 2, 3]
},
},
{
"type": "cone",
"x": [1, 2, 3],
"y": [1, 2, 3],
"z": [1, 2, 3],
"u": [0.1, 0, 0],
"v": [0, 0.3, 0],
"w": [0, 0, 0.2]
"u": [1, 0, 0],
"v": [0, 3, 0],
"w": [0, 0, 2],
"sizemode": "absolute",
"sizeref": 2
}
],
"layout": {
Expand Down