2150 |
mathias |
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 |
|
|
|
11 |
(function(){
|
|
|
12 |
var df = dojox.lang.functional, du = dojox.lang.utils,
|
|
|
13 |
dc = dojox.charting.plot2d.common,
|
|
|
14 |
purgeGroup = df.lambda("item.purgeGroup()");
|
|
|
15 |
|
|
|
16 |
dojo.declare("dojox.charting.plot2d.Bars", dojox.charting.plot2d.Base, {
|
|
|
17 |
defaultParams: {
|
|
|
18 |
hAxis: "x", // use a horizontal axis named "x"
|
|
|
19 |
vAxis: "y", // use a vertical axis named "y"
|
|
|
20 |
gap: 0, // gap between columns in pixels
|
|
|
21 |
shadows: null // draw shadows
|
|
|
22 |
},
|
|
|
23 |
optionalParams: {}, // no optional parameters
|
|
|
24 |
|
|
|
25 |
constructor: function(chart, kwArgs){
|
|
|
26 |
this.opt = dojo.clone(this.defaultParams);
|
|
|
27 |
du.updateWithObject(this.opt, kwArgs);
|
|
|
28 |
this.series = [];
|
|
|
29 |
this.hAxis = this.opt.hAxis;
|
|
|
30 |
this.vAxis = this.opt.vAxis;
|
|
|
31 |
},
|
|
|
32 |
|
|
|
33 |
calculateAxes: function(dim){
|
|
|
34 |
var stats = dc.collectSimpleStats(this.series), t;
|
|
|
35 |
stats.hmin -= 0.5;
|
|
|
36 |
stats.hmax += 0.5;
|
|
|
37 |
t = stats.hmin, stats.hmin = stats.vmin, stats.vmin = t;
|
|
|
38 |
t = stats.hmax, stats.hmax = stats.vmax, stats.vmax = t;
|
|
|
39 |
this._calc(dim, stats);
|
|
|
40 |
return this;
|
|
|
41 |
},
|
|
|
42 |
render: function(dim, offsets){
|
|
|
43 |
if(this.dirty){
|
|
|
44 |
dojo.forEach(this.series, purgeGroup);
|
|
|
45 |
this.cleanGroup();
|
|
|
46 |
var s = this.group;
|
|
|
47 |
df.forEachReversed(this.series, function(item){ item.cleanGroup(s); });
|
|
|
48 |
}
|
|
|
49 |
var t = this.chart.theme, color, stroke, fill, f,
|
|
|
50 |
gap = this.opt.gap < this._vScaler.scale / 3 ? this.opt.gap : 0;
|
|
|
51 |
for(var i = this.series.length - 1; i >= 0; --i){
|
|
|
52 |
var run = this.series[i];
|
|
|
53 |
if(!this.dirty && !run.dirty){ continue; }
|
|
|
54 |
run.cleanGroup();
|
|
|
55 |
var s = run.group;
|
|
|
56 |
if(!run.fill || !run.stroke){
|
|
|
57 |
// need autogenerated color
|
|
|
58 |
color = run.dyn.color = new dojo.Color(t.next("color"));
|
|
|
59 |
}
|
|
|
60 |
stroke = run.stroke ? run.stroke : dc.augmentStroke(t.series.stroke, color);
|
|
|
61 |
fill = run.fill ? run.fill : dc.augmentFill(t.series.fill, color);
|
|
|
62 |
var baseline = Math.max(0, this._hScaler.bounds.lower),
|
|
|
63 |
xoff = offsets.l + this._hScaler.scale * (baseline - this._hScaler.bounds.lower),
|
|
|
64 |
yoff = dim.height - offsets.b - this._vScaler.scale * (1.5 - this._vScaler.bounds.lower) + gap;
|
|
|
65 |
for(var j = 0; j < run.data.length; ++j){
|
|
|
66 |
var v = run.data[j],
|
|
|
67 |
width = this._hScaler.scale * (v - baseline),
|
|
|
68 |
height = this._vScaler.scale - 2 * gap,
|
|
|
69 |
w = Math.abs(width);
|
|
|
70 |
if(w >= 1 && height >= 1){
|
|
|
71 |
var shape = s.createRect({
|
|
|
72 |
x: xoff + (width < 0 ? width : 0),
|
|
|
73 |
y: yoff - this._vScaler.scale * j,
|
|
|
74 |
width: w, height: height
|
|
|
75 |
}).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 |
}
|