1 <!DOCTYPE html><html><head><title>Sencha Documentation Project</title><link rel="stylesheet" href="../reset.css" type="text/css"><link rel="stylesheet" href="../prettify.css" type="text/css"><link rel="stylesheet" href="../prettify_sa.css" type="text/css"><script type="text/javascript" src="../prettify.js"></script></head><body onload="prettyPrint()"><pre class="prettyprint"><pre><span id='Ext-chart.theme.Theme'>/**
2 </span> * @class Ext.chart.theme.Theme
5 Ext.define('Ext.chart.theme.Theme', {
7 /* Begin Definitions */
9 requires: ['Ext.draw.Color'],
16 initTheme: function(theme) {
18 themes = Ext.chart.theme,
21 theme = theme.split(':');
23 if (key == theme[0]) {
24 gradients = theme[1] == 'gradients';
25 me.themeAttrs = new themes[key]({
26 useGradients: gradients
29 me.gradients = me.themeAttrs.gradients;
31 if (me.themeAttrs.background) {
32 me.background = me.themeAttrs.background;
38 Ext.Error.raise('No theme found named "' + theme + '"');
43 // This callback is executed right after when the class is created. This scope refers to the newly created class itself
45 /* Theme constructor: takes either a complex object with styles like:
122 ...or also takes just an array of colors and creates the complex object:
125 colors: ['#aaa', '#bcd', '#eee']
128 ...or takes just a base color and makes a theme from it
134 To create a new theme you may add it to the Themes object:
136 Ext.chart.theme.MyNewTheme = Ext.extend(Object, {
137 constructor: function(config) {
138 Ext.chart.theme.call(this, config, {
139 baseColor: '#mybasecolor'
145 Ext.chart.theme.MyNewTheme = Ext.chart.createTheme('#basecolor');
147 ...and then to use it provide the name of the theme (as a lower case string) in the chart config.
155 Ext.chart.theme = function(config, base) {
156 config = config || {};
157 var i = 0, l, colors, color,
158 seriesThemes, markerThemes,
159 seriesTheme, markerTheme,
163 if (config.baseColor) {
164 midColor = Ext.draw.Color.fromString(config.baseColor);
165 midL = midColor.getHSL()[2];
166 if (midL < 0.15) {
167 midColor = midColor.getLighter(0.3);
168 } else if (midL < 0.3) {
169 midColor = midColor.getLighter(0.15);
170 } else if (midL > 0.85) {
171 midColor = midColor.getDarker(0.3);
172 } else if (midL > 0.7) {
173 midColor = midColor.getDarker(0.15);
175 config.colors = [ midColor.getDarker(0.3).toString(),
176 midColor.getDarker(0.15).toString(),
178 midColor.getLighter(0.15).toString(),
179 midColor.getLighter(0.3).toString()];
181 delete config.baseColor;
184 colors = config.colors.slice();
185 markerThemes = base.markerThemes;
186 seriesThemes = base.seriesThemes;
188 base.colors = colors;
189 for (; i < l; i++) {
191 markerTheme = markerThemes[i] || {};
192 seriesTheme = seriesThemes[i] || {};
193 markerTheme.fill = seriesTheme.fill = markerTheme.stroke = seriesTheme.stroke = color;
194 markerThemes[i] = markerTheme;
195 seriesThemes[i] = seriesTheme;
197 base.markerThemes = markerThemes.slice(0, l);
198 base.seriesThemes = seriesThemes.slice(0, l);
199 //the user is configuring something in particular (either markers, series or pie slices)
203 if (Ext.isObject(config[key]) && Ext.isObject(base[key])) {
204 Ext.apply(base[key], config[key]);
206 base[key] = config[key];
210 if (config.useGradients) {
211 colors = base.colors || (function () {
213 for (i = 0, seriesThemes = base.seriesThemes, l = seriesThemes.length; i < l; i++) {
214 ans.push(seriesThemes[i].fill || seriesThemes[i].stroke);
218 for (i = 0, l = colors.length; i < l; i++) {
219 midColor = Ext.draw.Color.fromString(colors[i]);
221 color = midColor.getDarker(0.1).toString();
222 midColor = midColor.toString();
223 key = 'theme-' + midColor.substr(1) + '-' + color.substr(1);
229 color: midColor.toString()
232 color: color.toString()
236 colors[i] = 'url(#' + key + ')';
239 base.gradients = gradients;
240 base.colors = colors;
243 base.axis = Ext.apply(base.axis || {}, config.axis || {});
244 base.axisLabel = Ext.apply(base.axisLabel || {}, config.axisLabel || {});
245 base.axisTitle = Ext.apply(base.axisTitle || {}, config.axisTitle || {});
247 Ext.apply(this, base);
251 </pre></pre></body></html>