[perf-web] Support double-clicking to zoom in



commit 8a5c4a553b87ef3399415b00073a21a59c271af1
Author: Owen W. Taylor <otaylor fishsoup net>
Date:   Sun Sep 14 15:51:30 2014 -0400

    Support double-clicking to zoom in
    
    Double clicking zooms in around the double click point.

 static/main.js |   28 ++++++++++++++++++++++++++++
 1 files changed, 28 insertions(+), 0 deletions(-)
---
diff --git a/static/main.js b/static/main.js
index b50011d..6cfe2d6 100644
--- a/static/main.js
+++ b/static/main.js
@@ -93,12 +93,40 @@ function Chart(svg) {
 
     this.top = 10;
     this.bottom = 10;
+
+    svg.addEventListener("dblclick", function(event) {
+        var rangeType;
+        switch (theDisplay.rangeType) {
+        case 'day':
+            return;
+        case 'week':
+            rangeType = 'day';
+            break;
+        case 'month':
+            rangeType = 'week';
+            break;
+        case 'year':
+            rangeType = 'month';
+            break;
+        }
+
+        var offset = $( this.body ).offset();
+        var x = event.pageX - offset.left;
+        var centerTime = this.time(x);
+
+        theDisplay.setPositionAndRange(centerTime, rangeType, false);
+        theDisplay.updateElementsForRange();
+    }.bind(this));
 }
 
 Chart.prototype.x = function(time) {
     return this.bodyWidth * (time - theDisplay.startSeconds) / theDisplay.rangeSeconds;
 }
 
+Chart.prototype.time = function(x) {
+    return theDisplay.startSeconds + (x / this.bodyWidth) * theDisplay.rangeSeconds;
+}
+
 Chart.prototype.y = function(value) {
     return this.bodyHeight * (1 - (value - this.bottom) / (this.top - this.bottom));
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]