Skip to content

Commit 2f6c6e7

Browse files
authored
Merge pull request #3256 from plotly/issue-2425
Bug fix: applying camera up.z vector at scene init
2 parents 11bec79 + f43f944 commit 2f6c6e7

File tree

6 files changed

+157
-19
lines changed

6 files changed

+157
-19
lines changed

src/plot_api/helpers.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ exports.cleanLayout = function(layout) {
114114
scene.camera = {
115115
eye: {x: eye[0], y: eye[1], z: eye[2]},
116116
center: {x: center[0], y: center[1], z: center[2]},
117-
up: {x: mat[1], y: mat[5], z: mat[9]}
117+
up: {x: 0, y: 0, z: 1} // we just ignore calculating camera z up in this case
118118
};
119119

120120
delete scene.cameraposition;

src/plots/gl3d/layout/defaults.js

+26-1
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,31 @@ function handleGl3dDefaults(sceneLayoutIn, sceneLayoutOut, coerce, opts) {
110110
sceneLayoutIn, sceneLayoutOut, opts
111111
);
112112

113-
coerce('dragmode', opts.getDfltFromLayout('dragmode'));
113+
var dragmode = opts.getDfltFromLayout('dragmode');
114+
115+
if(dragmode !== false) {
116+
if(!dragmode) {
117+
118+
dragmode = 'orbit';
119+
120+
if(sceneLayoutIn.camera &&
121+
sceneLayoutIn.camera.up) {
122+
123+
var x = sceneLayoutIn.camera.up.x;
124+
var y = sceneLayoutIn.camera.up.y;
125+
var z = sceneLayoutIn.camera.up.z;
126+
127+
if(!x || !y || !z) {
128+
dragmode = 'turntable';
129+
} else if(z / Math.sqrt(x * x + y * y + z * z) > 0.999) {
130+
dragmode = 'turntable';
131+
}
132+
} else {
133+
dragmode = 'turntable';
134+
}
135+
}
136+
}
137+
138+
coerce('dragmode', dragmode);
114139
coerce('hovermode', opts.getDfltFromLayout('hovermode'));
115140
}

src/plots/gl3d/layout/layout_attributes.js

-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,6 @@ module.exports = {
140140
valType: 'enumerated',
141141
role: 'info',
142142
values: ['orbit', 'turntable', 'zoom', 'pan', false],
143-
dflt: 'turntable',
144143
editType: 'plot',
145144
description: [
146145
'Determines the mode of drag interactions for this scene.'
-2 Bytes
Loading

test/image/mocks/gl3d_text-weirdness.json

-16
Original file line numberDiff line numberDiff line change
@@ -42,22 +42,6 @@
4242
],
4343
"layout": {
4444
"autosize": true,
45-
"undefined": {
46-
"cameraposition": [
47-
[
48-
0.13855639464070454,
49-
0.5365430934822464,
50-
0.7678929376547012,
51-
-0.32134727420767745
52-
],
53-
[
54-
0,
55-
0,
56-
0
57-
],
58-
1.8771354322421991
59-
]
60-
},
6145
"title": "Scatter3d with text weirdness",
6246
"showlegend": false,
6347
"height": 758,

test/jasmine/tests/gl3d_plot_interact_test.js

+130
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,135 @@ describe('Test gl3d plots', function() {
392392
.then(done);
393393
});
394394

395+
it('@gl should set the camera dragmode to orbit if the camera.up.z vector is set to be tilted', function(done) {
396+
Plotly.plot(gd, {
397+
data: [{
398+
type: 'scatter3d',
399+
x: [1, 2, 3],
400+
y: [2, 3, 1],
401+
z: [3, 1, 2]
402+
}],
403+
layout: {
404+
scene: {
405+
camera: {
406+
up: {
407+
x: -0.5777,
408+
y: -0.5777,
409+
z: 0.5777
410+
}
411+
}
412+
}
413+
}
414+
})
415+
.then(delay(20))
416+
.then(function() {
417+
expect(gd._fullLayout.scene.dragmode === 'orbit').toBe(true);
418+
})
419+
.then(done);
420+
});
421+
422+
it('@gl should set the camera dragmode to turntable if the camera.up.z vector is set to be upwards', function(done) {
423+
Plotly.plot(gd, {
424+
data: [{
425+
type: 'scatter3d',
426+
x: [1, 2, 3],
427+
y: [2, 3, 1],
428+
z: [3, 1, 2]
429+
}],
430+
layout: {
431+
scene: {
432+
camera: {
433+
up: {
434+
x: -0.0001,
435+
y: 0,
436+
z: 123.45
437+
}
438+
}
439+
}
440+
}
441+
})
442+
.then(delay(20))
443+
.then(function() {
444+
expect(gd._fullLayout.scene.dragmode === 'turntable').toBe(true);
445+
})
446+
.then(done);
447+
});
448+
449+
it('@gl should set the camera dragmode to turntable if the camera.up is not set', function(done) {
450+
Plotly.plot(gd, {
451+
data: [{
452+
type: 'scatter3d',
453+
x: [1, 2, 3],
454+
y: [2, 3, 1],
455+
z: [3, 1, 2]
456+
}],
457+
layout: {
458+
scene: {
459+
camera: {
460+
}
461+
}
462+
}
463+
})
464+
.then(delay(20))
465+
.then(function() {
466+
expect(gd._fullLayout.scene.dragmode === 'turntable').toBe(true);
467+
})
468+
.then(done);
469+
});
470+
471+
it('@gl should set the camera dragmode to turntable if any of camera.up.[x|y|z] is missing', function(done) {
472+
Plotly.plot(gd, {
473+
data: [{
474+
type: 'scatter3d',
475+
x: [1, 2, 3],
476+
y: [2, 3, 1],
477+
z: [3, 1, 2]
478+
}],
479+
layout: {
480+
scene: {
481+
camera: {
482+
up: {
483+
x: null,
484+
z: 0
485+
}
486+
}
487+
}
488+
}
489+
})
490+
.then(delay(20))
491+
.then(function() {
492+
expect(gd._fullLayout.scene.dragmode === 'turntable').toBe(true);
493+
})
494+
.then(done);
495+
});
496+
497+
it('@gl should set the camera dragmode to turntable if all camera.up.[x|y|z] are zero or missing', function(done) {
498+
Plotly.plot(gd, {
499+
data: [{
500+
type: 'scatter3d',
501+
x: [1, 2, 3],
502+
y: [2, 3, 1],
503+
z: [3, 1, 2]
504+
}],
505+
layout: {
506+
scene: {
507+
camera: {
508+
up: {
509+
x: 0,
510+
y: 0,
511+
z: 0
512+
}
513+
}
514+
}
515+
}
516+
})
517+
.then(delay(20))
518+
.then(function() {
519+
expect(gd._fullLayout.scene.dragmode === 'turntable').toBe(true);
520+
})
521+
.then(done);
522+
});
523+
395524
it('@gl should be able to reversibly change trace type', function(done) {
396525
var _mock = Lib.extendDeep({}, mock2);
397526
var sceneLayout = { aspectratio: { x: 1, y: 1, z: 1 } };
@@ -405,6 +534,7 @@ describe('Test gl3d plots', function() {
405534
expect(gd.layout.yaxis === undefined).toBe(true);
406535
expect(gd._fullLayout._has('gl3d')).toBe(true);
407536
expect(gd._fullLayout.scene._scene).toBeDefined();
537+
expect(gd._fullLayout.scene._scene.camera).toBeDefined(true);
408538

409539
return Plotly.restyle(gd, 'type', 'scatter');
410540
})

0 commit comments

Comments
 (0)