"use strict";var Grafico={Version:"0.9",Base:{},BaseGraph:{},Normaliser:{},LineGraph:{},AreaGraph:{},StackGraph:{},StreamGraph:{},BarGraph:{},StackedBarGraph:{},HorizontalBarGraph:{},SparkLine:{},SparkBar:{}};Grafico.Base=Class.create({normaliseData:function(a){return $A(a).collect(function(b){return this.normalise(b)}.bind(this))},deepCopy:function(d){var b,c,a;if(Object.prototype.toString.call(d)==="[object Array]"){b=[];a=d.length;for(c=0;c<a;c++){b[c]=arguments.callee(d[c])}return b}if(typeof d==="object"){b={};for(c in d){b[c]=arguments.callee(d[c])}return b}return d}});Grafico.Normaliser=Class.create({initialize:function(c,b){this.options={start_value:undefined,number_of_tickmarks:10};Object.extend(this.options,b||{});this.min=c.min();this.max=c.max();this.start_value=undefined;this.zero_value=undefined;this.range=undefined;this.step=undefined;if(this.options.start_value!==undefined){this.start_value=this.options.start_value;this.zero_value=this.options.start_value}if(this.min==0&&this.min==this.max){this.start_value=0;this.zero_value=0;this.range=1;this.step=1}else{var a;if(this.start_value!==undefined&&this.min>=0){a=this.start_value}else{a=this.min}this.looseLabels(a,this.max)}},looseLabels:function(f,a){var c=f==a?this.niceNumber(Math.abs(a),false):this.niceNumber(a-f,false),h=this.niceNumber(c/(this.options.number_of_tickmarks-1),true),b=[(-Math.floor(Math.LOG10E*Math.log(h))),0].max(),e=this.floorToPrecision(f/h,b)*h,i=this.ceilToPrecision(a/h,b)*h,g=this.roundToPrecision(this.niceNumber(0.5*h,true),b);this.step=this.roundToPrecision(h,b);if(this.max<=0){i=[i+g,0].min()}else{i=i+g}if(this.min<0){e=e-g}else{e=[e-g,0].max()}if(f!==a){e=this.roundToOrigin(e,1)}this.range=this.roundToPrecision(Math.abs(this.ceilToPrecision(i,b)-this.floorToPrecision(e,b)),b);this.start_value=this.floorToPrecision(e,b);this.zero_value=this.roundToPrecision(Math.abs(e)/this.step,b)},roundToPrecision:function(a,b){var c=Math.pow(10,b);return Math.round(a*c)/c},floorToPrecision:function(a,b){var c=Math.pow(10,b);return Math.floor(a*c)/c},ceilToPrecision:function(a,b){var c=Math.pow(10,b);return Math.ceil(a*c)/c},niceNumber:function(a,b){var g=Math.floor(Math.LOG10E*Math.log(a)),e,d,c;if(g<0){e=parseFloat(Math.pow(10,g).toFixed(Math.abs(g)))}else{e=Math.pow(10,g)}d=a/e;if(b){if(d<1.5){c=1}else{if(d<3){c=2}else{if(d<7){c=5}else{c=10}}}}else{if(d<=1){c=1}else{if(d<=2){c=2}else{if(d<=5){c=5}else{c=10}}}}return c*e},roundToOrigin:function(b,c){var a=b,d;c=c||1;d=Math.pow(10,-c);a=Math.round(b*d)/d;return(a>this.min)?this.roundToOrigin(b-this.step):a}});Grafico.BaseGraph=Class.create(Grafico.Base,{initialize:function(b,c,a){this.options={width:parseInt(b.getStyle("width"),10),height:parseInt(b.getStyle("height"),10),grid:true,show_vertical_grid:true,show_horizontal_grid:true,plot_padding:10,font_size:10,show_horizontal_labels:true,show_vertical_labels:true,show_ticks:true,vertical_label_unit:"",background_color:"#fff",label_color:"#000",grid_color:"#ccc",hover_text_color:"#fff",markers:false,marker_size:5,meanline:false,padding_top:20,draw_axis:true,datalabels:"",hover_color:"",watermark:false,watermark_location:false,hide_empty_label_grid:false,left_padding:false,label_rotation:0,label_max_size:false,focus_hint:true,min:0,max:null};Object.extend(this.options,this.chartDefaults()||{});Object.extend(this.options,a||{});this.element=b;this.data_sets=Object.isArray(c)?new Hash({one:c}):$H(c);if(this.chartDefaults().stacked===true){this.real_data=this.deepCopy(this.data_sets);this.data_sets=this.stackData(this.data_sets)}this.flat_data=this.data_sets.collect(function(d){return d[1]}).flatten();if(this.hasBaseLine()){this.flat_data.push(this.base_line);this.flat_data=this.flat_data.flatten()}this.normaliser=new Grafico.Normaliser(this.flat_data,this.normaliserOptions());this.label_step=this.normaliser.step;this.range=this.normaliser.range;this.start_value=this.normaliser.start_value;this.zero_value=this.normaliser.zero_value;this.data_size=this.longestDataSetLength();if(a&&a.color){a.colors={};this.data_sets.keys().each(function(d){a.colors[d]=a.color})}this.options.colors=this.makeRandomColors();this.options.labels=$A($R(1,this.data_size));Object.extend(this.options,this.chartDefaults()||{});Object.extend(this.options,a||{});this.x_padding_left=10+this.paddingLeftOffset();this.x_padding_left+=this.options.vertical_label_unit?6:0;this.x_padding_left=this.options.left_padding?this.options.left_padding:this.x_padding_left;this.x_padding_right=20;this.x_padding=this.x_padding_left+this.x_padding_right;this.y_padding_top=this.options.padding_top;this.y_padding_bottom=20+this.paddingBottomOffset();this.y_padding=this.y_padding_top+this.y_padding_bottom;this.graph_width=this.options.width-this.x_padding;this.graph_height=this.options.height-this.y_padding;this.step=this.calculateStep();this.y_label_count=(this.range/this.label_step).round();if(isNaN(this.y_label_count)){this.y_label_count=1;this.options.show_vertical_labels=false}if((this.normaliser.min+(this.y_label_count*this.normaliser.step))<this.normaliser.max){this.y_label_count+=1}this.value_labels=this.makeValueLabels(this.y_label_count);this.top_value=this.value_labels.last();this.grid_start_offset=-1;this.paper=new Raphael(this.element,this.options.width,this.options.height);this.background=this.paper.rect(this.x_padding_left,this.y_padding_top,this.graph_width,this.graph_height);this.background.attr({fill:this.options.background_color,stroke:"none"});this.options.meanline=(this.options.meanline===true)?{"stroke-width":"2px",stroke:"#BBBBBB"}:this.options.meanline;this.globalMarkerSet=this.paper.set();this.globalHoverSet=this.paper.set();this.globalBlockSet=this.paper.set();this.globalAreaLineSet=this.paper.set();this.setChartSpecificOptions();this.draw();this.globalAreaLineSet.toFront();this.globalMarkerSet.toFront();this.globalHoverSet.toFront();this.globalBlockSet.toFront()},normaliserOptions:function(){return{graph_height:parseInt(this.element.getStyle("height"),10)}},hasBaseLine:function(){return false},getNormalizedBaseLine:function(){if(this.normalized_base_line==undefined){this.normalized_base_line=this.normaliseData(this.base_line)}return this.normalized_base_line},getNormalizedRealData:function(){if(this.normalized_real_data==undefined){this.normalized_real_data=this.real_data.collect(function(a){return this.normaliseData(a[1])}.bind(this))}return this.normalized_real_data},chartDefaults:function(){},drawPlot:function(e,i,h,f,b,g,a,c,d){},calculateStep:function(){},getMousePos:function(c){var a=0,d=0,b;if(!c){c=window.event}if(c.pageX||c.pageY){a=c.pageX;d=c.pageY}else{if(c.clientX||c.clientY){a=c.clientX+document.body.scrollLeft-document.documentElement.scrollLeft;d=c.clientY+document.body.scrollTop-document.documentElement.scrollTop}}b={x:a,y:d};return b},makeRandomColors:function(d){var a={};var c=1/this.data_sets.size();var b=Math.random();this.data_sets.each(function(e){a[e[0]]=Raphael.hsb2rgb(b,0.85,0.75).hex;b=(b+c)%1});return a},longestDataSetLength:function(){var a=0;this.data_sets.each(function(b){a=b[1].length>a?b[1].length:a});return a},roundValue:function(b,a){var c=Math.pow(10,a);b*=c;b=Math.round(b)/c;return b},roundValues:function(b,a){return $A(b).collect(function(c){return this.roundValue(c,a)}.bind(this))},paddingLeftOffset:function(){var a=0;if(this.options.show_vertical_labels){var c=this.flat_data,b;c=this.roundValues(c,2);b=$A(c).max(function(e,d){return e.toString().length});b=b>2?b-1:b;a=b*this.options.font_size}return a},paddingBottomOffset:function(){return this.options.font_size},normalise:function(b){var a=this.start_value===0?this.top_value:this.range;if(a===0){a=1}return((b/a)*this.graph_height)},draw:function(){if(this.options.grid){this.drawGrid()}if(this.options.watermark){this.drawWatermark()}if(this.options.show_vertical_labels){this.drawVerticalLabels()}if(this.options.show_horizontal_labels){this.drawHorizontalLabels()}if(!this.options.watermark){this.drawLinesInit(this)}if(this.options.draw_axis){this.drawAxis()}if(this.start_value!==0&&this.options.focus_hint){this.drawFocusHint()}if(this.options.meanline){this.drawMeanLine(this.normaliseData(this.flat_data))}},drawLinesInit:function(a){a.data_sets.each(function(c,b){a.drawLines(c[0],a.options.colors[c[0]],a.normaliseData(c[1]),a.options.datalabels[c[0]],a.element,b)}.bind(a))},drawWatermark:function(){var a=this.options.watermark,c=new Image(),b=this;c.onload=function(){var e,d,f;if(b.options.watermark_location==="middle"){e=(b.graph_width-c.width)/2+b.x_padding_left;d=(b.graph_height-c.height)/2+b.y_padding_top}else{e=b.graph_width-c.width+b.x_padding_left-2;d=b.graph_height-c.height+b.y_padding_top-2}f=b.paper.image(c.src,e,d,c.width,c.height).attr({opacity:"0.4"});b.drawLinesInit(b,b.data);if(b.options.stacked_fill||b.options.area){f.toFront()}};c.src=a.src||a},drawGrid:function(){var d=this.paper.path().attr({stroke:this.options.grid_color}),e,a,b,c;if(this.options.show_horizontal_grid){e=this.graph_height+this.y_padding_top;for(c=0;c<this.y_label_count+1;c++){d.moveTo(this.x_padding_left-0.5,parseInt(e,10)+0.5);d.lineTo(this.x_padding_left+this.graph_width-0.5,parseInt(e,10)+0.5);e=e-(this.graph_height/this.y_label_count)}}if(this.options.show_vertical_grid){a=this.x_padding_left+this.options.plot_padding+this.grid_start_offset;b=this.options.labels.length;for(c=0;c<b;c++){if((this.options.hide_empty_label_grid===true&&this.options.labels[c]!=="")||this.options.hide_empty_label_grid===false){d.moveTo(parseInt(a,10),this.y_padding_top);d.lineTo(parseInt(a,10),this.y_padding_top+this.graph_height)}a=a+this.step}}},drawLines:function(j,c,d,b,e,g){var i=this.calculateCoords(d),a=(this.graph_height+this.y_padding_top),k,l,f,h;if(this.options.start_at_zero===false){f=0;$A(i).each(function(n,m){if(n[1]===a){f++}});this.options.odd_horizontal_offset=f;if(this.options.odd_horizontal_offset>1){i.splice(0,this.options.odd_horizontal_offset)}}if(this.options.stacked_fill||this.options.area){if(this.options.area){h=this.options.area_opacity?this.options.area_opacity:1.5/this.data_sets.collect(function(m){return m.length}).length;k=this.paper.path().attr({stroke:c,fill:c,"stroke-width":"0",opacity:h,"stroke-opacity":0})}else{k=this.paper.path().attr({stroke:c,fill:c,"stroke-width":"0"})}if(!this.hasBaseLine()){i.unshift([i[0][0],a]);i.push([i[i.length-1][0],a])}}else{k=this.paper.path().attr({stroke:c,"stroke-width":this.options.stroke_width+"px"})}$A(i).each(function(q,n){var m=q[0],p=q[1];if(c instanceof Array){var o=n%c.length;this.drawPlot(n,k,m,p,c[o],i,b,e,g)}else{this.drawPlot(n,k,m,p,c,i,b,e,g)}}.bind(this));if(this.options.area&&this.options.stroke_width>0){l=this.paper.path().attr({stroke:c,"stroke-width":this.options.stroke_width+"px"});i.remove(0);i.remove(-1);$A(i).each(function(p,n){var m=p[0],o=p[1];this.drawPlot(n,l,m,o,c,i,b,e,g,true)}.bind(this));this.globalAreaLineSet.push(l)}if(this.options.datalabels&&this.options.draw_hovers){this.drawHover(k,b,e,c);this.globalHoverSet.toFront()}},calculateCoords:function(e){var b=this.x_padding_left+this.options.plot_padding-this.step,a=(this.graph_height+this.y_padding_top)+this.normalise(this.start_value);var f=$A(e).collect(function(g){b+=this.step;return[b,a-g]}.bind(this));if(!this.hasBaseLine()){return f}b+=this.step;var c=this.getNormalizedBaseLine();for(var d=c.length-1;d>=0;d--){b-=this.step;f.push([b,a-c[d]])}return f},drawFocusHint:function(){var b=5,a=this.x_padding_left+(b/2)-1,d=this.options.height-this.y_padding_bottom,c=this.paper.path().attr({stroke:this.options.label_color,"stroke-width":2});c.moveTo(a,d);c.lineTo(a-b,d-b);c.moveTo(a,d-b);c.lineTo(a-b,d-(b*2))},drawMeanLine:function(a){var c=this.paper.path().attr(this.options.meanline),b=$A(a).inject(0,function(e,d){return d+e})/a.length-0.5;b=this.options.bar?b+(this.zero_value*(this.graph_height/this.y_label_count)):b;c.moveTo(this.x_padding_left-1,this.options.height-this.y_padding_bottom-b).lineTo(this.graph_width+this.x_padding_left,this.options.height-this.y_padding_bottom-b)},drawAxis:function(){var a=this.paper.path().attr({stroke:this.options.label_color});a.moveTo(parseInt(this.x_padding_left,10)-0.5,this.options.height-parseInt(this.y_padding_bottom,10)+0.5);a.lineTo(parseInt(this.graph_width+this.x_padding_left,10)-0.5,this.options.height-parseInt(this.y_padding_bottom,10)+0.5);a.moveTo(parseInt(this.x_padding_left,10)-0.5,parseInt(this.options.height-this.y_padding_bottom,10)+0.5);a.lineTo(parseInt(this.x_padding_left,10)-0.5,parseInt(this.y_padding_top,10))},makeValueLabels:function(a){var d=this.label_step,b=this.start_value,e=[];for(var c=0;c<a;c++){b=this.roundValue((b+d),3);e.push(b)}return e},drawMarkers:function(e,k,b,f,h,c){function d(m){return m*k[0]}function a(m){return m*k[1]}var j=parseInt(this.x_padding_left,10)-0.5+d(f),i=this.options.height-this.y_padding_bottom+a(f),l=this.paper.path().attr({stroke:this.options.label_color}),g={font:this.options.font_size+'px "Arial"',stroke:"none",fill:this.options.label_color};Object.extend(g,c||{});e.each(function(m){if(this.options.draw_axis&&((this.options.hide_empty_label_grid===true&&m!=="")||this.options.hide_empty_label_grid===false)&&this.options.show_ticks){l.moveTo(parseInt(j,10),parseInt(i,10)+0.5);l.lineTo(parseInt(j,10)+a(5),parseInt(i,10)+0.5+d(5))}if(m!==""){this.paper.text(j+h[0],i-2-h[1],m.toString()).attr(g)}j=j+d(b);i=i+a(b)}.bind(this))},drawVerticalLabels:function(){var b=this.graph_height/this.y_label_count;var c=this.options.vertical_label_unit?" "+this.options.vertical_label_unit:"";for(var a=0;a<this.value_labels.length;a++){this.value_labels[a]+=c}this.drawMarkers(this.value_labels,[0,-1],b,b,[-8,-2],{"text-anchor":"end"})},drawHorizontalLabels:function(){var a=this.options.label_rotation?{rotation:this.options.label_rotation,translation:-this.options.font_size+" 0"}:{},c=this.options.labels;if(this.options.label_max_size){for(var b=0;b<c.length;b++){c[b]=c[b].truncate(this.options.label_max_size+1,"â€¦")}}this.drawMarkers(c,[1,0],this.step,this.options.plot_padding,[0,(this.options.font_size+7)*-1],a)},drawHover:function(k,c,e,d){var g=this,b=(this.options.stacked_fill||this.options.area)?"fill":"stroke",f=this.options.hover_color||d,l=this.paper.set(),a=4,j=this.paper.text(k.attrs.x,k.attrs.y-(this.options.font_size*1.5)-a,c).attr({"font-size":this.options.font_size,fill:this.options.hover_text_color,opacity:1}),h=j.getBBox(),i=this.drawRoundRect(j,h,a);l.push(i,j).attr({opacity:0});this.checkHoverPos({rect:i,set:l});this.globalHoverSet.push(l);k.hover(function(n){if(b==="fill"){k.animate({fill:f,stroke:f},200)}else{k.animate({stroke:f},200)}var m=g.getMousePos(n);l[0].attr({x:m.x-(h.width/2)-a-e.offsetLeft,y:m.y-(h.height/2)-(g.options.font_size*1.5)-a-e.offsetTop,opacity:1});l[1].attr({x:m.x-e.offsetLeft,y:m.y-(g.options.font_size*1.5)-e.offsetTop,opacity:1});k.mousemove(function(p){var o=g.getMousePos(p);l[0].attr({x:o.x-(h.width/2)-a-e.offsetLeft,y:o.y-(h.height/2)-(g.options.font_size*1.5)-a-e.offsetTop,opacity:1});l[1].attr({x:o.x-e.offsetLeft,y:o.y-(g.options.font_size*1.5)-e.offsetTop,opacity:1});g.checkHoverPos(i,l)})},function(m){if(b==="fill"){k.animate({fill:d,stroke:d},200)}else{k.animate({stroke:d},200)}l.attr({opacity:0})})},checkHoverPos:function(b){var i,g,e,h,f,d,c,a;if(b.rect){g=b.rect;e=g.getBBox()}if(b.set){h=b.set}if(b.marker){d=b.marker}if(b.nib){c=b.nib}if(b.textpadding){a=b.textpadding}if(g&&h){if(g.attrs.y<0){if(c&&d){f=h.getBBox();h.translate(0,f.height+(a*2));d.translate(0,-f.height-(a*2));c.translate(0,-e.height-a+1.5).scale(1,-1)}else{i=g.attrs.y;h.translate(0,1-i)}}if((g.attrs.y+e.height)>this.options.height){i=(g.attrs.y+e.height)-this.options.height;h.translate(0,-i-1);if(d){d.translate(0,i+1)}}if(g.attrs.x<0){i=g.attrs.x;h.translate(-i+1,0);if(c){c.translate(i-1,0)}if(d){d.translate(i-1,0)}}if((g.attrs.x+e.width)>this.options.width){i=(g.attrs.x+e.width)-this.options.width;h.translate(-i-1,0);if(c){c.translate(i+1,0)}if(d){d.translate(i+1,0)}}}},drawNib:function(b,a,c){return this.paper.path().attr({fill:this.options.label_color,opacity:1,stroke:this.options.label_color,"stroke-width":"0px"}).moveTo(b.attrs.x-c,b.attrs.y+(a.height/2)+c-1).lineTo(b.attrs.x,b.attrs.y+(a.height/2)+(c*2)).lineTo(b.attrs.x+c,b.attrs.y+(a.height/2)+c-1).andClose()},drawRoundRect:function(b,a,c){return this.paper.rect(b.attrs.x-(a.width/2)-c,b.attrs.y-(a.height/2)-c,a.width+(c*2),a.height+(c*2),c*1.5).attr({fill:this.options.label_color,opacity:1,stroke:this.options.label_color,"stroke-width":"0px"})}});Array.prototype.sum=function(){for(var a=0,b=0;a<this.length;b+=this[a++]){}return b};if(typeof Array.prototype.max==="undefined"){Array.prototype.max=function(){return Math.max.apply({},this)}}if(typeof Array.prototype.min==="undefined"){Array.prototype.min=function(){return Math.min.apply({},this)}}Array.prototype.mean=function(){return this.sum()/this.length};Array.prototype.variance=function(){var a=this.mean(),b=0;for(var c=0;c<this.length;c++){b+=Math.pow(this[c]-a,2)}return b/(this.length-1)};Array.prototype.standard_deviation=function(){return Math.sqrt(this.variance())};Array.prototype.remove=function(c,b){var a=this.slice((b||c)+1||this.length);this.length=c<0?this.length+c:c;return this.push.apply(this,a)};Raphael.el.isAbsolute=true;Raphael.el.absolutely=function(){this.isAbsolute=1;return this};Raphael.el.relatively=function(){this.isAbsolute=0;return this};Raphael.el.moveTo=function(a,b){this._last={x:a,y:b};return this.attr({path:this.attrs.path+["m","M"][+this.isAbsolute]+parseFloat(a)+" "+parseFloat(b)})};Raphael.el.lineTo=function(a,b){this._last={x:a,y:b};return this.attr({path:this.attrs.path+["l","L"][+this.isAbsolute]+parseFloat(a)+" "+parseFloat(b)})};Raphael.el.cplineTo=function(a,c,b){if(a>this._last.x){this.attr({path:this.attrs.path+["C",this._last.x+b,this._last.y,a-b,c,a,c]})}else{if(a==this._last.x){this.lineTo(a,c)}else{this.attr({path:this.attrs.path+["C",this._last.x-b,this._last.y,a+b,c,a,c]})}}this._last={x:a,y:c};return this};Raphael.el.andClose=function(){return this.attr({path:this.attrs.path+"z"})};"use strict";Grafico.LineGraph=Class.create(Grafico.BaseGraph,{chartDefaults:function(){return{line:true,start_at_zero:true,stroke_width:5,curve_amount:10}},setChartSpecificOptions:function(){},calculateStep:function(){return(this.graph_width-(this.options.plot_padding*2))/(this.data_size-1)},startPlot:function(c,a,d,b){c.moveTo(a,d)},drawPlot:function(e,i,h,f,b,g,a,c,d){if(e===0){return this.startPlot(i,h-0.5,f,b)}if(this.options.curve_amount){i.cplineTo(h,f,this.options.curve_amount)}else{i.lineTo(h,f)}if(this.options.markers==="circle"){this.drawGraphMarkers(e,h,f,b,a,c)}else{if(this.options.markers==="value"){this.drawGraphValueMarkers(e,h,f,b,a,c,d)}}},drawGraphMarkers:function(e,h,f,c,b,d){var a=this.paper.circle(h,f,this.options.marker_size),g=this.options.marker_size,i=this.options.hover_color||c,j=parseInt(1.7*g,10);a.attr({"stroke-width":"1px",stroke:this.options.background_color,fill:c});this.globalMarkerSet.push(a);a.hover(function(k){a.animate({r:j,fill:i},200)},function(k){a.animate({r:g,fill:c},200)})},drawGraphValueMarkers:function(h,m,k,r,t,d,q){h+=this.options.odd_horizontal_offset>1?this.options.odd_horizontal_offset:0;h-=this.options.stacked_fill||this.options.area?1:0;var u=this.options.stacked?this.real_data:this.data_sets,e=u.collect(function(v){return v[1][h]})[q];if(e){e=""+e.toString().split(".");if(e[1]){e[1]=e[1].truncate(3,"")}}if((this.options.line||this.options.stacked)||((this.options.stacked_fill||this.options.area)&&h!=-1)&&typeof e!="undefined"){var b=m-(this.step/2),a=this.options.stacked?k-(this.graph_height/18):k-(this.graph_height/6),c=this.step,l=this.options.stacked?this.graph_height/9:this.graph_height/3,g=this.paper.circle(m,k,this.options.marker_size).attr({"stroke-width":"1px",stroke:this.options.background_color,fill:r,opacity:0}),i=this.paper.rect(b,a,c,l).attr({fill:r,"stroke-width":0,stroke:r,opacity:0});if(this.options.datalabels){if(typeof(t)=="function"){t=t.call(this,h,e)}else{t=t+": "+e}}else{t=""+e}t+=this.options.vertical_label_unit?" "+this.options.vertical_label_unit:"";var j=this.paper.set(),f=4,o=this.paper.text(g.attrs.cx,g.attrs.cy-(this.options.font_size*1.5)-2*f,t).attr({"font-size":this.options.font_size,fill:this.options.hover_text_color,opacity:1}),p=o.getBBox(),s=this.drawRoundRect(o,p,f),n=this.drawNib(o,p,f);j.push(g,s,n,o).attr({opacity:0});this.checkHoverPos({rect:s,set:j,marker:g,nib:n,textpadding:f});this.globalHoverSet.push(j);this.globalBlockSet.push(i);i.hover(function(v){j.animate({opacity:1},200)},function(v){j.animate({opacity:0},200)})}}});Grafico.AreaGraph=Class.create(Grafico.LineGraph,{chartDefaults:function(){return{area:true,area_opacity:false,stroke_width:0,curve_amount:10}},drawPlot:function(f,k,j,h,c,i,b,d,e,g){var a=this.options.area||this.options.stacked_fill;if(!g){if(a===true){if(f!==0&&f!==i.length-1){if(this.options.markers==="circle"){this.drawGraphMarkers(f,j,h,c,b,d)}else{if(this.options.markers==="value"){this.drawGraphValueMarkers(f,j,h,c,b,d,e)}}}}else{if(this.options.markers==="circle"){this.drawGraphMarkers(f,j,h,c,b,d)}else{if(this.options.markers==="value"){this.drawGraphValueMarkers(f,j,h,c,b,d,e)}}}}j-=0.5;if(f===0){return this.startPlot(k,j,h,c)}if(this.options.curve_amount&&f>1&&(f<i.length-1)){k.cplineTo(j,h,this.options.curve_amount)}else{if(this.options.curve_amount&&!a&&(f=1||(f=i.length-1))){k.cplineTo(j,h,this.options.curve_amount)}else{k.lineTo(j,h)}}}});Grafico.StackGraph=Class.create(Grafico.AreaGraph,{chartDefaults:function(){return{stacked:true,stacked_fill:true,stroke_width:0,curve_amount:10}},setChartSpecificOptions:function(){if(!this.options.stacked_fill){this.options.stroke_width=5}},stackData:function(a){var d=a.collect(function(e){return e[1]});for(var c=d.length-2;c>=0;c--){for(var b=0;b<d[0].length;b++){d[c][b]+=d[c+1][b]}}return a}});Grafico.StreamGraph=Class.create(Grafico.StackGraph,{chartDefaults:function(){return{stacked:true,stacked_fill:true,stroke_width:5,grid:false,draw_axis:false,show_horizontal_labels:false,show_vertical_labels:false,stream:true,stream_line_smoothing:false,stream_smart_insertion:false,curve_amount:4,stream_label_threshold:0}},hasBaseLine:function(){return true},calcBaseLine:function(a){var c=a.collect(function(g){return g[1]});var b=[],e,d;for(d=0;d<c[0].length;d++){sum=0;for(e=0;e<c.length;e++){if(this.options.stream_line_smoothing==false){sum+=c[e][d]}else{sum+=(e+1)*c[e][d]}}if(this.options.stream_line_smoothing==false){b[d]=-sum/2}else{b[d]=-sum/(c.length+1)}}var f=b.min();for(e=0;e<b.length;e++){b[e]-=f}this.base_line=b},stackData:function(a){var f,d;if(this.options.stream_smart_insertion){a=$A(a);a.each(function(h){f=0;while(f<h[1].length&&h[1][f]<=1e-7){f++}h[2]=f});var e=a.sortBy(function(h){return h[2]});var b=[];var c=false;e.each(function(h){if(c){b.push(h)}else{b.unshift(h)}c=!c});a=$H();b.each(function(h){a.set(h[0],h[1])})}this.real_data=this.deepCopy(a);this.calcBaseLine(a);var g=a.collect(function(h){return h[1]});for(d=0;d<g[0].length;d++){g[g.length-1][d]+=this.base_line[d]}for(f=g.length-2;f>=0;f--){for(d=0;d<g[0].length;d++){g[f][d]+=g[f+1][d]}}return a},drawPlot:function(g,l,k,i,c,j,b,d,f,h){if(this.options.datalabels&&!h){var a=this.getNormalizedRealData();var e=this.bestMarkerPositions();if(g<j.length/2){if(e[f]>=g&&e[f]<g+1){this.drawStreamMarker(g+1,k+(e[f]-g)*this.step,i+a[f][g]/2,c,b,d)}}}k-=0.5;if(g===0){return this.startPlot(l,k,i,c)}l.cplineTo(k,i,this.options.curve_amount)},bestMarkerPositions:function(){if(this.best_marker_positions==undefined){this.best_marker_positions=this.real_data.collect(function(e){var d=-1,a=0,f=0;for(var b=0;b<e[1].length;b++){var c=e[1][b];if(c>a&&c>=this.options.stream_label_threshold){a=c;d=b;f=0}else{if(c==a&&a>0){f++}}}return d+f/2}.bind(this))}return this.best_marker_positions},drawStreamMarker:function(e,i,h,c,b,d,f){if(this.options.datalabels){var l=this.paper.set(),a=4,k=this.paper.text(i,h-2*a+this.options.font_size/2,b).attr({"font-size":this.options.font_size,fill:this.options.hover_text_color,opacity:1}),g=k.getBBox(),j=this.drawRoundRect(k,g,a);l.push(j,k);this.checkHoverPos({rect:j,set:l,textpadding:a});this.globalHoverSet.push(l)}}});"use strict";Grafico.BarGraph=Class.create(Grafico.BaseGraph,{chartDefaults:function(){return{bar:true,plot_padding:0,bargraph_lastcolor:false,bargraph_negativecolor:false}},normaliserOptions:function(){return{start_value:0,bar:true}},setChartSpecificOptions:function(){this.bar_padding=5;this.bar_width=this.calculateBarWidth();this.options.plot_padding=(this.bar_width/2);this.step=this.calculateStep();this.grid_start_offset=this.bar_padding-1},calculateBarWidth:function(){return(this.graph_width/this.data_size)-this.bar_padding},calculateStep:function(){this.data_size=this.data_size===1?2:this.data_size;return(this.graph_width-(this.options.plot_padding*2)-(this.bar_padding*2))/(this.data_size-1)},drawPlot:function(e,l,i,g,b,h,a,c){var j=this.options.height-this.y_padding_bottom-(this.zero_value*(this.graph_height/this.y_label_count)),d=this.options.bargraph_lastcolor,f=this.options.bargraph_negativecolor||b,k;i=i+this.bar_padding;g=this.options.height-this.y_padding_bottom-g-(this.zero_value*(this.graph_height/this.y_label_count));if(d&&e===h.length-1){k=d}else{k=g<0?f:b}var m=this.paper.rect(i-(this.bar_width/2),j,this.bar_width,g).attr({fill:k,"stroke-width":this.options.stroke_width,stroke:k,"stroke-opacity":0});if(g<0){m.attr({height:-m.attrs.height})}else{m.translate(0,-g)}if(this.options.datalabels){this.drawGraphValueMarkers(i,e,m,a,k)}i=i+this.step;this.options.count++},drawHorizontalLabels:function(){var b=this.bar_padding+this.options.plot_padding,a=this.options.label_rotation?{rotation:this.options.label_rotation,translation:-this.options.font_size+" 0"}:{},d=this.options.labels;if(this.options.label_max_size){for(var c=0;c<d.length;c++){d[c]=d[c].truncate(this.options.label_max_size+1,"â€¦")}}this.drawMarkers(this.options.labels,[1,0],this.step,b,[0,(this.options.font_size+7)*-1],a)},drawGrid:function(){var e=this.paper.path().attr({stroke:this.options.grid_color,"stroke-width":1}),f=this.graph_height+this.y_padding_top,a,b,d;if(!this.options.horizontalbar){if(this.options.show_horizontal_grid){for(var c=0;c<this.y_label_count+1;c++){e.moveTo(this.x_padding_left-0.5,parseInt(f,10)+0.5);e.lineTo(this.x_padding_left+this.graph_width-0.5,parseInt(f,10)+0.5);f=f-(this.graph_height/this.y_label_count)}}}else{e.moveTo(this.x_padding_left-0.5,parseInt(f,10)+0.5);e.lineTo(this.x_padding_left+this.graph_width-0.5,parseInt(f,10)+0.5);f-=this.graph_height;e.moveTo(this.x_padding_left-0.5,parseInt(f,10)+0.5);e.lineTo(this.x_padding_left+this.graph_width-0.5,parseInt(f,10)+0.5)}if(this.options.horizontalbar){a=this.x_padding_left+this.options.plot_padding+this.grid_start_offset;b=this.y_label_count;d=this.options.horizontalbar?this.graph_width/this.y_label_count:this.step;for(c=0;c<b;c++){if((this.options.hide_empty_label_grid===true&&this.options.labels[c]!=="")||this.options.hide_empty_label_grid===false){e.moveTo(parseInt(a,10)+0.5,this.y_padding_top);e.lineTo(parseInt(a,10)+0.5,this.y_padding_top+this.graph_height)}a=a+d}}e.moveTo(parseInt(this.x_padding_left,10)-0.5,this.y_padding_top);e.lineTo(parseInt(this.x_padding_left,10)-0.5,this.y_padding_top+this.graph_height);e.moveTo(parseInt(this.x_padding_left+this.graph_width,10)-0.5,this.y_padding_top);e.lineTo(parseInt(this.x_padding_left+this.graph_width,10)-0.5,this.y_padding_top+this.graph_height)},drawGraphValueMarkers:function(i,f,m,c,d){var e=this.options.hover_color||d,l=this.paper.set(),k,h=this.paper.rect(i-(this.bar_width/2),this.y_padding_top,this.bar_width,this.options.height);c=c?c[f].toString():"";k=this.paper.text(m.attrs.x+(this.bar_width/2),m.attrs.y-(this.options.font_size*1.5),c);h.attr({fill:d,"stroke-width":0,stroke:d,opacity:0});k.attr({"font-size":this.options.font_size,fill:this.options.hover_text_color,opacity:1});var g=k.getBBox(),a=4,j=this.drawRoundRect(k,g,a),b=this.drawNib(k,g,a);l.push(j,b,k).attr({opacity:0});this.checkHoverPos({rect:j,set:l,nib:b});this.globalHoverSet.push(l);this.globalBlockSet.push(h);if(j.attrs.y<0){l.translate(0,1+(j.attrs.y*-1))}h.hover(function(n){m.animate({fill:e,stroke:e},200);l.animate({opacity:1},200)},function(n){m.animate({fill:d,stroke:d},200);l.animate({opacity:0},200)})}});Grafico.StackedBarGraph=Class.create(Grafico.BarGraph,{chartDefaults:function(){return{opacity:100,bar:true,plot_padding:0,stacked:true,stacked_fill:true}},setChartSpecificOptions:function(){this.bar_padding=5;this.bar_width=this.calculateBarWidth();this.options.plot_padding=(this.bar_width/2);this.step=this.calculateStep();this.grid_start_offset=this.bar_padding-1;this.options.stroke_width=1},stackData:function(a){var d=a.collect(function(e){return e[1]});for(var c=d.length-2;c>=0;c--){for(var b=0;b<d[0].length;b++){d[c][b]+=d[c+1][b]}}return a},calculateCoords:function(e){var b=this.x_padding_left+this.options.plot_padding-this.step,a=(this.graph_height+this.y_padding_top)+this.normalise(this.start_value);var f=$A(e).collect(function(g){b+=this.step;return[b,a-g]}.bind(this));b+=this.step;var c=this.getNormalizedBaseLine();for(var d=c.length-1;d>=0;d--){b-=this.step;f.push([b,a-c[d]])}return f},drawLines:function(j,c,d,b,e,g){var i=this.calculateCoords(d),a=(this.graph_height+this.y_padding_top),k,l,f,h;k=this.paper.path().attr({stroke:c,"stroke-width":0});$A(i).each(function(p,n){var m=p[0],o=p[1];this.drawPlot(n,k,m,o,c,i,b,e,g)}.bind(this));if(this.options.datalabels&&this.options.draw_hovers){this.drawHover(k,b,e,c);this.globalHoverSet.toFront()}},drawPlot:function(f,l,i,g,b,h,a,d,e){var j=this.options.height-this.y_padding_bottom-(this.zero_value*(this.graph_height/this.y_label_count)),k=b;i=i+this.bar_padding;g=this.options.height-this.y_padding_bottom-g-(this.zero_value*(this.graph_height/this.y_label_count));var c={fill:k,"stroke-width":0,stroke:this.options.color2,opacity:this.options.opacity};var m=this.paper.rect(i-(this.bar_width/2),j,this.bar_width,g).attr(c);if(g<0){m.attr({height:-m.attrs.height})}else{m.translate(0,-g)}if(this.options.datalabels){this.drawGraphValueMarkers(i,f,m,a,k)}i=i+this.step;this.options.count++},drawGraphValueMarkers:function(m,h,q,c,e){var i=m-(this.bar_width/2),g=q.attrs.y,j=this.bar_width,d=q.attrs.height;var f=this.options.hover_color||e,p=this.paper.set(),o,l=this.paper.rect(i,g,j,d);c=c&&c.length>h?c[h].toString():"";o=this.paper.text(q.attrs.x+(this.bar_width/2),q.attrs.y-(this.options.font_size*1.5),c);l.attr({fill:e,"stroke-width":0,stroke:e,opacity:0});o.attr({"font-size":this.options.font_size,fill:this.options.hover_text_color,opacity:1});var k=o.getBBox(),a=4,n=this.drawRoundRect(o,k,a),b=this.drawNib(o,k,a);p.push(n,b,o).attr({opacity:0});this.checkHoverPos({rect:n,set:p,nib:b});this.globalHoverSet.push(p);this.globalBlockSet.push(l);if(n.attrs.y<0){p.translate(0,1+(n.attrs.y*-1))}l.hover(function(r){q.animate({fill:f},200);p.animate({opacity:1},200)},function(r){q.animate({fill:e},200);p.animate({opacity:0},200)})}});Grafico.HorizontalBarGraph=Class.create(Grafico.BarGraph,{chartDefaults:function(){return{bar:true,horizontalbar:true,plot_padding:0,horizontal_rounded:false,bargraph_lastcolor:false}},setChartSpecificOptions:function(){this.x_padding_left=20+this.longestLabel()*(this.options.font_size/2);this.bar_padding=5;this.bar_width=this.calculateBarHeight();this.step=this.calculateStep();this.graph_width=this.options.width-this.x_padding_right-this.x_padding_left},normalise:function(b){var a=this.makeValueLabels(this.y_label_count);a=a[a.length-1];return((b/a)*this.graph_width)},longestLabel:function(){return $A(this.options.labels).sort(function(d,c){return d.toString().length<c.toString().length}).first().toString().length},calculateBarHeight:function(){return(this.graph_height/this.data_size)-this.bar_padding},calculateStep:function(){return(this.graph_height-(this.options.plot_padding*2))/this.data_size},drawLines:function(k,b,d,a,e,g){var i=this.y_padding_top+(this.bar_padding/2)-0.5,c=this.zero_value*(this.graph_width/this.y_label_count),j=this.x_padding_left+c-0.5,f=this.options.bargraph_lastcolor,h=this.options.bargraph_negativecolor||b;this.datalabel=a;$A(d).each(function(v,r){var x,p=this.options.horizontal_rounded?this.bar_width/2:0,A;if(f&&r===d.length-1){x=f}else{x=v<0?h:b}v=v/this.graph_width*(this.graph_width-c);A=this.paper.rect(j,i,v,this.bar_width,p).attr({fill:x,"stroke-width":0,stroke:x,"stroke-opacity":0});if(v<0){A.attr({width:-A.attrs.width}).translate(v,0)}if(p){var s=this.paper.set(),n=this.paper.rect(j,i,v-this.bar_width/2,this.bar_width).attr({fill:x,"stroke-width":0,stroke:x,"stroke-opacity":0});s.push(n,A);if(v<0){n.attr({width:-n.attrs.width-this.bar_width}).translate(v+this.bar_width/2,0)}}if(this.options.datalabels){var q=this.options.hover_color||x,z=this.paper.set(),o=this.datalabel[r].toString(),y=this.paper.text(c+v+this.x_padding_left/2,A.attrs.y-(this.options.font_size*1.5),o).attr({"font-size":this.options.font_size,fill:this.options.hover_text_color,opacity:1}),u=this.paper.rect(this.x_padding_left,i,this.graph_width,this.bar_width).attr({fill:x,"stroke-width":0,stroke:x,opacity:0}),t=y.getBBox();if(v<0){y.translate(t.width,0)}var l=4,w=this.drawRoundRect(y,t,l),m=this.drawNib(y,t,l);z.push(w,m,y).attr({opacity:0});this.checkHoverPos({rect:w,set:z,nib:m});this.globalHoverSet.push(z);this.globalBlockSet.push(u);if(w.attrs.y<0){z.translate(0,1-w.attrs.y)}u.hover(function(B){if(p){s.animate({fill:q,stroke:q},200)}else{A.animate({fill:q,stroke:over_color},200)}z.animate({opacity:1},200)},function(B){if(p){s.animate({fill:x,stroke:x},200)}else{A.animate({fill:x,stroke:x},200)}z.animate({opacity:0},200)})}i=i+this.step}.bind(this))},drawFocusHint:function(){var b=5,a=this.x_padding_left+b*2,c=this.options.height-this.y_padding_bottom-b/2;this.paper.path().attr({stroke:this.options.label_color,"stroke-width":2}).moveTo(a,c).lineTo(a-b,c+b).moveTo(a-b,c).lineTo(a-(b*2),c+b)},drawVerticalLabels:function(){var c=(this.step/2),a=this.options.label_rotation?{"text-anchor":"end",rotation:this.options.label_rotation,translation:"0 "+this.options.font_size/2}:{"text-anchor":"end"},d=this.options.labels;if(this.options.label_max_size){for(var b=0;b<d.length;b++){d[b]=d[b].truncate(this.options.label_max_size+1,"â€¦")}}this.drawMarkers(this.options.labels.reverse(),[0,-1],this.step,c,[-8,-(this.options.font_size/5)],a)},drawHorizontalLabels:function(){var c=this.graph_width/this.y_label_count,a=this.makeValueLabels(this.y_label_count);if(this.options.vertical_label_unit){for(var b=0;b<a.length;b++){a[b]+=this.options.vertical_label_unit}}this.drawMarkers(a,[1,0],c,c,[0,(this.options.font_size+7)*-1])},drawMeanLine:function(a){var b=$A(a).inject(0,function(d,c){return c+d})/a.length;b=this.options.bar?b+(this.zero_value*(this.graph_height/this.y_label_count)):b;this.paper.path().attr(this.options.meanline).moveTo(this.x_padding_left-1+b,this.y_padding_top).lineTo(this.x_padding_left-1+b,this.y_padding_top+this.graph_height)}});