add another underlay callback parameter, plus a nicer demo
authorDan Vanderkam <danvk@google.com>
Tue, 13 Apr 2010 21:40:12 +0000 (14:40 -0700)
committerDan Vanderkam <danvk@google.com>
Tue, 13 Apr 2010 21:40:12 +0000 (14:40 -0700)
dygraph-canvas.js
tests/highlighted-region.html [new file with mode: 0644]

index 2c18345..b83e54a 100644 (file)
@@ -279,7 +279,7 @@ DygraphCanvasRenderer.prototype.render = function() {
   var ctx = this.element.getContext("2d");
 
   if (this.options.underlayCallback) {
-    this.options.underlayCallback(ctx, this.area, this.layout);
+    this.options.underlayCallback(ctx, this.area, this.layout, this.dygraph_);
   }
 
   if (this.options.drawYGrid) {
diff --git a/tests/highlighted-region.html b/tests/highlighted-region.html
new file mode 100644 (file)
index 0000000..48d803e
--- /dev/null
@@ -0,0 +1,55 @@
+<html>
+  <head>
+    <title>Highlighted Region</title>
+    <!--[if IE]>
+    <script type="text/javascript" src="excanvas.js"></script>
+    <![endif]-->
+    <script type="text/javascript" src="../strftime/strftime-min.js"></script>
+    <script type="text/javascript" src="../rgbcolor/rgbcolor.js"></script>
+    <script type="text/javascript" src="../dygraph-canvas.js"></script>
+    <script type="text/javascript" src="../dygraph.js"></script>
+    <script type="text/javascript" src="data.js"></script>
+  </head>
+  <body>
+    <p>Should draw a time series with an unusual region highlighted:</p>
+    <div id="div_g" style="width:600px; height:300px;"></div>
+
+    <p>When you zoom/pan, the region should remain highlighted.</p>
+
+    <script type="text/javascript">
+      // A basic sinusoidal data series.
+      var data = [];
+      for (var i = 0; i < 1000; i++) {
+        var base = 10 * Math.sin(i / 90.0);
+        data.push([i, base, base + Math.sin(i / 2.0)]);
+      }
+
+      // Shift one portion out of line.
+      var highlight_start = 450;
+      var highlight_end = 500;
+      for (var i = highlight_start; i <= highlight_end; i++) {
+        data[i][2] += 5.0;
+      }
+
+
+      new Dygraph(
+          document.getElementById("div_g"),
+          data,
+          {
+            labels: ['X', 'Est.', 'Actual'],
+            underlayCallback: function(canvas, area, layout, g) {
+              var bottom_left = g.toDomCoords(highlight_start, -20);
+              var top_right = g.toDomCoords(highlight_end, +20);
+
+              var left = bottom_left[0];
+              var right = top_right[0];
+
+              canvas.fillStyle = "rgba(255, 255, 102, 0.5)";
+              canvas.fillRect(left, area.y, right - left, area.h);
+            }
+
+          }
+      );
+    </script>
+  </body>
+</html>