-
-
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
Conversation
src/components/modebar/buttons.js
Outdated
@@ -347,15 +347,19 @@ function handleCamera3d(gd, ev) { | |||
var key = sceneId + '.camera'; | |||
var scene = fullLayout[sceneId]._scene; | |||
|
|||
if(attr === 'resetDefault') { | |||
if(attr === 'resetDefault' || attr === 'resetLastSave') { | |||
aobj[key] = Lib.extendDeep({}, scene.cameraInitial); |
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.
Wouldn't it be easier to just save keys up
, eye
and center
in scene.cameraInitial
instead of saving the all scene.camera
keys and then doing this fancy footwork to get the correct projection.type
?
In other words, do we really need a cameraInitial
stash? Could we instead just use a "view" stash:
scene.viewInitial = {
up: {x: /**/, y: /**/, z: /**/},
eye: {x: /**/, y: /**/, z: /**/},
center: {x: /**/, y: /**/, z: /**/}
}
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.
Good call.
Done in 9e1aa7a.
src/components/modebar/buttons.js
Outdated
if(attr === 'resetDefault' || attr === 'resetLastSave') { | ||
aobj[key] = Lib.extendDeep({}, scene.viewInitial); | ||
|
||
aobj[key].projection = { |
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.
We shouldn't need this after 9e1aa7a
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.
Actually, you'll need to tweak aobj
/ key
logic. In the end, aobj
should look like:
aobj = {
'scene.camera.up': {/**/},
'scene.camera.eye': {/**/},
'scene.camera.center': {/**/}
}
as opposed to
aobj = {
'scene.camera': {
up: {/**/},
eye: {/**/},
center: {/**/}
}
}
src/components/modebar/buttons.js
Outdated
'up': scene.viewInitial.up, | ||
'eye': scene.viewInitial.eye, | ||
'center': scene.viewInitial.center, | ||
'projection': { |
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.
We shouldn't need to update projection
at all, am I right?
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.
You are right. But in order to that we need to explicitly pass the current projection here.
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.
Ok, that's a bug then. Calling
Plotly.relayout('graph', 'scene.camera.up', {/**/})
should not change the projection type.
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.
don't we just need to flatten it to aobj[key + '.up'] = ...
etc?
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.
Thanks @alexcjohnson & @etpinard.
Flattening was really helpful.
Nicely done 💃 |
|
ok. |
src/components/modebar/buttons.js
Outdated
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 comment
The reason will be displayed to describe this comment to others. Learn more.
Wait. Why do we need this?
@@ -1490,7 +1490,7 @@ describe('Test gl3d relayout calls', function() { | |||
.then(done); | |||
}); | |||
|
|||
it('@gl should maintain projection type when resetCamera buttons clicked after switching projection type from perspective to orthographic', function(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 comment
The 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 comment
The 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.
If the user is not happy with the changes made to the camera and wants to get back to initial/home view this allows that. Codepen.
I disagree. The reset camera buttons should reset only the attribute that can be changed via user interactions i.e. drag/scroll/clicking on modebar buttons. As we can't change the I'm voting for the version pre 8444b99 |
src/components/modebar/buttons.js
Outdated
@@ -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; |
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?
Well earned 💃 Thanks for following through from my comments. |
Fixes the issue described in #3596.
codepen Before.
codepen After.
fixes #3596