@@ -135,6 +135,7 @@ var MPLCanvasView = widgets.DOMWidgetView.extend({
135
135
136
136
canvas_div . addEventListener ( 'keydown' , this . key_event ( 'key_press' ) ) ;
137
137
canvas_div . addEventListener ( 'keyup' , this . key_event ( 'key_release' ) ) ;
138
+
138
139
// this is important to make the div 'focusable'
139
140
canvas_div . setAttribute ( 'tabindex' , 0 ) ;
140
141
this . figure . appendChild ( canvas_div ) ;
@@ -170,6 +171,8 @@ var MPLCanvasView = widgets.DOMWidgetView.extend({
170
171
rubberband_canvas . addEventListener ( 'mouseenter' , this . mouse_event ( 'figure_enter' ) ) ;
171
172
rubberband_canvas . addEventListener ( 'mouseleave' , this . mouse_event ( 'figure_leave' ) ) ;
172
173
174
+ rubberband_canvas . addEventListener ( 'wheel' , this . mouse_event ( 'scroll' ) ) ;
175
+
173
176
canvas_div . appendChild ( canvas ) ;
174
177
canvas_div . appendChild ( rubberband_canvas ) ;
175
178
@@ -375,8 +378,16 @@ var MPLCanvasView = widgets.DOMWidgetView.extend({
375
378
return function ( event ) {
376
379
var canvas_pos = utils . get_mouse_position ( event ) ;
377
380
378
- if ( name === 'button_press' )
379
- {
381
+ if ( name === 'scroll' ) {
382
+ event [ 'data' ] = 'scroll'
383
+ if ( event . deltaY < 0 ) {
384
+ event . step = 1 ;
385
+ } else {
386
+ event . step = - 1 ;
387
+ }
388
+ }
389
+
390
+ if ( name === 'button_press' ) {
380
391
that . canvas . focus ( ) ;
381
392
that . canvas_div . focus ( ) ;
382
393
}
@@ -404,15 +415,15 @@ var MPLCanvasView = widgets.DOMWidgetView.extend({
404
415
event . preventDefault ( ) ;
405
416
406
417
// Prevent repeat events
407
- if ( name == 'key_press' )
408
- {
418
+ if ( name == 'key_press' ) {
409
419
if ( event . which === that . _key )
410
420
return ;
411
421
else
412
422
that . _key = event . which ;
413
423
}
414
- if ( name == 'key_release' )
424
+ if ( name == 'key_release' ) {
415
425
that . _key = null ;
426
+ }
416
427
417
428
var value = '' ;
418
429
if ( event . ctrlKey && event . which != 17 )
0 commit comments