From e44a7e37b6c7b5961adaffc62b9042b8d442938e Mon Sep 17 00:00:00 2001 From: mensonge Date: Thu, 13 Nov 2008 09:49:11 +0000 Subject: New feature: basic Ajax suggestion for tags and implementation of Dojo toolkit git-svn-id: https://semanticscuttle.svn.sourceforge.net/svnroot/semanticscuttle/trunk@151 b3834d28-1941-0410-a4f8-b48e95affb8f --- includes/js/dojox/charting/plot2d/StackedBars.js | 85 ++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 includes/js/dojox/charting/plot2d/StackedBars.js (limited to 'includes/js/dojox/charting/plot2d/StackedBars.js') diff --git a/includes/js/dojox/charting/plot2d/StackedBars.js b/includes/js/dojox/charting/plot2d/StackedBars.js new file mode 100644 index 0000000..e5c9c22 --- /dev/null +++ b/includes/js/dojox/charting/plot2d/StackedBars.js @@ -0,0 +1,85 @@ +if(!dojo._hasResource["dojox.charting.plot2d.StackedBars"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code. +dojo._hasResource["dojox.charting.plot2d.StackedBars"] = true; +dojo.provide("dojox.charting.plot2d.StackedBars"); + +dojo.require("dojox.charting.plot2d.common"); +dojo.require("dojox.charting.plot2d.Bars"); + +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.StackedBars", dojox.charting.plot2d.Bars, { + calculateAxes: function(dim){ + var stats = dc.collectStackedStats(this.series), t; + this._maxRunLength = stats.hmax; + stats.hmin -= 0.5; + stats.hmax += 0.5; + t = stats.hmin, stats.hmin = stats.vmin, stats.vmin = t; + t = stats.hmax, stats.hmax = stats.vmax, stats.vmax = t; + 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 + 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, + gap = this.opt.gap < this._vScaler.scale / 3 ? this.opt.gap : 0; + 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], + width = this._hScaler.scale * (v - this._hScaler.bounds.lower), + height = this._vScaler.scale - 2 * gap; + if(width >= 1 && height >= 1){ + var shape = s.createRect({ + x: offsets.l, + y: dim.height - offsets.b - this._vScaler.scale * (j + 1.5 - this._vScaler.bounds.lower) + gap, + width: width, height: height + }).setFill(fill).setStroke(stroke); + run.dyn.fill = shape.getFill(); + run.dyn.stroke = shape.getStroke(); + } + } + 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; + } + }); +})(); + +} -- cgit v1.2.3