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

Bug fix: applying camera up.z vector at scene init #3256

Merged
merged 23 commits into from
Nov 22, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion src/plot_api/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ exports.cleanLayout = function(layout) {
scene.camera = {
eye: {x: eye[0], y: eye[1], z: eye[2]},
center: {x: center[0], y: center[1], z: center[2]},
up: {x: mat[1], y: mat[5], z: mat[9]}
up: {x: 0, y: 0, z: 1} // we just ignore calculating camera z up in this case
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Previous calculations of camera.up for gl3d_surface-lighting & gl3d_ibm-plot didn't set up vector close to [0,0,1].
I thought we may ignore camera z up if cameraposition depreciated setting is used.

Copy link
Contributor

Choose a reason for hiding this comment

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

Nice solution.

Copy link
Contributor

Choose a reason for hiding this comment

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

... and I presume the gl3d_opacity-surface.png baseline changed because of this?

Copy link
Contributor

Choose a reason for hiding this comment

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

Ignore that last comment. I didn't see #3256 (comment)

Thanks!

};

delete scene.cameraposition;
Expand Down
27 changes: 26 additions & 1 deletion src/plots/gl3d/layout/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,31 @@ function handleGl3dDefaults(sceneLayoutIn, sceneLayoutOut, coerce, opts) {
sceneLayoutIn, sceneLayoutOut, opts
);

coerce('dragmode', opts.getDfltFromLayout('dragmode'));
var dragmode = opts.getDfltFromLayout('dragmode');

if(dragmode !== false) {
if(!dragmode) {

dragmode = 'orbit';

if(sceneLayoutIn.camera &&
sceneLayoutIn.camera.up) {

var x = sceneLayoutIn.camera.up.x;
var y = sceneLayoutIn.camera.up.y;
var z = sceneLayoutIn.camera.up.z;

if(!x || !y || !z) {
dragmode = 'turntable';
} else if(z / Math.sqrt(x * x + y * y + z * z) > 0.999) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This PR is getting better by the minute. Thanks for your efforts @archmoj

Now, would there be a way to tweak this condition such that gl3d_ibm-plot and gl3d_surface-lighting still default to dragmode: 'turntable'?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point @etpinard. Let me check.

dragmode = 'turntable';
}
} else {
dragmode = 'turntable';
}
}
}

coerce('dragmode', dragmode);
coerce('hovermode', opts.getDfltFromLayout('hovermode'));
}
1 change: 0 additions & 1 deletion src/plots/gl3d/layout/layout_attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ module.exports = {
valType: 'enumerated',
role: 'info',
values: ['orbit', 'turntable', 'zoom', 'pan', false],
dflt: 'turntable',
editType: 'plot',
description: [
'Determines the mode of drag interactions for this scene.'
Expand Down
Binary file modified test/image/baselines/gl3d_opacity-surface.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: 0 additions & 16 deletions test/image/mocks/gl3d_text-weirdness.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,22 +42,6 @@
],
"layout": {
"autosize": true,
"undefined": {
"cameraposition": [
[
0.13855639464070454,
0.5365430934822464,
0.7678929376547012,
-0.32134727420767745
],
[
0,
0,
0
],
1.8771354322421991
]
},
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I thought this might not be necessary. If one wants to enable cameraposition it is required to use "scene" instead of "undefined"! Also now I am curious about this mock & why it was named weirdness? Also if we could possibly remove it or reduce the width/height.

Copy link
Contributor

Choose a reason for hiding this comment

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

Wow. Thanks for fixing this. That undefined shouldn't be there.

"title": "Scatter3d with text weirdness",
"showlegend": false,
"height": 758,
Expand Down
130 changes: 130 additions & 0 deletions test/jasmine/tests/gl3d_plot_interact_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,135 @@ describe('Test gl3d plots', function() {
.then(done);
});

it('@gl should set the camera dragmode to orbit if the camera.up.z vector is set to be tilted', function(done) {
Plotly.plot(gd, {
data: [{
type: 'scatter3d',
x: [1, 2, 3],
y: [2, 3, 1],
z: [3, 1, 2]
}],
layout: {
scene: {
camera: {
up: {
x: -0.5777,
y: -0.5777,
z: 0.5777
}
}
}
}
})
.then(delay(20))
.then(function() {
expect(gd._fullLayout.scene.dragmode === 'orbit').toBe(true);
})
.then(done);
});

it('@gl should set the camera dragmode to turntable if the camera.up.z vector is set to be upwards', function(done) {
Plotly.plot(gd, {
data: [{
type: 'scatter3d',
x: [1, 2, 3],
y: [2, 3, 1],
z: [3, 1, 2]
}],
layout: {
scene: {
camera: {
up: {
x: -0.0001,
y: 0,
z: 123.45
}
}
}
}
})
.then(delay(20))
.then(function() {
expect(gd._fullLayout.scene.dragmode === 'turntable').toBe(true);
})
.then(done);
});

it('@gl should set the camera dragmode to turntable if the camera.up is not set', function(done) {
Plotly.plot(gd, {
data: [{
type: 'scatter3d',
x: [1, 2, 3],
y: [2, 3, 1],
z: [3, 1, 2]
}],
layout: {
scene: {
camera: {
}
}
}
})
.then(delay(20))
.then(function() {
expect(gd._fullLayout.scene.dragmode === 'turntable').toBe(true);
})
.then(done);
});

it('@gl should set the camera dragmode to turntable if any of camera.up.[x|y|z] is missing', function(done) {
Plotly.plot(gd, {
data: [{
type: 'scatter3d',
x: [1, 2, 3],
y: [2, 3, 1],
z: [3, 1, 2]
}],
layout: {
scene: {
camera: {
up: {
x: null,
z: 0
}
}
}
}
})
.then(delay(20))
.then(function() {
expect(gd._fullLayout.scene.dragmode === 'turntable').toBe(true);
})
.then(done);
});

it('@gl should set the camera dragmode to turntable if all camera.up.[x|y|z] are zero or missing', function(done) {
Plotly.plot(gd, {
data: [{
type: 'scatter3d',
x: [1, 2, 3],
y: [2, 3, 1],
z: [3, 1, 2]
}],
layout: {
scene: {
camera: {
up: {
x: 0,
y: 0,
z: 0
}
}
}
}
})
.then(delay(20))
.then(function() {
expect(gd._fullLayout.scene.dragmode === 'turntable').toBe(true);
})
.then(done);
});

it('@gl should be able to reversibly change trace type', function(done) {
var _mock = Lib.extendDeep({}, mock2);
var sceneLayout = { aspectratio: { x: 1, y: 1, z: 1 } };
Expand All @@ -405,6 +534,7 @@ describe('Test gl3d plots', function() {
expect(gd.layout.yaxis === undefined).toBe(true);
expect(gd._fullLayout._has('gl3d')).toBe(true);
expect(gd._fullLayout.scene._scene).toBeDefined();
expect(gd._fullLayout.scene._scene.camera).toBeDefined(true);

return Plotly.restyle(gd, 'type', 'scatter');
})
Expand Down