Skip to content

Commit a49a261

Browse files
committed
#30a emit an event upon manipulation
1 parent 1f406e5 commit a49a261

File tree

1 file changed

+41
-30
lines changed

1 file changed

+41
-30
lines changed

src/plots/gl3d/scene.js

Lines changed: 41 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ function render(scene) {
5050
var lastPicked = null;
5151
var selection = scene.glplot.selection;
5252
for(var i = 0; i < keys.length; ++i) {
53-
var trace = scene.traces[keys[i]];
53+
trace = scene.traces[keys[i]];
5454
if(trace.handlePick(selection)) {
5555
lastPicked = trace;
5656
}
@@ -172,6 +172,15 @@ function initializeGLPlot(scene, fullLayout, canvas, gl) {
172172
showNoWebGlMsg(scene);
173173
}
174174

175+
var relayoutCallback = function(scene, domEvent) {
176+
var update = {};
177+
update[scene.id] = getLayoutCamera(scene.camera);
178+
scene.graphDiv.emit('plotly_relayout', update);
179+
};
180+
181+
scene.glplot.canvas.addEventListener('mouseup', relayoutCallback.bind(null, scene));
182+
scene.glplot.canvas.addEventListener('wheel', relayoutCallback.bind(null, scene));
183+
175184
if(!scene.staticMode) {
176185
scene.glplot.canvas.addEventListener('webglcontextlost', function(ev) {
177186
console.log('lost context');
@@ -255,7 +264,7 @@ function Scene(options, fullLayout) {
255264

256265
this.contourLevels = [ [], [], [] ];
257266

258-
if(!initializeGLPlot(this, fullLayout)) return;
267+
if(!initializeGLPlot(this, fullLayout)) return; // todo check the necessity for this line
259268
}
260269

261270
var proto = Scene.prototype;
@@ -286,7 +295,7 @@ function coordinateBound(axis, coord, d, bounds) {
286295
for(var i=0; i<coord.length; ++i) {
287296
if(Array.isArray(coord[i])) {
288297
for(var j=0; j<coord[i].length; ++j) {
289-
var x = axis.d2l(coord[i][j]);
298+
x = axis.d2l(coord[i][j]);
290299
if(!isNaN(x) && isFinite(x)) {
291300
bounds[0][d] = Math.min(bounds[0][d], x);
292301
bounds[1][d] = Math.max(bounds[1][d], x);
@@ -354,14 +363,14 @@ proto.plot = function(sceneData, fullLayout, layout) {
354363
[Infinity, Infinity, Infinity],
355364
[-Infinity, -Infinity, -Infinity]
356365
];
357-
for(var i=0; i<sceneData.length; ++i) {
358-
var data = sceneData[i];
366+
for(i=0; i<sceneData.length; ++i) {
367+
data = sceneData[i];
359368
if(data.visible !== true) continue;
360369

361370
computeTraceBounds(this, data, dataBounds);
362371
}
363372
var dataScale = [1,1,1];
364-
for(var j=0; j<3; ++j) {
373+
for(j=0; j<3; ++j) {
365374
if(dataBounds[0][j] > dataBounds[1][j]) {
366375
dataScale[j] = 1.0;
367376
}
@@ -379,7 +388,7 @@ proto.plot = function(sceneData, fullLayout, layout) {
379388
this.dataScale = dataScale;
380389

381390
//Update traces
382-
for(var i = 0; i < sceneData.length; ++i) {
391+
for(i = 0; i < sceneData.length; ++i) {
383392
data = sceneData[i];
384393
if(data.visible!==true) {
385394
continue;
@@ -416,7 +425,7 @@ proto.plot = function(sceneData, fullLayout, layout) {
416425
axisTypeRatios = {};
417426

418427
for(i = 0; i < 3; ++i) {
419-
var axis = fullSceneLayout[axisProperties[i]];
428+
axis = fullSceneLayout[axisProperties[i]];
420429
var axisType = axis.type;
421430

422431
if(axisType in axisTypeRatios) {
@@ -471,9 +480,9 @@ proto.plot = function(sceneData, fullLayout, layout) {
471480
var axesScaleRatio = [1, 1, 1];
472481

473482
//Compute axis scale per category
474-
for(var i=0; i<3; ++i) {
475-
var axis = fullSceneLayout[axisProperties[i]];
476-
var axisType = axis.type;
483+
for(i=0; i<3; ++i) {
484+
axis = fullSceneLayout[axisProperties[i]];
485+
axisType = axis.type;
477486
var axisRatio = axisTypeRatios[axisType];
478487
axesScaleRatio[i] = Math.pow(axisRatio.acc, 1.0/axisRatio.count) / dataScale[i];
479488
}
@@ -567,33 +576,35 @@ proto.setCameraToDefault = function setCameraToDefault() {
567576
});
568577
};
569578

570-
// get camera position in plotly coords from 'orbit-camera' coords
571-
proto.getCamera = function getCamera() {
572-
this.glplot.camera.view.recalcMatrix(this.camera.view.lastT());
573-
574-
var up = this.glplot.camera.up;
575-
var center = this.glplot.camera.center;
576-
var eye = this.glplot.camera.eye;
579+
// getOrbitCamera :: plotly_coords -> orbit_camera_coords
580+
// inverse of getLayoutCamera
581+
function getOrbitCamera(camera) {
582+
return [
583+
[camera.eye.x, camera.eye.y, camera.eye.z],
584+
[camera.center.x, camera.center.y, camera.center.z],
585+
[camera.up.x, camera.up.y, camera.up.z]
586+
];
587+
}
577588

589+
// getLayoutCamera :: orbit_camera_coords -> plotly_coords
590+
// inverse of getOrbitCamera
591+
function getLayoutCamera(camera) {
578592
return {
579-
up: {x: up[0], y: up[1], z: up[2]},
580-
center: {x: center[0], y: center[1], z: center[2]},
581-
eye: {x: eye[0], y: eye[1], z: eye[2]}
593+
up: {x: camera.up[0], y: camera.up[1], z: camera.up[2]},
594+
center: {x: camera.center[0], y: camera.center[1], z: camera.center[2]},
595+
eye: {x: camera.eye[0], y: camera.eye[1], z: camera.eye[2]}
582596
};
597+
}
598+
599+
// get camera position in plotly coords from 'orbit-camera' coords
600+
proto.getCamera = function getCamera() {
601+
this.glplot.camera.view.recalcMatrix(this.camera.view.lastT());
602+
return getLayoutCamera(this.glplot.camera);
583603
};
584604

585605
// set camera position with a set of plotly coords
586606
proto.setCamera = function setCamera(cameraData) {
587607

588-
// getOrbitCamera :: plotly_coords -> orbit_camera_coords
589-
function getOrbitCamera(camera) {
590-
return [
591-
[camera.eye.x, camera.eye.y, camera.eye.z],
592-
[camera.center.x, camera.center.y, camera.center.z],
593-
[camera.up.x, camera.up.y, camera.up.z]
594-
];
595-
}
596-
597608
var update = {};
598609

599610
update[this.id] = cameraData;

0 commit comments

Comments
 (0)