@@ -133,6 +133,7 @@ var MPLCanvasView = widgets.DOMWidgetView.extend({
133
133
134
134
canvas_div . addEventListener ( 'keydown' , this . key_event ( 'key_press' ) ) ;
135
135
canvas_div . addEventListener ( 'keyup' , this . key_event ( 'key_release' ) ) ;
136
+
136
137
// this is important to make the div 'focusable'
137
138
canvas_div . setAttribute ( 'tabindex' , 0 ) ;
138
139
this . figure . appendChild ( canvas_div ) ;
@@ -166,6 +167,8 @@ var MPLCanvasView = widgets.DOMWidgetView.extend({
166
167
rubberband_canvas . addEventListener ( 'mouseenter' , this . mouse_event ( 'figure_enter' ) ) ;
167
168
rubberband_canvas . addEventListener ( 'mouseleave' , this . mouse_event ( 'figure_leave' ) ) ;
168
169
170
+ rubberband_canvas . addEventListener ( 'wheel' , this . mouse_event ( 'scroll' ) ) ;
171
+
169
172
canvas_div . appendChild ( canvas ) ;
170
173
canvas_div . appendChild ( rubberband_canvas ) ;
171
174
@@ -366,8 +369,16 @@ var MPLCanvasView = widgets.DOMWidgetView.extend({
366
369
return function ( event ) {
367
370
var canvas_pos = utils . get_mouse_position ( event ) ;
368
371
369
- if ( name === 'button_press' )
370
- {
372
+ if ( name === 'scroll' ) {
373
+ event [ 'data' ] = 'scroll'
374
+ if ( event . deltaY < 0 ) {
375
+ event . step = 1 ;
376
+ } else {
377
+ event . step = - 1 ;
378
+ }
379
+ }
380
+
381
+ if ( name === 'button_press' ) {
371
382
that . canvas . focus ( ) ;
372
383
that . canvas_div . focus ( ) ;
373
384
}
@@ -395,15 +406,15 @@ var MPLCanvasView = widgets.DOMWidgetView.extend({
395
406
event . preventDefault ( ) ;
396
407
397
408
// Prevent repeat events
398
- if ( name == 'key_press' )
399
- {
409
+ if ( name == 'key_press' ) {
400
410
if ( event . which === that . _key )
401
411
return ;
402
412
else
403
413
that . _key = event . which ;
404
414
}
405
- if ( name == 'key_release' )
415
+ if ( name == 'key_release' ) {
406
416
that . _key = null ;
417
+ }
407
418
408
419
var value = '' ;
409
420
if ( event . ctrlKey && event . which != 17 )
0 commit comments