4 <title>Custom underlay callback
</title>
6 For production (minified) code, use:
7 <script type=
"text/javascript" src=
"dygraph-combined.js"></script>
9 <script type=
"text/javascript" src=
"../dygraph-dev.js"></script>
11 <script type=
"text/javascript" src=
"data.js"></script>
14 <p>Should draw a three-colored background, split horizontally at y:
2.25, and
15 again on the top at x:
19Nov:
</p>
16 <div id=
"div_g" style=
"width:600px; height:300px;"></div>
18 <div id=
"status" style=
"width:100%; height:200px;"></div>
20 <script type=
"text/javascript">
21 s = document.getElementById(
"status");
24 document.getElementById(
"div_g"),
30 underlayCallback: function(canvas, area, g) {
31 // Selecting a date in the middle of the graph.
32 var splitDate = new Date(
"2006-11-19").getTime();
33 var coords = g.toDomCoords(splitDate,
2.25);
35 // splitX and splitY are the coordinates on the canvas for (
2006-
11-
19,
2.25).
36 var splitX = coords[
0];
37 var splitY = coords[
1];
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;
47 // fillRect(x, y, width, height)
48 // Top section: y = (
2.25, +Infinity)
49 // left: (x <
2006-
11-
19)
50 canvas.fillStyle = 'lightblue';
51 canvas.fillRect(area.x, area.y, leftSideWidth, topHeight);
53 // right: (x
> 2006-
11-
19)
54 canvas.fillStyle = 'orange';
55 canvas.fillRect(splitX, area.y, rightSideWidth, topHeight);
57 // Bottom section: y = (-Infinity,
2.25)
58 canvas.fillStyle = 'pink';
59 canvas.fillRect(area.x, splitY, area.w, bottomHeight);