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 21 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
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_ibm-plot.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_surface-lighting.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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