Skip to content

Commit bb252af

Browse files
committed
enable mouse listener when the scene is complete and improved jasmine test - also avoid return in updateFx to ensure dragmode and hovermode stay on the same ground
1 parent 54b1ca1 commit bb252af

File tree

2 files changed

+49
-35
lines changed

2 files changed

+49
-35
lines changed

src/plots/gl3d/scene.js

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,9 @@ function Scene(options, fullLayout) {
354354
var camera = fullLayout.scene.camera;
355355

356356
initializeGLPlot(this, camera, this.pixelRatio);
357+
358+
// enable mouse listener which was disabled at camera init
359+
this.camera.mouseListener.enabled = true;
357360
}
358361

359362
var proto = Scene.prototype;
@@ -854,7 +857,6 @@ proto.saveCamera = function saveCamera(layout) {
854857

855858
proto.updateFx = function(dragmode, hovermode) {
856859
var camera = this.camera;
857-
858860
if(camera) {
859861
// rotate and orbital are synonymous
860862
if(dragmode === 'orbit') {
@@ -876,16 +878,16 @@ proto.updateFx = function(dragmode, hovermode) {
876878
var y = fullCamera.up.y;
877879
var z = fullCamera.up.z;
878880
// only push `up` back to (full)layout if it's going to change
879-
if(z / Math.sqrt(x * x + y * y + z * z) > 0.999) return;
880-
881-
var attr = this.id + '.camera.up';
882-
var zUp = {x: 0, y: 0, z: 1};
883-
var edits = {};
884-
edits[attr] = zUp;
885-
var layout = gd.layout;
886-
Registry.call('_storeDirectGUIEdit', layout, fullLayout._preGUI, edits);
887-
fullCamera.up = zUp;
888-
Lib.nestedProperty(layout, attr).set(zUp);
881+
if(z / Math.sqrt(x * x + y * y + z * z) < 0.999) {
882+
var attr = this.id + '.camera.up';
883+
var zUp = {x: 0, y: 0, z: 1};
884+
var edits = {};
885+
edits[attr] = zUp;
886+
var layout = gd.layout;
887+
Registry.call('_storeDirectGUIEdit', layout, fullLayout._preGUI, edits);
888+
fullCamera.up = zUp;
889+
Lib.nestedProperty(layout, attr).set(zUp);
890+
}
889891
} else {
890892
// none rotation modes [pan or zoom]
891893
camera.keyBindingMode = dragmode;

test/jasmine/tests/gl3d_plot_interact_test.js

Lines changed: 36 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ describe('Test gl3d plots', function() {
7575
destroyGraphDiv();
7676
});
7777

78-
it('@gl should not rotate camera on the very first click before scene is complete and modebar setup', function(done) {
78+
it('@gl should not rotate camera on the very first click before scene is complete and then should rotate', function(done) {
7979
var _mock = Lib.extendDeep(
8080
{
8181
layout: {
@@ -117,28 +117,43 @@ describe('Test gl3d plots', function() {
117117
ptData = eventData.points[0];
118118
});
119119
})
120+
.then(delay(20))
121+
.then(function() {
122+
var cameraIn = gd._fullLayout.scene.camera;
123+
expect(cameraIn.up.x).toEqual(0, 'cameraIn.up.x');
124+
expect(cameraIn.up.y).toEqual(0, 'cameraIn.up.y');
125+
expect(cameraIn.up.z).toEqual(1, 'cameraIn.up.z');
126+
expect(cameraIn.center.x).toEqual(0, 'cameraIn.center.x');
127+
expect(cameraIn.center.y).toEqual(0, 'cameraIn.center.y');
128+
expect(cameraIn.center.z).toEqual(0, 'cameraIn.center.z');
129+
expect(cameraIn.eye.x).toEqual(1.2, 'cameraIn.eye.x');
130+
expect(cameraIn.eye.y).toEqual(1.2, 'cameraIn.eye.y');
131+
expect(cameraIn.eye.z).toEqual(1.2, 'cameraIn.eye.z');
132+
133+
var cameraBefore = gd._fullLayout.scene._scene.glplot.camera;
134+
expect(cameraBefore.up[0]).toBeCloseTo(0, 3, 'cameraBefore.up[0]');
135+
expect(cameraBefore.up[1]).toBeCloseTo(0, 3, 'cameraBefore.up[1]');
136+
expect(cameraBefore.up[2]).toBeCloseTo(1, 3, 'cameraBefore.up[2]');
137+
expect(cameraBefore.center[0]).toBeCloseTo(0, 3, 'cameraBefore.center[0]');
138+
expect(cameraBefore.center[1]).toBeCloseTo(0, 3, 'cameraBefore.center[1]');
139+
expect(cameraBefore.center[2]).toBeCloseTo(0, 3, 'cameraBefore.center[2]');
140+
expect(cameraBefore.eye[0]).toBeCloseTo(1.2, 3, 'cameraBefore.eye[0]');
141+
expect(cameraBefore.eye[1]).toBeCloseTo(1.2, 3, 'cameraBefore.eye[1]');
142+
expect(cameraBefore.eye[2]).toBeCloseTo(1.2, 3, 'cameraBefore.eye[2]');
143+
})
120144
.then(_click)
121145
.then(delay(20))
122146
.then(function() {
123-
expect(gd._fullLayout.scene.camera.up.x).toEqual(0, 'camera.up.x');
124-
expect(gd._fullLayout.scene.camera.up.y).toEqual(0, 'camera.up.y');
125-
expect(gd._fullLayout.scene.camera.up.z).toEqual(1, 'camera.up.z');
126-
expect(gd._fullLayout.scene.camera.eye.x).toEqual(1.2, 'camera.eye.x');
127-
expect(gd._fullLayout.scene.camera.eye.y).toEqual(1.2, 'camera.eye.y');
128-
expect(gd._fullLayout.scene.camera.eye.z).toEqual(1.2, 'camera.eye.z');
129-
expect(gd._fullLayout.scene.camera.center.x).toEqual(0, 'camera.center.x');
130-
expect(gd._fullLayout.scene.camera.center.y).toEqual(0, 'camera.center.y');
131-
expect(gd._fullLayout.scene.camera.center.z).toEqual(0, 'camera.center.z');
132-
133-
expect(gd._fullLayout.scene._scene.glplot.camera.up[0]).toEqual(0, 'camera.up[0]');
134-
expect(gd._fullLayout.scene._scene.glplot.camera.up[1]).toEqual(0, 'camera.up[1]');
135-
expect(gd._fullLayout.scene._scene.glplot.camera.up[2]).toEqual(1, 'camera.up[2]');
136-
expect(gd._fullLayout.scene._scene.glplot.camera.eye[0]).toBeCloseTo(1.2, 6, 'camera.eye[0]');
137-
expect(gd._fullLayout.scene._scene.glplot.camera.eye[1]).toBeCloseTo(1.2, 6, 'camera.eye[1]');
138-
expect(gd._fullLayout.scene._scene.glplot.camera.eye[2]).toBeCloseTo(1.2, 6, 'camera.eye[2]');
139-
expect(gd._fullLayout.scene._scene.glplot.camera.center[0]).toEqual(0, 'camera.center[0]');
140-
expect(gd._fullLayout.scene._scene.glplot.camera.center[1]).toEqual(0, 'camera.center[1]');
141-
expect(gd._fullLayout.scene._scene.glplot.camera.center[2]).toEqual(0, 'camera.center[2]');
147+
var cameraAfter = gd._fullLayout.scene._scene.glplot.camera;
148+
expect(cameraAfter.up[0]).toBeCloseTo(0, 3, 'cameraAfter.up[0]');
149+
expect(cameraAfter.up[1]).toBeCloseTo(0, 3, 'cameraAfter.up[1]');
150+
expect(cameraAfter.up[2]).toBeCloseTo(1, 3, 'cameraAfter.up[2]');
151+
expect(cameraAfter.center[0]).toBeCloseTo(0, 3, 'cameraAfter.center[0]');
152+
expect(cameraAfter.center[1]).toBeCloseTo(0, 3, 'cameraAfter.center[1]');
153+
expect(cameraAfter.center[2]).toBeCloseTo(0, 3, 'cameraAfter.center[2]');
154+
expect(cameraAfter.eye[0]).not.toBeCloseTo(1.2, 3, 'cameraAfter.eye[0]');
155+
expect(cameraAfter.eye[1]).not.toBeCloseTo(1.2, 3, 'cameraAfter.eye[1]');
156+
expect(cameraAfter.eye[2]).not.toBeCloseTo(1.2, 3, 'cameraAfter.eye[2]');
142157
})
143158
.then(done);
144159
});
@@ -433,10 +448,7 @@ describe('Test gl3d plots', function() {
433448
// N.B. gl3d click events are 'mouseover' events
434449
// with button 1 pressed
435450
function _click() {
436-
var x = 605;
437-
var y = 271;
438-
mouseEvent('mousemove', x, y);
439-
mouseEvent('mouseover', x, y, {buttons: 1});
451+
mouseEvent('mouseover', 605, 271, {buttons: 1});
440452
return delay(20)();
441453
}
442454

0 commit comments

Comments
 (0)