!function(a){a.fn.extend({cssCharts:function(c){var d={};return c=a.extend(d,c),this.each(function(){"bar"==c.type?b.bar(this):"line"==c.type?b.line(this):"donut"==c.type?b.donut(this):"pie"==c.type?b.pie(this):a(this).parent().hide()})}});var b={pie:function(b){var c=function(b,c,d,f,g,h){var i=a(document.createElementNS("http://www.w3.org/2000/svg",b)),k=a(document.createElementNS("http://www.w3.org/2000/svg","g")),l=a("
");l.find("p").html(f+": "+d),l.find("i").css({background:h}),e.find("."+j.attr("class")).append(l);for(var m in c)i.attr(m,c[m]).attr("data-val",d).attr("data-title",f).attr("id","path"+g).attr("class","path"),k.append(i).attr("id","pathCont"+g).attr("class","pathCont");return k[0]},d=function(b,d){var f=[],h=[];a.each(d,function(a,b){h.push(b[1]),f.push(b[0])}),d=h;for(var i=d.reduce(function(a,b){return b+a},0),j=d.map(function(a){return 360*a/i}),k=-90,l=-90,m=0;m180?1:0)+",1 "+o+","+q+" z",s=function(a,b){return parseInt(Math.random()*(b-a+1),10)+a},t=function(){var a;if(g)a=g[m];else{var b=s(10,60),c=s(20,100),d=s(30,60);a="hsl("+b+","+c+"%,"+d+"%)"}return a};parseInt(360*(m/j.length));var v=t(),w=c("path",{d:r,fill:v},d[m],f[m],m,v);b.prepend(w),e.prepend(b)}},e=a(b),f=a(b).attr("data-set"),g=a(b).attr("data-colors");g&&(g=g.split(","));var h=JSON.parse(f),i=a(''),j=a('');e.append(j),e.parent().addClass("pie"),d(i,h);var k={x:-1,y:-1};!function(){var b=a('');e.mousemove(function(c){k.x=c.pageX,k.y=c.pageY;var d=a(c.target).clone(),f=a(c.target).parent().clone(),g=e.find(".pathCont:last-child .path:last-child"),h=d.attr("data-val"),i=d.attr("data-title");d.attr("id");var l=d.attr("fill");h&&(b.css({left:k.x,top:k.y}),function(){a("body").find("."+b.attr("class")).remove(),b.html(i+": "+h),a("body").append(b)}(),l&&a(c.target).attr("stroke",l),function(){var a=g.attr("id"),b=d.attr("id");a!==b&&(e.find("#"+d.attr("id")).parent().remove(),e.find(".svg").append(f))}())}),e.mouseleave(function(){a("body").find("."+b.attr("class")).remove()})}()},donut:function(b){var c=a(b),d=a(b).attr("data-percent"),e=a(b).attr("data-title");if(c.parent().addClass("donut"),e||(e="%"),d>1||0>d)return"between 0 - 1 please";var f=180,g=360;d=parseFloat(d).toFixed(2)*g;var h=a("").addClass("pie spinner"),i=a("");i.find("p").text(100*(d/360)),i.find("span").text(e),c.on("show-donut-chart",function(){i.find("p").text(0),a({countNum:i.find("p").text()}).animate({countNum:100*(d/360)},{duration:500,easing:"linear",step:function(){i.find("p").text(Math.floor(this.countNum))},complete:function(){i.find("p").text(this.countNum)}}),c.on("hide-donut-chart",function(){i.find("p").text(0)})}),c.append(i);var l,m,n,j={nodes:{spinner:function(){return h.clone().attr("style","-webkit-transform: rotate("+j.values.spinner+"deg);"+"-moz-transform: rotate("+j.values.spinner+"deg);"+"transform: rotate("+j.values.spinner+"deg);")},mask:function(){return h.clone().addClass(j.values.selector).attr("style","-webkit-transform: rotate("+j.values.mask+"deg);"+"-moz-transform: rotate("+j.values.mask+"deg);"+"transform: rotate("+j.values.mask+"deg);")}},values:{spinner:d,mask:g,selector:""}},k=function(b){a.each(b,function(a,b){c.prepend(b())})};f>d?(m=d,l=jQuery.extend({},j),l.values.spinner=m,l.values.selector="mask",k(l.nodes)):(n=d-f,m=d-n,n+=f,l=jQuery.extend({},j),l.values.spinner=m,l.values.mask=n,k(l.nodes))},bar:function(b){var c=a(b);c.parent().addClass("bar");var d=c.attr("data-bars"),e=c.attr("data-unit"),f=c.height(),g=c.attr("data-grid"),h=c.attr("data-width"),i=c.attr("data-max");if(0===parseInt(g,10)&&c.css("background","none"),!d)return"No data to work with";e||(e="%");var j=function(){var a=JSON.parse("["+d+"]");return Math.max.apply(Math,a.map(function(a){return a[0]}))};(j()>i||!i)&&(i=j()),d=JSON.parse("[["+d+"]]"),d[0].length,a.each(d,function(b,g){var j=a(""),k=a("").height(f);for(b=0;b");c.parent().append(l);for(var m=0;10>=m;m++){var n=(10*m).toFixed(0),o=i/100,p=(n*o).toFixed(0);if(0===m%2){var q=a("
").css({bottom:n+"%"}).attr("data-y",p+e);c.parent().find(".grid").append(q)}}c.parent().width(c.width())},line:function(b){var c=function(b,c){var d=a(c).clone();return d.find("a").attr("data-x",b.x).attr("data-y",b.y),d},d=function(b,c){x=100*(c.x/o.maxX)+"%",y=100*(c.y/p)+"%",c.x=c.x+"px",c.y=c.y+"px",a("ul").find(b).css("left",x),a("ul").find(b).css("bottom",y)},e=function(b,c){var d=[],e=[];return a.each(c,function(b){a.each(c[b][1],function(a,b){d.push(b)}),a.each(c[b][0],function(a,b){e.push(b)})}),maxY=Math.max.apply(Math,d)+20,maxX=Math.max.apply(Math,e)+20,d=maxY,e=b.parent().width(),b.parent().css({width:e,height:d}),b.parent().addClass("line"),{width:e,height:d,maxX:maxX,maxY:maxY}},f=function(a){var c=a.slice(0),d=c.shift(),e=0,f=0,g=null,h=[];for(e=0;e'),g.addClass(".p"+e),2==b&&g.addClass("fill"),h.parent().append(g));var i=f(c,d),j=0,k=function(a,c,d){var e;if("last"==d){var f=Object.keys(a).length-1;e=" L"+a[f].x+","+a[f].x+" L"+0+","+a[f].x+" Z"}else{var i=Math.floor(a[c].x),j=Math.floor(a[c].y);e=(d?"M":" ")+i+","+j}h.parent().find(g).find("path").attr("d",h.parent().find(g).find("path").attr("d")+""+e),c++,c");h.parent().append(j),a('');var m="["+h.attr("data-cord")+"]",n=h.attr("data-cord");n=JSON.parse("["+n+"]"),2!==n[0].length&&(n=JSON.parse("["+m+"]"));var o=e(h,n),p=o.height,q=o.width,r=function(b,e,f){for(var j=0;j"));if(h.append(k),d(k,n),0===j%2){var l=f/10,m=a("
").css({bottom:j*l}).attr("data-y",j*l);h.parent().find(".grid").append(m)}}g(1,e,f,b),i&&g(2,e,f,b)};a.each(n,function(a,b){r(a,b,p)})}}}(jQuery);