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