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