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");
5 dojo.require("dojox.charting.plot2d.common");
6 dojo.require("dojox.charting.plot2d.Base");
8 dojo.require("dojox.lang.utils");
9 dojo.require("dojox.lang.functional");
10 dojo.require("dojox.lang.functional.reversed");
13 var df = dojox.lang.functional, du = dojox.lang.utils,
14 dc = dojox.charting.plot2d.common,
15 purgeGroup = df.lambda("item.purgeGroup()");
17 dojo.declare("dojox.charting.plot2d.Bars", dojox.charting.plot2d.Base, {
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
24 optionalParams: {}, // no optional parameters
26 constructor: function(chart, kwArgs){
27 this.opt = dojo.clone(this.defaultParams);
28 du.updateWithObject(this.opt, kwArgs);
30 this.hAxis = this.opt.hAxis;
31 this.vAxis = this.opt.vAxis;
34 calculateAxes: function(dim){
35 var stats = dc.collectSimpleStats(this.series), t;
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);
43 render: function(dim, offsets){
45 dojo.forEach(this.series, purgeGroup);
48 df.forEachRev(this.series, function(item){ item.cleanGroup(s); });
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; }
57 if(!run.fill || !run.stroke){
58 // need autogenerated color
59 color = run.dyn.color = new dojo.Color(t.next("color"));
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){
68 width = this._hScaler.scale * (v - baseline),
69 height = this._vScaler.scale - 2 * gap,
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();