Skip to content

Commit 27567cb

Browse files
committed
Call newPlot on phosphorjs's 'after-attach' event.
This way the plot defaults to the full width of the notebook output cell
1 parent 2827283 commit 27567cb

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

js/src/Figure.js

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -712,12 +712,13 @@ var FigureModel = widgets.DOMWidgetModel.extend({
712712
var FigureView = widgets.DOMWidgetView.extend({
713713

714714
/**
715-
* The render method is called when a view is first displayed to a
716-
* notebook output cell. This happens after the initialize of the
715+
* The perform_render method is called by processPhosphorMessage
716+
* after the widget's DOM element has been attached to the notebook
717+
* output cell. This happens after the initialize of the
717718
* FigureModel, and it won't happen at all if the Python FigureWidget
718719
* is never displayed in a notebook output cell
719720
*/
720-
render: function() {
721+
perform_render: function() {
721722

722723
var that = this;
723724

@@ -809,6 +810,19 @@ var FigureView = widgets.DOMWidgetView.extend({
809810
});
810811
});
811812
},
813+
814+
/**
815+
* Respond to phosphorjs events
816+
*/
817+
processPhosphorMessage: function(msg) {
818+
FigureView.__super__.processPhosphorMessage.apply(this, arguments);
819+
switch (msg.type) {
820+
case 'after-attach':
821+
this.perform_render();
822+
break;
823+
}
824+
},
825+
812826
/**
813827
* Purge Plotly.js data structures from the notebook output display
814828
* element when the view is destroyed

0 commit comments

Comments
 (0)