Skip to content

Commit 8444b99

Browse files
committed
modebar now able to switch projection type
1 parent eb8737b commit 8444b99

File tree

3 files changed

+18
-7
lines changed

3 files changed

+18
-7
lines changed

src/components/modebar/buttons.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,8 @@ modeBarButtons.resetCameraLastSave3d = {
338338
function handleCamera3d(gd, ev) {
339339
var button = ev.currentTarget;
340340
var attr = button.getAttribute('data-attr');
341+
if(attr !== 'resetLastSave' && attr !== 'resetDefault') return;
342+
341343
var fullLayout = gd._fullLayout;
342344
var sceneIds = fullLayout._subplots.gl3d;
343345
var aobj = {};
@@ -351,12 +353,18 @@ function handleCamera3d(gd, ev) {
351353
aobj[key + '.up'] = scene.viewInitial.up;
352354
aobj[key + '.eye'] = scene.viewInitial.eye;
353355
aobj[key + '.center'] = scene.viewInitial.center;
354-
355356
} else if(attr === 'resetDefault') {
356357
aobj[key + '.up'] = null;
357358
aobj[key + '.eye'] = null;
358359
aobj[key + '.center'] = null;
359360
}
361+
362+
var newOrtho = (scene.viewInitial.projection.type === 'orthographic');
363+
var oldOrtho = scene.camera._ortho;
364+
365+
if(newOrtho !== oldOrtho) {
366+
aobj[key + '.projection'] = scene.viewInitial.projection;
367+
}
360368
}
361369

362370
Registry.call('_guiRelayout', gd, aobj);

src/plots/gl3d/index.js

+3
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ exports.plot = function plotGl3d(gd) {
7070
// save 'initial' camera view settings for modebar button
7171
if(!scene.viewInitial) {
7272
scene.viewInitial = {
73+
projection: {
74+
type: camera.projection.type
75+
},
7376
up: {
7477
x: camera.up.x,
7578
y: camera.up.y,

test/jasmine/tests/gl3d_plot_interact_test.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -1490,7 +1490,7 @@ describe('Test gl3d relayout calls', function() {
14901490
.then(done);
14911491
});
14921492

1493-
it('@gl should maintain projection type when resetCamera buttons clicked after switching projection type from perspective to orthographic', function(done) {
1493+
it('@gl resetCamera buttons should be able to reset projection type after switching projection type from perspective to orthographic', function(done) {
14941494
Plotly.plot(gd, {
14951495
data: [{
14961496
type: 'surface',
@@ -1525,19 +1525,19 @@ describe('Test gl3d relayout calls', function() {
15251525
return selectButton(gd._fullLayout._modeBar, 'resetCameraLastSave3d').click();
15261526
})
15271527
.then(function() {
1528-
expect(gd._fullLayout.scene._scene.camera._ortho).toEqual(true, 'orthographic');
1528+
expect(gd._fullLayout.scene._scene.camera._ortho).toEqual(false, 'perspective');
15291529
})
15301530
.then(function() {
15311531
return selectButton(gd._fullLayout._modeBar, 'resetCameraDefault3d').click();
15321532
})
15331533
.then(function() {
1534-
expect(gd._fullLayout.scene._scene.camera._ortho).toEqual(true, 'orthographic');
1534+
expect(gd._fullLayout.scene._scene.camera._ortho).toEqual(false, 'perspective');
15351535
})
15361536
.catch(failTest)
15371537
.then(done);
15381538
});
15391539

1540-
it('@gl should maintain projection type when resetCamera buttons clicked after switching projection type from orthographic to perspective', function(done) {
1540+
it('@gl resetCamera buttons should be able to reset projection type after switching projection type from orthographic to perspective', function(done) {
15411541
Plotly.plot(gd, {
15421542
data: [{
15431543
type: 'surface',
@@ -1575,13 +1575,13 @@ describe('Test gl3d relayout calls', function() {
15751575
return selectButton(gd._fullLayout._modeBar, 'resetCameraLastSave3d').click();
15761576
})
15771577
.then(function() {
1578-
expect(gd._fullLayout.scene._scene.camera._ortho).toEqual(false, 'perspective');
1578+
expect(gd._fullLayout.scene._scene.camera._ortho).toEqual(true, 'orthographic');
15791579
})
15801580
.then(function() {
15811581
return selectButton(gd._fullLayout._modeBar, 'resetCameraDefault3d').click();
15821582
})
15831583
.then(function() {
1584-
expect(gd._fullLayout.scene._scene.camera._ortho).toEqual(false, 'perspective');
1584+
expect(gd._fullLayout.scene._scene.camera._ortho).toEqual(true, 'orthographic');
15851585
})
15861586
.catch(failTest)
15871587
.then(done);

0 commit comments

Comments
 (0)