Merge
[dygraphs.git] / tests / underlay-callback.html
CommitLineData
54425b14 1<!DOCTYPE html>
e7746234
EC
2<html>
3 <head>
10494b48 4 <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7; IE=EmulateIE9">
e7746234
EC
5 <title>Custom underlay callback</title>
6 <!--[if IE]>
a2b2c3a1 7 <script type="text/javascript" src="../excanvas.js"></script>
e7746234 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
e7746234
EC
15 <script type="text/javascript" src="data.js"></script>
16 </head>
17 <body>
c7371f01
RK
18 <p>Should draw a three-colored background, split horizontally at y:2.25, and
19 again on the top at x:19Nov:</p>
e7746234
EC
20 <div id="div_g" style="width:600px; height:300px;"></div>
21
22 <div id="status" style="width:100%; height:200px;"></div>
23
24 <script type="text/javascript">
25 s = document.getElementById("status");
26
27 g = new Dygraph(
28 document.getElementById("div_g"),
29 NoisyData, {
30 rollPeriod: 7,
31 showRoller: true,
32 errorBars: true,
33
04143109 34 underlayCallback: function(canvas, area, g) {
fdcf1ce4
RK
35 // Selecting a date in the middle of the graph.
36 var splitDate = new Date("2006-11-19").getTime();
5879c20d 37 var coords = g.toDomCoords(splitDate, 2.25);
04143109 38
5879c20d 39 // splitX and splitY are the coordinates on the canvas for (2006-11-19, 2.25).
fdcf1ce4
RK
40 var splitX = coords[0];
41 var splitY = coords[1];
42
5879c20d
RK
43 // The drawing area doesn't start at (0, 0), it starts at (area.x, area.y).
44 // That's why we subtract them from splitX and splitY. This gives us the
45 // actual distance from the upper-left hand corder of the graph itself.
46 var leftSideWidth = splitX - area.x;
47 var rightSideWidth = area.w - leftSideWidth;
48 var topHeight = splitY - area.y;
49 var bottomHeight = area.h - topHeight;
2fc82862 50
fdcf1ce4 51 // fillRect(x, y, width, height)
2fc82862 52 // Top section: y = (2.25, +Infinity)
5879c20d 53 // left: (x < 2006-11-19)
e7746234 54 canvas.fillStyle = 'lightblue';
5879c20d 55 canvas.fillRect(area.x, area.y, leftSideWidth, topHeight);
fdcf1ce4 56
5879c20d 57 // right: (x > 2006-11-19)
fdcf1ce4
RK
58 canvas.fillStyle = 'orange';
59 canvas.fillRect(splitX, area.y, rightSideWidth, topHeight);
60
61 // Bottom section: y = (-Infinity, 2.25)
62 canvas.fillStyle = 'pink';
63 canvas.fillRect(area.x, splitY, area.w, bottomHeight);
e7746234
EC
64 }
65 }
66 );
67 </script>
68 </body>
69</html>