From 82f05fab9e37addcc26fd2107c998d50246e9358 Mon Sep 17 00:00:00 2001 From: Dan Vanderkam Date: Thu, 18 Jul 2013 22:55:00 +0200 Subject: [PATCH] remove dependence on rgbcolor; unclear if this works in IE --- dygraph-canvas.js | 4 ++-- dygraph-utils.js | 23 +++++++++++++++++++++++ generate-combined.sh | 1 - 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/dygraph-canvas.js b/dygraph-canvas.js index cba4f44..c43b6e2 100644 --- a/dygraph-canvas.js +++ b/dygraph-canvas.js @@ -610,7 +610,7 @@ DygraphCanvasRenderer._errorPlotter = function(e) { 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; @@ -736,7 +736,7 @@ DygraphCanvasRenderer._fillPlotter = function(e) { 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; diff --git a/dygraph-utils.js b/dygraph-utils.js index 648adbd..b5cec4c 100644 --- a/dygraph-utils.js +++ b/dygraph-utils.js @@ -1283,3 +1283,26 @@ Dygraph.setDateSameTZ = function(d, parts) { } } }; + +/** + * 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) + }; +}; diff --git a/generate-combined.sh b/generate-combined.sh index 33c410e..d5aefeb 100755 --- a/generate-combined.sh +++ b/generate-combined.sh @@ -5,7 +5,6 @@ GetSources () { # This list needs to be kept in sync w/ the one in dygraph-dev.js # and the one in jsTestDriver.conf. Order matters, except for the plugins. for F in \ - rgbcolor/rgbcolor.js \ dashed-canvas.js \ dygraph-options.js \ dygraph-layout.js \ -- 2.7.4