- Author:
- David Nickerson <nickerso@users.sourceforge.net>
- Date:
- 2009-07-16 02:00:03+12:00
- Desc:
- the starting point for the HH tutorial example
- Permanent Source URI:
- https://models.fieldml.org/workspace/a1/rawfile/f6a8f90307388eb4b040ee3566b84d88b59247f7/dojo-presentation/js/dojo/dojox/charting/plot2d/StackedColumns.js
dojo.provide("dojox.charting.plot2d.StackedColumns");
dojo.require("dojox.charting.plot2d.common");
dojo.require("dojox.charting.plot2d.Columns");
dojo.require("dojox.lang.functional");
dojo.require("dojox.lang.functional.reversed");
(function(){
var df = dojox.lang.functional, dc = dojox.charting.plot2d.common,
purgeGroup = df.lambda("item.purgeGroup()");
dojo.declare("dojox.charting.plot2d.StackedColumns", dojox.charting.plot2d.Columns, {
calculateAxes: function(dim){
var stats = dc.collectStackedStats(this.series);
this._maxRunLength = stats.hmax;
stats.hmin -= 0.5;
stats.hmax += 0.5;
this._calc(dim, stats);
return this;
},
render: function(dim, offsets){
// stack all values
var acc = df.repeat(this._maxRunLength, "-> 0", 0);
for(var i = 0; i < this.series.length; ++i){
var run = this.series[i];
for(var j = 0; j < run.data.length; ++j){
var v = run.data[j];
if(isNaN(v)){ v = 0; }
acc[j] += v;
}
}
// draw runs in backwards
this.dirty = this.isDirty();
if(this.dirty){
dojo.forEach(this.series, purgeGroup);
this.cleanGroup();
var s = this.group;
df.forEachRev(this.series, function(item){ item.cleanGroup(s); });
}
var t = this.chart.theme, color, stroke, fill, f,
ht = this._hScaler.scaler.getTransformerFromModel(this._hScaler),
vt = this._vScaler.scaler.getTransformerFromModel(this._vScaler);
gap = this.opt.gap < this._hScaler.bounds.scale / 3 ? this.opt.gap : 0,
width = this._hScaler.bounds.scale - 2 * gap,
events = this.events();
for(var i = this.series.length - 1; i >= 0; --i){
var run = this.series[i];
if(!this.dirty && !run.dirty){ continue; }
run.cleanGroup();
var s = run.group;
if(!run.fill || !run.stroke){
// need autogenerated color
color = run.dyn.color = new dojo.Color(t.next("color"));
}
stroke = run.stroke ? run.stroke : dc.augmentStroke(t.series.stroke, color);
fill = run.fill ? run.fill : dc.augmentFill(t.series.fill, color);
for(var j = 0; j < acc.length; ++j){
var v = acc[j],
height = vt(v);
if(width >= 1 && height >= 1){
var shape = s.createRect({
x: offsets.l + ht(j + 0.5) + gap,
y: dim.height - offsets.b - vt(v),
width: width, height: height
}).setFill(fill).setStroke(stroke);
run.dyn.fill = shape.getFill();
run.dyn.stroke = shape.getStroke();
if(events){
var o = {
element: "column",
index: j,
run: run,
plot: this,
hAxis: this.hAxis || null,
vAxis: this.vAxis || null,
shape: shape,
x: j + 0.5,
y: v
};
this._connectEvents(shape, o);
}
}
}
run.dirty = false;
// update the accumulator
for(var j = 0; j < run.data.length; ++j){
var v = run.data[j];
if(isNaN(v)){ v = 0; }
acc[j] -= v;
}
}
this.dirty = false;
return this;
}
});
})();