Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
46 changes: 45 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,26 @@ describe('Test gl plot interactions', function() {
.toEqual({x: 2.5, y: 2.5, z: 2.5});

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

setTimeout(function() {

expect(relayoutCallback).toHaveBeenCalledTimes(2); // initiator: resetCameraDefault3d; 2 scenes
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(relayoutCallback).toHaveBeenCalledWith({
scene2: {
center: { x: 0, y: 0, z: 0 },
eye: { x: 1.25, y: 1.25, z: 1.25 },
up: { x: 0, y: 0, z: 1 }
}
});
relayoutCallback.calls.reset();
Copy link
Contributor

Choose a reason for hiding this comment

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

nice move.


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 +377,25 @@ describe('Test gl plot interactions', function() {
.toBeCloseToArray([1.25, 1.25, 1.25], 4);

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

setTimeout(function() {

expect(relayoutCallback).toHaveBeenCalledTimes(2); // initiator: resetCameraLastSave3d; 2 scenes
expect(relayoutCallback).toHaveBeenCalledWith({
scene: {
center: { x: 0, y: 0, z: 0 },
eye: { x: 0.1, y: 0.1, z: 1 },
up: { x: 0, y: 0, z: 1 }
}
});
expect(relayoutCallback).toHaveBeenCalledWith({
scene2: {
center: { x: 0, y: 0, z: 0 },
eye: { x: 2.5, y: 2.5, z: 2.5 },
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 @@ -364,7 +406,9 @@ describe('Test gl plot interactions', function() {
.toBeCloseToArray([2.5, 2.5, 2.5], 4);

done();

}, MODEBAR_DELAY);

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