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