| 1 | define(["dojo/_base/lang", "dojo/_base/array", "dojo/_base/Color", "../Theme", "dojox/color/_base", "./common"], |
| 2 | function(lang, arr, Color, Theme, dxcolor, themes){ |
| 3 | |
| 4 | var gg = lang.getObject("gradientGenerator", true, themes); |
| 5 | |
| 6 | gg.generateFills = function(colors, fillPattern, lumFrom, lumTo){ |
| 7 | // summary: |
| 8 | // generates 2-color gradients using pure colors, a fill pattern, and two luminance values |
| 9 | // colors: Array |
| 10 | // Array of colors to generate gradients for each. |
| 11 | // fillPattern: Object |
| 12 | // Gradient fill descriptor which colors list will be generated. |
| 13 | // lumFrom: Number |
| 14 | // Initial luminance value (0-100). |
| 15 | // lumTo: Number |
| 16 | // Final luminance value (0-100). |
| 17 | return arr.map(colors, function(c){ // Array |
| 18 | return Theme.generateHslGradient(c, fillPattern, lumFrom, lumTo); |
| 19 | }); |
| 20 | }; |
| 21 | |
| 22 | gg.updateFills = function(themes, fillPattern, lumFrom, lumTo){ |
| 23 | // summary: |
| 24 | // transforms solid color fills into 2-color gradients using a fill pattern, and two luminance values |
| 25 | // themes: Array |
| 26 | // Array of mini-themes (usually series themes or marker themes), which fill will be transformed. |
| 27 | // fillPattern: Object |
| 28 | // Gradient fill descriptor which colors list will be generated. |
| 29 | // lumFrom: Number |
| 30 | // Initial luminance value (0-100). |
| 31 | // lumTo: Number |
| 32 | // Final luminance value (0-100). |
| 33 | arr.forEach(themes, function(t){ |
| 34 | if(t.fill && !t.fill.type){ |
| 35 | t.fill = Theme.generateHslGradient(t.fill, fillPattern, lumFrom, lumTo); |
| 36 | } |
| 37 | }); |
| 38 | }; |
| 39 | |
| 40 | gg.generateMiniTheme = function(colors, fillPattern, lumFrom, lumTo, lumStroke){ |
| 41 | // summary: |
| 42 | // generates mini-themes with 2-color gradients using colors, a fill pattern, and three luminance values |
| 43 | // colors: Array |
| 44 | // Array of colors to generate gradients for each. |
| 45 | // fillPattern: Object |
| 46 | // Gradient fill descriptor which colors list will be generated. |
| 47 | // lumFrom: Number |
| 48 | // Initial luminance value (0-100). |
| 49 | // lumTo: Number |
| 50 | // Final luminance value (0-100). |
| 51 | // lumStroke: Number |
| 52 | // Stroke luminance value (0-100). |
| 53 | return arr.map(colors, function(c){ // Array |
| 54 | c = new dxcolor.Color(c); |
| 55 | return { |
| 56 | fill: Theme.generateHslGradient(c, fillPattern, lumFrom, lumTo), |
| 57 | stroke: {color: Theme.generateHslColor(c, lumStroke)} |
| 58 | }; |
| 59 | }); |
| 60 | }; |
| 61 | |
| 62 | gg.generateGradientByIntensity = function(color, intensityMap){ |
| 63 | // summary: |
| 64 | // generates gradient colors using an intensity map |
| 65 | // color: dojo.Color |
| 66 | // Color to use to generate gradients. |
| 67 | // intensityMap: Array |
| 68 | // Array of tuples {o, i}, where o is a gradient offset (0-1), |
| 69 | // and i is an intensity (0-255). |
| 70 | color = new Color(color); |
| 71 | return arr.map(intensityMap, function(stop){ // Array |
| 72 | var s = stop.i / 255; |
| 73 | return { |
| 74 | offset: stop.o, |
| 75 | color: new Color([color.r * s, color.g * s, color.b * s, color.a]) |
| 76 | }; |
| 77 | }); |
| 78 | }; |
| 79 | |
| 80 | return gg; |
| 81 | }); |