4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5 <title>The source code</title>
6 <link href="../prettify/prettify.css" type="text/css" rel="stylesheet" />
7 <script type="text/javascript" src="../prettify/prettify.js"></script>
8 <style type="text/css">
9 .highlight { display: block; background-color: #ddd; }
11 <script type="text/javascript">
12 function highlight() {
13 document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
17 <body onload="prettyPrint(); highlight();">
18 <pre class="prettyprint lang-js"><span id='Ext-chart-theme-Theme'>/**
19 </span> * @class Ext.chart.theme.Theme
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];
183 if (midL < 0.15) {
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;
206 for (; i < l; i++) {
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);