﻿/**
* Copyright (c) 2009 Chris Leonello
* jqPlot is currently available for use in all personal or commercial projects 
* under both the MIT and GPL version 2.0 licenses. This means that you can 
* choose the license that best suits your project and use it accordingly. 
*
* Although not required, the author would appreciate an email letting him 
* know of any substantial use of jqPlot.  You can reach the author at: 
* chris dot leonello at gmail dot com or see http://www.jqplot.com/info.php .
*
* If you are feeling kind and generous, consider supporting the project by
* making a donation at: http://www.jqplot.com/donate.php .
*/
(function(b) { b.jqplot.BarRenderer = function() { b.jqplot.LineRenderer.call(this) }; b.jqplot.BarRenderer.prototype = new b.jqplot.LineRenderer(); b.jqplot.BarRenderer.prototype.constructor = b.jqplot.BarRenderer; b.jqplot.BarRenderer.prototype.init = function(d) { this.barPadding = 8; this.barMargin = 10; this.barDirection = "vertical"; this.barWidth = null; this.shadowOffset = 2; this.shadowDepth = 5; this.shadowAlpha = 0.08; this.waterfall = false; this.varyBarColor = false; b.extend(true, this, d); this.fill = true; if (this.waterfall) { this.fillToZero = false; this.disableStack = true } if (this.barDirection == "vertical") { this._primaryAxis = "_xaxis"; this._stackAxis = "y"; this.fillAxis = "y" } else { this._primaryAxis = "_yaxis"; this._stackAxis = "x"; this.fillAxis = "x" } var e = { lineJoin: "miter", lineCap: "round", fill: true, isarc: false, strokeStyle: this.color, fillStyle: this.color, closePath: this.fill }; this.renderer.shapeRenderer.init(e); var c = { lineJoin: "miter", lineCap: "round", fill: true, isarc: false, angle: this.shadowAngle, offset: this.shadowOffset, alpha: this.shadowAlpha, depth: this.shadowDepth, closePath: this.fill }; this.renderer.shadowRenderer.init(c) }; function a(h, g, f, c) { if (this.rendererOptions.barDirection == "horizontal") { this._stackAxis = "x"; this._primaryAxis = "_yaxis" } if (this.rendererOptions.waterfall == true) { this._data = b.extend(true, [], this.data); var e = 0; var j = (!this.rendererOptions.barDirection || this.rendererOptions.barDirection == "vertical") ? 1 : 0; for (var d = 0; d < this.data.length; d++) { e += this.data[d][j]; if (d > 0) { this.data[d][j] += this.data[d - 1][j] } } this.data[this.data.length] = (j == 1) ? [this.data.length + 1, e] : [e, this.data.length + 1]; this._data[this._data.length] = (j == 1) ? [this._data.length + 1, e] : [e, this._data.length + 1] } } b.jqplot.preSeriesInitHooks.push(a); b.jqplot.BarRenderer.prototype.calcSeriesNumbers = function() { var g = 0; var h = 0; var f = this[this._primaryAxis]; var e, d, j; for (var c = 0; c < f._series.length; c++) { d = f._series[c]; if (d === this) { j = c } if (d.renderer.constructor == b.jqplot.BarRenderer) { g += d.data.length; h += 1 } } return [g, h, j] }; b.jqplot.BarRenderer.prototype.setBarWidth = function() { var f; var c = 0; var d = 0; var h = this[this._primaryAxis]; var m, g, k; var l = this.renderer.calcSeriesNumbers.call(this); c = l[0]; d = l[1]; var j = h.numberTicks; var e = (j - 1) / 2; if (h.name == "xaxis" || h.name == "x2axis") { if (this._stack) { this.barWidth = (h._offsets.max - h._offsets.min) / c * d - this.barMargin } else { this.barWidth = ((h._offsets.max - h._offsets.min) / e - this.barPadding * (d - 1) - this.barMargin * 2) / d } } else { if (this._stack) { this.barWidth = (h._offsets.min - h._offsets.max) / c * d - this.barMargin } else { this.barWidth = ((h._offsets.min - h._offsets.max) / e - this.barPadding * (d - 1) - this.barMargin * 2) / d } } return [c, d] }; b.jqplot.BarRenderer.prototype.draw = function(s, x, e) { var u; var o = (e != undefined) ? e : {}; var k = (o.shadow != undefined) ? o.shadow : this.shadow; var A = (o.showLine != undefined) ? o.showLine : this.showLine; var t = (o.fill != undefined) ? o.fill : this.fill; var d = this.xaxis; var v = this.yaxis; var n = this._xaxis.series_u2p; var w = this._yaxis.series_u2p; var r, q, m, l, g; if (this.barWidth == null) { this.renderer.setBarWidth.call(this) } var z = this.renderer.calcSeriesNumbers.call(this); m = z[0]; l = z[1]; g = z[2]; if (this._stack) { this._barNudge = 0 } else { this._barNudge = (-Math.abs(l / 2 - 0.5) + g) * (this.barWidth + this.barPadding) } if (A) { var j = new b.jqplot.ColorGenerator(this.negativeSeriesColors); var p = new b.jqplot.ColorGenerator(this.seriesColors); var y = j.get(this.index); if (!this.useNegativeColors) { y = o.fillStyle } var h = o.fillStyle; if (this.barDirection == "vertical") { for (var u = 0; u < x.length; u++) { points = []; var f = x[u][0] + this._barNudge; var c; if (this._stack && this._prevGridData.length) { c = this._prevGridData[u][1] } else { if (this.fillToZero) { c = this._yaxis.series_u2p(0) } else { if (this.waterfall && u > 0 && u < this.gridData.length - 1) { c = this.gridData[u - 1][1] } else { c = s.canvas.height } } } if ((this.fillToZero && this._plotData[u][1] < 0) || (this.waterfall && this._data[u][1] < 0)) { if (this.varyBarColor) { if (this.useNegativeColors) { o.fillStyle = j.next() } else { o.fillStyle = p.next() } } else { o.fillStyle = y } } else { if (this.varyBarColor) { o.fillStyle = p.next() } else { o.fillStyle = h } } points.push([f - this.barWidth / 2, c]); points.push([f - this.barWidth / 2, x[u][1]]); points.push([f + this.barWidth / 2, x[u][1]]); points.push([f + this.barWidth / 2, c]); if (k && !this._stack) { this.renderer.shadowRenderer.draw(s, points, o) } this.renderer.shapeRenderer.draw(s, points, o) } } else { if (this.barDirection == "horizontal") { for (var u = 0; u < x.length; u++) { points = []; var f = x[u][1] - this._barNudge; var B; if (this._stack && this._prevGridData.length) { B = this._prevGridData[u][0] } else { if (this.fillToZero) { B = this._xaxis.series_u2p(0) } else { if (this.waterfall && u > 0 && u < this.gridData.length - 1) { B = this.gridData[u - 1][1] } else { B = 0 } } } if ((this.fillToZero && this._plotData[u][1] < 0) || (this.waterfall && this._data[u][1] < 0)) { if (this.varyBarColor) { if (this.useNegativeColors) { o.fillStyle = j.next() } else { o.fillStyle = p.next() } } } else { if (this.varyBarColor) { o.fillStyle = p.next() } else { o.fillStyle = h } } points.push([B, f + this.barWidth / 2]); points.push([x[u][0], f + this.barWidth / 2]); points.push([x[u][0], f - this.barWidth / 2]); points.push([B, f - this.barWidth / 2]); if (k && !this._stack) { this.renderer.shadowRenderer.draw(s, points, o) } this.renderer.shapeRenderer.draw(s, points, o) } } } } }; b.jqplot.BarRenderer.prototype.drawShadow = function(p, u, e) { var r; var m = (e != undefined) ? e : {}; var h = (m.shadow != undefined) ? m.shadow : this.shadow; var w = (m.showLine != undefined) ? m.showLine : this.showLine; var q = (m.fill != undefined) ? m.fill : this.fill; var d = this.xaxis; var s = this.yaxis; var l = this._xaxis.series_u2p; var t = this._yaxis.series_u2p; var o, n, k, j, g; if (this._stack && this.shadow) { if (this.barWidth == null) { this.renderer.setBarWidth.call(this) } var v = this.renderer.calcSeriesNumbers.call(this); k = v[0]; j = v[1]; g = v[2]; if (this._stack) { this._barNudge = 0 } else { this._barNudge = (-Math.abs(j / 2 - 0.5) + g) * (this.barWidth + this.barPadding) } if (w) { if (this.barDirection == "vertical") { for (var r = 0; r < u.length; r++) { points = []; var f = u[r][0] + this._barNudge; var c; if (this._stack && this._prevGridData.length) { c = this._prevGridData[r][1] } else { if (this.fillToZero) { c = this._yaxis.series_u2p(0) } else { c = p.canvas.height } } points.push([f - this.barWidth / 2, c]); points.push([f - this.barWidth / 2, u[r][1]]); points.push([f + this.barWidth / 2, u[r][1]]); points.push([f + this.barWidth / 2, c]); this.renderer.shadowRenderer.draw(p, points, m) } } else { if (this.barDirection == "horizontal") { for (var r = 0; r < u.length; r++) { points = []; var f = u[r][1] - this._barNudge; var x; if (this._stack && this._prevGridData.length) { x = this._prevGridData[r][0] } else { x = 0 } points.push([x, f + this.barWidth / 2]); points.push([u[r][0], f + this.barWidth / 2]); points.push([u[r][0], f - this.barWidth / 2]); points.push([x, f - this.barWidth / 2]); this.renderer.shadowRenderer.draw(p, points, m) } } } } } } })(jQuery);
