@@ -33,6 +33,14 @@ Dygraph.Plugins.Crosshair = (function _extras_crosshair_closure() {
3333 this . strokeStyle_ = opt_options . strokeStyle || "rgba(0, 0, 0, 0.3)" ;
3434 } ;
3535
36+ crosshair . prototype . updateCanvasSize = function updateCanvasSize ( width , height ) {
37+ if ( width === this . canvas_ . width && height === this . canvas_ . height ) return ;
38+ this . canvas_ . width = width ;
39+ this . canvas_ . height = height ;
40+ this . canvas_ . style . width = width + 'px' ; // for IE
41+ this . canvas_ . style . height = height + 'px' ; // for IE
42+ } ;
43+
3644 crosshair . prototype . toString = function toString ( ) {
3745 return "Crosshair Plugin" ;
3846 } ;
@@ -42,6 +50,7 @@ Dygraph.Plugins.Crosshair = (function _extras_crosshair_closure() {
4250 * @return {object.<string, function(ev)> } Mapping of event names to callbacks.
4351 */
4452 crosshair . prototype . activate = function activate ( g ) {
53+ this . updateCanvasSize ( g . width_ , g . height_ ) ;
4554 g . graphDiv . appendChild ( this . canvas_ ) ;
4655
4756 return {
@@ -57,21 +66,20 @@ Dygraph.Plugins.Crosshair = (function _extras_crosshair_closure() {
5766
5867 var width = e . dygraph . width_ ;
5968 var height = e . dygraph . height_ ;
60- this . canvas_ . width = width ;
61- this . canvas_ . height = height ;
62- this . canvas_ . style . width = width + "px" ; // for IE
63- this . canvas_ . style . height = height + "px" ; // for IE
69+ this . updateCanvasSize ( width , height ) ;
6470
6571 var ctx = this . canvas_ . getContext ( "2d" ) ;
6672 ctx . clearRect ( 0 , 0 , width , height ) ;
6773 ctx . strokeStyle = this . strokeStyle_ ;
6874 ctx . beginPath ( ) ;
69-
70- var canvasx = Math . floor ( e . dygraph . selPoints_ [ 0 ] . canvasx ) + 0.5 ; // crisper rendering
71-
72- if ( this . direction_ === "vertical" || this . direction_ === "both" ) {
73- ctx . moveTo ( canvasx , 0 ) ;
74- ctx . lineTo ( canvasx , height ) ;
75+
76+ if ( e . dygraph . selPoints_ . length !== 0 ) {
77+ var canvasx = Math . floor ( e . dygraph . selPoints_ [ 0 ] . canvasx ) + 0.5 ; // crisper rendering
78+
79+ if ( this . direction_ === "vertical" || this . direction_ === "both" ) {
80+ ctx . moveTo ( canvasx , 0 ) ;
81+ ctx . lineTo ( canvasx , height ) ;
82+ }
7583 }
7684
7785 if ( this . direction_ === "horizontal" || this . direction_ === "both" ) {
0 commit comments