Merge branch 'master' of https://github.com/kberg/dygraphs
[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 8 <![endif]-->
7e5ddc94
DV
9 <!--
10 For production (minified) code, use:
11 <script type="text/javascript" src="dygraph-combined.js"></script>
12 -->
13 <script type="text/javascript" src="../dygraph-dev.js"></script>
14
d9e6fa47
DV
15 <script type="text/javascript" src="data.js"></script>
16 </head>
17 <body>
18 <p>Should draw a time series with an unusual region highlighted:</p>
19 <div id="div_g" style="width:600px; height:300px;"></div>
20
21 <p>When you zoom/pan, the region should remain highlighted.</p>
22
23 <script type="text/javascript">
24 // A basic sinusoidal data series.
25 var data = [];
26 for (var i = 0; i < 1000; i++) {
27 var base = 10 * Math.sin(i / 90.0);
28 data.push([i, base, base + Math.sin(i / 2.0)]);
29 }
30
31 // Shift one portion out of line.
32 var highlight_start = 450;
33 var highlight_end = 500;
34 for (var i = highlight_start; i <= highlight_end; i++) {
35 data[i][2] += 5.0;
36 }
37
38
39 new Dygraph(
40 document.getElementById("div_g"),
41 data,
42 {
43 labels: ['X', 'Est.', 'Actual'],
04143109 44 underlayCallback: function(canvas, area, g) {
d9e6fa47
DV
45 var bottom_left = g.toDomCoords(highlight_start, -20);
46 var top_right = g.toDomCoords(highlight_end, +20);
47
48 var left = bottom_left[0];
49 var right = top_right[0];
50
eb7bf005 51 canvas.fillStyle = "rgba(255, 255, 102, 1.0)";
d9e6fa47
DV
52 canvas.fillRect(left, area.y, right - left, area.h);
53 }
54
55 }
56 );
57 </script>
58 </body>
59</html>