123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148 |
- if(!dojo._hasResource["dojox.charting.plot2d.StackedColumns"]){
- dojo._hasResource["dojox.charting.plot2d.StackedColumns"] = true;
- 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");
- dojo.require("dojox.lang.functional.sequence");
- (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, {
-
-
- getSeriesStats: function(){
-
-
-
-
- var stats = dc.collectStackedStats(this.series);
- this._maxRunLength = stats.hmax;
- stats.hmin -= 0.5;
- stats.hmax += 0.5;
- return stats;
- },
- render: function(dim, offsets){
-
-
-
-
-
-
-
-
- if(this._maxRunLength <= 0){
- return this;
- }
-
- 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 value = run.data[j];
- if(value !== null){
- var v = typeof value == "number" ? value : value.y;
- if(isNaN(v)){ v = 0; }
- acc[j] += v;
- }
- }
- }
-
- if(this.zoom && !this.isDataDirty()){
- return this.performZoom(dim, offsets);
- }
- this.resetEvents();
- this.dirty = this.isDirty();
- if(this.dirty){
- dojo.forEach(this.series, purgeGroup);
- this._eventSeries = {};
- this.cleanGroup();
- var s = this.group;
- df.forEachRev(this.series, function(item){ item.cleanGroup(s); });
- }
- var t = this.chart.theme, f, gap, width,
- ht = this._hScaler.scaler.getTransformerFromModel(this._hScaler),
- vt = this._vScaler.scaler.getTransformerFromModel(this._vScaler),
- events = this.events();
- f = dc.calculateBarSize(this._hScaler.bounds.scale, this.opt);
- gap = f.gap;
- width = f.size;
- for(var i = this.series.length - 1; i >= 0; --i){
- var run = this.series[i];
- if(!this.dirty && !run.dirty){
- t.skip();
- this._reconnectEvents(run.name);
- continue;
- }
- run.cleanGroup();
- var theme = t.next("column", [this.opt, run]), s = run.group,
- eventSeries = new Array(acc.length);
- for(var j = 0; j < acc.length; ++j){
- var value = run.data[j];
- if(value !== null){
- var v = acc[j],
- height = vt(v),
- finalTheme = typeof value != "number" ?
- t.addMixin(theme, "column", value, true) :
- t.post(theme, "column");
- if(width >= 1 && height >= 0){
- var rect = {
- x: offsets.l + ht(j + 0.5) + gap,
- y: dim.height - offsets.b - vt(v),
- width: width, height: height
- };
- var specialFill = this._plotFill(finalTheme.series.fill, dim, offsets);
- specialFill = this._shapeFill(specialFill, rect);
- var shape = s.createRect(rect).setFill(specialFill).setStroke(finalTheme.series.stroke);
- run.dyn.fill = shape.getFill();
- run.dyn.stroke = shape.getStroke();
- if(events){
- var o = {
- element: "column",
- index: j,
- run: run,
- shape: shape,
- x: j + 0.5,
- y: v
- };
- this._connectEvents(o);
- eventSeries[j] = o;
- }
- if(this.animate){
- this._animateColumn(shape, dim.height - offsets.b, height);
- }
- }
- }
- }
- this._eventSeries[run.name] = eventSeries;
- run.dirty = false;
-
- for(var j = 0; j < run.data.length; ++j){
- var value = run.data[j];
- if(value !== null){
- var v = typeof value == "number" ? value : value.y;
- if(isNaN(v)){ v = 0; }
- acc[j] -= v;
- }
- }
- }
- this.dirty = false;
- return this;
- }
- });
- })();
- }
|