From 9f468a5c695ff618c01359d5d37d07f73ed6ff9d Mon Sep 17 00:00:00 2001 From: Petr Shevtsov Date: Thu, 23 Apr 2015 23:51:11 +0600 Subject: [PATCH] Move to the proper directory --- extras/crosshair.js | 87 ------------------------------------------------- src/extras/crosshair.js | 87 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 87 insertions(+), 87 deletions(-) delete mode 100644 extras/crosshair.js create mode 100644 src/extras/crosshair.js diff --git a/extras/crosshair.js b/extras/crosshair.js deleted file mode 100644 index 0df61d4..0000000 --- a/extras/crosshair.js +++ /dev/null @@ -1,87 +0,0 @@ -/** - * @license - * Copyright 2015 Petr Shevtsov (petr.shevtsov@gmail.com) - * MIT-licensed (http://opensource.org/licenses/MIT) - */ - -/*global Dygraph:false */ -/*jshint globalstrict: true */ -Dygraph.Plugins.Crosshair = (function() { - "use strict"; - - /** - * Creates the crosshair - * - * @constructor - */ - - var crosshair = function(opt_options) { - this.canvas_ = document.createElement("canvas"); - opt_options = opt_options || {}; - this.direction_ = opt_options.direction || null; - }; - - crosshair.prototype.toString = function() { - return "Crosshair Plugin"; - }; - - /** - * @param {Dygraph} g Graph instance. - * @return {object.} Mapping of event names to callbacks. - */ - crosshair.prototype.activate = function(g) { - g.graphDiv.appendChild(this.canvas_); - - return { - select: this.select, - deselect: this.deselect - }; - }; - - crosshair.prototype.select = function(e) { - if (this.direction_ === null) { - return; - } - - 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 - - var ctx = this.canvas_.getContext("2d"); - ctx.clearRect(0, 0, width, height); - ctx.strokeStyle = "rgba(0, 0, 0,0.3)"; - ctx.beginPath(); - - var canvasx = Math.floor(e.dygraph.selPoints_[0].canvasx) + 0.5; // crisper rendering - - if (this.direction_ === "vertical" || this.direction_ === "both") { - ctx.moveTo(canvasx, 0); - ctx.lineTo(canvasx, height); - } - - if (this.direction_ === "horizontal" || this.direction_ === "both") { - for (var i = 0; i < e.dygraph.selPoints_.length; i++) { - var canvasy = Math.floor(e.dygraph.selPoints_[i].canvasy) + 0.5; // crisper rendering - ctx.moveTo(0, canvasy); - ctx.lineTo(width, canvasy); - } - } - - ctx.stroke(); - ctx.closePath(); - }; - - crosshair.prototype.deselect = function(e) { - var ctx = this.canvas_.getContext("2d"); - ctx.clearRect(0, 0, this.canvas_.width, this.canvas_.height); - }; - - crosshair.prototype.destroy = function() { - this.canvas_ = null; - }; - - return crosshair; -})(); diff --git a/src/extras/crosshair.js b/src/extras/crosshair.js new file mode 100644 index 0000000..0df61d4 --- /dev/null +++ b/src/extras/crosshair.js @@ -0,0 +1,87 @@ +/** + * @license + * Copyright 2015 Petr Shevtsov (petr.shevtsov@gmail.com) + * MIT-licensed (http://opensource.org/licenses/MIT) + */ + +/*global Dygraph:false */ +/*jshint globalstrict: true */ +Dygraph.Plugins.Crosshair = (function() { + "use strict"; + + /** + * Creates the crosshair + * + * @constructor + */ + + var crosshair = function(opt_options) { + this.canvas_ = document.createElement("canvas"); + opt_options = opt_options || {}; + this.direction_ = opt_options.direction || null; + }; + + crosshair.prototype.toString = function() { + return "Crosshair Plugin"; + }; + + /** + * @param {Dygraph} g Graph instance. + * @return {object.} Mapping of event names to callbacks. + */ + crosshair.prototype.activate = function(g) { + g.graphDiv.appendChild(this.canvas_); + + return { + select: this.select, + deselect: this.deselect + }; + }; + + crosshair.prototype.select = function(e) { + if (this.direction_ === null) { + return; + } + + 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 + + var ctx = this.canvas_.getContext("2d"); + ctx.clearRect(0, 0, width, height); + ctx.strokeStyle = "rgba(0, 0, 0,0.3)"; + ctx.beginPath(); + + var canvasx = Math.floor(e.dygraph.selPoints_[0].canvasx) + 0.5; // crisper rendering + + if (this.direction_ === "vertical" || this.direction_ === "both") { + ctx.moveTo(canvasx, 0); + ctx.lineTo(canvasx, height); + } + + if (this.direction_ === "horizontal" || this.direction_ === "both") { + for (var i = 0; i < e.dygraph.selPoints_.length; i++) { + var canvasy = Math.floor(e.dygraph.selPoints_[i].canvasy) + 0.5; // crisper rendering + ctx.moveTo(0, canvasy); + ctx.lineTo(width, canvasy); + } + } + + ctx.stroke(); + ctx.closePath(); + }; + + crosshair.prototype.deselect = function(e) { + var ctx = this.canvas_.getContext("2d"); + ctx.clearRect(0, 0, this.canvas_.width, this.canvas_.height); + }; + + crosshair.prototype.destroy = function() { + this.canvas_ = null; + }; + + return crosshair; +})(); -- 2.7.4