Change no-series-defined behavior so that it computes the
[dygraphs.git] / tests / highlighted-region.html
CommitLineData
54425b14 1<!DOCTYPE html>
d9e6fa47
DV
2<html>
3 <head>
10494b48 4 <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7; IE=EmulateIE9">
d9e6fa47
DV
5 <title>Highlighted Region</title>
6 <!--[if IE]>
a2b2c3a1 7 <script type="text/javascript" src="../excanvas.js"></script>
d9e6fa47
DV
8 <![endif]-->
9 <script type="text/javascript" src="../strftime/strftime-min.js"></script>
10 <script type="text/javascript" src="../rgbcolor/rgbcolor.js"></script>
11 <script type="text/javascript" src="../dygraph-canvas.js"></script>
12 <script type="text/javascript" src="../dygraph.js"></script>
13 <script type="text/javascript" src="data.js"></script>
14 </head>
15 <body>
16 <p>Should draw a time series with an unusual region highlighted:</p>
17 <div id="div_g" style="width:600px; height:300px;"></div>
18
19 <p>When you zoom/pan, the region should remain highlighted.</p>
20
21 <script type="text/javascript">
22 // A basic sinusoidal data series.
23 var data = [];
24 for (var i = 0; i < 1000; i++) {
25 var base = 10 * Math.sin(i / 90.0);
26 data.push([i, base, base + Math.sin(i / 2.0)]);
27 }
28
29 // Shift one portion out of line.
30 var highlight_start = 450;
31 var highlight_end = 500;
32 for (var i = highlight_start; i <= highlight_end; i++) {
33 data[i][2] += 5.0;
34 }
35
36
37 new Dygraph(
38 document.getElementById("div_g"),
39 data,
40 {
41 labels: ['X', 'Est.', 'Actual'],
04143109 42 underlayCallback: function(canvas, area, g) {
d9e6fa47
DV
43 var bottom_left = g.toDomCoords(highlight_start, -20);
44 var top_right = g.toDomCoords(highlight_end, +20);
45
46 var left = bottom_left[0];
47 var right = top_right[0];
48
eb7bf005 49 canvas.fillStyle = "rgba(255, 255, 102, 1.0)";
d9e6fa47
DV
50 canvas.fillRect(left, area.y, right - left, area.h);
51 }
52
53 }
54 );
55 </script>
56 </body>
57</html>