Skip to content

Commit

Permalink
Merge pull request #3256 from plotly/issue-2425
Browse files Browse the repository at this point in the history
Bug fix: applying camera up.z vector at scene init
  • Loading branch information
archmoj authored Nov 22, 2018
2 parents 11bec79 + f43f944 commit 2f6c6e7
Show file tree
Hide file tree
Showing 6 changed files with 157 additions and 19 deletions.
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
};

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) {
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
]
},
"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

0 comments on commit 2f6c6e7

Please sign in to comment.