Skip to content

Commit

Permalink
Merge pull request #235 from ianhi/capture-scroll
Browse files Browse the repository at this point in the history
Add option to preventDefault on scroll event
  • Loading branch information
martinRenou authored Jun 18, 2020
2 parents 7dabbff + c0c1004 commit 6b44a6f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
9 changes: 9 additions & 0 deletions examples/ipympl.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,15 @@
"fig.canvas.resizable = False"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"fig.canvas.capture_scroll = True"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand Down
1 change: 1 addition & 0 deletions ipympl/backend_nbagg.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ class Canvas(DOMWidget, FigureCanvasWebAggCore):
footer_visible = Bool(True).tag(sync=True)

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

_width = CInt().tag(sync=True)
_height = CInt().tag(sync=True)
Expand Down
4 changes: 4 additions & 0 deletions js/src/mpl_widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export class MPLCanvasModel extends widgets.DOMWidgetModel {
toolbar_visible: true,
toolbar_position: 'horizontal',
resizable: true,
capture_scroll: false,
_width: 0,
_height: 0,
_figure_label: 'Figure',
Expand Down Expand Up @@ -565,6 +566,9 @@ export class MPLCanvasView extends widgets.DOMWidgetView {
} else {
event.step = -1;
}
if (this.model.get('capture_scroll')) {
event.preventDefault();
}
}

if (name === 'button_press') {
Expand Down

0 comments on commit 6b44a6f

Please sign in to comment.