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