-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Changes from 2 commits
4a649f0
fe19e47
b92230a
d825c0e
d486dcd
496059c
e4a30be
3b28fae
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,8 +9,10 @@ | |
|
||
'use strict'; | ||
|
||
var createCamera = require('gl-plot3d').createCamera; | ||
var createPlot = require('gl-plot3d').createScene; | ||
var glPlot3d = require('gl-plot3d'); | ||
var createCamera = glPlot3d.createCamera; | ||
var createPlot = glPlot3d.createScene; | ||
|
||
var getContext = require('webgl-context'); | ||
var passiveSupported = require('has-passive-events'); | ||
|
||
|
@@ -260,21 +262,45 @@ function initializeGLPlot(scene, pixelRatio, canvas, gl) { | |
|
||
var gd = scene.graphDiv; | ||
|
||
var makeUpdate = function() { | ||
var update = {}; | ||
|
||
// camera updates | ||
update[scene.id + '.camera'] = getLayoutCamera(scene.camera); | ||
|
||
// scene updates | ||
update[scene.id + '.aspectratio'] = scene.glplot.getAspectratio(); | ||
|
||
return update; | ||
}; | ||
|
||
var relayoutCallback = function(scene) { | ||
if(scene.fullSceneLayout.dragmode === false) return; | ||
|
||
var update = {}; | ||
update[scene.id + '.camera'] = getLayoutCamera(scene.camera); | ||
scene.saveCamera(gd.layout); | ||
var update = makeUpdate(); | ||
scene.saveLayout(gd.layout); | ||
scene.graphDiv.emit('plotly_relayout', update); | ||
}; | ||
|
||
scene.glplot.canvas.addEventListener('mouseup', function() { | ||
relayoutCallback(scene); | ||
}); | ||
|
||
scene.glplot.canvas.addEventListener('wheel', function() { | ||
scene.glplot.canvas.addEventListener('wheel', function(e) { | ||
if(gd._context._scrollZoom.gl3d) { | ||
if(scene.glplot.camera._ortho) { | ||
var s = (e.deltaX > e.deltaY) ? 1.1 : 1.0 / 1.1; | ||
|
||
var aspectratio = scene.fullSceneLayout.aspectratio; | ||
|
||
aspectratio.x = scene.glplot.aspect[0] *= s; | ||
aspectratio.y = scene.glplot.aspect[1] *= s; | ||
aspectratio.z = scene.glplot.aspect[2] *= s; | ||
|
||
scene.glplot.setAspectratio(aspectratio); | ||
scene.glplot.redraw(); | ||
} | ||
|
||
relayoutCallback(scene); | ||
} | ||
}, passiveSupported ? {passive: false} : false); | ||
|
@@ -283,8 +309,7 @@ function initializeGLPlot(scene, pixelRatio, canvas, gl) { | |
if(scene.fullSceneLayout.dragmode === false) return; | ||
if(scene.camera.mouseListener.buttons === 0) return; | ||
|
||
var update = {}; | ||
update[scene.id + '.camera'] = getLayoutCamera(scene.camera); | ||
var update = makeUpdate(); | ||
scene.graphDiv.emit('plotly_relayouting', update); | ||
}); | ||
|
||
|
@@ -496,7 +521,7 @@ proto.plot = function(sceneData, fullLayout, layout) { | |
this.spikeOptions.merge(fullSceneLayout); | ||
|
||
// Update camera and camera mode | ||
this.setCamera(fullSceneLayout.camera); | ||
this.setViewport(fullSceneLayout); | ||
this.updateFx(fullSceneLayout.dragmode, fullSceneLayout.hovermode); | ||
this.camera.enableWheel = this.graphDiv._context._scrollZoom.gl3d; | ||
|
||
|
@@ -720,8 +745,7 @@ proto.plot = function(sceneData, fullLayout, layout) { | |
* Finally assign the computed aspecratio to the glplot module. This will have an effect | ||
* on the next render cycle. | ||
*/ | ||
this.glplot.aspect = aspectRatio; | ||
|
||
this.glplot.setAspectratio(fullSceneLayout.aspectratio); | ||
|
||
// Update frame position for multi plots | ||
var domain = fullSceneLayout.domain || null; | ||
|
@@ -751,9 +775,9 @@ proto.destroy = function() { | |
this.glplot = null; | ||
}; | ||
|
||
// getOrbitCamera :: plotly_coords -> orbit_camera_coords | ||
// getCameraArrays :: plotly_coords -> orbit_camera_coords | ||
// inverse of getLayoutCamera | ||
function getOrbitCamera(camera) { | ||
function getCameraArrays(camera) { | ||
return [ | ||
[camera.eye.x, camera.eye.y, camera.eye.z], | ||
[camera.center.x, camera.center.y, camera.center.z], | ||
|
@@ -762,7 +786,7 @@ function getOrbitCamera(camera) { | |
} | ||
|
||
// getLayoutCamera :: orbit_camera_coords -> plotly_coords | ||
// inverse of getOrbitCamera | ||
// inverse of getCameraArrays | ||
function getLayoutCamera(camera) { | ||
return { | ||
up: {x: camera.up[0], y: camera.up[1], z: camera.up[2]}, | ||
|
@@ -778,9 +802,12 @@ proto.getCamera = function getCamera() { | |
return getLayoutCamera(this.glplot.camera); | ||
}; | ||
|
||
// set camera position with a set of plotly coords | ||
proto.setCamera = function setCamera(cameraData) { | ||
this.glplot.camera.lookAt.apply(this, getOrbitCamera(cameraData)); | ||
// set gl-plot3d camera position and scene aspects with a set of plotly coords | ||
proto.setViewport = function setViewport(sceneLayout) { | ||
var cameraData = sceneLayout.camera; | ||
|
||
this.glplot.camera.lookAt.apply(this, getCameraArrays(cameraData)); | ||
this.glplot.setAspectratio(sceneLayout.aspectratio); | ||
|
||
var newOrtho = (cameraData.projection.type === 'orthographic'); | ||
var oldOrtho = this.glplot.camera._ortho; | ||
|
@@ -807,11 +834,17 @@ proto.setCamera = function setCamera(cameraData) { | |
}; | ||
|
||
// save camera to user layout (i.e. gd.layout) | ||
proto.saveCamera = function saveCamera(layout) { | ||
proto.saveLayout = function saveLayout(layout) { | ||
var fullLayout = this.fullLayout; | ||
|
||
var cameraData = this.getCamera(); | ||
var cameraNestedProp = Lib.nestedProperty(layout, this.id + '.camera'); | ||
var cameraDataLastSave = cameraNestedProp.get(); | ||
|
||
var aspectData = this.glplot.getAspectratio(); | ||
var aspectNestedProp = Lib.nestedProperty(layout, this.id + '.camera'); | ||
var aspectDataLastSave = aspectNestedProp.get(); | ||
|
||
var hasChanged = false; | ||
|
||
function same(x, y, i, j) { | ||
|
@@ -839,15 +872,33 @@ proto.saveCamera = function saveCamera(layout) { | |
} | ||
} | ||
|
||
if(!hasChanged) { | ||
if(aspectDataLastSave === undefined) { | ||
hasChanged = true; | ||
} else { | ||
if( | ||
aspectDataLastSave.x !== aspectData.x || | ||
aspectDataLastSave.y !== aspectData.y || | ||
aspectDataLastSave.z !== aspectData.z | ||
) { | ||
hasChanged = true; | ||
} | ||
} | ||
} | ||
|
||
if(hasChanged) { | ||
var preGUI = {}; | ||
preGUI[this.id + '.camera'] = cameraDataLastSave; | ||
preGUI[this.id + '.aspectratio'] = aspectDataLastSave; | ||
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. Here too, we should only store the aspectratio change for orthographic projections. 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. Done in b92230a. |
||
Registry.call('_storeDirectGUIEdit', layout, fullLayout._preGUI, preGUI); | ||
|
||
cameraNestedProp.set(cameraData); | ||
|
||
var cameraFullNP = Lib.nestedProperty(fullLayout, this.id + '.camera'); | ||
cameraFullNP.set(cameraData); | ||
|
||
var aspectFullNP = Lib.nestedProperty(fullLayout, this.id + '.aspectratio'); | ||
aspectFullNP.set(aspectData); | ||
} | ||
|
||
return hasChanged; | ||
|
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.
This should only part of the event data on scenes with orthographic projections
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.
... in other words, the event data should have the minimal set of keys that changed during the (here: scroll) interaction.
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.
Done in b92230a.
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.
And in d825c0e.