Project

General

Profile

Statistics
| Revision:

root / trunk / web / dojo / dojox / charting / Theme.js @ 9

History | View | Annotate | Download (7.08 KB)

1 9 andrej.cim
/*
2
        Copyright (c) 2004-2010, The Dojo Foundation All Rights Reserved.
3
        Available via Academic Free License >= 2.1 OR the modified BSD license.
4
        see: http://dojotoolkit.org/license for details
5
*/
6
7
8
if(!dojo._hasResource["dojox.charting.Theme"]){
9
dojo._hasResource["dojox.charting.Theme"]=true;
10
dojo.provide("dojox.charting.Theme");
11
dojo.require("dojox.color");
12
dojo.require("dojox.color.Palette");
13
dojo.require("dojox.lang.utils");
14
dojo.require("dojox.gfx.gradutils");
15
dojo.declare("dojox.charting.Theme",null,{shapeSpaces:{shape:1,shapeX:1,shapeY:1},constructor:function(_1){
16
_1=_1||{};
17
var _2=dojox.charting.Theme.defaultTheme;
18
dojo.forEach(["chart","plotarea","axis","series","marker"],function(_3){
19
this[_3]=dojo.delegate(_2[_3],_1[_3]);
20
},this);
21
if(_1.seriesThemes&&_1.seriesThemes.length){
22
this.colors=null;
23
this.seriesThemes=_1.seriesThemes.slice(0);
24
}else{
25
this.seriesThemes=null;
26
this.colors=(_1.colors||dojox.charting.Theme.defaultColors).slice(0);
27
}
28
this.markerThemes=null;
29
if(_1.markerThemes&&_1.markerThemes.length){
30
this.markerThemes=_1.markerThemes.slice(0);
31
}
32
this.markers=dojo.delegate(dojox.charting.Theme.defaultMarkers,_1.markers);
33
this.noGradConv=_1.noGradConv;
34
this.noRadialConv=_1.noRadialConv;
35
if(_1.reverseFills){
36
this.reverseFills();
37
}
38
this._current=0;
39
this._buildMarkerArray();
40
},clone:function(){
41
var _4=new dojox.charting.Theme({chart:this.chart,plotarea:this.plotarea,axis:this.axis,series:this.series,marker:this.marker,colors:this.colors,markers:this.markers,seriesThemes:this.seriesThemes,markerThemes:this.markerThemes,noGradConv:this.noGradConv,noRadialConv:this.noRadialConv});
42
dojo.forEach(["clone","clear","next","skip","addMixin","post","getTick"],function(_5){
43
if(this.hasOwnProperty(_5)){
44
_4[_5]=this[_5];
45
}
46
},this);
47
return _4;
48
},clear:function(){
49
this._current=0;
50
},next:function(_6,_7,_8){
51
var _9=dojox.lang.utils.merge,_a,_b;
52
if(this.colors){
53
_a=dojo.delegate(this.series);
54
_b=dojo.delegate(this.marker);
55
var _c=new dojo.Color(this.colors[this._current%this.colors.length]),_d;
56
if(_a.stroke&&_a.stroke.color){
57
_a.stroke=dojo.delegate(_a.stroke);
58
_d=new dojo.Color(_a.stroke.color);
59
_a.stroke.color=new dojo.Color(_c);
60
_a.stroke.color.a=_d.a;
61
}else{
62
_a.stroke={color:_c};
63
}
64
if(_b.stroke&&_b.stroke.color){
65
_b.stroke=dojo.delegate(_b.stroke);
66
_d=new dojo.Color(_b.stroke.color);
67
_b.stroke.color=new dojo.Color(_c);
68
_b.stroke.color.a=_d.a;
69
}else{
70
_b.stroke={color:_c};
71
}
72
if(!_a.fill||_a.fill.type){
73
_a.fill=_c;
74
}else{
75
_d=new dojo.Color(_a.fill);
76
_a.fill=new dojo.Color(_c);
77
_a.fill.a=_d.a;
78
}
79
if(!_b.fill||_b.fill.type){
80
_b.fill=_c;
81
}else{
82
_d=new dojo.Color(_b.fill);
83
_b.fill=new dojo.Color(_c);
84
_b.fill.a=_d.a;
85
}
86
}else{
87
_a=this.seriesThemes?_9(this.series,this.seriesThemes[this._current%this.seriesThemes.length]):this.series;
88
_b=this.markerThemes?_9(this.marker,this.markerThemes[this._current%this.markerThemes.length]):_a;
89
}
90
var _e=_b&&_b.symbol||this._markers[this._current%this._markers.length];
91
var _f={series:_a,marker:_b,symbol:_e};
92
++this._current;
93
if(_7){
94
_f=this.addMixin(_f,_6,_7);
95
}
96
if(_8){
97
_f=this.post(_f,_6);
98
}
99
return _f;
100
},skip:function(){
101
++this._current;
102
},addMixin:function(_10,_11,_12,_13){
103
if(dojo.isArray(_12)){
104
dojo.forEach(_12,function(m){
105
_10=this.addMixin(_10,_11,m);
106
},this);
107
}else{
108
var t={};
109
if("color" in _12){
110
if(_11=="line"||_11=="area"){
111
dojo.setObject("series.stroke.color",_12.color,t);
112
dojo.setObject("marker.stroke.color",_12.color,t);
113
}else{
114
dojo.setObject("series.fill",_12.color,t);
115
}
116
}
117
dojo.forEach(["stroke","outline","shadow","fill","font","fontColor"],function(_14){
118
var _15="marker"+_14.charAt(0).toUpperCase()+_14.substr(1),b=_15 in _12;
119
if(_14 in _12){
120
dojo.setObject("series."+_14,_12[_14],t);
121
if(!b){
122
dojo.setObject("marker."+_14,_12[_14],t);
123
}
124
}
125
if(b){
126
dojo.setObject("marker."+_14,_12[_15],t);
127
}
128
});
129
if("marker" in _12){
130
t.symbol=_12.marker;
131
}
132
_10=dojox.lang.utils.merge(_10,t);
133
}
134
if(_13){
135
_10=this.post(_10,_11);
136
}
137
return _10;
138
},post:function(_16,_17){
139
var _18=_16.series.fill,t;
140
if(!this.noGradConv&&this.shapeSpaces[_18.space]&&_18.type=="linear"){
141
if(_17=="bar"){
142
t={x1:_18.y1,y1:_18.x1,x2:_18.y2,y2:_18.x2};
143
}else{
144
if(!this.noRadialConv&&_18.space=="shape"&&(_17=="slice"||_17=="circle")){
145
t={type:"radial",cx:0,cy:0,r:100};
146
}
147
}
148
if(t){
149
return dojox.lang.utils.merge(_16,{series:{fill:t}});
150
}
151
}
152
return _16;
153
},getTick:function(_19,_1a){
154
var _1b=this.axis.tick,_1c=_19+"Tick";
155
merge=dojox.lang.utils.merge;
156
if(_1b){
157
if(this.axis[_1c]){
158
_1b=merge(_1b,this.axis[_1c]);
159
}
160
}else{
161
_1b=this.axis[_1c];
162
}
163
if(_1a){
164
if(_1b){
165
if(_1a[_1c]){
166
_1b=merge(_1b,_1a[_1c]);
167
}
168
}else{
169
_1b=_1a[_1c];
170
}
171
}
172
return _1b;
173
},inspectObjects:function(f){
174
dojo.forEach(["chart","plotarea","axis","series","marker"],function(_1d){
175
f(this[_1d]);
176
},this);
177
if(this.seriesThemes){
178
dojo.forEach(this.seriesThemes,f);
179
}
180
if(this.markerThemes){
181
dojo.forEach(this.markerThemes,f);
182
}
183
},reverseFills:function(){
184
this.inspectObjects(function(o){
185
if(o&&o.fill){
186
o.fill=dojox.gfx.gradutils.reverse(o.fill);
187
}
188
});
189
},addMarker:function(_1e,_1f){
190
this.markers[_1e]=_1f;
191
this._buildMarkerArray();
192
},setMarkers:function(obj){
193
this.markers=obj;
194
this._buildMarkerArray();
195
},_buildMarkerArray:function(){
196
this._markers=[];
197
for(var p in this.markers){
198
this._markers.push(this.markers[p]);
199
}
200
}});
201
dojo.mixin(dojox.charting.Theme,{defaultMarkers:{CIRCLE:"m-3,0 c0,-4 6,-4 6,0 m-6,0 c0,4 6,4 6,0",SQUARE:"m-3,-3 l0,6 6,0 0,-6 z",DIAMOND:"m0,-3 l3,3 -3,3 -3,-3 z",CROSS:"m0,-3 l0,6 m-3,-3 l6,0",X:"m-3,-3 l6,6 m0,-6 l-6,6",TRIANGLE:"m-3,3 l3,-6 3,6 z",TRIANGLE_INVERTED:"m-3,-3 l3,6 3,-6 z"},defaultColors:["#54544c","#858e94","#6e767a","#948585","#474747"],defaultTheme:{chart:{stroke:null,fill:"white",pageStyle:null},plotarea:{stroke:null,fill:"white"},axis:{stroke:{color:"#333",width:1},tick:{color:"#666",position:"center",font:"normal normal normal 7pt Tahoma",fontColor:"#333"},majorTick:{width:1,length:6},minorTick:{width:0.8,length:3},microTick:{width:0.5,length:1}},series:{stroke:{width:1.5,color:"#333"},outline:{width:0.1,color:"#ccc"},shadow:null,fill:"#ccc",font:"normal normal normal 8pt Tahoma",fontColor:"#000"},marker:{stroke:{width:1.5,color:"#333"},outline:{width:0.1,color:"#ccc"},shadow:null,fill:"#ccc",font:"normal normal normal 8pt Tahoma",fontColor:"#000"}},defineColors:function(_20){
202
_20=_20||{};
203
var c=[],n=_20.num||5;
204
if(_20.colors){
205
var l=_20.colors.length;
206
for(var i=0;i<n;i++){
207
c.push(_20.colors[i%l]);
208
}
209
return c;
210
}
211
if(_20.hue){
212
var s=_20.saturation||100;
213
var st=_20.low||30;
214
var end=_20.high||90;
215
var l=(end+st)/2;
216
return dojox.color.Palette.generate(dojox.color.fromHsv(_20.hue,s,l),"monochromatic").colors;
217
}
218
if(_20.generator){
219
return dojox.color.Palette.generate(_20.base,_20.generator).colors;
220
}
221
return c;
222
},generateGradient:function(_21,_22,_23){
223
var _24=dojo.delegate(_21);
224
_24.colors=[{offset:0,color:_22},{offset:1,color:_23}];
225
return _24;
226
},generateHslColor:function(_25,_26){
227
_25=new dojox.color.Color(_25);
228
var hsl=_25.toHsl(),_27=dojox.color.fromHsl(hsl.h,hsl.s,_26);
229
_27.a=_25.a;
230
return _27;
231
},generateHslGradient:function(_28,_29,_2a,_2b){
232
_28=new dojox.color.Color(_28);
233
var hsl=_28.toHsl(),_2c=dojox.color.fromHsl(hsl.h,hsl.s,_2a),_2d=dojox.color.fromHsl(hsl.h,hsl.s,_2b);
234
_2c.a=_2d.a=_28.a;
235
return dojox.charting.Theme.generateGradient(_29,_2c,_2d);
236
}});
237
}