angular.module("angular-doughnut-chart",[]).directive("doughnutChart",["$animateCss","$interval",function(e,t){"use strict";var n={stroke:14},r={index:0,isSupported:!(!document.createElementNS||!document.createElementNS("http://www.w3.org/2000/svg","svg").createSVGRect),getPercent:function(e,t){return(100-e)*t/100},getLengthCircle:function(e){return Math.floor(2*Math.PI*e)},setCircleAttrs:function(e,t){return{r:e,cx:-(e+t/2),cy:e+t/2}},getClass:function(){return this.index+=1,"doughnut-chart-"+this.index}},a={restrict:"E",scope:{percentage:"=",stroke:"="}};return r.isSupported?angular.extend(a,{link:function(a,c){function s(e){if(t.cancel(a.intervalText),a.percentage!==a.curPercent){a.oldPecentage=a.oldPecentage||0,a.curPercent=a.oldPecentage;var n=a.percentage-a.oldPecentage;e?a.curPercent=a.percentage:a.intervalText=t(function(){a.curPercent+=n>0?1:-1,a.curPercent===a.percentage&&t.cancel(a.intervalText)},1e3/Math.abs(n))}a.dashOffset=r.getPercent(a.percentage,a.length),e?a.$apply():c.find("circle").eq(1).addClass("doughnut-allow-animation")}function i(){a.animate=!0,e(c.find("circle").eq(1),{addClass:"doughnut-allow-animation"}).start().then(s)}function l(e){a.drawed=!0,a.circles=c.find("circle").attr(r.setCircleAttrs(a.radius,a.stroke)),e&&s(!0),a.percentage&&!a.animate&&i()}function o(t){a.radius=(document.querySelectorAll("."+a["class"])[0].offsetWidth-a.stroke)/2,a.length=r.getLengthCircle(a.radius),a.dashOffset=a.length,t?l(!0):e(c.find("circle").eq(1),{to:{"stroke-dashoffset":a.length}}).start().then(l)}a.stroke=a.stroke||n.stroke,a["class"]=r.getClass(),e(c.children(),{addClass:a["class"]}).start().then(o),a.$watch("percentage",function(e,t){e!==t&&(a.percentage=e,a.oldPecentage=t,a.animate?(a.circles.eq(1).addClass("doughnut-allow-animation"),s()):a.drawed&&i())}),angular.element(window).on("resize",function(){a.circles.eq(1).removeClass("doughnut-allow-animation"),t.cancel(a.intervalText),o(!0)})},template:'
{{curPercent}}%
'}):angular.extend(a,{template:'
Not supported
'})}]);