squash a few remaining "use strict" errors
[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 Dygraph.warn(ex);
380 }
381
382 var margin = .5;
383 this.bgcanvas_ctx_.lineWidth = 1;
384 ctx.strokeStyle = 'gray';
385 ctx.beginPath();
386 ctx.moveTo(margin, margin);
387 ctx.lineTo(margin, this.canvasRect_.h-margin);
388 ctx.lineTo(this.canvasRect_.w-margin, this.canvasRect_.h-margin);
389 ctx.lineTo(this.canvasRect_.w-margin, margin);
390 ctx.stroke();
391 };
392
393
394 /**
395 * @private
396 * Draws the mini plot in the background canvas.
397 */
398 DygraphRangeSelector.prototype.drawMiniPlot_ = function() {
399 var fillStyle = this.attr_('rangeSelectorPlotFillColor');
400 var strokeStyle = this.attr_('rangeSelectorPlotStrokeColor');
401 if (!fillStyle && !strokeStyle) {
402 return;
403 }
404
405 var combinedSeriesData = this.computeCombinedSeriesAndLimits_();
406 var yRange = combinedSeriesData.yMax - combinedSeriesData.yMin;
407
408 // Draw the mini plot.
409 var ctx = this.bgcanvas_ctx_;
410 var margin = .5;
411
412 var xExtremes = this.dygraph_.xAxisExtremes();
413 var xRange = Math.max(xExtremes[1] - xExtremes[0], 1.e-30);
414 var xFact = (this.canvasRect_.w - margin)/xRange;
415 var yFact = (this.canvasRect_.h - margin)/yRange;
416 var canvasWidth = this.canvasRect_.w - margin;
417 var canvasHeight = this.canvasRect_.h - margin;
418
419 ctx.beginPath();
420 ctx.moveTo(margin, canvasHeight);
421 for (var i = 0; i < combinedSeriesData.data.length; i++) {
422 var dataPoint = combinedSeriesData.data[i];
423 var x = (dataPoint[0] - xExtremes[0])*xFact;
424 var y = canvasHeight - (dataPoint[1] - combinedSeriesData.yMin)*yFact;
425 if (isFinite(x) && isFinite(y)) {
426 ctx.lineTo(x, y);
427 }
428 }
429 ctx.lineTo(canvasWidth, canvasHeight);
430 ctx.closePath();
431
432 if (fillStyle) {
433 var lingrad = this.bgcanvas_ctx_.createLinearGradient(0, 0, 0, canvasHeight);
434 lingrad.addColorStop(0, 'white');
435 lingrad.addColorStop(1, fillStyle);
436 this.bgcanvas_ctx_.fillStyle = lingrad;
437 ctx.fill();
438 }
439
440 if (strokeStyle) {
441 this.bgcanvas_ctx_.strokeStyle = strokeStyle;
442 this.bgcanvas_ctx_.lineWidth = 1.5;
443 ctx.stroke();
444 }
445 };
446
447 /**
448 * @private
449 * Computes and returns the combinded series data along with min/max for the mini plot.
450 * @return {Object} An object containing combinded series array, ymin, ymax.
451 */
452 DygraphRangeSelector.prototype.computeCombinedSeriesAndLimits_ = function() {
453 var data = this.dygraph_.rawData_;
454 var logscale = this.attr_('logscale');
455
456 // Create a combined series (average of all series values).
457 var combinedSeries = [];
458 var sum;
459 var count;
460 var mutipleValues = typeof data[0][1] != 'number';
461
462 if (mutipleValues) {
463 sum = [];
464 count = [];
465 for (var k = 0; k < data[0][1].length; k++) {
466 sum.push(0);
467 count.push(0);
468 }
469 mutipleValues = true;
470 }
471
472 for (var i = 0; i < data.length; i++) {
473 var dataPoint = data[i];
474 var xVal = dataPoint[0];
475 var yVal;
476
477 if (mutipleValues) {
478 for (var k = 0; k < sum.length; k++) {
479 sum[k] = count[k] = 0;
480 }
481 } else {
482 sum = count = 0;
483 }
484
485 for (var j = 1; j < dataPoint.length; j++) {
486 if (this.dygraph_.visibility()[j-1]) {
487 if (mutipleValues) {
488 for (var k = 0; k < sum.length; k++) {
489 var y = dataPoint[j][k];
490 if (y == null || isNaN(y)) continue;
491 sum[k] += y;
492 count[k]++;
493 }
494 } else {
495 var y = dataPoint[j];
496 if (y == null || isNaN(y)) continue;
497 sum += y;
498 count++;
499 }
500 }
501 }
502
503 if (mutipleValues) {
504 for (var k = 0; k < sum.length; k++) {
505 sum[k] /= count[k];
506 }
507 yVal = sum.slice(0);
508 } else {
509 yVal = sum/count;
510 }
511
512 combinedSeries.push([xVal, yVal]);
513 }
514
515 // Account for roll period, fractions.
516 combinedSeries = this.dygraph_.rollingAverage(combinedSeries, this.dygraph_.rollPeriod_);
517
518 if (typeof combinedSeries[0][1] != 'number') {
519 for (var i = 0; i < combinedSeries.length; i++) {
520 var yVal = combinedSeries[i][1];
521 combinedSeries[i][1] = yVal[0];
522 }
523 }
524
525 // Compute the y range.
526 var yMin = Number.MAX_VALUE;
527 var yMax = -Number.MAX_VALUE;
528 for (var i = 0; i < combinedSeries.length; i++) {
529 var yVal = combinedSeries[i][1];
530 if (yVal != null && isFinite(yVal) && (!logscale || yVal > 0)) {
531 yMin = Math.min(yMin, yVal);
532 yMax = Math.max(yMax, yVal);
533 }
534 }
535
536 // Convert Y data to log scale if needed.
537 // Also, expand the Y range to compress the mini plot a little.
538 var extraPercent = .25;
539 if (logscale) {
540 yMax = Dygraph.log10(yMax);
541 yMax += yMax*extraPercent;
542 yMin = Dygraph.log10(yMin);
543 for (var i = 0; i < combinedSeries.length; i++) {
544 combinedSeries[i][1] = Dygraph.log10(combinedSeries[i][1]);
545 }
546 } else {
547 var yExtra;
548 var yRange = yMax - yMin;
549 if (yRange <= Number.MIN_VALUE) {
550 yExtra = yMax*extraPercent;
551 } else {
552 yExtra = yRange*extraPercent;
553 }
554 yMax += yExtra;
555 yMin -= yExtra;
556 }
557
558 return {data: combinedSeries, yMin: yMin, yMax: yMax};
559 };
560
561 /**
562 * @private
563 * Places the zoom handles in the proper position based on the current X data window.
564 */
565 DygraphRangeSelector.prototype.placeZoomHandles_ = function() {
566 var xExtremes = this.dygraph_.xAxisExtremes();
567 var xWindowLimits = this.dygraph_.xAxisRange();
568 var xRange = xExtremes[1] - xExtremes[0];
569 var leftPercent = Math.max(0, (xWindowLimits[0] - xExtremes[0])/xRange);
570 var rightPercent = Math.max(0, (xExtremes[1] - xWindowLimits[1])/xRange);
571 var leftCoord = this.canvasRect_.x + this.canvasRect_.w*leftPercent;
572 var rightCoord = this.canvasRect_.x + this.canvasRect_.w*(1 - rightPercent);
573 var handleTop = Math.max(this.canvasRect_.y, this.canvasRect_.y + (this.canvasRect_.h - this.leftZoomHandle_.height)/2);
574 var halfHandleWidth = this.leftZoomHandle_.width/2;
575 this.leftZoomHandle_.style.left = (leftCoord - halfHandleWidth) + 'px';
576 this.leftZoomHandle_.style.top = handleTop + 'px';
577 this.rightZoomHandle_.style.left = (rightCoord - halfHandleWidth) + 'px';
578 this.rightZoomHandle_.style.top = this.leftZoomHandle_.style.top;
579
580 this.leftZoomHandle_.style.visibility = 'visible';
581 this.rightZoomHandle_.style.visibility = 'visible';
582 };
583
584 /**
585 * @private
586 * Draws the interactive layer in the foreground canvas.
587 */
588 DygraphRangeSelector.prototype.drawInteractiveLayer_ = function() {
589 var ctx = this.fgcanvas_ctx_;
590 ctx.clearRect(0, 0, this.canvasRect_.w, this.canvasRect_.h);
591 var margin = 1;
592 var width = this.canvasRect_.w - margin;
593 var height = this.canvasRect_.h - margin;
594 var zoomHandleStatus = this.getZoomHandleStatus_();
595
596 ctx.strokeStyle = 'black';
597 if (!zoomHandleStatus.isZoomed) {
598 ctx.beginPath();
599 ctx.moveTo(margin, margin);
600 ctx.lineTo(margin, height);
601 ctx.lineTo(width, height);
602 ctx.lineTo(width, margin);
603 ctx.stroke();
604 if (this.iePanOverlay_) {
605 this.iePanOverlay_.style.display = 'none';
606 }
607 } else {
608 var leftHandleCanvasPos = Math.max(margin, zoomHandleStatus.leftHandlePos - this.canvasRect_.x);
609 var rightHandleCanvasPos = Math.min(width, zoomHandleStatus.rightHandlePos - this.canvasRect_.x);
610
611 ctx.fillStyle = 'rgba(240, 240, 240, 0.6)';
612 ctx.fillRect(0, 0, leftHandleCanvasPos, this.canvasRect_.h);
613 ctx.fillRect(rightHandleCanvasPos, 0, this.canvasRect_.w - rightHandleCanvasPos, this.canvasRect_.h);
614
615 ctx.beginPath();
616 ctx.moveTo(margin, margin);
617 ctx.lineTo(leftHandleCanvasPos, margin);
618 ctx.lineTo(leftHandleCanvasPos, height);
619 ctx.lineTo(rightHandleCanvasPos, height);
620 ctx.lineTo(rightHandleCanvasPos, margin);
621 ctx.lineTo(width, margin);
622 ctx.stroke();
623
624 if (this.isUsingExcanvas_) {
625 this.iePanOverlay_.style.width = (rightHandleCanvasPos - leftHandleCanvasPos) + 'px';
626 this.iePanOverlay_.style.left = leftHandleCanvasPos + 'px';
627 this.iePanOverlay_.style.height = height + 'px';
628 this.iePanOverlay_.style.display = 'inline';
629 }
630 }
631 };
632
633 /**
634 * @private
635 * Returns the current zoom handle position information.
636 * @return {Object} The zoom handle status.
637 */
638 DygraphRangeSelector.prototype.getZoomHandleStatus_ = function() {
639 var halfHandleWidth = this.leftZoomHandle_.width/2;
640 var leftHandlePos = parseInt(this.leftZoomHandle_.style.left) + halfHandleWidth;
641 var rightHandlePos = parseInt(this.rightZoomHandle_.style.left) + halfHandleWidth;
642 return {
643 leftHandlePos: leftHandlePos,
644 rightHandlePos: rightHandlePos,
645 isZoomed: (leftHandlePos - 1 > this.canvasRect_.x || rightHandlePos + 1 < this.canvasRect_.x+this.canvasRect_.w)
646 };
647 };