Skip to content

Keep orthographic zoom scales in fullLayout #4292

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

Merged
merged 8 commits into from
Oct 25, 2019
5 changes: 2 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
"gl-mat4": "^1.2.0",
"gl-mesh3d": "^2.1.1",
"gl-plot2d": "^1.4.2",
"gl-plot3d": "^2.2.2",
"gl-plot3d": "git://github.com/gl-vis/gl-plot3d.git#4d41ca21b3c0a25db8776ce92261995323bb62e8",
"gl-pointcloud2d": "^1.0.2",
"gl-scatter3d": "^1.2.2",
"gl-select-box": "^1.0.3",
Expand Down
22 changes: 21 additions & 1 deletion src/plots/gl3d/scene.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

var createCamera = require('gl-plot3d').createCamera;
var createPlot = require('gl-plot3d').createScene;
var mouseWheel = require('mouse-wheel');
var getContext = require('webgl-context');
var passiveSupported = require('has-passive-events');

Expand Down Expand Up @@ -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

// TODO remove now that we can disable scroll via scrollZoom?
if(scene.glplot.camera.keyBindingMode === false) return;
if(!scene.glplot.camera.enableWheel) return;

if(scene.glplot.camera._ortho) {
var s = (dx > dy) ? 1.1 : 1.0 / 1.1;

scene.fullSceneLayout.aspectratio.x = scene.glplot.aspect[0] *= s;
scene.fullSceneLayout.aspectratio.y = scene.glplot.aspect[1] *= s;
scene.fullSceneLayout.aspectratio.z = scene.glplot.aspect[2] *= s;

scene.glplot.redraw();
}
}, true);

return true;
}
return false;
}

function initializeGLPlot(scene, pixelRatio, canvas, gl) {
Expand Down
18 changes: 18 additions & 0 deletions test/jasmine/tests/gl3d_plot_interact_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -906,6 +906,24 @@ describe('Test gl3d drag and wheel interactions', function() {
return scroll(sceneTarget2);
})
.then(function() {
expect(
gd._fullLayout.scene2.aspectratio.x
).toEqual(
gd._fullLayout.scene2._scene.glplot.aspect[0]
);

expect(
gd._fullLayout.scene2.aspectratio.y
).toEqual(
gd._fullLayout.scene2._scene.glplot.aspect[1]
);

expect(
gd._fullLayout.scene2.aspectratio.z
).toEqual(
gd._fullLayout.scene2._scene.glplot.aspect[2]
);

_assertAndReset(2);
})
.catch(failTest)
Expand Down