2 * g.Raphael 0.51 - Charting library, based on Raphaƫl
4 * Copyright (c) 2009-2012 Dmitry Baranovskiy (http://g.raphaeljs.com)
5 * Licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) license.
8 if (typeof(Raphael) == 'undefined') {
9 // support for seed/simple browser usage
10 importz = imports['seed/importz.js'].importz;
12 Raphael = importz('Raphael');
18 function clearAr(ar) {
19 var ret = new Array();
20 //Roo.log(JSON.stringify(ar));
21 for (var i = 0; i < ar.length; i++) {
22 //print(typeof(ar[i]));
23 if (Raphael.is(ar[i], "object")) {
24 ret.push(clearAr(ar[i]));
27 ret.push(parseInt(ar[i]));
37 * Creates a vertical bar chart
41 - x (number) x coordinate of the chart
42 - y (number) y coordinate of the chart
43 - width (number) width of the chart (respected by all elements in the set)
44 - height (number) height of the chart (respected by all elements in the set)
45 - values (array) values
46 - opts (object) options for the chart
48 o type (string) type of endings of the bar. Default: 'square'. Other options are: 'round', 'sharp', 'soft'.
49 o gutter (number)(string) default '20%' (WHAT DOES IT DO?)
51 o colors (array) colors be used repeatedly to plot the bars. If multicolumn bar is used each sequence of bars with use a different color.
52 o stacked (boolean) whether or not to tread values as in a stacked bar chart
57 = (object) path element of the popup
59 | r.vbarchart(0, 0, 620, 260, [[76, 70], [67, 71]], {})
63 function MVBarchart(paper, x, y, width, height, values, opts) {
65 values = clearAr(values);
71 barsteps = opts.barsteps || 20,
72 colors = opts.colors || chartinst.colors,
75 opts.axis = opts.axis || "";
76 opts.baroffset = opts.baroffset || 50;
77 opts.asixxheight = opts.asixxheight || 100;
78 opts.asixywidth = opts.asixywidth || 100;
79 opts.axisxlabels = opts.axisxlabels || [];
82 paper.rect(0, 0, width, height).attr({ stroke: "none", fill: (opts.background || "#F0F4F7") });
83 // background.toBack();
86 var barwidth = Math.floor((width - x - opts.asixywidth - opts.baroffset) / barsteps);
87 var barheight = height - y - opts.asixxheight || 100;
88 var path = ["M", x + 1, y, "l", 0, barheight]
90 for (var i = 0; i < barsteps; i++) {
91 path = path.concat(["M", x + (i * barwidth), y + 1, "l", barwidth, 0, "l", 0, barheight]);
94 paper.path(path).attr({ stroke: "#fff", "stroke-width": 2 });
97 var unit = barheight / max;
99 values.forEach((value,i) => {
100 if (!Raphael.is(values[0], "array")) {
104 value.forEach((v,k) => {
105 paper.rect(x + 1 + (k * barwidth) , y + (max - v) * unit, barwidth - 2, v * unit).attr({ stroke: "none", fill: colors[i%colors.length] });
106 paper.rect(x + 1 + (k * barwidth) + barwidth / 4 , y + (max - v) * unit - 42, barwidth / 2, 30, 5).attr({ stroke: "none", fill: "#0C014D" });
107 indicator = indicator.concat(["M", x + 1 + (k * barwidth) + barwidth / 4 + 10, y + (max - v) * unit - 12, "l", 5, 10, "l", 5, -10]);
108 paper.text(x + 1 + (k * barwidth) + barwidth / 2, y + (max - v) * unit - 28, Roo.util.Format.number(v, 0)).attr({
110 "font-family": "'Fontin Sans', Fontin-Sans, sans-serif",
111 "font-weight": "bold",
118 paper.path(indicator).attr({ stroke: "none", fill: "#0C014D" });
120 var ax = (opts.axis + "").split(/[,\s]+/),
126 x + width - opts.asixywidth ,
127 y + height - opts.asixxheight,
128 height - y - opts.asixxheight,
130 opts.axisystep || 10,
138 chartinst.bottomAxis(
140 height - opts.asixxheight,
142 opts.axisxlabels.length,
150 chart.push(bars, covers);
152 chart.covers = covers;
157 var F = function() {};
158 F.prototype = Raphael.g;
159 MVBarchart.prototype = new F; //prototype reused by hbarchart
161 Raphael.fn.mbarchart = function(x, y, width, height, values, opts) {
162 return new MVBarchart(this, x, y, width, height, values, opts);
165 MVBarchart.prototype.rightAxis = function (x, y, length, max, steps, ewidth, paper)
167 // Roo.log('Right Axis');
168 // Roo.log([x, y, length, max, steps, ewidth]);
173 d = Math.ceil(max / steps);
180 for(var i = 0; i <= steps; i++) {
183 paper.text(x + (ewidth / 2), Y + 15, label).attr({
185 "font-family": "'Fontin Sans', Fontin-Sans, sans-serif",
186 "font-weight": "bold",
187 "text-anchor": "end",
190 path = path.concat(["M", x, Y, "l", (ewidth / 2), 0]);
198 var res = paper.path(path).attr({ stroke: color, "stroke-width": 2 });
201 res.all = paper.set([res, text]);
202 res.remove = function () {
204 this.constructor.prototype.remove.call(this);
210 MVBarchart.prototype.bottomAxis = function (x, y, length, steps, labels, barwidth, eheight, paper)
212 // Roo.log('Bottom Axis');
213 // Roo.log([x, y, length, steps, labels, barwidth]);
215 var path = ["M", x, y, "l", length, 0],
218 offset = Math.round(barwidth / 2);
220 labels.forEach((v,k) => {
221 paper.text(x + (k * barwidth) + offset, y + (eheight / 2), v).attr({
223 "font-family": "'Fontin Sans', Fontin-Sans, sans-serif",
224 "font-weight": "bold",
229 var res = paper.path(path).attr({ stroke: color, "stroke-width": 2 });
232 res.all = paper.set([res, text]);
233 res.remove = function () {
235 this.constructor.prototype.remove.call(this);