Skip to content

Commit

Permalink
ensure having glplot.canvas before attaching events to it
Browse files Browse the repository at this point in the history
  • Loading branch information
archmoj committed Oct 25, 2020
1 parent 94e98d7 commit f0208c7
Showing 1 changed file with 34 additions and 32 deletions.
66 changes: 34 additions & 32 deletions src/plots/gl3d/scene.js
Original file line number Diff line number Diff line change
Expand Up @@ -247,43 +247,45 @@ proto.initializeGLPlot = function() {
scene.graphDiv.emit('plotly_relayout', update);
};

scene.glplot.canvas.addEventListener('mouseup', function() {
relayoutCallback(scene);
});
if(scene.glplot.canvas) {
scene.glplot.canvas.addEventListener('mouseup', function() {
relayoutCallback(scene);
});

scene.glplot.canvas.addEventListener('wheel', function(e) {
if(gd._context._scrollZoom.gl3d) {
if(scene.camera._ortho) {
var s = (e.deltaX > e.deltaY) ? 1.1 : 1.0 / 1.1;
var o = scene.glplot.getAspectratio();
scene.glplot.setAspectratio({
x: s * o.x,
y: s * o.y,
z: s * o.z
});
}

scene.glplot.canvas.addEventListener('wheel', function(e) {
if(gd._context._scrollZoom.gl3d) {
if(scene.camera._ortho) {
var s = (e.deltaX > e.deltaY) ? 1.1 : 1.0 / 1.1;
var o = scene.glplot.getAspectratio();
scene.glplot.setAspectratio({
x: s * o.x,
y: s * o.y,
z: s * o.z
});
relayoutCallback(scene);
}
}, passiveSupported ? {passive: false} : false);

relayoutCallback(scene);
}
}, passiveSupported ? {passive: false} : false);
scene.glplot.canvas.addEventListener('mousemove', function() {
if(scene.fullSceneLayout.dragmode === false) return;
if(scene.camera.mouseListener.buttons === 0) return;

scene.glplot.canvas.addEventListener('mousemove', function() {
if(scene.fullSceneLayout.dragmode === false) return;
if(scene.camera.mouseListener.buttons === 0) return;

var update = makeUpdate();
scene.graphDiv.emit('plotly_relayouting', update);
});
var update = makeUpdate();
scene.graphDiv.emit('plotly_relayouting', update);
});

if(!scene.staticMode) {
scene.glplot.canvas.addEventListener('webglcontextlost', function(event) {
if(gd && gd.emit) {
gd.emit('plotly_webglcontextlost', {
event: event,
layer: scene.id
});
}
}, false);
if(!scene.staticMode) {
scene.glplot.canvas.addEventListener('webglcontextlost', function(event) {
if(gd && gd.emit) {
gd.emit('plotly_webglcontextlost', {
event: event,
layer: scene.id
});
}
}, false);
}
}

scene.glplot.oncontextloss = function() {
Expand Down

0 comments on commit f0208c7

Please sign in to comment.