X-Git-Url: https://adrianiainlam.tk/git/?a=blobdiff_plain;f=dygraph.js;h=4e159851dd13338b6435982c7c06bf21b721e7b3;hb=48423521405286de95fe42cffe548464ffba8b7d;hp=effe10df29fa6f6bb783dbadaf9303c1e34cf90e;hpb=00179556c038e85a6059c1393fcf2b72d1481414;p=dygraphs.git diff --git a/dygraph.js b/dygraph.js index effe10d..4e15985 100644 --- a/dygraph.js +++ b/dygraph.js @@ -1161,14 +1161,41 @@ Dygraph.prototype.setColors_ = function() { var num = labels.length - 1; this.colors_ = []; this.colorsMap_ = {}; + + // These are used for when no custom colors are specified. + var sat = this.attr_('colorSaturation') || 1.0; + var val = this.attr_('colorValue') || 0.5; + var half = Math.ceil(num / 2); + var colors = this.attr_('colors'); - var i; + var visibility = this.visibility(); + for (var i = 0; i < num; i++) { + if (!visibility[i]) { + continue; + } + var label = labels[i + 1]; + var colorStr = this.attributes_.getForSeries('color', label); + if (!colorStr) { + if (colors) { + colorStr = colors[i % colors.length]; + } else { + // alternate colors for high contrast. + var idx = i % 2 ? (half + (i + 1)/ 2) : Math.ceil((i + 1) / 2); + var hue = (1.0 * idx / (1 + num)); + colorStr = Dygraph.hsvToRGB(hue, sat, val); + } + } + this.colors_.push(colorStr); + this.colorsMap_[label] = colorStr; + } +/* if (!colors) { var sat = this.attr_('colorSaturation') || 1.0; var val = this.attr_('colorValue') || 0.5; var half = Math.ceil(num / 2); for (i = 1; i <= num; i++) { if (!this.visibility()[i-1]) continue; + var customColor = this.attributes_.getForSeries('color', labels[i]); // alternate colors for high contrast. var idx = i % 2 ? Math.ceil(i / 2) : (half + i / 2); var hue = (1.0 * idx/ (1 + num)); @@ -1184,6 +1211,8 @@ Dygraph.prototype.setColors_ = function() { this.colorsMap_[labels[1 + i]] = colorStr; } } +*/ + }; /**