Added pixelRatio option to override canvas upscaling. Resolves #876, test included...
[dygraphs.git] / src / plugins / range-selector.js
index 2090fae..c1f70f9 100644 (file)
@@ -15,6 +15,7 @@
 
 import * as utils from '../dygraph-utils';
 import DygraphInteraction from '../dygraph-interaction-model';
+import IFrameTarp from '../iframe-tarp';
 
 var rangeSelector = function() {
   this.hasTouchInterface_ = typeof(TouchEvent) != 'undefined';
@@ -160,8 +161,8 @@ rangeSelector.prototype.updateVisibility_ = function() {
  * Resizes the range selector.
  */
 rangeSelector.prototype.resize_ = function() {
-  function setElementRect(canvas, context, rect) {
-    var canvasScale = utils.getContextPixelRatio(context);
+  function setElementRect(canvas, context, rect, pixelRatioOption) {
+    var canvasScale = pixelRatioOption || utils.getContextPixelRatio(context);
 
     canvas.style.top = rect.y + 'px';
     canvas.style.left = rect.x + 'px';
@@ -188,8 +189,9 @@ rangeSelector.prototype.resize_ = function() {
     h: this.getOption_('rangeSelectorHeight')
   };
 
-  setElementRect(this.bgcanvas_, this.bgcanvas_ctx_, this.canvasRect_);
-  setElementRect(this.fgcanvas_, this.fgcanvas_ctx_, this.canvasRect_);
+  var pixelRatioOption = this.dygraph_.getNumericOption('pixelRatio');
+  setElementRect(this.bgcanvas_, this.bgcanvas_ctx_, this.canvasRect_, pixelRatioOption);
+  setElementRect(this.fgcanvas_, this.fgcanvas_ctx_, this.canvasRect_, pixelRatioOption);
 };
 
 /**
@@ -256,7 +258,7 @@ rangeSelector.prototype.initInteraction_ = function() {
 
   // We cover iframes during mouse interactions. See comments in
   // dygraph-utils.js for more info on why this is a good idea.
-  var tarp = new utils.IFrameTarp();
+  var tarp = new IFrameTarp();
 
   // functions, defined below.  Defining them this way (rather than with
   // "function foo() {...}" makes JSHint happy.
@@ -634,13 +636,23 @@ rangeSelector.prototype.computeCombinedSeriesAndLimits_ = function() {
   var labels = g.getLabels();
   var includeSeries = new Array(numColumns);
   var anySet = false;
+  var visibility = g.visibility();
+  var inclusion = [];
+
   for (i = 1; i < numColumns; i++) {
     var include = this.getOption_('showInRangeSelector', labels[i]);
-    includeSeries[i] = include;
+    inclusion.push(include);
     if (include !== null) anySet = true;  // it's set explicitly for this series
   }
-  if (!anySet) {
-    for (i = 0; i < includeSeries.length; i++) includeSeries[i] = true;
+
+  if (anySet) {
+    for (i = 1; i < numColumns; i++) {
+      includeSeries[i] = inclusion[i - 1];
+    }
+  } else {
+    for (i = 1; i < numColumns; i++) {
+      includeSeries[i] = visibility[i - 1];
+    }
   }
 
   // Create a combined series (average of selected series values).