3 This file is part of Ext JS 4
5 Copyright (c) 2011 Sencha Inc
7 Contact: http://www.sencha.com/contact
9 GNU General Public License Usage
10 This file may be used under the terms of the GNU General Public License version 3.0 as published by the Free Software Foundation and appearing in the file LICENSE included in the packaging of this file. Please review the following information to ensure the GNU General Public License version 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html.
12 If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact.
16 * @class Ext.chart.theme.Theme
18 * Provides chart theming.
20 * Used as mixins by Ext.chart.Chart.
22 Ext.define('Ext.chart.theme.Theme', {
24 /* Begin Definitions */
26 requires: ['Ext.draw.Color'],
33 initTheme: function(theme) {
35 themes = Ext.chart.theme,
38 theme = theme.split(':');
40 if (key == theme[0]) {
41 gradients = theme[1] == 'gradients';
42 me.themeAttrs = new themes[key]({
43 useGradients: gradients
46 me.gradients = me.themeAttrs.gradients;
48 if (me.themeAttrs.background) {
49 me.background = me.themeAttrs.background;
55 Ext.Error.raise('No theme found named "' + theme + '"');
60 // This callback is executed right after when the class is created. This scope refers to the newly created class itself
62 /* Theme constructor: takes either a complex object with styles like:
139 ...or also takes just an array of colors and creates the complex object:
142 colors: ['#aaa', '#bcd', '#eee']
145 ...or takes just a base color and makes a theme from it
151 To create a new theme you may add it to the Themes object:
153 Ext.chart.theme.MyNewTheme = Ext.extend(Object, {
154 constructor: function(config) {
155 Ext.chart.theme.call(this, config, {
156 baseColor: '#mybasecolor'
162 Ext.chart.theme.MyNewTheme = Ext.chart.createTheme('#basecolor');
164 ...and then to use it provide the name of the theme (as a lower case string) in the chart config.
172 Ext.chart.theme = function(config, base) {
173 config = config || {};
174 var i = 0, l, colors, color,
175 seriesThemes, markerThemes,
176 seriesTheme, markerTheme,
180 if (config.baseColor) {
181 midColor = Ext.draw.Color.fromString(config.baseColor);
182 midL = midColor.getHSL()[2];
184 midColor = midColor.getLighter(0.3);
185 } else if (midL < 0.3) {
186 midColor = midColor.getLighter(0.15);
187 } else if (midL > 0.85) {
188 midColor = midColor.getDarker(0.3);
189 } else if (midL > 0.7) {
190 midColor = midColor.getDarker(0.15);
192 config.colors = [ midColor.getDarker(0.3).toString(),
193 midColor.getDarker(0.15).toString(),
195 midColor.getLighter(0.15).toString(),
196 midColor.getLighter(0.3).toString()];
198 delete config.baseColor;
201 colors = config.colors.slice();
202 markerThemes = base.markerThemes;
203 seriesThemes = base.seriesThemes;
205 base.colors = colors;
208 markerTheme = markerThemes[i] || {};
209 seriesTheme = seriesThemes[i] || {};
210 markerTheme.fill = seriesTheme.fill = markerTheme.stroke = seriesTheme.stroke = color;
211 markerThemes[i] = markerTheme;
212 seriesThemes[i] = seriesTheme;
214 base.markerThemes = markerThemes.slice(0, l);
215 base.seriesThemes = seriesThemes.slice(0, l);
216 //the user is configuring something in particular (either markers, series or pie slices)
220 if (Ext.isObject(config[key]) && Ext.isObject(base[key])) {
221 Ext.apply(base[key], config[key]);
223 base[key] = config[key];
227 if (config.useGradients) {
228 colors = base.colors || (function () {
230 for (i = 0, seriesThemes = base.seriesThemes, l = seriesThemes.length; i < l; i++) {
231 ans.push(seriesThemes[i].fill || seriesThemes[i].stroke);
235 for (i = 0, l = colors.length; i < l; i++) {
236 midColor = Ext.draw.Color.fromString(colors[i]);
238 color = midColor.getDarker(0.1).toString();
239 midColor = midColor.toString();
240 key = 'theme-' + midColor.substr(1) + '-' + color.substr(1);
246 color: midColor.toString()
249 color: color.toString()
253 colors[i] = 'url(#' + key + ')';
256 base.gradients = gradients;
257 base.colors = colors;
260 base.axis = Ext.apply(base.axis || {}, config.axis || {});
261 base.axisLabel = Ext.apply(base.axisLabel || {}, config.axisLabel || {});
262 base.axisTitle = Ext.apply(base.axisTitle || {}, config.axisTitle || {});
264 Ext.apply(this, base);