Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
35 changes: 22 additions & 13 deletions src/plots/gl3d/scene.js
Original file line number Diff line number Diff line change
Expand Up @@ -559,11 +559,12 @@ proto.destroy = function() {
// for reset camera button in mode bar
proto.setCameraToDefault = function setCameraToDefault() {
// as in Gl3d.layoutAttributes
this.glplot.camera.lookAt(
[1.25, 1.25, 1.25],
[0, 0, 0],
[0, 0, 1]
);

this.setCamera({
Copy link
Contributor

Choose a reason for hiding this comment

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

nice clean up.

eye: { x: 1.25, y: 1.25, z: 1.25 },
center: { x: 0, y: 0, z: 0 },
up: { x: 0, y: 0, z: 1 }
});
};

// get camera position in plotly coords from 'orbit-camera' coords
Expand All @@ -583,14 +584,22 @@ proto.getCamera = function getCamera() {

// set camera position with a set of plotly coords
proto.setCamera = function setCamera(cameraData) {
var up = cameraData.up;
var center = cameraData.center;
var eye = cameraData.eye;
this.glplot.camera.lookAt(
[eye.x, eye.y, eye.z],
[center.x, center.y, center.z],
[up.x, up.y, up.z]
);

// getOrbitCamera :: plotly_coords -> orbit_camera_coords
function getOrbitCamera(camera) {
return [
[camera.eye.x, camera.eye.y, camera.eye.z],
[camera.center.x, camera.center.y, camera.center.z],
[camera.up.x, camera.up.y, camera.up.z]
];
}

var update = {};

update[this.id] = cameraData;

this.glplot.camera.lookAt.apply(this, getOrbitCamera(cameraData));
this.graphDiv.emit('plotly_relayout', update);
};

// save camera to user layout (i.e. gd.layout)
Expand Down
31 changes: 30 additions & 1 deletion test/jasmine/tests/gl_plot_interact_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ describe('Test gl plot interactions', function() {
});

describe('gl3d modebar click handlers', function() {
var modeBar;
var modeBar, relayoutCallback;

beforeEach(function(done) {
var mockData = [{
Expand All @@ -245,8 +245,13 @@ describe('Test gl plot interactions', function() {

gd = createGraphDiv();
Plotly.plot(gd, mockData, mockLayout).then(function() {

modeBar = gd._fullLayout._modeBar;

relayoutCallback = jasmine.createSpy('relayoutCallback');

gd.on('plotly_relayout', relayoutCallback);

delay(done);
});
});
Expand Down Expand Up @@ -342,7 +347,18 @@ describe('Test gl plot interactions', function() {
.toEqual({x: 2.5, y: 2.5, z: 2.5});

selectButton(modeBar, 'resetCameraDefault3d').click();

setTimeout(function() {

expect(relayoutCallback).toHaveBeenCalled(); // initiator: resetCameraDefault3d
expect(relayoutCallback).toHaveBeenCalledWith({
scene: {
eye: { x: 1.25, y: 1.25, z: 1.25 },
center: { x: 0, y: 0, z: 0 },
up: { x: 0, y: 0, z: 1 }
}
});

expect(sceneLayout.camera.eye)
.toEqual({x: 0.1, y: 0.1, z: 1}, 'does not change the layout objects');
expect(scene.camera.eye)
Expand All @@ -353,7 +369,18 @@ describe('Test gl plot interactions', function() {
.toBeCloseToArray([1.25, 1.25, 1.25], 4);

selectButton(modeBar, 'resetCameraLastSave3d').click();

setTimeout(function() {

expect(relayoutCallback).toHaveBeenCalled(); // initiator: resetCameraLastSave3d
expect(relayoutCallback).toHaveBeenCalledWith({
scene: {
eye: { x: 1.25, y: 1.25, z: 1.25 },
Copy link
Contributor

Choose a reason for hiding this comment

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

This assertion is misleading. Adding

console.log(getOrbitCamera(cameraData))

above this line in Scene.prototype.setCamera logs

[[0.1, 0.1, 1], [0, 0, 0], [0, 0, 1]]

for the first scene, and

[[2.5, 2.5, 2.5], [0, 0, 0], [0, 0, 1]]

for the second scene.

I think the jasmine spy, holds on to the arguments of the first relayoutCallback call and isn't updated for subsequent calls.

Moreover, we should make it clear that plotly_relayout is triggered twice (one per each scene) when clicking on these buttons.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks @etpinard, I'll try to capture the multi-scene aspect.

center: { x: 0, y: 0, z: 0 },
up: { x: 0, y: 0, z: 1 }
}
}); // looks like there's no real saved data so it reverts to default

expect(sceneLayout.camera.eye)
.toEqual({x: 0.1, y: 0.1, z: 1}, 'does not change the layout objects');
expect(scene.camera.eye)
Expand All @@ -364,7 +391,9 @@ describe('Test gl plot interactions', function() {
.toBeCloseToArray([2.5, 2.5, 2.5], 4);

done();

}, MODEBAR_DELAY);

}, MODEBAR_DELAY);
});
});
Expand Down