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