@@ -40,11 +40,12 @@ mpl.figure = function(figure_id, websocket, ondownload, parent_element) {
40
40
this . rubberband_context = undefined ;
41
41
this . format_dropdown = undefined ;
42
42
43
- this . focus_on_mousover = false ;
44
43
this . image_mode = 'full' ;
45
44
46
45
this . root = $ ( '<div/>' ) ;
46
+ this . _root_extra_style ( this . root )
47
47
this . root . attr ( 'style' , 'display: inline-block' ) ;
48
+
48
49
$ ( parent_element ) . append ( this . root ) ;
49
50
50
51
this . _init_header ( this ) ;
@@ -93,6 +94,15 @@ mpl.figure.prototype._init_header = function() {
93
94
this . header = titletext [ 0 ] ;
94
95
}
95
96
97
+ mpl . figure . prototype . _canvas_extra_style = function ( canvas_div ) {
98
+
99
+ }
100
+
101
+
102
+ mpl . figure . prototype . _root_extra_style = function ( canvas_div ) {
103
+
104
+ }
105
+
96
106
mpl . figure . prototype . _init_canvas = function ( ) {
97
107
var fig = this ;
98
108
@@ -101,17 +111,22 @@ mpl.figure.prototype._init_canvas = function() {
101
111
function ( event , ui ) { fig . request_resize ( ui . size . width , ui . size . height ) ; }
102
112
, 50 ) } ) ;
103
113
104
- canvas_div . attr ( 'style' , 'position: relative; clear: both;' ) ;
105
- this . root . append ( canvas_div ) ;
106
-
107
- var canvas = $ ( '<canvas/>' ) ;
108
- canvas . addClass ( 'mpl-canvas' ) ;
109
- canvas . attr ( 'style' , "left: 0; top: 0; z-index: 0;" )
114
+ canvas_div . attr ( 'style' , 'position: relative; clear: both; outline: 0' ) ;
110
115
111
116
function canvas_keyboard_event ( event ) {
112
117
return fig . key_event ( event , event [ 'data' ] ) ;
113
118
}
114
119
120
+ canvas_div . keydown ( 'key_press' , canvas_keyboard_event ) ;
121
+ canvas_div . keydown ( 'key_release' , canvas_keyboard_event ) ;
122
+ this . canvas_div = canvas_div
123
+ this . _canvas_extra_style ( canvas_div )
124
+ this . root . append ( canvas_div ) ;
125
+
126
+ var canvas = $ ( '<canvas/>' ) ;
127
+ canvas . addClass ( 'mpl-canvas' ) ;
128
+ canvas . attr ( 'style' , "left: 0; top: 0; z-index: 0; outline: 0" )
129
+
115
130
this . canvas = canvas [ 0 ] ;
116
131
this . context = canvas [ 0 ] . getContext ( "2d" ) ;
117
132
@@ -131,9 +146,6 @@ mpl.figure.prototype._init_canvas = function() {
131
146
canvas_div . append ( canvas ) ;
132
147
canvas_div . append ( rubberband ) ;
133
148
134
- canvas_div . keydown ( 'key_press' , canvas_keyboard_event ) ;
135
- canvas_div . keydown ( 'key_release' , canvas_keyboard_event ) ;
136
-
137
149
this . rubberband = rubberband ;
138
150
this . rubberband_canvas = rubberband [ 0 ] ;
139
151
this . rubberband_context = rubberband [ 0 ] . getContext ( "2d" ) ;
@@ -155,6 +167,13 @@ mpl.figure.prototype._init_canvas = function() {
155
167
// Set the figure to an initial 600x600px, this will subsequently be updated
156
168
// upon first draw.
157
169
this . _resize_canvas ( 600 , 600 ) ;
170
+
171
+ function set_focus ( ) {
172
+ canvas . focus ( ) ;
173
+ canvas_div . focus ( ) ;
174
+ }
175
+
176
+ window . setTimeout ( set_focus , 100 ) ;
158
177
}
159
178
160
179
mpl . figure . prototype . _init_toolbar = function ( ) {
@@ -172,7 +191,7 @@ mpl.figure.prototype._init_toolbar = function() {
172
191
return fig . toolbar_button_onmouseover ( event [ 'data' ] ) ;
173
192
}
174
193
175
- for ( var toolbar_ind in mpl . toolbar_items ) {
194
+ for ( var toolbar_ind in mpl . toolbar_items ) {
176
195
var name = mpl . toolbar_items [ toolbar_ind ] [ 0 ] ;
177
196
var tooltip = mpl . toolbar_items [ toolbar_ind ] [ 1 ] ;
178
197
var image = mpl . toolbar_items [ toolbar_ind ] [ 2 ] ;
@@ -397,9 +416,10 @@ mpl.findpos = function(e) {
397
416
mpl . figure . prototype . mouse_event = function ( event , name ) {
398
417
var canvas_pos = mpl . findpos ( event )
399
418
400
- if ( this . focus_on_mouseover && name === 'motion_notify ' )
419
+ if ( name === 'button_press ' )
401
420
{
402
421
this . canvas . focus ( ) ;
422
+ this . canvas_div . focus ( ) ;
403
423
}
404
424
405
425
var x = canvas_pos . x ;
@@ -422,7 +442,7 @@ mpl.figure.prototype.key_event = function(event, name) {
422
442
return ;
423
443
}
424
444
425
- value = '' ;
445
+ var value = '' ;
426
446
if ( event . ctrlKey ) {
427
447
value += "ctrl+" ;
428
448
}
@@ -432,6 +452,7 @@ mpl.figure.prototype.key_event = function(event, name) {
432
452
value += String . fromCharCode ( event . keyCode ) . toLowerCase ( ) ;
433
453
434
454
this . send_message ( name , { key : value } ) ;
455
+ return false ;
435
456
}
436
457
437
458
mpl . figure . prototype . toolbar_button_onclick = function ( name ) {
@@ -448,18 +469,18 @@ mpl.figure.prototype.toolbar_button_onmouseover = function(tooltip) {
448
469
this . message . textContent = tooltip ;
449
470
} ;
450
471
451
- mpl . debounce_event = function ( func , time ) {
472
+ mpl . debounce_event = function ( func , time ) {
452
473
var timer ;
453
- return function ( event ) {
474
+ return function ( event ) {
454
475
clearTimeout ( timer ) ;
455
- timer = setTimeout ( function ( ) { func ( event ) ; } , time ) ;
476
+ timer = setTimeout ( function ( ) { func ( event ) ; } , time ) ;
456
477
} ;
457
478
}
458
479
459
- mpl . debounce_resize = function ( func , time ) {
480
+ mpl . debounce_resize = function ( func , time ) {
460
481
var timer ;
461
- return function ( event , ui ) {
482
+ return function ( event , ui ) {
462
483
clearTimeout ( timer ) ;
463
- timer = setTimeout ( function ( ) { func ( event , ui ) ; } , time ) ;
484
+ timer = setTimeout ( function ( ) { func ( event , ui ) ; } , time ) ;
464
485
} ;
465
486
}
0 commit comments