2 function downV3(event
, g
, context
) {
3 context
.initializeMouseDown(event
, g
, context
);
4 if (event
.altKey
|| event
.shiftKey
) {
5 Dygraph
.startZoom(event
, g
, context
);
7 Dygraph
.startPan(event
, g
, context
);
11 function moveV3(event
, g
, context
) {
12 if (context
.isPanning
) {
13 Dygraph
.movePan(event
, g
, context
);
14 } else if (context
.isZooming
) {
15 Dygraph
.moveZoom(event
, g
, context
);
19 function upV3(event
, g
, context
) {
20 if (context
.isPanning
) {
21 Dygraph
.endPan(event
, g
, context
);
22 } else if (context
.isZooming
) {
23 Dygraph
.endZoom(event
, g
, context
);
27 // Take the offset of a mouse event on the dygraph canvas and
28 // convert it to a pair of percentages from the bottom left.
29 // (Not top left, bottom is where the lower value is.)
30 function offsetToPercentage(g
, offsetX
, offsetY
) {
31 // This is calculating the pixel offset of the leftmost date.
32 var xOffset
= g
.toDomCoords(g
.xAxisRange()[0], null)[0];
33 var yar0
= g
.yAxisRange(0);
35 // This is calculating the pixel of the higest value. (Top pixel)
36 var yOffset
= g
.toDomCoords(null, yar0
[1])[1];
38 // x y w and h are relative to the corner of the drawing area,
39 // so that the upper corner of the drawing area is (0, 0).
40 var x
= offsetX
- xOffset
;
41 var y
= offsetY
- yOffset
;
43 // This is computing the rightmost pixel, effectively defining the
45 var w
= g
.toDomCoords(g
.xAxisRange()[1], null)[0] - xOffset
;
47 // This is computing the lowest pixel, effectively defining the height.
48 var h
= g
.toDomCoords(null, yar0
[0])[1] - yOffset
;
50 // Percentage from the left.
51 var xPct
= w
== 0 ? 0 : (x
/ w
);
52 // Percentage from the top.
53 var yPct
= h
== 0 ? 0 : (y
/ h
);
55 // The (1-) part below changes it from "% distance down from the top"
56 // to "% distance up from the bottom".
57 return [xPct
, (1-yPct
)];
60 function dblClickV3(event
, g
, context
) {
61 // Reducing by 20% makes it 80% the original size, which means
62 // to restore to original size it must grow by 25%
63 var percentages
= offsetToPercentage(g
, event
.offsetX
, event
.offsetY
);
64 var xPct
= percentages
[0];
65 var yPct
= percentages
[1];
68 zoom(g
, -.25, xPct
, yPct
);
70 zoom(g
, +.2, xPct
, yPct
);
74 var lastClickedGraph
= null;
76 function clickV3(event
, g
, context
) {
78 Dygraph
.cancelEvent(event
);
81 function scrollV3(event
, g
, context
) {
82 if (lastClickedGraph
!= g
) {
85 var normal
= event
.detail
? event
.detail
* -1 : event
.wheelDelta
/ 40;
86 // For me the normalized value shows 0.075 for one click. If I took
87 // that verbatim, it would be a 7.5%.
88 var percentage
= normal
/ 50;
90 var percentages
= offsetToPercentage(g
, event
.offsetX
, event
.offsetY
);
91 var xPct
= percentages
[0];
92 var yPct
= percentages
[1];
94 zoom(g
, percentage
, xPct
, yPct
);
95 Dygraph
.cancelEvent(event
);
98 // Adjusts [x, y] toward each other by zoomInPercentage%
99 // Split it so the left/bottom axis gets xBias
/yBias of that change and
100 // tight/top
gets (1-xBias
)/(1-yBias
) of that change
.
102 // If a bias is missing it splits it down the middle.
103 function zoom(g
, zoomInPercentage
, xBias
, yBias
) {
104 xBias
= xBias
|| 0.5;
105 yBias
= yBias
|| 0.5;
106 function adjustAxis(axis
, zoomInPercentage
, bias
) {
107 var delta
= axis
[1] - axis
[0];
108 var increment
= delta
* zoomInPercentage
;
109 var foo
= [increment
* bias
, increment
* (1-bias
)];
110 return [ axis
[0] + foo
[0], axis
[1] - foo
[1] ];
112 var yAxes
= g
.yAxisRanges();
114 for (var i
= 0; i
< yAxes
.length
; i
++) {
115 newYAxes
[i
] = adjustAxis(yAxes
[i
], zoomInPercentage
, yBias
);
119 dateWindow
: adjustAxis(g
.xAxisRange(), zoomInPercentage
, xBias
),
120 valueRange
: newYAxes
[0]
124 var v4Active
= false;
127 function downV4(event
, g
, context
) {
128 context
.initializeMouseDown(event
, g
, context
);
130 moveV4(event
, g
, context
); // in case the mouse went down on a data point.
135 function moveV4(event
, g
, context
) {
139 var canvasx
= Dygraph
.pageX(event
) - Dygraph
.findPosX(g
.graphDiv
);
140 var canvasy
= Dygraph
.pageY(event
) - Dygraph
.findPosY(g
.graphDiv
);
142 var rows
= g
.numRows();
144 // [date, [val1, stdev1], [val2, stdev2]]
145 for (var row
= 0; row
< rows
; row
++) {
146 var date
= g
.getValue(row
, 0);
147 var x
= g
.toDomCoords(date
, null)[0];
148 var diff
= Math
.abs(canvasx
- x
);
150 for (var col
= 1; col
< 3; col
++) {
151 // TODO(konigsberg): these will throw exceptions as data is removed.
152 var vals
= g
.getValue(row
, col
);
153 if (vals
== null) { continue; }
155 var y
= g
.toDomCoords(null, val
)[1];
156 var diff2
= Math
.abs(canvasy
- y
);
159 for (var i
in processed
) {
160 var stored
= processed
[i
];
161 if(stored
[0] == row
&& stored
[1] == col
) {
167 processed
.push([row
, col
]);
178 function upV4(event
, g
, context
) {
184 function dblClickV4(event
, g
, context
) {
185 restorePositioning(g4
);
188 function drawV4(x
, y
) {
191 ctx
.strokeStyle
= "#000000";
192 ctx
.fillStyle
= "#FFFF00";
194 ctx
.arc(x
,y
,5,0,Math
.PI
*2,true);
200 function captureCanvas(canvas
, area
, g
) {
204 function restorePositioning(g
) {