Merge branch 'master' of github.com:danvk/dygraphs
[dygraphs.git] / gallery / interaction.js
CommitLineData
abfadf4c
RK
1Gallery.register(
2 'interaction',
3 {
4 name: 'Custom interaction models',
5 title: 'title',
6 setup: function(parent) {
605b6119 7 parent.innerHTML = [
2a3953eb 8 "<h3>Default interaction model</h3>",
3e81f5dd
RK
9 "<div style='width:600px;'>",
10 " <p style='text-align:center;'>",
11 " Zoom: click-drag, Pan: shift-click-drag, Restore: double-click",
12 " </p>",
13 " <div id='div_g' style='width:600px; height:300px;'></div>",
14 "</div>",
15 "",
2a3953eb 16 "<h3>Empty interaction model</h3>",
3e81f5dd
RK
17 "<div style='width:600px;'>",
18 " <p style='text-align:center;'>",
19 " Click and drag all you like, it won't do anything!",
20 " </p>",
21 " <div id='div_g2' style='width:600px; height:300px;'></div>",
22 "</div>",
23 "<div id='g2_console'></div>", // what is this?
24 "",
2a3953eb 25 "<h3>Custom interaction model</h3>",
3e81f5dd
RK
26 "<div style='width:600px;'>",
27 " <p style='text-align:center;'>",
28 " Zoom in: double-click, scroll wheel<br/>",
29 " Zoom out: ctrl-double-click, scroll wheel<br/>",
30 " Standard Zoom: shift-click-drag",
31 " Standard Pan: click-drag<br/>",
32 " Restore zoom level: press button<br/>",
33 " </p>",
34 " <button id='restore3'>Restore position</button>",
35 " <div id='div_g3' style='width:600px; height:300px;'></div>",
36 "</div>",
2a3953eb 37 "<h3>Fun model!</h3>",
3e81f5dd
RK
38 "<div style='width:600px;'>",
39 " <p style='text-align:center;'>",
40 " Keep the mouse button pressed, and hover over all points",
41 " to mark them.",
42 " </p>",
43 " <div id='div_g4' style='width:600px; height:300px;'></div>",
e1e80cce 44 "</div>"
3e81f5dd 45 ].join('\n');
abfadf4c
RK
46
47 },
48 run: function() {
49 // TODO(konigsberg): Add cleanup to remove callbacks.
50 Dygraph.addEvent(document, "mousewheel", function() { lastClickedGraph = null; });
51 Dygraph.addEvent(document, "click", function() { lastClickedGraph = null; });
52 var g = new Dygraph(document.getElementById("div_g"),
53 NoisyData, { errorBars : true });
54 var s = document.getElementById("g2_console");
55 var g2 = new Dygraph(document.getElementById("div_g2"),
56 NoisyData,
57 {
58 errorBars : true,
59 interactionModel: {}
60 });
61 var g3 = new Dygraph(document.getElementById("div_g3"),
62 NoisyData, { errorBars : true, interactionModel : {
63 'mousedown' : downV3,
64 'mousemove' : moveV3,
65 'mouseup' : upV3,
66 'click' : clickV3,
67 'dblclick' : dblClickV3,
68 'mousewheel' : scrollV3
69 }});
70 document.getElementById("restore3").onclick = function() {
71 restorePositioning(g3);
e1e80cce 72 };
abfadf4c 73 var g4 = new Dygraph(document.getElementById("div_g4"),
e1e80cce
DV
74 NoisyData, {
75 errorBars : true,
76 drawPoints : true,
77 interactionModel : {
78 'mousedown' : downV4,
79 'mousemove' : moveV4,
80 'mouseup' : upV4,
81 'dblclick' : dblClickV4
82 },
83 underlayCallback : captureCanvas
84 });
c1f22b5a 85 }
c1f22b5a 86 });