Skip to content

Commit

Permalink
Process Lumino messages with compatibility with Phosphor
Browse files Browse the repository at this point in the history
See github.com/jupyter-widgets/ipywidgets/pull/3124 for resize change rationale
  • Loading branch information
abdelq committed Oct 20, 2022
1 parent c72eb38 commit 6ee61a4
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions packages/javascript/jupyterlab-plotly/src/Figure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -806,7 +806,7 @@ export class FigureView extends DOMWidgetView {
viewID: string;

/**
* The perform_render method is called by processPhosphorMessage
* The perform_render method is called by processLuminoMessage
* after the widget's DOM element has been attached to the notebook
* output cell. This happens after the initialize of the
* FigureModel, and it won't happen at all if the Python FigureWidget
Expand Down Expand Up @@ -900,10 +900,10 @@ export class FigureView extends DOMWidgetView {
}

/**
* Respond to phosphorjs events
* Respond to Lumino events
*/
processPhosphorMessage(msg: any) {
super.processPhosphorMessage.apply(this, arguments);
_processLuminoMessage(msg: any, _super: any) {
_super.apply(this, arguments);
var that = this;
switch (msg.type) {
case "before-attach":
Expand All @@ -921,10 +921,6 @@ export class FigureView extends DOMWidgetView {
xaxis: axisHidden,
yaxis: axisHidden,
});

window.addEventListener("resize", function () {
that.autosizeFigure();
});
break;
case "after-attach":
// Rendering actual figure in the after-attach event allows
Expand All @@ -938,6 +934,21 @@ export class FigureView extends DOMWidgetView {
}
}

processPhosphorMessage(msg: any) {
this._processLuminoMessage(msg, super["processPhosphorMessage"]);

var that = this;
if (msg.type === "before-attach") {
window.addEventListener("resize", function () {
that.autosizeFigure();
});
}
}

processLuminoMessage(msg: any) {
this._processLuminoMessage(msg, super["processLuminoMessage"]);
}

autosizeFigure() {
var that = this;
var layout = that.model.get("_layout");
Expand Down

0 comments on commit 6ee61a4

Please sign in to comment.