Skip to content
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

Keep orthographic zoom scales in fullLayout #4292

Merged
merged 8 commits into from
Oct 25, 2019
Merged

Conversation

archmoj
Copy link
Contributor

@archmoj archmoj commented Oct 21, 2019

Fix #4274.
Orthographic scroll zoom changes aspectratio values. These changes should be reflected in fullLayout and also relayout should be emitted.

Before
After

In addition, there was a mistake noticed in calling arguments i.e. when try recovering the context which was fixed in d486dcd.

Also to mention commit 496059c simplifies calling arguments by applying scene pixelRatio.

@plotly/plotly_js

@archmoj archmoj added bug something broken status: reviewable labels Oct 21, 2019
package.json Outdated Show resolved Hide resolved
@@ -243,7 +244,26 @@ function tryCreatePlot(scene, cameraObject, pixelRatio, canvas, gl) {
}
}

return failed < 2;
if(failed < 2) {
scene.wheelListener = mouseWheel(scene.glplot.canvas, function(dx, dy) {
Copy link
Contributor

Choose a reason for hiding this comment

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

A couple questions:

  • why can't we add logic to this block:

scene.glplot.canvas.addEventListener('wheel', function() {
if(gd._context._scrollZoom.gl3d) {
relayoutCallback(scene);
}
}, passiveSupported ? {passive: false} : false);

which looks like also adds a mouse-wheel handler to the scene

  • Shouldn't we also emit a plotly_relayout event with the aspectratio keys just like we do here:

var relayoutCallback = function(scene) {
if(scene.fullSceneLayout.dragmode === false) return;
var update = {};
update[scene.id + '.camera'] = getLayoutCamera(scene.camera);
scene.saveCamera(gd.layout);
scene.graphDiv.emit('plotly_relayout', update);
};

for perspective projections?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Addressed in fe19e47

@archmoj
Copy link
Contributor Author

archmoj commented Oct 21, 2019

@etpinard thanks very much for the review.
Setting the status to in progress...

- combine two wheel listeners
- use gl-plot3d aspect setter and getter
update[scene.id + '.camera'] = getLayoutCamera(scene.camera);

// scene updates
update[scene.id + '.aspectratio'] = scene.glplot.getAspectratio();
Copy link
Contributor

@etpinard etpinard Oct 23, 2019

Choose a reason for hiding this comment

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

This should only part of the event data on scenes with orthographic projections

Copy link
Contributor

Choose a reason for hiding this comment

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

... in other words, the event data should have the minimal set of keys that changed during the (here: scroll) interaction.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done in b92230a.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

And in d825c0e.

if(hasChanged) {
var preGUI = {};
preGUI[this.id + '.camera'] = cameraDataLastSave;
preGUI[this.id + '.aspectratio'] = aspectDataLastSave;
Copy link
Contributor

Choose a reason for hiding this comment

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

Here too, we should only store the aspectratio change for orthographic projections.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done in b92230a.

- consider aspectratio changes in modebar home and initial views
- bump gl-plot3d 2.3.0
@archmoj archmoj added this to the v1.51.0 milestone Oct 23, 2019
@archmoj
Copy link
Contributor Author

archmoj commented Oct 24, 2019

@etpinard This PR should be ready for another review.
Thanks!

var aspectFullNP = Lib.nestedProperty(fullLayout, this.id + '.aspectratio');
aspectFullNP.set(aspectData);

this.glplot.redraw();
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm, why do we need to redraw here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We used to redraw in scene wheel listener after updating gl-plot3d.aspect which is now moved to here so that we record the new before update.

Copy link
Contributor

Choose a reason for hiding this comment

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

I guess that's ok, it's just feels a little odd to me that a method called saveLayout ends up redrawing things in some cases.

Non-blocking.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We could possibly make gl3d/scene.js file more readable at one point.
I keep this in mind when we have time to refactor it in another PR.

Copy link
Contributor

Choose a reason for hiding this comment

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

I keep this in mind when we have time to refactor it in another PR.

Awesome. Thank you very much cleaning up this code!!

@etpinard
Copy link
Contributor

Nicely done @archmoj - 💃

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug something broken
Projects
None yet
Development

Successfully merging this pull request may close these issues.

When mouse-zooming with 3d orthographic projection, no exposed property is updated
2 participants