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
3 changes: 1 addition & 2 deletions src/plots/gl3d/scene.js
Original file line number Diff line number Diff line change
Expand Up @@ -507,8 +507,7 @@ proto.plot = function(sceneData, fullLayout, layout) {
for(j = 0; j < objects.length; j++) {
var obj = objects[j];
var objBounds = obj.bounds;
var fullTrace = obj._trace.data;
var pad = fullTrace._pad || 0;
var pad = obj._trace.data._pad || 0;

sceneBounds[0][i] = Math.min(sceneBounds[0][i], objBounds[0][i] / dataScale[i] - pad);
sceneBounds[1][i] = Math.max(sceneBounds[1][i], objBounds[1][i] / dataScale[i] + pad);
Expand Down
5 changes: 0 additions & 5 deletions src/traces/cone/calc.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,7 @@ module.exports = function calc(gd, trace) {
compMax = Math.max(compMax, u2, v2, w2);
}

// stash max norm value to convert cmix/cmax -> vertexIntensityBounds
trace._normMax = normMax;
// stash autorange pad using max 'component' value
trace._pad = trace.sizemode === 'absolute' ?
trace.sizeref :
2 * (Math.sqrt(compMax) / (normMax || 1)) * trace.sizeref;

colorscaleCalc(trace, [normMin, normMax], '', 'c');
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Shoutout to @alexcjohnson for the tip!

};
4 changes: 4 additions & 0 deletions src/traces/cone/convert.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ 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};

function convert(scene, trace) {
var sceneLayout = scene.fullSceneLayout;
Expand Down Expand Up @@ -107,6 +108,9 @@ function convert(scene, trace) {
meshData.fresnel = trace.lighting.fresnel;
meshData.opacity = trace.opacity;

// stash autorange pad value
trace._pad = anchor2coneSpan[trace.anchor] * meshData.vectorScale * trace._normMax * trace.sizeref;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Awesome, I think we have a winner now! I don't see any cases (As I change the cone spacing, cone count in each direction, and vector length) where this fails to encompass all the cones, nor any where the padding looks unpleasantly large. 🏆


return meshData;
}

Expand Down
Binary file modified test/image/baselines/gl3d_cone-autorange.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-lighting.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-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-wind.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 10 additions & 10 deletions test/jasmine/tests/cone_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ describe('@gl Test cone autorange:', function() {

function _assertAxisRanges(msg, xrng, yrng, zrng) {
var sceneLayout = gd._fullLayout.scene;
expect(sceneLayout.xaxis.range).toBeCloseToArray(xrng, 2, 'xaxis range -' + msg);
expect(sceneLayout.yaxis.range).toBeCloseToArray(yrng, 2, 'yaxis range -' + msg);
expect(sceneLayout.zaxis.range).toBeCloseToArray(zrng, 2, 'zaxis range -' + msg);
expect(sceneLayout.xaxis.range).toBeCloseToArray(xrng, 2, 'xaxis range - ' + msg);
expect(sceneLayout.yaxis.range).toBeCloseToArray(yrng, 2, 'yaxis range - ' + msg);
expect(sceneLayout.zaxis.range).toBeCloseToArray(zrng, 2, 'zaxis range - ' + msg);
}

it('should add pad around cone position to make sure they fit on the scene', function(done) {
Expand All @@ -89,7 +89,7 @@ describe('@gl Test cone autorange:', function() {

Plotly.plot(gd, fig).then(function() {
_assertAxisRanges('base',
[-0.39, 4.39], [-0.39, 4.39], [-0.39, 4.39]
[-0.66, 4.66], [-0.66, 4.66], [-0.66, 4.66]
);

var trace = fig.data[0];
Expand All @@ -102,7 +102,7 @@ describe('@gl Test cone autorange:', function() {
})
.then(function() {
_assertAxisRanges('scaled up',
[-0.39, 4.39], [-0.39, 4.39], [-0.39, 4.39]
[-0.66, 4.66], [-0.66, 4.66], [-0.66, 4.66]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you add one more test, to 🔒 this in a little more since it went through so many iterations: scale up the x/y/z arrays. At least one of the previous iterations had a problem with this but otherwise looked pretty good.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

there's this one:

var trace = fig.data[0];
var x = trace.x.slice();
x.push(5);
var y = trace.y.slice();
y.push(5);
var z = trace.z.slice();
z.push(5);
var u = trace.u.slice();
u.push(0);
var v = trace.v.slice();
v.push(0);
var w = trace.w.slice();
w.push(0);
return Plotly.restyle(gd, {
x: [x], y: [y], z: [z],
u: [u], v: [v], w: [w]
});
})
.then(function() {
_assertAxisRanges('after adding one cone outside range but with norm-0',
[-0.72, 6.72], [-0.72, 6.72], [-0.72, 6.72]
);

am I missing anything?

Copy link
Collaborator

Choose a reason for hiding this comment

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

It's close, but there's a difference between adding another point that doesn't change the minimum spacing between cones, and expanding the whole x/y/z space and therefore expanding the minimum spacing as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

got it. Thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done in -> 2c08357

);

var trace = fig.data[0];
Expand All @@ -115,7 +115,7 @@ describe('@gl Test cone autorange:', function() {
})
.then(function() {
_assertAxisRanges('scaled down',
[-0.39, 4.39], [-0.39, 4.39], [-0.39, 4.39]
[-0.66, 4.66], [-0.66, 4.66], [-0.66, 4.66]
);

var trace = fig.data[0];
Expand All @@ -140,21 +140,21 @@ describe('@gl Test cone autorange:', function() {
})
.then(function() {
_assertAxisRanges('after adding one cone outside range but with norm-0',
[-0.45, 6.45], [-0.45, 6.45], [-0.45, 6.45]
[-0.72, 6.72], [-0.72, 6.72], [-0.72, 6.72]
);

return Plotly.restyle(gd, 'sizeref', 10);
})
.then(function() {
_assertAxisRanges('after increasing sizeref',
[-12.4, 18.4], [-12.4, 18.4], [-12.4, 18.4]
[-15.06, 21.06], [-15.06, 21.06], [-15.06, 21.06]
);

return Plotly.restyle(gd, 'sizeref', 0.1);
})
.then(function() {
_assertAxisRanges('after decreasing sizeref',
[0.74, 5.26], [0.74, 5.26], [0.74, 5.26]
[0.72, 5.28], [0.72, 5.28], [0.72, 5.28]
);

return Plotly.restyle(gd, {
Expand All @@ -164,7 +164,7 @@ describe('@gl Test cone autorange:', function() {
})
.then(function() {
_assertAxisRanges('with sizemode absolute',
[-1.25, 7.25], [-1.25, 7.25], [-1.25, 7.25]
[-2.31, 8.31], [-2.31, 8.31], [-2.31, 8.31]
);
})
.catch(failTest)
Expand Down