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