var prevY = NaN;
var prevYs = [-1, -1];
// should be same color as the lines but only 15% opaque.
- var rgb = new RGBColorParser(color);
+ var rgb = Dygraph.toRGB_(color);
var err_color =
'rgba(' + rgb.r + ',' + rgb.g + ',' + rgb.b + ',' + fillAlpha + ')';
ctx.fillStyle = err_color;
var prevYs = [-1, -1];
var newYs;
// should be same color as the lines but only 15% opaque.
- var rgb = new RGBColorParser(color);
+ var rgb = Dygraph.toRGB_(color);
var err_color =
'rgba(' + rgb.r + ',' + rgb.g + ',' + rgb.b + ',' + fillAlpha + ')';
ctx.fillStyle = err_color;
}
}
};
+
+/**
+ * Converts any valid CSS color (hex, rgb(), named color) to an RGB tuple.
+ *
+ * @param {!string} color_str Any valid CSS color string.
+ * @return {{r:number,g:number,b:number}} Parsed RGB tuple.
+ * @private
+ */
+Dygraph.toRGB_ = function(color_str) {
+ // TODO(danvk): cache color parses to avoid repeated DOM manipulation.
+ var div = document.createElement('div');
+ div.style.backgroundColor = color_str;
+ div.style.visibility = 'hidden';
+ document.body.appendChild(div);
+ var rgb_str = window.getComputedStyle(div)['backgroundColor'];
+ document.body.removeChild(div);
+ var bits = /^rgb\((\d{1,3}),\s*(\d{1,3}),\s*(\d{1,3})\)$/.exec(rgb_str);
+ return {
+ r: parseInt(bits[1], 10),
+ g: parseInt(bits[2], 10),
+ b: parseInt(bits[3], 10)
+ };
+};