Skip to content

Commit ff1d418

Browse files
committed
plotly#29 different camera format, and ensuing code unification
1 parent 8dedb6e commit ff1d418

File tree

2 files changed

+36
-27
lines changed

2 files changed

+36
-27
lines changed

src/plots/gl3d/scene.js

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -559,13 +559,12 @@ proto.destroy = function() {
559559
// for reset camera button in mode bar
560560
proto.setCameraToDefault = function setCameraToDefault() {
561561
// as in Gl3d.layoutAttributes
562-
var lookAtInput = [
563-
[1.25, 1.25, 1.25],
564-
[0, 0, 0],
565-
[0, 0, 1]
566-
];
567-
this.glplot.camera.lookAt.apply(this, lookAtInput);
568-
this.graphDiv.emit('plotly_relayout', lookAtInput);
562+
563+
this.setCamera({
564+
eye: { x: 1.25, y: 1.25, z: 1.25 },
565+
center: { x: 0, y: 0, z: 0 },
566+
up: { x: 0, y: 0, z: 1 }
567+
});
569568
};
570569

571570
// get camera position in plotly coords from 'orbit-camera' coords
@@ -585,16 +584,22 @@ proto.getCamera = function getCamera() {
585584

586585
// set camera position with a set of plotly coords
587586
proto.setCamera = function setCamera(cameraData) {
588-
var up = cameraData.up;
589-
var center = cameraData.center;
590-
var eye = cameraData.eye;
591-
var lookAtInput = [
592-
[eye.x, eye.y, eye.z],
593-
[center.x, center.y, center.z],
594-
[up.x, up.y, up.z]
595-
];
596-
this.glplot.camera.lookAt.apply(this, lookAtInput);
597-
this.graphDiv.emit('plotly_relayout', lookAtInput);
587+
588+
// getOrbitCamera :: plotly_coords -> orbit_camera_coords
589+
function getOrbitCamera(camera) {
590+
return [
591+
[camera.eye.x, camera.eye.y, camera.eye.z],
592+
[camera.center.x, camera.center.y, camera.center.z],
593+
[camera.up.x, camera.up.y, camera.up.z]
594+
];
595+
}
596+
597+
var update = {};
598+
599+
update[this.id] = cameraData;
600+
601+
this.glplot.camera.lookAt.apply(this, getOrbitCamera(cameraData));
602+
this.graphDiv.emit('plotly_relayout', update);
598603
};
599604

600605
// save camera to user layout (i.e. gd.layout)

test/jasmine/tests/gl_plot_interact_test.js

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -351,11 +351,13 @@ describe('Test gl plot interactions', function() {
351351
setTimeout(function() {
352352

353353
expect(relayoutCallback).toHaveBeenCalled(); // initiator: resetCameraDefault3d
354-
expect(relayoutCallback).toHaveBeenCalledWith([
355-
[1.25, 1.25, 1.25],
356-
[0, 0, 0],
357-
[0, 0, 1]
358-
]);
354+
expect(relayoutCallback).toHaveBeenCalledWith({
355+
scene: {
356+
eye: { x: 1.25, y: 1.25, z: 1.25 },
357+
center: { x: 0, y: 0, z: 0 },
358+
up: { x: 0, y: 0, z: 1 }
359+
}
360+
});
359361

360362
expect(sceneLayout.camera.eye)
361363
.toEqual({x: 0.1, y: 0.1, z: 1}, 'does not change the layout objects');
@@ -371,11 +373,13 @@ describe('Test gl plot interactions', function() {
371373
setTimeout(function() {
372374

373375
expect(relayoutCallback).toHaveBeenCalled(); // initiator: resetCameraLastSave3d
374-
expect(relayoutCallback).toHaveBeenCalledWith([
375-
[1.25, 1.25, 1.25],
376-
[0, 0, 0],
377-
[0, 0, 1]
378-
]); // looks like there's no real saved data so it reverts to default
376+
expect(relayoutCallback).toHaveBeenCalledWith({
377+
scene: {
378+
eye: { x: 1.25, y: 1.25, z: 1.25 },
379+
center: { x: 0, y: 0, z: 0 },
380+
up: { x: 0, y: 0, z: 1 }
381+
}
382+
}); // looks like there's no real saved data so it reverts to default
379383

380384
expect(sceneLayout.camera.eye)
381385
.toEqual({x: 0.1, y: 0.1, z: 1}, 'does not change the layout objects');

0 commit comments

Comments
 (0)