root / trunk / web / dojo / dojox / charting / plot2d / StackedBars.js @ 12
History | View | Annotate | Download (2.81 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.plot2d.StackedBars"]){ |
||
9 | dojo._hasResource["dojox.charting.plot2d.StackedBars"]=true; |
||
10 | dojo.provide("dojox.charting.plot2d.StackedBars");
|
||
11 | dojo.require("dojox.charting.plot2d.common");
|
||
12 | dojo.require("dojox.charting.plot2d.Bars");
|
||
13 | dojo.require("dojox.lang.functional");
|
||
14 | dojo.require("dojox.lang.functional.reversed");
|
||
15 | (function(){
|
||
16 | var df=dojox.lang.functional,dc=dojox.charting.plot2d.common,_1=df.lambda("item.purgeGroup()"); |
||
17 | dojo.declare("dojox.charting.plot2d.StackedBars",dojox.charting.plot2d.Bars,{getSeriesStats:function(){ |
||
18 | var _2=dc.collectStackedStats(this.series),t; |
||
19 | this._maxRunLength=_2.hmax;
|
||
20 | _2.hmin-=0.5;
|
||
21 | _2.hmax+=0.5;
|
||
22 | t=_2.hmin,_2.hmin=_2.vmin,_2.vmin=t; |
||
23 | t=_2.hmax,_2.hmax=_2.vmax,_2.vmax=t; |
||
24 | return _2;
|
||
25 | },render:function(_3,_4){ |
||
26 | if(this._maxRunLength<=0){ |
||
27 | return this; |
||
28 | } |
||
29 | var _5=df.repeat(this._maxRunLength,"-> 0",0); |
||
30 | for(var i=0;i<this.series.length;++i){ |
||
31 | var _6=this.series[i]; |
||
32 | for(var j=0;j<_6.data.length;++j){ |
||
33 | var _7=_6.data[j];
|
||
34 | if(_7!==null){ |
||
35 | var v=typeof _7=="number"?_7:_7.y; |
||
36 | if(isNaN(v)){
|
||
37 | v=0;
|
||
38 | } |
||
39 | _5[j]+=v; |
||
40 | } |
||
41 | } |
||
42 | } |
||
43 | if(this.zoom&&!this.isDataDirty()){ |
||
44 | return this.performZoom(_3,_4); |
||
45 | } |
||
46 | this.resetEvents();
|
||
47 | this.dirty=this.isDirty(); |
||
48 | if(this.dirty){ |
||
49 | dojo.forEach(this.series,_1);
|
||
50 | this._eventSeries={};
|
||
51 | this.cleanGroup();
|
||
52 | var s=this.group; |
||
53 | df.forEachRev(this.series,function(_8){ |
||
54 | _8.cleanGroup(s); |
||
55 | }); |
||
56 | } |
||
57 | var t=this.chart.theme,f,_9,_a,ht=this._hScaler.scaler.getTransformerFromModel(this._hScaler),vt=this._vScaler.scaler.getTransformerFromModel(this._vScaler),_b=this.events(); |
||
58 | f=dc.calculateBarSize(this._vScaler.bounds.scale,this.opt); |
||
59 | _9=f.gap; |
||
60 | _a=f.size; |
||
61 | for(var i=this.series.length-1;i>=0;--i){ |
||
62 | var _6=this.series[i]; |
||
63 | if(!this.dirty&&!_6.dirty){ |
||
64 | t.skip(); |
||
65 | this._reconnectEvents(_6.name);
|
||
66 | continue;
|
||
67 | } |
||
68 | _6.cleanGroup(); |
||
69 | var _c=t.next("bar",[this.opt,_6]),s=_6.group,_d=new Array(_5.length); |
||
70 | for(var j=0;j<_5.length;++j){ |
||
71 | var _7=_6.data[j];
|
||
72 | if(_7!==null){ |
||
73 | var v=_5[j],_e=ht(v),_f=typeof _7!="number"?t.addMixin(_c,"bar",_7,true):t.post(_c,"bar"); |
||
74 | if(_e>=1&&_a>=1){ |
||
75 | var _10={x:_4.l,y:_3.height-_4.b-vt(j+1.5)+_9,width:_e,height:_a}; |
||
76 | var _11=this._plotFill(_f.series.fill,_3,_4); |
||
77 | _11=this._shapeFill(_11,_10);
|
||
78 | var _12=s.createRect(_10).setFill(_11).setStroke(_f.series.stroke);
|
||
79 | _6.dyn.fill=_12.getFill(); |
||
80 | _6.dyn.stroke=_12.getStroke(); |
||
81 | if(_b){
|
||
82 | var o={element:"bar",index:j,run:_6,shape:_12,x:v,y:j+1.5}; |
||
83 | this._connectEvents(o);
|
||
84 | _d[j]=o; |
||
85 | } |
||
86 | if(this.animate){ |
||
87 | this._animateBar(_12,_4.l,-_e);
|
||
88 | } |
||
89 | } |
||
90 | } |
||
91 | } |
||
92 | this._eventSeries[_6.name]=_d;
|
||
93 | _6.dirty=false;
|
||
94 | for(var j=0;j<_6.data.length;++j){ |
||
95 | var _7=_6.data[j];
|
||
96 | if(_7!==null){ |
||
97 | var v=typeof _7=="number"?_7:_7.y; |
||
98 | if(isNaN(v)){
|
||
99 | v=0;
|
||
100 | } |
||
101 | _5[j]-=v; |
||
102 | } |
||
103 | } |
||
104 | } |
||
105 | this.dirty=false; |
||
106 | return this; |
||
107 | }}); |
||
108 | })(); |
||
109 | } |