-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix reset camera buttons to work after switching projection between perspective and orthographic #3597
fix reset camera buttons to work after switching projection between perspective and orthographic #3597
Changes from 6 commits
58e47c4
4d7c1b4
9e1aa7a
5dfdbcf
eb8737b
8444b99
7408232
3c37554
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -338,6 +338,8 @@ modeBarButtons.resetCameraLastSave3d = { | |
function handleCamera3d(gd, ev) { | ||
var button = ev.currentTarget; | ||
var attr = button.getAttribute('data-attr'); | ||
if(attr !== 'resetLastSave' && attr !== 'resetDefault') return; | ||
|
||
var fullLayout = gd._fullLayout; | ||
var sceneIds = fullLayout._subplots.gl3d; | ||
var aobj = {}; | ||
|
@@ -347,14 +349,21 @@ function handleCamera3d(gd, ev) { | |
var key = sceneId + '.camera'; | ||
var scene = fullLayout[sceneId]._scene; | ||
|
||
if(attr === 'resetDefault') { | ||
aobj[key] = Lib.extendDeep({}, scene.cameraInitial); | ||
aobj[key].up = null; | ||
aobj[key].eye = null; | ||
aobj[key].center = null; | ||
if(attr === 'resetLastSave') { | ||
aobj[key + '.up'] = scene.viewInitial.up; | ||
aobj[key + '.eye'] = scene.viewInitial.eye; | ||
aobj[key + '.center'] = scene.viewInitial.center; | ||
} else if(attr === 'resetDefault') { | ||
aobj[key + '.up'] = null; | ||
aobj[key + '.eye'] = null; | ||
aobj[key + '.center'] = null; | ||
} | ||
else if(attr === 'resetLastSave') { | ||
aobj[key] = Lib.extendDeep({}, scene.cameraInitial); | ||
|
||
var newOrtho = (scene.viewInitial.projection.type === 'orthographic'); | ||
var oldOrtho = scene.camera._ortho; | ||
|
||
if(newOrtho !== oldOrtho) { | ||
aobj[key + '.projection'] = scene.viewInitial.projection; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wait. Why do we need this? |
||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1043,8 +1043,8 @@ describe('Test gl3d modebar handlers', function() { | |
it('@gl button resetCameraDefault3d should reset camera to default', function(done) { | ||
var buttonDefault = selectButton(modeBar, 'resetCameraDefault3d'); | ||
|
||
expect(gd._fullLayout.scene._scene.cameraInitial.eye).toEqual({ x: 0.1, y: 0.1, z: 1 }); | ||
expect(gd._fullLayout.scene2._scene.cameraInitial.eye).toEqual({ x: 2.5, y: 2.5, z: 2.5 }); | ||
expect(gd._fullLayout.scene._scene.viewInitial.eye).toEqual({ x: 0.1, y: 0.1, z: 1 }); | ||
expect(gd._fullLayout.scene2._scene.viewInitial.eye).toEqual({ x: 2.5, y: 2.5, z: 2.5 }); | ||
|
||
gd.once('plotly_relayout', function() { | ||
assertScenes(gd._fullLayout, 'camera.eye.x', 1.25); | ||
|
@@ -1099,8 +1099,8 @@ describe('Test gl3d modebar handlers', function() { | |
assertCameraEye(gd._fullLayout.scene, 0.1, 0.1, 1); | ||
assertCameraEye(gd._fullLayout.scene2, 2.5, 2.5, 2.5); | ||
|
||
delete gd._fullLayout.scene._scene.cameraInitial; | ||
delete gd._fullLayout.scene2._scene.cameraInitial; | ||
delete gd._fullLayout.scene._scene.viewInitial; | ||
delete gd._fullLayout.scene2._scene.viewInitial; | ||
|
||
Plotly.relayout(gd, { | ||
'scene.bgcolor': '#d3d3d3', | ||
|
@@ -1489,6 +1489,103 @@ describe('Test gl3d relayout calls', function() { | |
.catch(failTest) | ||
.then(done); | ||
}); | ||
|
||
it('@gl resetCamera buttons should be able to reset projection type after switching projection type from perspective to orthographic', function(done) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do you change your mind here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now that we could switch projections to initial projection I thought we may change this. |
||
Plotly.plot(gd, { | ||
data: [{ | ||
type: 'surface', | ||
x: [0, 1], | ||
y: [0, 1], | ||
z: [[0, 1], [1, 0]] | ||
}], | ||
layout: { | ||
width: 300, | ||
height: 200, | ||
scene: { | ||
camera: { | ||
eye: { | ||
x: 2, | ||
y: 1, | ||
z: 0.5 | ||
} | ||
} | ||
} | ||
} | ||
}) | ||
.then(function() { | ||
expect(gd._fullLayout.scene._scene.camera._ortho).toEqual(false, 'perspective'); | ||
}) | ||
.then(function() { | ||
return Plotly.relayout(gd, 'scene.camera.projection.type', 'orthographic'); | ||
}) | ||
.then(function() { | ||
expect(gd._fullLayout.scene._scene.camera._ortho).toEqual(true, 'orthographic'); | ||
}) | ||
.then(function() { | ||
return selectButton(gd._fullLayout._modeBar, 'resetCameraLastSave3d').click(); | ||
}) | ||
.then(function() { | ||
expect(gd._fullLayout.scene._scene.camera._ortho).toEqual(false, 'perspective'); | ||
}) | ||
.then(function() { | ||
return selectButton(gd._fullLayout._modeBar, 'resetCameraDefault3d').click(); | ||
}) | ||
.then(function() { | ||
expect(gd._fullLayout.scene._scene.camera._ortho).toEqual(false, 'perspective'); | ||
}) | ||
.catch(failTest) | ||
.then(done); | ||
}); | ||
|
||
it('@gl resetCamera buttons should be able to reset projection type after switching projection type from orthographic to perspective', function(done) { | ||
Plotly.plot(gd, { | ||
data: [{ | ||
type: 'surface', | ||
x: [0, 1], | ||
y: [0, 1], | ||
z: [[0, 1], [1, 0]] | ||
}], | ||
layout: { | ||
width: 300, | ||
height: 200, | ||
scene: { | ||
camera: { | ||
eye: { | ||
x: 2, | ||
y: 1, | ||
z: 0.5 | ||
}, | ||
projection: { | ||
type: 'orthographic' | ||
} | ||
} | ||
} | ||
} | ||
}) | ||
.then(function() { | ||
expect(gd._fullLayout.scene._scene.camera._ortho).toEqual(true, 'orthographic'); | ||
}) | ||
.then(function() { | ||
return Plotly.relayout(gd, 'scene.camera.projection.type', 'perspective'); | ||
}) | ||
.then(function() { | ||
expect(gd._fullLayout.scene._scene.camera._ortho).toEqual(false, 'perspective'); | ||
}) | ||
.then(function() { | ||
return selectButton(gd._fullLayout._modeBar, 'resetCameraLastSave3d').click(); | ||
}) | ||
.then(function() { | ||
expect(gd._fullLayout.scene._scene.camera._ortho).toEqual(true, 'orthographic'); | ||
}) | ||
.then(function() { | ||
return selectButton(gd._fullLayout._modeBar, 'resetCameraDefault3d').click(); | ||
}) | ||
.then(function() { | ||
expect(gd._fullLayout.scene._scene.camera._ortho).toEqual(true, 'orthographic'); | ||
}) | ||
.catch(failTest) | ||
.then(done); | ||
}); | ||
}); | ||
|
||
describe('Test gl3d annotations', function() { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When does this happen?