From bd029dfebd07ae4a6e188e8623cf99b228e5d577 Mon Sep 17 00:00:00 2001 From: Peter Chiocchetti Date: Sat, 13 Dec 2014 12:38:32 +0100 Subject: js/CGP: scroll wheel zoom center position Closes #111 --- js/CGP.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/js/CGP.js b/js/CGP.js index a83380f..5ed729b 100644 --- a/js/CGP.js +++ b/js/CGP.js @@ -44,8 +44,10 @@ var CGP = (function() { if (this.stidx < 0) this.stidx = 0; } if (cstime !== this.stime[this.stidx]) { - var middle = this.rrdgraph.start + Math.abs(Math.round((this.rrdgraph.end - this.rrdgraph.start) / 2)); - this.rrdgraph.start = Math.round(middle - this.stime[this.stidx] / 2); + var posx = e.clientX - e.target.getBoundingClientRect().left - this.rrdgraph.xorigin; + var relx = this.rrdgraph.xsize / Math.min(Math.max(posx, 0), this.rrdgraph.xsize); + var cntr = this.rrdgraph.start + Math.abs(Math.round((this.rrdgraph.end - this.rrdgraph.start) / relx)); + this.rrdgraph.start = Math.round(cntr - this.stime[this.stidx] / relx); this.rrdgraph.end = this.rrdgraph.start + this.stime[this.stidx]; try { -- cgit v1.1