]> git.pond.sub.org Git - eow/blob - static/dojo-release-1.1.1/dojox/charting/plot2d/StackedBars.js
Comment class stub
[eow] / static / dojo-release-1.1.1 / dojox / charting / plot2d / StackedBars.js
1 if(!dojo._hasResource["dojox.charting.plot2d.StackedBars"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
2 dojo._hasResource["dojox.charting.plot2d.StackedBars"] = true;
3 dojo.provide("dojox.charting.plot2d.StackedBars");
4
5 dojo.require("dojox.charting.plot2d.common");
6 dojo.require("dojox.charting.plot2d.Bars");
7
8 dojo.require("dojox.lang.functional");
9 dojo.require("dojox.lang.functional.reversed");
10
11 (function(){
12         var df = dojox.lang.functional, dc = dojox.charting.plot2d.common,
13                 purgeGroup = df.lambda("item.purgeGroup()");
14
15         dojo.declare("dojox.charting.plot2d.StackedBars", dojox.charting.plot2d.Bars, {
16                 calculateAxes: function(dim){
17                         var stats = dc.collectStackedStats(this.series), t;
18                         this._maxRunLength = stats.hmax;
19                         stats.hmin -= 0.5;
20                         stats.hmax += 0.5;
21                         t = stats.hmin, stats.hmin = stats.vmin, stats.vmin = t;
22                         t = stats.hmax, stats.hmax = stats.vmax, stats.vmax = t;
23                         this._calc(dim, stats);
24                         return this;
25                 },
26                 render: function(dim, offsets){
27                         // stack all values
28                         var acc = df.repeat(this._maxRunLength, "-> 0", 0);
29                         for(var i = 0; i < this.series.length; ++i){
30                                 var run = this.series[i];
31                                 for(var j = 0; j < run.data.length; ++j){
32                                         var v = run.data[j];
33                                         if(isNaN(v)){ v = 0; }
34                                         acc[j] += v;
35                                 }
36                         }
37                         // draw runs in backwards
38                         if(this.dirty){
39                                 dojo.forEach(this.series, purgeGroup);
40                                 this.cleanGroup();
41                                 var s = this.group;
42                                 df.forEachRev(this.series, function(item){ item.cleanGroup(s); });
43                         }
44                         var t = this.chart.theme, color, stroke, fill, f,
45                                 gap = this.opt.gap < this._vScaler.scale / 3 ? this.opt.gap : 0;
46                         for(var i = this.series.length - 1; i >= 0; --i){
47                                 var run = this.series[i];
48                                 if(!this.dirty && !run.dirty){ continue; }
49                                 run.cleanGroup();
50                                 var s = run.group;
51                                 if(!run.fill || !run.stroke){
52                                         // need autogenerated color
53                                         color = run.dyn.color = new dojo.Color(t.next("color"));
54                                 }
55                                 stroke = run.stroke ? run.stroke : dc.augmentStroke(t.series.stroke, color);
56                                 fill = run.fill ? run.fill : dc.augmentFill(t.series.fill, color);
57                                 for(var j = 0; j < acc.length; ++j){
58                                         var v = acc[j],
59                                                 width  = this._hScaler.scale * (v - this._hScaler.bounds.lower),
60                                                 height = this._vScaler.scale - 2 * gap;
61                                         if(width >= 1 && height >= 1){
62                                                 var shape = s.createRect({
63                                                         x: offsets.l,
64                                                         y: dim.height - offsets.b - this._vScaler.scale * (j + 1.5 - this._vScaler.bounds.lower) + gap,
65                                                         width: width, height: height
66                                                 }).setFill(fill).setStroke(stroke);
67                                                 run.dyn.fill   = shape.getFill();
68                                                 run.dyn.stroke = shape.getStroke();
69                                         }
70                                 }
71                                 run.dirty = false;
72                                 // update the accumulator
73                                 for(var j = 0; j < run.data.length; ++j){
74                                         var v = run.data[j];
75                                         if(isNaN(v)){ v = 0; }
76                                         acc[j] -= v;
77                                 }
78                         }
79                         this.dirty = false;
80                         return this;
81                 }
82         });
83 })();
84
85 }