Skip to content

Commit

Permalink
Embedding using ipywidgets.embed not working properly #320
Browse files Browse the repository at this point in the history
  • Loading branch information
artur-trzesiok committed Jan 11, 2022
1 parent b7240ed commit 671c2a2
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions js/src/k3d.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,19 +222,19 @@ const PlotView = widgets.DOMWidgetView.extend({
this.model.lastCameraSync = (new Date()).getTime();

this.model.on('msg:custom', function (obj) {
const { model } = this;
const {model} = this;

if (obj.msg_type === 'fetch_screenshot') {
this.K3DInstance.getScreenshot(this.K3DInstance.parameters.screenshotScale, obj.only_canvas)
.then((canvas) => {
const data = canvas.toDataURL().split(',')[1];

model.save('screenshot', data, { patch: true });
model.save('screenshot', data, {patch: true});
});
}

if (obj.msg_type === 'fetch_snapshot') {
model.save('snapshot', this.K3DInstance.getHTMLSnapshot(obj.compression_level), { patch: true });
model.save('snapshot', this.K3DInstance.getHTMLSnapshot(obj.compression_level), {patch: true});
}

if (obj.msg_type === 'start_auto_play') {
Expand Down Expand Up @@ -350,13 +350,15 @@ const PlotView = widgets.DOMWidgetView.extend({
this._setVoxelPaintColor();

this.model.get('object_ids').forEach(function (id) {
this.renderPromises.push(this.K3DInstance.load({ objects: [objectsList[id].attributes] }));
this.renderPromises.push(this.K3DInstance.load({objects: [objectsList[id].attributes]}));
}, this);

this.cameraChangeId = this.K3DInstance.on(this.K3DInstance.events.CAMERA_CHANGE, (control) => {
if ((new Date()).getTime() - self.model.lastCameraSync > 200) {
self.model.lastCameraSync = (new Date()).getTime();
self.model.save('camera', control, { patch: true });
if (self.model._comm_live) {
if ((new Date()).getTime() - self.model.lastCameraSync > 200) {
self.model.lastCameraSync = (new Date()).getTime();
self.model.save('camera', control, {patch: true});
}
}
});

Expand All @@ -367,18 +369,18 @@ const PlotView = widgets.DOMWidgetView.extend({
}

if (objectsList[change.id]) {
objectsList[change.id].save(change.key, change.value, { patch: true });
objectsList[change.id].save(change.key, change.value, {patch: true});
}
}
});

this.GUIParametersChanges = this.K3DInstance.on(this.K3DInstance.events.PARAMETERS_CHANGE, (change) => {
self.model.save(change.key, change.value, { patch: true });
self.model.save(change.key, change.value, {patch: true});
});

this.voxelsCallback = this.K3DInstance.on(this.K3DInstance.events.VOXELS_CALLBACK, (param) => {
if (objectsList[param.object.K3DIdentifier]) {
objectsList[param.object.K3DIdentifier].send({ msg_type: 'click_callback', coord: param.coord });
objectsList[param.object.K3DIdentifier].send({msg_type: 'click_callback', coord: param.coord});
}
});

Expand Down Expand Up @@ -558,7 +560,7 @@ const PlotView = widgets.DOMWidgetView.extend({
}, this);

_.difference(newObjectId, oldObjectId).forEach(function (id) {
this.renderPromises.push(this.K3DInstance.load({ objects: [objectsList[id].attributes] }));
this.renderPromises.push(this.K3DInstance.load({objects: [objectsList[id].attributes]}));
}, this);
},

Expand Down

0 comments on commit 671c2a2

Please sign in to comment.