dojox.charting.Theme.defineColors
dojo.require("dojox.charting.Theme");
defined in dojox/charting/Theme.js
Generate a set of colors for the theme based on keyword arguments
Usage
function (obj) (view source)
var kwArgs=obj||{}; // deal with caching var cache = false; if(kwArgs.cache === undefined){ cache = true; } if(kwArgs.cache == true){ cache = true; } if(cache){ this._colorCache=kwArgs; } else { var mix=this._colorCache||{}; kwArgs=dojo.mixin(dojo.clone(mix), kwArgs); } var c=[], n=kwArgs.num||32; // the number of colors to generate if(kwArgs.colors){ // we have an array of colors predefined, so fix for the number of series. var l=kwArgs.colors.length; for(var i=0; i<n; i++){ c.push(kwArgs.colors[i%l]); } this.colors=c; }else if(kwArgs.hue){ // single hue, generate a set based on brightness var s=kwArgs.saturation||100; // saturation var st=kwArgs.low||30; var end=kwArgs.high||90; var step=(end-st)/n; // brightness steps for(var i=0; i<n; i++){ c.push(dxc._color.fromHsb(kwArgs.hue, s, st+(step*i)).toHex()); } this.colors=c; }else if(kwArgs.stops){ // create color ranges that are either equally distributed, or // (optionally) based on a passed "offset" property. If you // pass an array of Colors, it will equally distribute, if // you pass an array of structs { color, offset }, it will // use the offset (0.0 - 1.0) to distribute. Note that offset // values should be plotted on a line from 0.0 to 1.0--i.e. // they should be additive. For example: // [ {color, offset:0}, { color, offset:0.2 }, { color, offset:0.5 }, { color, offset:1.0 } ] // // If you use stops for colors, you MUST have a color at 0.0 and one // at 1.0. // figure out how many stops we have var l=kwArgs.stops.length; if(l<2){ throw new Error( "dojox.charting.Theme::defineColors: when using stops to " + "define a color range, you MUST specify at least 2 colors." ); } // figure out if the distribution is equal or not. Note that // colors may not exactly match the stops you define; because // color generation is linear (i.e. evenly divided on a linear // axis), it's very possible that a color will land in between // two stops and not exactly *at* a stop. // // The only two colors guaranteed will be the end stops (i.e. // the first and last stop), which will *always* be set as // the end stops. if(typeof(kwArgs.stops[0].offset) == "undefined"){ // set up equal offsets var off=1/(l-1); for(var i=0; i<l; i++){ kwArgs.stops[i]={ color:kwArgs.stops[i], offset:off*i }; } } // ensure the ends. kwArgs.stops[0].offset=0; kwArgs.stops[l-1].offset=1; kwArgs.stops.sort(function(a,b){ return a.offset-b.offset; }); // create the colors. // first stop. c.push(kwArgs.stops[0].color.toHex()); // TODO: calculate the blend at n/steps and set the color // last stop c.push(kwArgs.stops[l-1].color.toHex()); this.colors=c; }
parameter | type | description |
---|---|---|
obj |