Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions examples/ipympl.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,15 @@
"fig.canvas.footer_visible = False"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"fig.canvas.resizable = False"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand Down
2 changes: 2 additions & 0 deletions ipympl/backend_nbagg.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ class Canvas(DOMWidget, FigureCanvasWebAggCore):
header_visible = Bool(True).tag(sync=True)
footer_visible = Bool(True).tag(sync=True)

resizable = Bool(True).tag(sync=True)

_width = CInt().tag(sync=True)
_height = CInt().tag(sync=True)

Expand Down
43 changes: 26 additions & 17 deletions js/src/mpl_widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class MPLCanvasModel extends widgets.DOMWidgetModel {
toolbar: null,
toolbar_visible: true,
toolbar_position: 'horizontal',
resizable: true,
_width: 0,
_height: 0,
_figure_label: 'Figure',
Expand Down Expand Up @@ -51,6 +52,11 @@ class MPLCanvasModel extends widgets.DOMWidgetModel {
this._init_image();

this.on('msg:custom', this.on_comm_message.bind(this));
this.on('change:resizable', () => {
this._for_each_view(function(view) {
view.update_canvas();
})
});

this.send_initialization_message();
}
Expand Down Expand Up @@ -421,26 +427,28 @@ class MPLCanvasView extends widgets.DOMWidgetView {
}

// Draw resize handle
this.top_context.save();
if (this.model.get('resizable')) {
this.top_context.save();

var gradient = this.top_context.createLinearGradient(
this.top_canvas.width - this.resize_handle_size / 3, this.top_canvas.height - this.resize_handle_size / 3,
this.top_canvas.width - this.resize_handle_size / 4, this.top_canvas.height - this.resize_handle_size / 4
);
gradient.addColorStop(0, 'rgba(0, 0, 0, 0)');
gradient.addColorStop(1, 'rgba(0, 0, 0, 255)');
var gradient = this.top_context.createLinearGradient(
this.top_canvas.width - this.resize_handle_size / 3, this.top_canvas.height - this.resize_handle_size / 3,
this.top_canvas.width - this.resize_handle_size / 4, this.top_canvas.height - this.resize_handle_size / 4
);
gradient.addColorStop(0, 'rgba(0, 0, 0, 0)');
gradient.addColorStop(1, 'rgba(0, 0, 0, 255)');

this.top_context.fillStyle = gradient;
this.top_context.fillStyle = gradient;

this.top_context.globalAlpha = 0.3;
this.top_context.beginPath();
this.top_context.moveTo(this.top_canvas.width, this.top_canvas.height);
this.top_context.lineTo(this.top_canvas.width, this.top_canvas.height - this.resize_handle_size);
this.top_context.lineTo(this.top_canvas.width - this.resize_handle_size, this.top_canvas.height);
this.top_context.closePath();
this.top_context.fill();
this.top_context.globalAlpha = 0.3;
this.top_context.beginPath();
this.top_context.moveTo(this.top_canvas.width, this.top_canvas.height);
this.top_context.lineTo(this.top_canvas.width, this.top_canvas.height - this.resize_handle_size);
this.top_context.lineTo(this.top_canvas.width - this.resize_handle_size, this.top_canvas.height);
this.top_context.closePath();
this.top_context.fill();

this.top_context.restore();
this.top_context.restore();
}
}

_update_cursor() {
Expand Down Expand Up @@ -492,7 +500,8 @@ class MPLCanvasView extends widgets.DOMWidgetView {
if (name === 'button_press') {
// If clicking on the resize handle
if (canvas_pos.x >= this.top_canvas.width - this.resize_handle_size &&
canvas_pos.y >= this.top_canvas.height - this.resize_handle_size) {
canvas_pos.y >= this.top_canvas.height - this.resize_handle_size &&
this.model.get('resizable')) {
this.resizing = true;
return;
} else {
Expand Down