4 <title>interaction model
</title>
6 <script type=
"text/javascript" src=
"../excanvas.js"></script>
8 <script type=
"text/javascript" src=
"../strftime/strftime-min.js"></script>
9 <script type=
"text/javascript" src=
"../rgbcolor/rgbcolor.js"></script>
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>
17 <b>Default interaction model
</b>
18 <div id=
"div_g" style=
"width:600px; height:300px;"></div>
19 </td><td>Zoom: click-drag
<br/>Pan: shift-click-drag
<br/>Restore zoom level: double-click
<br/>
22 <b>No interaction model
</b>
23 <div id=
"div_g2" style=
"width:600px; height:300px;"></div>
24 </td><td>Click and drag all you like, it won't do anything!
</td></tr>
26 <b>Custom interaction model
</b>
28 <input type=
"button" value=
"Unzoom" onclick=
"unzoomGraph(g3)">
29 <div id=
"div_g3" style=
"width:600px; height:300px;"></div>
31 Zoom in: double-click, scroll wheel
<br/>
32 Zoom out: ctrl-double-click, scroll wheel
<br/>
34 Restore zoom level: press button
<br/>
38 <div id=
"div_g4" style=
"width:600px; height:300px;"></div>
40 Keep the mouse button pressed, and hover over all points
46 <script type=
"text/javascript">
47 function downV3(event, g, context) {
48 context.initializeMouseDown(event, g, context);
49 Dygraph.startPan(event, g, context);
52 function moveV3(event, g, context) {
53 if (context.isPanning) {
54 Dygraph.movePan(event, g, context);
58 function upV3(event, g, context) {
59 if (context.isPanning) {
60 Dygraph.endPan(event, g, context);
64 function dblClickV3(event, g, context) {
72 function scrollV3(event, g, context) {
73 var normal = event.detail ? event.detail * -
1 : event.wheelDelta /
40;
74 // For me the normalized value shows
0.075 for one click. If I took
75 // that verbatim, it would be a
7.5%. I think I'm gonna take
1/
10 of that.
76 // (double for left and right side)
77 var percentage = normal /
100;
80 Dygraph.cancelEvent(event);
83 function zoom(g, percentage) {
84 // Adjusts [x, y] toward each other by percentage%
85 function adjustAxis(axis, percentage) {
86 var delta = axis[
1] - axis[
0];
87 var increment = delta * percentage;
88 return [ axis[
0] + increment, axis[
1] - increment ];
91 var yAxes = g.yAxisRanges();
93 for (var i =
0; i < yAxes.length; i++) {
94 newYAxes[i] = adjustAxis(yAxes[i], percentage);
98 dateWindow: adjustAxis(g.xAxisRange(), percentage),
99 valueRange: newYAxes[
0]
103 var v4Active = false;
106 function downV4(event, g, context) {
107 context.initializeMouseDown(event, g, context);
109 moveV4(event, g, context); // in case the mouse went down on a data point.
114 function moveV4(event, g, context) {
118 var canvasx = Dygraph.pageX(event) - Dygraph.findPosX(g.graphDiv);
119 var canvasy = Dygraph.pageY(event) - Dygraph.findPosY(g.graphDiv);
121 var rows = g.numRows();
123 // [date, [val1, stdev1], [val2, stdev2]]
124 for (var row =
0; row < rows; row++) {
125 var date = g.getValue(row,
0);
126 var x = g.toDomCoords(date, null)[
0];
127 var diff = Math.abs(canvasx - x);
129 for (var col =
1; col <
3; col++) {
130 // TODO(konigsberg): these will throw exceptions as data is removed.
131 var vals = g.getValue(row, col);
132 if (vals == null) { continue; }
134 var y = g.toDomCoords(null, val)[
1];
135 var diff2 = Math.abs(canvasy - y);
138 for (var i in processed) {
139 var stored = processed[i];
140 if(stored[
0] == row && stored[
1] == col) {
146 processed.push([row, col]);
152 // drawV4(false, canvasx, canvasy);
155 // drawV4(false, canvasx, canvasy);
159 function upV4(event, g, context) {
165 function dblClickV4(event, g, context) {
169 function drawV4(x, y) {
172 ctx.strokeStyle =
"#000000";
173 ctx.fillStyle =
"#FFFF00";
175 ctx.arc(x,y,
5,
0,Math.PI*
2,true);
181 function captureCanvas(canvas, area, g) {
185 var g = new Dygraph(document.getElementById(
"div_g"),
186 NoisyData, { errorBars : true });
187 var g2 = new Dygraph(document.getElementById(
"div_g2"),
188 NoisyData, { errorBars : true, interactionModel : {} });
189 var g3 = new Dygraph(document.getElementById(
"div_g3"),
190 NoisyData, { errorBars : true, interactionModel : {
191 'mousedown' : downV3,
192 'mousemove' : moveV3,
194 'dblclick' : dblClickV3,
195 'mousewheel' : scrollV3
197 var g4 = new Dygraph(document.getElementById(
"div_g4"),
198 NoisyData, { errorBars : true, drawPoints : true, interactionModel : {
199 'mousedown' : downV4,
200 'mousemove' : moveV4,
202 'dblclick' : dblClickV4,
204 underlayCallback : captureCanvas
207 function unzoomGraph(g) {