Enable "strict" mode -- and fix one missing "var" declaration.
[dygraphs.git] / dygraph-range-selector.js
1 // Copyright 2011 Paul Felix (paul.eric.felix@gmail.com)
2 // All Rights Reserved.
3
4 /**
5 * @fileoverview This file contains the DygraphRangeSelector class used to provide
6 * a timeline range selector widget for dygraphs.
7 */
8
9 "use strict";
10
11 /**
12 * The DygraphRangeSelector class provides a timeline range selector widget.
13 * @param {Dygraph} dygraph The dygraph object
14 * @constructor
15 */
16 var DygraphRangeSelector = function(dygraph) {
17 this.isIE_ = /MSIE/.test(navigator.userAgent) && !window.opera;
18 this.isUsingExcanvas_ = dygraph.isUsingExcanvas_;
19 this.dygraph_ = dygraph;
20 this.createCanvases_();
21 if (this.isUsingExcanvas_) {
22 this.createIEPanOverlay_();
23 }
24 this.createZoomHandles_();
25 this.initInteraction_();
26 };
27
28 /**
29 * Adds the range selector to the dygraph.
30 * @param {Object} graphDiv The container div for the range selector.
31 * @param {DygraphLayout} layout The DygraphLayout object for this graph.
32 */
33 DygraphRangeSelector.prototype.addToGraph = function(graphDiv, layout) {
34 this.layout_ = layout;
35 this.resize_();
36 graphDiv.appendChild(this.bgcanvas_);
37 graphDiv.appendChild(this.fgcanvas_);
38 graphDiv.appendChild(this.leftZoomHandle_);
39 graphDiv.appendChild(this.rightZoomHandle_);
40 };
41
42 /**
43 * Renders the static background portion of the range selector.
44 */
45 DygraphRangeSelector.prototype.renderStaticLayer = function() {
46 this.resize_();
47 this.drawStaticLayer_();
48 };
49
50 /**
51 * Renders the interactive foreground portion of the range selector.
52 */
53 DygraphRangeSelector.prototype.renderInteractiveLayer = function() {
54 if (this.isChangingRange_) {
55 return;
56 }
57 this.placeZoomHandles_();
58 this.drawInteractiveLayer_();
59 };
60
61 /**
62 * @private
63 * Resizes the range selector.
64 */
65 DygraphRangeSelector.prototype.resize_ = function() {
66 function setElementRect(canvas, rect) {
67 canvas.style.top = rect.y + 'px';
68 canvas.style.left = rect.x + 'px';
69 canvas.width = rect.w;
70 canvas.height = rect.h;
71 canvas.style.width = canvas.width + 'px'; // for IE
72 canvas.style.height = canvas.height + 'px'; // for IE
73 };
74
75 var plotArea = this.layout_.getPlotArea();
76 var xAxisLabelHeight = this.attr_('axisLabelFontSize') + 2 * this.attr_('axisTickSize');
77 this.canvasRect_ = {
78 x: plotArea.x,
79 y: plotArea.y + plotArea.h + xAxisLabelHeight + 4,
80 w: plotArea.w,
81 h: this.attr_('rangeSelectorHeight')
82 };
83
84 setElementRect(this.bgcanvas_, this.canvasRect_);
85 setElementRect(this.fgcanvas_, this.canvasRect_);
86 };
87
88 DygraphRangeSelector.prototype.attr_ = function(name) {
89 return this.dygraph_.attr_(name);
90 };
91
92 /**
93 * @private
94 * Creates the background and foreground canvases.
95 */
96 DygraphRangeSelector.prototype.createCanvases_ = function() {
97 this.bgcanvas_ = Dygraph.createCanvas();
98 this.bgcanvas_.className = 'dygraph-rangesel-bgcanvas';
99 this.bgcanvas_.style.position = 'absolute';
100 this.bgcanvas_.style.zIndex = 9;
101 this.bgcanvas_ctx_ = Dygraph.getContext(this.bgcanvas_);
102
103 this.fgcanvas_ = Dygraph.createCanvas();
104 this.fgcanvas_.className = 'dygraph-rangesel-fgcanvas';
105 this.fgcanvas_.style.position = 'absolute';
106 this.fgcanvas_.style.zIndex = 9;
107 this.fgcanvas_.style.cursor = 'default';
108 this.fgcanvas_ctx_ = Dygraph.getContext(this.fgcanvas_);
109 };
110
111 /**
112 * @private
113 * Creates overlay divs for IE/Excanvas so that mouse events are handled properly.
114 */
115 DygraphRangeSelector.prototype.createIEPanOverlay_ = function() {
116 this.iePanOverlay_ = document.createElement("div");
117 this.iePanOverlay_.style.position = 'absolute';
118 this.iePanOverlay_.style.backgroundColor = 'white';
119 this.iePanOverlay_.style.filter = 'alpha(opacity=0)';
120 this.iePanOverlay_.style.display = 'none';
121 this.iePanOverlay_.style.cursor = 'move';
122 this.fgcanvas_.appendChild(this.iePanOverlay_);
123 };
124
125 /**
126 * @private
127 * Creates the zoom handle elements.
128 */
129 DygraphRangeSelector.prototype.createZoomHandles_ = function() {
130 var img = new Image();
131 img.className = 'dygraph-rangesel-zoomhandle';
132 img.style.position = 'absolute';
133 img.style.zIndex = 10;
134 img.style.visibility = 'hidden'; // Initially hidden so they don't show up in the wrong place.
135 img.style.cursor = 'col-resize';
136 if (/MSIE 7/.test(navigator.userAgent)) { // IE7 doesn't support embedded src data.
137 img.width = 7;
138 img.height = 14;
139 img.style.backgroundColor = 'white';
140 img.style.border = '1px solid #333333'; // Just show box in IE7.
141 } else {
142 img.width = 9;
143 img.height = 16;
144 img.src = 'data:image/png;base64,\
145 iVBORw0KGgoAAAANSUhEUgAAAAkAAAAQCAYAAADESFVDAAAAAXNSR0IArs4c6QAAAAZiS0dEANAA\
146 zwDP4Z7KegAAAAlwSFlzAAAOxAAADsQBlSsOGwAAAAd0SU1FB9sHGw0cMqdt1UwAAAAZdEVYdENv\
147 bW1lbnQAQ3JlYXRlZCB3aXRoIEdJTVBXgQ4XAAAAaElEQVQoz+3SsRFAQBCF4Z9WJM8KCDVwownl\
148 6YXsTmCUsyKGkZzcl7zkz3YLkypgAnreFmDEpHkIwVOMfpdi9CEEN2nGpFdwD03yEqDtOgCaun7s\
149 qSTDH32I1pQA2Pb9sZecAxc5r3IAb21d6878xsAAAAAASUVORK5CYII=';
150 }
151
152 this.leftZoomHandle_ = img;
153 this.rightZoomHandle_ = img.cloneNode(false);
154 };
155
156 /**
157 * @private
158 * Sets up the interaction for the range selector.
159 */
160 DygraphRangeSelector.prototype.initInteraction_ = function() {
161 var self = this;
162 var topElem = this.isIE_ ? document : window;
163 var xLast = 0;
164 var handle = null;
165 var isZooming = false;
166 var isPanning = false;
167
168 function toXDataWindow(zoomHandleStatus) {
169 var xDataLimits = self.dygraph_.xAxisExtremes();
170 var fact = (xDataLimits[1] - xDataLimits[0])/self.canvasRect_.w;
171 var xDataMin = xDataLimits[0] + (zoomHandleStatus.leftHandlePos - self.canvasRect_.x)*fact;
172 var xDataMax = xDataLimits[0] + (zoomHandleStatus.rightHandlePos - self.canvasRect_.x)*fact;
173 return [xDataMin, xDataMax];
174 };
175
176 function onZoomStart(e) {
177 Dygraph.cancelEvent(e);
178 isZooming = true;
179 xLast = e.screenX;
180 handle = e.target ? e.target : e.srcElement;
181 Dygraph.addEvent(topElem, 'mousemove', onZoom);
182 Dygraph.addEvent(topElem, 'mouseup', onZoomEnd);
183 self.fgcanvas_.style.cursor = 'col-resize';
184 };
185
186 function onZoom(e) {
187 if (!isZooming) {
188 return;
189 }
190 var delX = e.screenX - xLast;
191 if (Math.abs(delX) < 4) {
192 return;
193 }
194 xLast = e.screenX;
195 var zoomHandleStatus = self.getZoomHandleStatus_();
196 if (handle == self.leftZoomHandle_) {
197 var newPos = zoomHandleStatus.leftHandlePos + delX;
198 newPos = Math.min(newPos, zoomHandleStatus.rightHandlePos - handle.width - 3);
199 newPos = Math.max(newPos, self.canvasRect_.x);
200 } else {
201 var newPos = zoomHandleStatus.rightHandlePos + delX;
202 newPos = Math.min(newPos, self.canvasRect_.x + self.canvasRect_.w);
203 newPos = Math.max(newPos, zoomHandleStatus.leftHandlePos + handle.width + 3);
204 }
205 var halfHandleWidth = handle.width/2;
206 handle.style.left = (newPos - halfHandleWidth) + 'px';
207 self.drawInteractiveLayer_();
208
209 // Zoom on the fly (if not using excanvas).
210 if (!self.isUsingExcanvas_) {
211 doZoom();
212 }
213 };
214
215 function onZoomEnd(e) {
216 if (!isZooming) {
217 return;
218 }
219 isZooming = false;
220 Dygraph.removeEvent(topElem, 'mousemove', onZoom);
221 Dygraph.removeEvent(topElem, 'mouseup', onZoomEnd);
222 self.fgcanvas_.style.cursor = 'default';
223
224 // If using excanvas, Zoom now.
225 if (self.isUsingExcanvas_) {
226 doZoom();
227 }
228 };
229
230 function doZoom() {
231 try {
232 var zoomHandleStatus = self.getZoomHandleStatus_();
233 self.isChangingRange_ = true;
234 if (!zoomHandleStatus.isZoomed) {
235 self.dygraph_.doUnzoom_();
236 } else {
237 var xDataWindow = toXDataWindow(zoomHandleStatus);
238 self.dygraph_.doZoomXDates_(xDataWindow[0], xDataWindow[1]);
239 }
240 } finally {
241 self.isChangingRange_ = false;
242 }
243 };
244
245 function isMouseInPanZone(e) {
246 if (self.isUsingExcanvas_) {
247 return e.srcElement == self.iePanOverlay_;
248 } else {
249 // Getting clientX directly from the event is not accurate enough :(
250 var clientX = self.canvasRect_.x + (e.layerX != undefined ? e.layerX : e.offsetX);
251 var zoomHandleStatus = self.getZoomHandleStatus_();
252 return (clientX > zoomHandleStatus.leftHandlePos && clientX < zoomHandleStatus.rightHandlePos);
253 }
254 };
255
256 function onPanStart(e) {
257 if (!isPanning && isMouseInPanZone(e) && self.getZoomHandleStatus_().isZoomed) {
258 Dygraph.cancelEvent(e);
259 isPanning = true;
260 xLast = e.screenX;
261 Dygraph.addEvent(topElem, 'mousemove', onPan);
262 Dygraph.addEvent(topElem, 'mouseup', onPanEnd);
263 }
264 };
265
266 function onPan(e) {
267 if (!isPanning) {
268 return;
269 }
270 Dygraph.cancelEvent(e);
271
272 var delX = e.screenX - xLast;
273 if (Math.abs(delX) < 4) {
274 return;
275 }
276 xLast = e.screenX;
277
278 // Move range view
279 var zoomHandleStatus = self.getZoomHandleStatus_();
280 var leftHandlePos = zoomHandleStatus.leftHandlePos;
281 var rightHandlePos = zoomHandleStatus.rightHandlePos;
282 var rangeSize = rightHandlePos - leftHandlePos;
283 if (leftHandlePos + delX <= self.canvasRect_.x) {
284 leftHandlePos = self.canvasRect_.x;
285 rightHandlePos = leftHandlePos + rangeSize;
286 } else if (rightHandlePos + delX >= self.canvasRect_.x + self.canvasRect_.w) {
287 rightHandlePos = self.canvasRect_.x + self.canvasRect_.w;
288 leftHandlePos = rightHandlePos - rangeSize;
289 } else {
290 leftHandlePos += delX;
291 rightHandlePos += delX;
292 }
293 var halfHandleWidth = self.leftZoomHandle_.width/2;
294 self.leftZoomHandle_.style.left = (leftHandlePos - halfHandleWidth) + 'px';
295 self.rightZoomHandle_.style.left = (rightHandlePos - halfHandleWidth) + 'px';
296 self.drawInteractiveLayer_();
297
298 // Do pan on the fly (if not using excanvas).
299 if (!self.isUsingExcanvas_) {
300 doPan();
301 }
302 };
303
304 function onPanEnd(e) {
305 if (!isPanning) {
306 return;
307 }
308 isPanning = false;
309 Dygraph.removeEvent(topElem, 'mousemove', onPan);
310 Dygraph.removeEvent(topElem, 'mouseup', onPanEnd);
311 // If using excanvas, do pan now.
312 if (self.isUsingExcanvas_) {
313 doPan();
314 }
315 };
316
317 function doPan() {
318 try {
319 self.isChangingRange_ = true;
320 self.dygraph_.dateWindow_ = toXDataWindow(self.getZoomHandleStatus_());
321 self.dygraph_.drawGraph_(false);
322 } finally {
323 self.isChangingRange_ = false;
324 }
325 };
326
327 function onCanvasMouseMove(e) {
328 if (isZooming || isPanning) {
329 return;
330 }
331 var cursor = isMouseInPanZone(e) ? 'move' : 'default';
332 if (cursor != self.fgcanvas_.style.cursor) {
333 self.fgcanvas_.style.cursor = cursor;
334 }
335 };
336
337 var interactionModel = {
338 mousedown: function(event, g, context) {
339 context.initializeMouseDown(event, g, context);
340 Dygraph.startPan(event, g, context);
341 },
342 mousemove: function(event, g, context) {
343 if (context.isPanning) {
344 Dygraph.movePan(event, g, context);
345 }
346 },
347 mouseup: function(event, g, context) {
348 if (context.isPanning) {
349 Dygraph.endPan(event, g, context);
350 }
351 }
352 };
353
354 this.dygraph_.attrs_.interactionModel = interactionModel;
355 this.dygraph_.attrs_.panEdgeFraction = .0001;
356
357 var dragStartEvent = window.opera ? 'mousedown' : 'dragstart';
358 Dygraph.addEvent(this.leftZoomHandle_, dragStartEvent, onZoomStart);
359 Dygraph.addEvent(this.rightZoomHandle_, dragStartEvent, onZoomStart);
360
361 if (this.isUsingExcanvas_) {
362 Dygraph.addEvent(this.iePanOverlay_, 'mousedown', onPanStart);
363 } else {
364 Dygraph.addEvent(this.fgcanvas_, 'mousedown', onPanStart);
365 Dygraph.addEvent(this.fgcanvas_, 'mousemove', onCanvasMouseMove);
366 }
367 };
368
369 /**
370 * @private
371 * Draws the static layer in the background canvas.
372 */
373 DygraphRangeSelector.prototype.drawStaticLayer_ = function() {
374 var ctx = this.bgcanvas_ctx_;
375 ctx.clearRect(0, 0, this.canvasRect_.w, this.canvasRect_.h);
376 try {
377 this.drawMiniPlot_();
378 } catch(ex) {
379 }
380
381 var margin = .5;
382 this.bgcanvas_ctx_.lineWidth = 1;
383 ctx.strokeStyle = 'gray';
384 ctx.beginPath();
385 ctx.moveTo(margin, margin);
386 ctx.lineTo(margin, this.canvasRect_.h-margin);
387 ctx.lineTo(this.canvasRect_.w-margin, this.canvasRect_.h-margin);
388 ctx.lineTo(this.canvasRect_.w-margin, margin);
389 ctx.stroke();
390 };
391
392
393 /**
394 * @private
395 * Draws the mini plot in the background canvas.
396 */
397 DygraphRangeSelector.prototype.drawMiniPlot_ = function() {
398 var fillStyle = this.attr_('rangeSelectorPlotFillColor');
399 var strokeStyle = this.attr_('rangeSelectorPlotStrokeColor');
400 if (!fillStyle && !strokeStyle) {
401 return;
402 }
403
404 var combinedSeriesData = this.computeCombinedSeriesAndLimits_();
405 var yRange = combinedSeriesData.yMax - combinedSeriesData.yMin;
406
407 // Draw the mini plot.
408 var ctx = this.bgcanvas_ctx_;
409 var margin = .5;
410
411 var xExtremes = this.dygraph_.xAxisExtremes();
412 var xRange = Math.max(xExtremes[1] - xExtremes[0], 1.e-30);
413 var xFact = (this.canvasRect_.w - margin)/xRange;
414 var yFact = (this.canvasRect_.h - margin)/yRange;
415 var canvasWidth = this.canvasRect_.w - margin;
416 var canvasHeight = this.canvasRect_.h - margin;
417
418 ctx.beginPath();
419 ctx.moveTo(margin, canvasHeight);
420 for (var i = 0; i < combinedSeriesData.data.length; i++) {
421 var dataPoint = combinedSeriesData.data[i];
422 var x = (dataPoint[0] - xExtremes[0])*xFact;
423 var y = canvasHeight - (dataPoint[1] - combinedSeriesData.yMin)*yFact;
424 if (isFinite(x) && isFinite(y)) {
425 ctx.lineTo(x, y);
426 }
427 }
428 ctx.lineTo(canvasWidth, canvasHeight);
429 ctx.closePath();
430
431 if (fillStyle) {
432 var lingrad = this.bgcanvas_ctx_.createLinearGradient(0, 0, 0, canvasHeight);
433 lingrad.addColorStop(0, 'white');
434 lingrad.addColorStop(1, fillStyle);
435 this.bgcanvas_ctx_.fillStyle = lingrad;
436 ctx.fill();
437 }
438
439 if (strokeStyle) {
440 this.bgcanvas_ctx_.strokeStyle = strokeStyle;
441 this.bgcanvas_ctx_.lineWidth = 1.5;
442 ctx.stroke();
443 }
444 };
445
446 /**
447 * @private
448 * Computes and returns the combinded series data along with min/max for the mini plot.
449 * @return {Object} An object containing combinded series array, ymin, ymax.
450 */
451 DygraphRangeSelector.prototype.computeCombinedSeriesAndLimits_ = function() {
452 var data = this.dygraph_.rawData_;
453 var logscale = this.attr_('logscale');
454
455 // Create a combined series (average of all series values).
456 var combinedSeries = [];
457 var sum;
458 var count;
459 var mutipleValues = typeof data[0][1] != 'number';
460
461 if (mutipleValues) {
462 sum = [];
463 count = [];
464 for (var k = 0; k < data[0][1].length; k++) {
465 sum.push(0);
466 count.push(0);
467 }
468 mutipleValues = true;
469 }
470
471 for (var i = 0; i < data.length; i++) {
472 var dataPoint = data[i];
473 var xVal = dataPoint[0];
474 var yVal;
475
476 if (mutipleValues) {
477 for (var k = 0; k < sum.length; k++) {
478 sum[k] = count[k] = 0;
479 }
480 } else {
481 sum = count = 0;
482 }
483
484 for (var j = 1; j < dataPoint.length; j++) {
485 if (this.dygraph_.visibility()[j-1]) {
486 if (mutipleValues) {
487 for (var k = 0; k < sum.length; k++) {
488 var y = dataPoint[j][k];
489 if (y == null || isNaN(y)) continue;
490 sum[k] += y;
491 count[k]++;
492 }
493 } else {
494 var y = dataPoint[j];
495 if (y == null || isNaN(y)) continue;
496 sum += y;
497 count++;
498 }
499 }
500 }
501
502 if (mutipleValues) {
503 for (var k = 0; k < sum.length; k++) {
504 sum[k] /= count[k];
505 }
506 yVal = sum.slice(0);
507 } else {
508 yVal = sum/count;
509 }
510
511 combinedSeries.push([xVal, yVal]);
512 }
513
514 // Account for roll period, fractions.
515 combinedSeries = this.dygraph_.rollingAverage(combinedSeries, this.dygraph_.rollPeriod_);
516
517 if (typeof combinedSeries[0][1] != 'number') {
518 for (var i = 0; i < combinedSeries.length; i++) {
519 var yVal = combinedSeries[i][1];
520 combinedSeries[i][1] = yVal[0];
521 }
522 }
523
524 // Compute the y range.
525 var yMin = Number.MAX_VALUE;
526 var yMax = -Number.MAX_VALUE;
527 for (var i = 0; i < combinedSeries.length; i++) {
528 var yVal = combinedSeries[i][1];
529 if (yVal != null && isFinite(yVal) && (!logscale || yVal > 0)) {
530 yMin = Math.min(yMin, yVal);
531 yMax = Math.max(yMax, yVal);
532 }
533 }
534
535 // Convert Y data to log scale if needed.
536 // Also, expand the Y range to compress the mini plot a little.
537 var extraPercent = .25;
538 if (logscale) {
539 yMax = Dygraph.log10(yMax);
540 yMax += yMax*extraPercent;
541 yMin = Dygraph.log10(yMin);
542 for (var i = 0; i < combinedSeries.length; i++) {
543 combinedSeries[i][1] = Dygraph.log10(combinedSeries[i][1]);
544 }
545 } else {
546 var yExtra;
547 yRange = yMax - yMin;
548 if (yRange <= Number.MIN_VALUE) {
549 yExtra = yMax*extraPercent;
550 } else {
551 yExtra = yRange*extraPercent;
552 }
553 yMax += yExtra;
554 yMin -= yExtra;
555 }
556
557 return {data: combinedSeries, yMin: yMin, yMax: yMax};
558 };
559
560 /**
561 * @private
562 * Places the zoom handles in the proper position based on the current X data window.
563 */
564 DygraphRangeSelector.prototype.placeZoomHandles_ = function() {
565 var xExtremes = this.dygraph_.xAxisExtremes();
566 var xWindowLimits = this.dygraph_.xAxisRange();
567 var xRange = xExtremes[1] - xExtremes[0];
568 var leftPercent = Math.max(0, (xWindowLimits[0] - xExtremes[0])/xRange);
569 var rightPercent = Math.max(0, (xExtremes[1] - xWindowLimits[1])/xRange);
570 var leftCoord = this.canvasRect_.x + this.canvasRect_.w*leftPercent;
571 var rightCoord = this.canvasRect_.x + this.canvasRect_.w*(1 - rightPercent);
572 var handleTop = Math.max(this.canvasRect_.y, this.canvasRect_.y + (this.canvasRect_.h - this.leftZoomHandle_.height)/2);
573 var halfHandleWidth = this.leftZoomHandle_.width/2;
574 this.leftZoomHandle_.style.left = (leftCoord - halfHandleWidth) + 'px';
575 this.leftZoomHandle_.style.top = handleTop + 'px';
576 this.rightZoomHandle_.style.left = (rightCoord - halfHandleWidth) + 'px';
577 this.rightZoomHandle_.style.top = this.leftZoomHandle_.style.top;
578
579 this.leftZoomHandle_.style.visibility = 'visible';
580 this.rightZoomHandle_.style.visibility = 'visible';
581 };
582
583 /**
584 * @private
585 * Draws the interactive layer in the foreground canvas.
586 */
587 DygraphRangeSelector.prototype.drawInteractiveLayer_ = function() {
588 var ctx = this.fgcanvas_ctx_;
589 ctx.clearRect(0, 0, this.canvasRect_.w, this.canvasRect_.h);
590 var margin = 1;
591 var width = this.canvasRect_.w - margin;
592 var height = this.canvasRect_.h - margin;
593 var zoomHandleStatus = this.getZoomHandleStatus_();
594
595 ctx.strokeStyle = 'black';
596 if (!zoomHandleStatus.isZoomed) {
597 ctx.beginPath();
598 ctx.moveTo(margin, margin);
599 ctx.lineTo(margin, height);
600 ctx.lineTo(width, height);
601 ctx.lineTo(width, margin);
602 ctx.stroke();
603 if (this.iePanOverlay_) {
604 this.iePanOverlay_.style.display = 'none';
605 }
606 } else {
607 leftHandleCanvasPos = Math.max(margin, zoomHandleStatus.leftHandlePos - this.canvasRect_.x);
608 rightHandleCanvasPos = Math.min(width, zoomHandleStatus.rightHandlePos - this.canvasRect_.x);
609
610 ctx.fillStyle = 'rgba(240, 240, 240, 0.6)';
611 ctx.fillRect(0, 0, leftHandleCanvasPos, this.canvasRect_.h);
612 ctx.fillRect(rightHandleCanvasPos, 0, this.canvasRect_.w - rightHandleCanvasPos, this.canvasRect_.h);
613
614 ctx.beginPath();
615 ctx.moveTo(margin, margin);
616 ctx.lineTo(leftHandleCanvasPos, margin);
617 ctx.lineTo(leftHandleCanvasPos, height);
618 ctx.lineTo(rightHandleCanvasPos, height);
619 ctx.lineTo(rightHandleCanvasPos, margin);
620 ctx.lineTo(width, margin);
621 ctx.stroke();
622
623 if (this.isUsingExcanvas_) {
624 this.iePanOverlay_.style.width = (rightHandleCanvasPos - leftHandleCanvasPos) + 'px';
625 this.iePanOverlay_.style.left = leftHandleCanvasPos + 'px';
626 this.iePanOverlay_.style.height = height + 'px';
627 this.iePanOverlay_.style.display = 'inline';
628 }
629 }
630 };
631
632 /**
633 * @private
634 * Returns the current zoom handle position information.
635 * @return {Object} The zoom handle status.
636 */
637 DygraphRangeSelector.prototype.getZoomHandleStatus_ = function() {
638 var halfHandleWidth = this.leftZoomHandle_.width/2;
639 var leftHandlePos = parseInt(this.leftZoomHandle_.style.left) + halfHandleWidth;
640 var rightHandlePos = parseInt(this.rightZoomHandle_.style.left) + halfHandleWidth;
641 return {
642 leftHandlePos: leftHandlePos,
643 rightHandlePos: rightHandlePos,
644 isZoomed: (leftHandlePos - 1 > this.canvasRect_.x || rightHandlePos + 1 < this.canvasRect_.x+this.canvasRect_.w)
645 };
646 };