@@ -325,7 +325,6 @@ mpl.figure.prototype._init_canvas = function () {
325325 canvas_div . appendChild ( rubberband_canvas ) ;
326326
327327 this . rubberband_context = rubberband_canvas . getContext ( '2d' ) ;
328- this . rubberband_context . strokeStyle = '#000000' ;
329328
330329 this . _resize_canvas = function ( width , height , forward ) {
331330 if ( forward ) {
@@ -469,19 +468,38 @@ mpl.figure.prototype.handle_rubberband = function (fig, msg) {
469468 y0 = Math . floor ( y0 ) + 0.5 ;
470469 x1 = Math . floor ( x1 ) + 0.5 ;
471470 y1 = Math . floor ( y1 ) + 0.5 ;
472- var min_x = Math . min ( x0 , x1 ) ;
473- var min_y = Math . min ( y0 , y1 ) ;
474- var width = Math . abs ( x1 - x0 ) ;
475- var height = Math . abs ( y1 - y0 ) ;
476471
477- fig . rubberband_context . clearRect (
472+ var ctx = fig . rubberband_context ;
473+ ctx . clearRect (
478474 0 ,
479475 0 ,
480476 fig . canvas . width / fig . ratio ,
481477 fig . canvas . height / fig . ratio
482478 ) ;
483479
484- fig . rubberband_context . strokeRect ( min_x , min_y , width , height ) ;
480+ var drawRubberband = function ( ) {
481+ // Draw the lines from x0, y0 towards x1, y1 so that the
482+ // dashes don't "jump" when moving the zoom box.
483+ ctx . beginPath ( ) ;
484+ ctx . moveTo ( x0 , y0 ) ;
485+ ctx . lineTo ( x0 , y1 ) ;
486+ ctx . moveTo ( x0 , y0 ) ;
487+ ctx . lineTo ( x1 , y0 ) ;
488+ ctx . moveTo ( x0 , y1 ) ;
489+ ctx . lineTo ( x1 , y1 ) ;
490+ ctx . moveTo ( x1 , y0 ) ;
491+ ctx . lineTo ( x1 , y1 ) ;
492+ ctx . stroke ( ) ;
493+ } ;
494+
495+ fig . rubberband_context . lineWidth = 1 ;
496+ fig . rubberband_context . setLineDash ( [ 3 ] ) ;
497+ fig . rubberband_context . lineDashOffset = 0 ;
498+ fig . rubberband_context . strokeStyle = '#000000' ;
499+ drawRubberband ( ) ;
500+ fig . rubberband_context . strokeStyle = '#ffffff' ;
501+ fig . rubberband_context . lineDashOffset = 3 ;
502+ drawRubberband ( ) ;
485503} ;
486504
487505mpl . figure . prototype . handle_figure_label = function ( fig , msg ) {
0 commit comments