Skip to content

Commit

Permalink
Merge pull request #1038 from n-gist/crosshair-initial-canvas-size
Browse files Browse the repository at this point in the history
Crosshair plugin - initial canvas size fix
  • Loading branch information
mirabilos authored Jan 11, 2025
2 parents 09252ae + 48472f0 commit cc74acf
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/extras/crosshair.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ Dygraph.Plugins.Crosshair = (function _extras_crosshair_closure() {
this.strokeStyle_ = opt_options.strokeStyle || "rgba(0, 0, 0, 0.3)";
};

crosshair.prototype.updateCanvasSize = function updateCanvasSize(width, height) {
if (width === this.canvas_.width && height === this.canvas_.height) return;
this.canvas_.width = width;
this.canvas_.height = height;
this.canvas_.style.width = width + 'px'; // for IE
this.canvas_.style.height = height + 'px'; // for IE
};

crosshair.prototype.toString = function toString() {
return "Crosshair Plugin";
};
Expand All @@ -42,6 +50,7 @@ Dygraph.Plugins.Crosshair = (function _extras_crosshair_closure() {
* @return {object.<string, function(ev)>} Mapping of event names to callbacks.
*/
crosshair.prototype.activate = function activate(g) {
this.updateCanvasSize(g.width_, g.height_);
g.graphDiv.appendChild(this.canvas_);

return {
Expand All @@ -57,10 +66,7 @@ Dygraph.Plugins.Crosshair = (function _extras_crosshair_closure() {

var width = e.dygraph.width_;
var height = e.dygraph.height_;
this.canvas_.width = width;
this.canvas_.height = height;
this.canvas_.style.width = width + "px"; // for IE
this.canvas_.style.height = height + "px"; // for IE
this.updateCanvasSize(width, height);

var ctx = this.canvas_.getContext("2d");
ctx.clearRect(0, 0, width, height);
Expand Down

0 comments on commit cc74acf

Please sign in to comment.