angular.module("angularCharts",["angularChartsTemplates"]),angular.module("angularCharts").directive("acChart",["$templateCache","$compile","$rootElement","$window","$timeout","$sce",function(a,b,c,d,e,f){function g(){var a=(Math.round(127*Math.random())+127).toString(16),b=(Math.round(127*Math.random())+127).toString(16),c=(Math.round(127*Math.random())+127).toString(16);return"#"+a+b+c}function h(a,b){var c=null;for(var d in a)if(angular.isElement(a[d])&&(c=angular.element(a[d]),c.hasClass(b)))return c;return c}function i(c,i){function k(){if(l()){p(),m(),n();var a=q(O);a(),A()}}function l(){if(G&&F)return!0;if(E.waitForHeightAndWidth)return!1;throw new Error("Please set height and width for the chart element")}function m(){if(!E.legend.display)return K=G,void(L=F);switch(E.legend.position){case"top":case"bottom":K=.75*G,L=F;break;case"left":case"right":K=G,L=.75*F}}function n(){var d=a.get("angularChartsTemplate_"+E.legend.position);i.html(d),b(i.contents())(c);var e=i.find("div");M=h(e,"ac-chart"),N=h(e,"ac-legend"),K-=h(e,"ac-title")[0].clientHeight}function o(){c.acConfig&&angular.extend(E,c.acConfig)}function p(){H=c.acData,O=c.acChart,I=H?H.series||[]:[],J=H?H.data||[]:[]}function q(a){var b={pie:v,bar:s,line:t,area:u,point:w};return b[a]}function r(a,b){var c=b.domain();if(E.xAxisMaxTicks&&c.length>E.xAxisMaxTicks){var d=Math.ceil(c.length/E.xAxisMaxTicks);a.tickValues(c.filter(function(a,b){return b%d===0}))}}function s(){var a={top:0,right:20,bottom:30,left:40};L-=a.left+a.right,K-=a.top+a.bottom;var b=d3.scale.ordinal().rangeRoundBands([0,L],.1),d=d3.scale.linear().range([K,10]),e=d3.scale.ordinal().rangeRoundBands([0,L],.1),f=[0];J.forEach(function(a){a.nicedata=a.y.map(function(b,c){return f.push(b),{x:a.x,y:b,s:c,tooltip:angular.isArray(a.tooltip)?a.tooltip[c]:a.tooltip}})});var g=d3.max(J.map(function(a){return a.y.length}));c.yMaxData=g,b.domain(J.map(function(a){return a.x}));var h=.2*d3.max(f);d.domain([d3.min(f),d3.max(f)+h]),e.domain(d3.range(g)).rangeRoundBands([0,b.rangeBand()]);var i=d3.svg.axis().scale(b).orient("bottom");r(i,b);var j=d3.svg.axis().scale(d).orient("left").ticks(10).tickFormat(d3.format(E.yAxisTickFormat)),k=d3.select(M[0]).append("svg").attr("width",L+a.left+a.right).attr("height",K+a.top+a.bottom).append("g").attr("transform","translate("+a.left+","+a.top+")");k.append("g").attr("class","x axis").attr("transform","translate(0,"+K+")").call(i),k.append("g").attr("class","y axis").call(j);var l=k.selectAll(".state").data(J).enter().append("g").attr("class","g").attr("transform",function(a){return"translate("+b(a.x)+",0)"}),m=l.selectAll("rect").data(function(a){return a.nicedata}).enter().append("rect");m.attr("width",e.rangeBand()),m.attr("x",function(a,b){return e(b)}).attr("y",K).style("fill",function(a){return D(a.s)}).attr("height",0).transition().ease("cubic-in-out").duration(E.isAnimate?1e3:0).attr("y",function(a){return d(Math.max(0,a.y))}).attr("height",function(a){return Math.abs(d(a.y)-d(0))}),m.on("mouseover",function(a){x({index:a.x,value:a.tooltip?a.tooltip:a.y,series:I[a.s]},d3.event),E.mouseover(a,d3.event),c.$apply()}).on("mouseleave",function(a){y(),E.mouseout(a,d3.event),c.$apply()}).on("mousemove",function(a){z(a,d3.event)}).on("click",function(a){E.click.call(a,d3.event),c.$apply()}),E.labels&&l.selectAll("not-a-class").data(function(a){return a.nicedata}).enter().append("text").attr("x",function(a,b){return e(b)}).attr("y",function(a){return K-Math.abs(d(a.y)-d(0))}).text(function(a){return a.y}),k.append("line").attr("x1",L).attr("y1",d(0)).attr("y2",d(0)).style("stroke","silver")}function t(){function a(a){return Math.round(d(a))+d.rangeBand()/2}var b={top:0,right:40,bottom:20,left:40};L-=b.left+b.right,K-=b.top+b.bottom;var d=d3.scale.ordinal().domain(J.map(function(a){return a.x})).rangeRoundBands([0,L]),e=d3.scale.linear().range([K,10]),f=d3.svg.axis().scale(d).orient("bottom");r(f,d);var g=d3.svg.axis().scale(e).orient("left").ticks(5).tickFormat(d3.format(E.yAxisTickFormat)),h=d3.svg.line().interpolate(E.lineCurveType).x(function(b){return a(b.x)}).y(function(a){return e(a.y)}),i=[0],j=[];J.forEach(function(a){a.y.map(function(a){i.push(a)})});var k=d3.max(J.map(function(a){return a.y.length}));c.yMaxData=k,I.slice(0,k).forEach(function(a,b){var c={};c.series=a,c.values=J.map(function(a){return a.y.map(function(b){return{x:a.x,y:b,tooltip:a.tooltip}})[b]||{x:J[b].x,y:0}}),j.push(c)});var l=d3.select(M[0]).append("svg").attr("width",L+b.left+b.right).attr("height",K+b.top+b.bottom).append("g").attr("transform","translate("+b.left+","+b.top+")"),m=.2*d3.max(i);e.domain([d3.min(i),d3.max(i)+m]),l.append("g").attr("class","x axis").attr("transform","translate(0,"+K+")").call(f),l.append("g").attr("class","y axis").call(g);var n=l.selectAll(".points").data(j).enter().append("g"),o=n.attr("points","points").append("path").attr("class","ac-line").style("stroke",function(a,b){return D(b)}).attr("d",function(a){return h(a.values)}).attr("stroke-width","2").attr("fill","none");if(j.length>0){var p=j[j.length-1].values;if(p.length>0){var q=o.node().getTotalLength()+a(p[p.length-1].x);o.attr("stroke-dasharray",q+" "+q).attr("stroke-dashoffset",q).transition().duration(E.isAnimate?1500:0).ease("linear").attr("stroke-dashoffset",0).attr("d",function(a){return h(a.values)})}}return angular.forEach(j,function(b){var d=l.selectAll(".circle").data(b.values).enter();d.append("circle").attr("cx",function(b){return a(b.x)}).attr("cy",function(a){return e(a.y)}).attr("r",3).style("fill",D(j.indexOf(b))).style("stroke",D(j.indexOf(b))).on("mouseover",function(a){return function(b){x({index:b.x,value:b.tooltip?b.tooltip:b.y,series:a},d3.event),E.mouseover(b,d3.event),c.$apply()}}(b.series)).on("mouseleave",function(a){y(),E.mouseout(a,d3.event),c.$apply()}).on("mousemove",function(){z(d3.event)}).on("click",function(a){E.click(a,d3.event),c.$apply()}),E.labels&&d.append("text").attr("x",function(b){return a(b.x)}).attr("y",function(a){return e(a.y)}).text(function(a){return a.y})}),"lineEnd"===E.lineLegend&&n.append("text").datum(function(a){return{name:a.series,value:a.values[a.values.length-1]}}).attr("transform",function(b){return"translate("+a(b.value.x)+","+e(b.value.y)+")"}).attr("x",3).text(function(a){return a.name}),j}function u(){function a(a){return Math.round(d(a))+d.rangeBand()/2}var b={top:0,right:40,bottom:20,left:40};L-=b.left+b.right,K-=b.top+b.bottom;var d=d3.scale.ordinal().domain(J.map(function(a){return a.x})).rangePoints([0,L]),e=d3.scale.linear().range([K,10]),f=d3.svg.axis().scale(d).orient("bottom");r(f,d);var g=d3.svg.axis().scale(e).orient("left").ticks(5).tickFormat(d3.format(E.yAxisTickFormat));d3.svg.line().interpolate(E.lineCurveType).x(function(b){return a(b.x)}).y(function(a){return e(a.y)});var h=[0],i=[];J.forEach(function(a){a.y.map(function(a){h.push(a)})});var j=d3.max(J.map(function(a){return a.y.length}));c.yMaxData=j,I.slice(0,j).forEach(function(a,b){var c={};c.series=a,c.values=J.map(function(a){return a.y.map(function(b){return{x:a.x,y:b}})[b]||{x:J[b].x,y:0}}),i.push(c)});var k=d3.select(M[0]).append("svg").attr("width",L+b.left+b.right).attr("height",K+b.top+b.bottom).append("g").attr("transform","translate("+b.left+","+b.top+")"),l=.2*d3.max(h);e.domain([d3.min(h),d3.max(h)+l]),k.append("g").attr("class","x axis").attr("transform","translate(0,"+K+")").call(f),k.append("g").attr("class","y axis").call(g);var m=k.selectAll(".points").data(i).enter().append("g"),n=d3.svg.area().interpolate("basis").x(function(b){return a(b.x)}).y0(function(){return e(0)}).y1(function(a){return e(0+a.y)});m.append("path").attr("class","area").attr("d",function(a){return n(a.values)}).style("fill",function(a,b){return D(b)}).style("opacity","0.7")}function v(){function a(a){a.innerRadius=0;var b=d3.interpolate({startAngle:0,endAngle:0},a);return function(a){return g(b(a))}}var b=Math.min(L,K)/2,d=d3.select(M[0]).append("svg").attr("width",L).attr("height",K).append("g").attr("transform","translate("+L/2+","+K/2+")"),e=0;if(E.innerRadius){var f=E.innerRadius;f="string"==typeof f&&f.indexOf("%")>0?.01*b*parseFloat(f):Number(f),f>=0&&(e=f)}c.yMaxData=J.length;var g=d3.svg.arc().outerRadius(b-10).innerRadius(e);d3.svg.arc().outerRadius(b+5).innerRadius(0);var h=d3.layout.pie().sort(null).value(function(a){return a.y[0]}),i=d.selectAll(".arc").data(h(J)).enter().append("g"),j=!1;i.append("path").style("fill",function(a,b){return D(b)}).transition().ease("linear").duration(E.isAnimate?500:0).attrTween("d",a).attr("class","arc").each("end",function(){j||(j=!0,i.on("mouseover",function(a){x({value:a.data.tooltip?a.data.tooltip:a.data.y[0]},d3.event),d3.select(this).select("path").transition().duration(200).style("stroke","white").style("stroke-width","2px"),E.mouseover(a,d3.event),c.$apply()}).on("mouseleave",function(a){d3.select(this).select("path").transition().duration(200).style("stroke","").style("stroke-width",""),y(),E.mouseout(a,d3.event),c.$apply()}).on("mousemove",function(a){z(a,d3.event)}).on("click",function(a){E.click(a,d3.event),c.$apply()}))}),E.labels&&i.append("text").attr("transform",function(a){return"translate("+g.centroid(a)+")"}).attr("dy",".35em").style("text-anchor","middle").text(function(a){return a.data.y[0]})}function w(){function a(a){return Math.round(d(a))+d.rangeBand()/2}var b={top:0,right:40,bottom:20,left:40};L-=b.left-b.right,K-=b.top-b.bottom;var d=d3.scale.ordinal().domain(J.map(function(a){return a.x})).rangeRoundBands([0,L]),e=d3.scale.linear().range([K,10]),f=d3.svg.axis().scale(d).orient("bottom");r(f,d);var g=d3.svg.axis().scale(e).orient("left").ticks(5).tickFormat(d3.format(E.yAxisTickFormat)),h=[0],i=[];J.forEach(function(a){a.y.map(function(a){h.push(a)})});var j=d3.max(J.map(function(a){return a.y.length}));c.yMaxPoints=j,I.slice(0,j).forEach(function(a,b){var c={};c.series=a,c.values=J.map(function(a){return a.y.map(function(b){return{x:a.x,y:b}})[b]||{x:J[b].x,y:0}}),i.push(c)});var k=d3.select(M[0]).append("svg").attr("width",L+b.left+b.right).attr("height",K+b.top+b.bottom).append("g").attr("transform","translate("+b.left+","+b.top+")"),l=.2*d3.max(h);e.domain([d3.min(h),d3.max(h)+l]),k.append("g").attr("class","x axis").attr("transform","translate(0,"+K+")").call(f),k.append("g").attr("class","y axis").call(g),k.selectAll(".points").data(i).enter().append("g"),angular.forEach(i,function(b){var d=k.selectAll(".circle").data(b.values).enter();d.append("circle").attr("cx",function(b){return a(b.x)}).attr("cy",function(a){return e(a.y)}).attr("r",3).style("fill",D(i.indexOf(b))).style("stroke",D(i.indexOf(b))).on("mouseover",function(a){return function(b){x({index:b.x,value:b.tooltip?b.tooltip:b.y,series:a},d3.event),E.mouseover(b,d3.event),c.$apply()}}(b.series)).on("mouseleave",function(a){y(),E.mouseout(a,d3.event),c.$apply()}).on("mousemove",function(){z(d3.event)}).on("click",function(a){E.click(a,d3.event),c.$apply()}),E.labels&&d.append("text").attr("x",function(b){return a(b.x)}).attr("y",function(a){return e(a.y)}).text(function(a){return a.y})})}function x(a,b){if(E.tooltips){a="function"==typeof E.tooltips?E.tooltips(a):a.value;var d=angular.element('
').html(a).css({left:b.pageX+20+"px",top:b.pageY-30+"px"});angular.element(document.querySelector(".ac-tooltip")).remove(),angular.element(document.body).append(d),c.$tooltip=d}}function y(){c.$tooltip&&c.$tooltip.remove()}function z(a,b){c.$tooltip&&c.$tooltip.css({left:b.pageX+20+"px",top:b.pageY-30+"px"})}function A(){c.legends=[],"pie"===O&&angular.forEach(J,function(a,b){c.legends.push({color:E.colors[b],title:C(a.x)})}),("bar"===O||"area"===O||"point"===O||"line"===O&&"traditional"===E.lineLegend)&&angular.forEach(I,function(a,b){c.legends.push({color:E.colors[b],title:C(a)})})}function B(a){return String(a).replace(/[&<>"'\/]/g,function(a){return P[a]})}function C(a){return f.trustAsHtml(E.legend.htmlEnabled?a:B(a))}function D(a){if(a