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
21 * Provides chart theming.
23 * Used as mixins by Ext.chart.Chart.
25 Ext.define('Ext.chart.theme.Theme', {
27 /* Begin Definitions */
29 requires: ['Ext.draw.Color'],
36 initTheme: function(theme) {
38 themes = Ext.chart.theme,
41 theme = theme.split(':');
43 if (key == theme[0]) {
44 gradients = theme[1] == 'gradients';
45 me.themeAttrs = new themes[key]({
46 useGradients: gradients
49 me.gradients = me.themeAttrs.gradients;
51 if (me.themeAttrs.background) {
52 me.background = me.themeAttrs.background;
58 Ext.Error.raise('No theme found named "' + theme + '"');
63 // This callback is executed right after when the class is created. This scope refers to the newly created class itself
65 /* Theme constructor: takes either a complex object with styles like:
142 ...or also takes just an array of colors and creates the complex object:
145 colors: ['#aaa', '#bcd', '#eee']
148 ...or takes just a base color and makes a theme from it
154 To create a new theme you may add it to the Themes object:
156 Ext.chart.theme.MyNewTheme = Ext.extend(Object, {
157 constructor: function(config) {
158 Ext.chart.theme.call(this, config, {
159 baseColor: '#mybasecolor'
165 Ext.chart.theme.MyNewTheme = Ext.chart.createTheme('#basecolor');
167 ...and then to use it provide the name of the theme (as a lower case string) in the chart config.
175 Ext.chart.theme = function(config, base) {
176 config = config || {};
177 var i = 0, l, colors, color,
178 seriesThemes, markerThemes,
179 seriesTheme, markerTheme,
183 if (config.baseColor) {
184 midColor = Ext.draw.Color.fromString(config.baseColor);
185 midL = midColor.getHSL()[2];
186 if (midL < 0.15) {
187 midColor = midColor.getLighter(0.3);
188 } else if (midL < 0.3) {
189 midColor = midColor.getLighter(0.15);
190 } else if (midL > 0.85) {
191 midColor = midColor.getDarker(0.3);
192 } else if (midL > 0.7) {
193 midColor = midColor.getDarker(0.15);
195 config.colors = [ midColor.getDarker(0.3).toString(),
196 midColor.getDarker(0.15).toString(),
198 midColor.getLighter(0.15).toString(),
199 midColor.getLighter(0.3).toString()];
201 delete config.baseColor;
204 colors = config.colors.slice();
205 markerThemes = base.markerThemes;
206 seriesThemes = base.seriesThemes;
208 base.colors = colors;
209 for (; i < l; i++) {
211 markerTheme = markerThemes[i] || {};
212 seriesTheme = seriesThemes[i] || {};
213 markerTheme.fill = seriesTheme.fill = markerTheme.stroke = seriesTheme.stroke = color;
214 markerThemes[i] = markerTheme;
215 seriesThemes[i] = seriesTheme;
217 base.markerThemes = markerThemes.slice(0, l);
218 base.seriesThemes = seriesThemes.slice(0, l);
219 //the user is configuring something in particular (either markers, series or pie slices)
223 if (Ext.isObject(config[key]) && Ext.isObject(base[key])) {
224 Ext.apply(base[key], config[key]);
226 base[key] = config[key];
230 if (config.useGradients) {
231 colors = base.colors || (function () {
233 for (i = 0, seriesThemes = base.seriesThemes, l = seriesThemes.length; i < l; i++) {
234 ans.push(seriesThemes[i].fill || seriesThemes[i].stroke);
238 for (i = 0, l = colors.length; i < l; i++) {
239 midColor = Ext.draw.Color.fromString(colors[i]);
241 color = midColor.getDarker(0.1).toString();
242 midColor = midColor.toString();
243 key = 'theme-' + midColor.substr(1) + '-' + color.substr(1);
249 color: midColor.toString()
252 color: color.toString()
256 colors[i] = 'url(#' + key + ')';
259 base.gradients = gradients;
260 base.colors = colors;
263 base.axis = Ext.apply(base.axis || {}, config.axis || {});
264 base.axisLabel = Ext.apply(base.axisLabel || {}, config.axisLabel || {});
265 base.axisTitle = Ext.apply(base.axisTitle || {}, config.axisTitle || {});
267 Ext.apply(this, base);