Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 2 additions & 0 deletions src/components/modebar/buttons.js
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,7 @@ function handleCamera3d(gd, ev) {
var sceneId = sceneIds[i];
var camera = sceneId + '.camera';
var aspectratio = sceneId + '.aspectratio';
var aspectmode = sceneId + '.aspectmode';
var scene = fullLayout[sceneId]._scene;
var didUpdate;

Expand All @@ -365,6 +366,7 @@ function handleCamera3d(gd, ev) {
aobj[aspectratio + '.x'] = scene.viewInitial.aspectratio.x;
aobj[aspectratio + '.y'] = scene.viewInitial.aspectratio.y;
aobj[aspectratio + '.z'] = scene.viewInitial.aspectratio.z;
aobj[aspectmode] = scene.viewInitial.aspectmode;
}
}

Expand Down
3 changes: 3 additions & 0 deletions src/plots/gl3d/scene.js
Original file line number Diff line number Diff line change
Expand Up @@ -790,6 +790,9 @@ proto.plot = function(sceneData, fullLayout, layout) {
y: fullSceneLayout.aspectratio.y,
z: fullSceneLayout.aspectratio.z
};

// also keep track of aspectmode here
scene.viewInitial.aspectmode = fullSceneLayout.aspectmode;
Copy link
Contributor

@etpinard etpinard Feb 14, 2020

Choose a reason for hiding this comment

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

Shouldn't this be

if(!scene.viewInitial.aspectmode) {
  scene.viewInitial.aspectmode = fullSceneLayout.aspectmode
}

that way we don't override viewInitia.aspectmodel on updates?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good call.
We could. Done in c730f12.

}

// Update frame position for multi plots
Expand Down
57 changes: 51 additions & 6 deletions test/jasmine/tests/gl3d_plot_interact_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -575,13 +575,19 @@ describe('Test gl3d modebar handlers - perspective case', function() {
buttonDefault.click();
});

it('@gl button resetCameraDefault3d should reset to initial aspectratios', function(done) {
it('@gl button resetCameraDefault3d should reset to initial aspectmode & aspectratios', function(done) {
var buttonDefault = selectButton(modeBar, 'resetCameraDefault3d');

expect(gd._fullLayout.scene._scene.viewInitial.aspectmode).toEqual('auto');
expect(gd._fullLayout.scene2._scene.viewInitial.aspectmode).toEqual('manual');

expect(gd._fullLayout.scene._scene.viewInitial.aspectratio).toEqual({ x: 1, y: 1, z: 1 });
expect(gd._fullLayout.scene2._scene.viewInitial.aspectratio).toEqual({ x: 3, y: 2, z: 1 });

gd.once('plotly_relayout', function() {
expect(gd._fullLayout.scene._scene.fullSceneLayout.aspectmode).toBe('auto');
expect(gd._fullLayout.scene2._scene.fullSceneLayout.aspectmode).toBe('manual');

expect(gd._fullLayout.scene._scene.glplot.getAspectratio().x).toBeCloseTo(1);
expect(gd._fullLayout.scene._scene.glplot.getAspectratio().y).toBeCloseTo(1);
expect(gd._fullLayout.scene._scene.glplot.getAspectratio().z).toBeCloseTo(1);
Expand All @@ -595,9 +601,12 @@ describe('Test gl3d modebar handlers - perspective case', function() {
buttonDefault.click();
});

it('@gl button resetCameraLastSave3d should reset to initial aspectratios', function(done) {
it('@gl button resetCameraLastSave3d should reset to initial aspectmode & aspectratios', function(done) {
var buttonDefault = selectButton(modeBar, 'resetCameraDefault3d');

expect(gd._fullLayout.scene._scene.viewInitial.aspectmode).toEqual('auto');
expect(gd._fullLayout.scene2._scene.viewInitial.aspectmode).toEqual('manual');

expect(gd._fullLayout.scene._scene.viewInitial.aspectratio).toEqual({ x: 1, y: 1, z: 1 });
expect(gd._fullLayout.scene2._scene.viewInitial.aspectratio).toEqual({ x: 3, y: 2, z: 1 });

Expand Down Expand Up @@ -771,13 +780,19 @@ describe('Test gl3d modebar handlers - orthographic case', function() {
buttonDefault.click();
});

it('@gl button resetCameraDefault3d should reset to initial aspectratios', function(done) {
it('@gl button resetCameraDefault3d should reset to initial aspectmode & aspectratios', function(done) {
var buttonDefault = selectButton(modeBar, 'resetCameraDefault3d');

expect(gd._fullLayout.scene._scene.viewInitial.aspectmode).toEqual('auto');
expect(gd._fullLayout.scene2._scene.viewInitial.aspectmode).toEqual('manual');

expect(gd._fullLayout.scene._scene.viewInitial.aspectratio).toEqual({ x: 1, y: 1, z: 1 });
expect(gd._fullLayout.scene2._scene.viewInitial.aspectratio).toEqual({ x: 3, y: 2, z: 1 });

gd.once('plotly_relayout', function() {
expect(gd._fullLayout.scene._scene.aspectmode).toEqual(undefined);
expect(gd._fullLayout.scene2._scene.aspectmode).toEqual(undefined);

expect(gd._fullLayout.scene._scene.glplot.getAspectratio().x).toBeCloseTo(1);
expect(gd._fullLayout.scene._scene.glplot.getAspectratio().y).toBeCloseTo(1);
expect(gd._fullLayout.scene._scene.glplot.getAspectratio().z).toBeCloseTo(1);
Expand All @@ -791,13 +806,19 @@ describe('Test gl3d modebar handlers - orthographic case', function() {
buttonDefault.click();
});

it('@gl button resetCameraLastSave3d should reset to initial aspectratios', function(done) {
it('@gl button resetCameraLastSave3d should reset to initial aspectmode & aspectratios', function(done) {
var buttonDefault = selectButton(modeBar, 'resetCameraDefault3d');

expect(gd._fullLayout.scene._scene.viewInitial.aspectmode).toEqual('auto');
expect(gd._fullLayout.scene2._scene.viewInitial.aspectmode).toEqual('manual');

expect(gd._fullLayout.scene._scene.viewInitial.aspectratio).toEqual({ x: 1, y: 1, z: 1 });
expect(gd._fullLayout.scene2._scene.viewInitial.aspectratio).toEqual({ x: 3, y: 2, z: 1 });

gd.once('plotly_relayout', function() {
expect(gd._fullLayout.scene._scene.fullSceneLayout.aspectmode).toBe('auto');
expect(gd._fullLayout.scene2._scene.fullSceneLayout.aspectmode).toBe('manual');

expect(gd._fullLayout.scene._scene.glplot.getAspectratio().x).toBeCloseTo(1);
expect(gd._fullLayout.scene._scene.glplot.getAspectratio().y).toBeCloseTo(1);
expect(gd._fullLayout.scene._scene.glplot.getAspectratio().z).toBeCloseTo(1);
Expand Down Expand Up @@ -1175,7 +1196,7 @@ describe('Test gl3d drag and wheel interactions', function() {
.then(done);
});

it('@gl should update the scene aspectratio when zooming with scroll wheel i.e. orthographic case', function(done) {
it('@gl should update the scene aspectmode & aspectratio when zooming with scroll wheel i.e. orthographic case', function(done) {
var sceneLayout, sceneLayout2, sceneTarget, sceneTarget2;

var mock = {
Expand All @@ -1192,8 +1213,13 @@ describe('Test gl3d drag and wheel interactions', function() {
var aspectratio;
var relayoutEvent;
var relayoutCnt = 0;
var modeBar;

Plotly.plot(gd, mock)
.then(delay(20))
.then(function() {
modeBar = gd._fullLayout._modeBar;
})
.then(function() {
gd.on('plotly_relayout', function(e) {
relayoutCnt++;
Expand All @@ -1220,6 +1246,7 @@ describe('Test gl3d drag and wheel interactions', function() {
expect(aspectratio.z).toBeCloseTo(0.909, 3, 'aspectratio.z');

expect(relayoutEvent['scene.aspectmode']).toBe('manual');
expect(gd._fullLayout.scene._scene.fullSceneLayout.aspectmode).toBe('manual');
})
.then(function() {
return scroll(sceneTarget2);
Expand All @@ -1232,7 +1259,24 @@ describe('Test gl3d drag and wheel interactions', function() {
expect(aspectratio.y).toBeCloseTo(1.818, 3, 'aspectratio.y');
expect(aspectratio.z).toBeCloseTo(0.909, 3, 'aspectratio.z');

expect(relayoutEvent['scene.aspectmode']).not.toBe('manual');
expect(relayoutEvent['scene2.aspectmode']).toBe('manual');
expect(gd._fullLayout.scene2._scene.fullSceneLayout.aspectmode).toBe('manual');
})
.then(function() {
var buttonDefault = selectButton(modeBar, 'resetCameraDefault3d');

buttonDefault.click();
})
.then(function() {
expect(gd._fullLayout.scene._scene.aspectmode).toEqual(undefined);
expect(gd._fullLayout.scene2._scene.aspectmode).toEqual(undefined);

expect(gd._fullLayout.scene._scene.glplot.getAspectratio().x).toBeCloseTo(1);
expect(gd._fullLayout.scene._scene.glplot.getAspectratio().y).toBeCloseTo(1);
expect(gd._fullLayout.scene._scene.glplot.getAspectratio().z).toBeCloseTo(1);
expect(gd._fullLayout.scene2._scene.glplot.getAspectratio().x).toBeCloseTo(3);
expect(gd._fullLayout.scene2._scene.glplot.getAspectratio().y).toBeCloseTo(2);
expect(gd._fullLayout.scene2._scene.glplot.getAspectratio().z).toBeCloseTo(1);
})
.catch(failTest)
.then(done);
Expand Down Expand Up @@ -1464,6 +1508,7 @@ describe('Test gl3d drag and wheel interactions', function() {
expect(aspectratio.z).toBeCloseTo(1.269, 3, 'aspectratio.z');

expect(relayoutEvent['scene.aspectmode']).toBe('manual');
expect(gd._fullLayout.scene._scene.fullSceneLayout.aspectmode).toBe('manual');
})
.then(function() {
// select a point
Expand Down