]> git.pond.sub.org Git - eow/blob - static/dojo-release-1.1.1/dojox/charting/plot2d/Columns.js
ff973933c69b22e2c207065e18d3fe437f491a17
[eow] / static / dojo-release-1.1.1 / dojox / charting / plot2d / Columns.js
1 if(!dojo._hasResource["dojox.charting.plot2d.Columns"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
2 dojo._hasResource["dojox.charting.plot2d.Columns"] = true;
3 dojo.provide("dojox.charting.plot2d.Columns");
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.Columns", 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);
36                         stats.hmin -= 0.5;
37                         stats.hmax += 0.5;
38                         this._calc(dim, stats);
39                         return this;
40                 },
41                 render: function(dim, offsets){
42                         if(this.dirty){
43                                 dojo.forEach(this.series, purgeGroup);
44                                 this.cleanGroup();
45                                 var s = this.group;
46                                 df.forEachRev(this.series, function(item){ item.cleanGroup(s); });
47                         }
48                         var t = this.chart.theme, color, stroke, fill, f,
49                                 gap = this.opt.gap < this._hScaler.scale / 3 ? this.opt.gap : 0;
50                         for(var i = this.series.length - 1; i >= 0; --i){
51                                 var run = this.series[i];
52                                 if(!this.dirty && !run.dirty){ continue; }
53                                 run.cleanGroup();
54                                 var s = run.group;
55                                 if(!run.fill || !run.stroke){
56                                         // need autogenerated color
57                                         color = run.dyn.color = new dojo.Color(t.next("color"));
58                                 }
59                                 stroke = run.stroke ? run.stroke : dc.augmentStroke(t.series.stroke, color);
60                                 fill = run.fill ? run.fill : dc.augmentFill(t.series.fill, color);
61                                 var baseline = Math.max(0, this._vScaler.bounds.lower),
62                                         xoff = offsets.l + this._hScaler.scale * (0.5 - this._hScaler.bounds.lower) + gap,
63                                         yoff = dim.height - offsets.b - this._vScaler.scale * (baseline - this._vScaler.bounds.lower);
64                                 for(var j = 0; j < run.data.length; ++j){
65                                         var v = run.data[j], 
66                                                 width  = this._hScaler.scale - 2 * gap,
67                                                 height = this._vScaler.scale * (v - baseline),
68                                                 h = Math.abs(height);
69                                         if(width >= 1 && h >= 1){
70                                                 var rect = {
71                                                                 x: xoff + this._hScaler.scale * j,
72                                                                 y: yoff - (height < 0 ? 0 : height),
73                                                                 width: width, height: h
74                                                         },
75                                                         shape = s.createRect(rect).setFill(fill).setStroke(stroke);
76                                                 run.dyn.fill   = shape.getFill();
77                                                 run.dyn.stroke = shape.getStroke();
78                                         }
79                                 }
80                                 run.dirty = false;
81                         }
82                         this.dirty = false;
83                         return this;
84                 }
85         });
86 })();
87
88 }