File: callback.html

package info (click to toggle)
dygraphs 2.2.1-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 4,340 kB
  • sloc: javascript: 24,842; sh: 800; python: 581; makefile: 45
file content (97 lines) | stat: -rw-r--r-- 3,303 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8">
    <title>callbacks</title>

    <link rel="stylesheet" type="text/css" href="../dist/dygraph.css" />
    <link rel="stylesheet" type="text/css" href="../common/vextlnk.css" />
    <script type="text/javascript" src="../dist/dygraph.js"></script>
    <script type="text/javascript" src="data.js"></script>

    <style type="text/css">
      #div_g {
        position: absolute;
        left: 200px;
        top: 100px;
      }
      #status {
        position: absolute;
        top: 400px;
      }
    </style>
  </head>
  <body>
    <p>Hover, click and zoom to test the callbacks:</p>
    <div id="div_g" style="width:600px; height:300px;"></div>

    <input type="button" value="Clear list" onclick="javascript:document.getElementById('status').innerHTML=''" />
    <input type="checkbox" id="highlight" checked><label for="highlight"> Show 'highlight' events</label>
    <input type="checkbox" id="unhighlight" checked><label for="unhighlight">Show 'unhighlight' events</label>
    <input type="checkbox" id="showLabels" checked
    onclick='g.updateOptions({showLabelsOnHighlight: this.checked});'>
    <label for="showLabels"> Show Labels on highlight</label>
    <div id="status" style="width:100%; height:200px;"></div>

    <script type="text/javascript"><!--//--><![CDATA[//><!--
    Dygraph.onDOMready(function onDOMready() {
      s = document.getElementById("status");
      g = null;
      pts_info = function(e, x, pts, row) {
        var str = "(" + x + ") ";
        for (var i = 0; i < pts.length; i++) {
          var p = pts[i];
          if (i) str += ", ";
          str += p.name + ": " + p.yval;
        }

        var x = e.offsetX;
        var y = e.offsetY;
        var dataXY = g.toDataCoords(x, y);
        str += ", (" + x + ", " + y + ")";
        str += " -> (" + dataXY[0] + ", " + dataXY[1] + ")";
        str += ", row #"+row;

        return str;
      };

      g = new Dygraph(
            document.getElementById("div_g"),
            NoisyData, {
              rollPeriod: 7,
              showRoller: true,
              errorBars: true,

              highlightCallback: function(e, x, pts, row) {
                if (document.getElementById('highlight').checked) {
                  s.innerHTML += "<b>Highlight</b> " + pts_info(e,x,pts,row) + "<br />";
                }
              },

              unhighlightCallback: function(e) {
                if (document.getElementById('unhighlight').checked) {
                  s.innerHTML += "<b>Unhighlight</b><br />";
                }
              },

              clickCallback: function(e, x, pts) {
                s.innerHTML += "<b>Click</b> " + pts_info(e,x,pts) + "<br />";
              },

              pointClickCallback: function(e, p) {
                s.innerHTML += "<b>Point Click</b> " + p.name + ": " + p.x + "<br />";
              },

              zoomCallback: function(minX, maxX, yRanges) {
                s.innerHTML += "<b>Zoom</b> [" + minX + ", " + maxX + ", [" + yRanges + "]]<br />";
              },

              drawCallback: function(g) {
                s.innerHTML += "<b>Draw</b> [" + g.xAxisRange() + "]<br />";
              }
            }
          );
    });
    //--><!]]></script>
  </body>
</html>