1 |
- !function(e,t){var n=t(e);"function"==typeof define&&define.amd?define(function(){return n}):"object"==typeof module&&module.exports?module.exports=n:e.Gauge=n}("undefined"==typeof window?this:window,function(e,t){function n(e){function t(){var e=a++/i,n=s*l(e)+u;d(n),e<1&&r(t)}var n=e.duration,a=1,i=60*n,u=e.start||0,o=e.end,s=o-u,d=e.step,l=e.easing||function(e){return(e/=.5)<1?.5*Math.pow(e,3):.5*(Math.pow(e-2,3)+2)};r(t)}var a=e.document,r=e.requestAnimationFrame||e.mozRequestAnimationFrame||e.webkitRequestAnimationFrame||e.msRequestAnimationFrame||function(e){return setTimeout(e,1e3/60)},i=function(){function e(e,t,n){var r=a.createElementNS(d,e);for(var i in t)r.setAttribute(i,t[i]);return n&&n.forEach(function(e){r.appendChild(e)}),r}function t(e,t){return e*t/100}function r(e,t){var n=Number(e);return n>t?t:n<0?0:n}function i(e,t){return 100*e/t}function u(e,t,n,a){var r=a*Math.PI/180;return{x:Math.round(1e3*(e+n*Math.cos(r)))/1e3,y:Math.round(1e3*(t+n*Math.sin(r)))/1e3}}function o(e,t,n){var a=l.centerX,r=l.centerY;return{end:u(a,r,e,n),start:u(a,r,e,t)}}function s(e){return Math.round(e)}var d="http://www.w3.org/2000/svg",l={dialStartAngle:135,dialEndAngle:45,centerX:500,centerY:500,radius:400};return function(a,u){function d(e,t,n,a){var r=o(e,t,n),i=r.start,u=r.end,s="undefined"==typeof a?1:a;return["M",i.x,i.y,"A",e,e,"0",s,"1",u.x,u.y].join(" ")}function l(n){c=e("text",{"class":C,x:500,y:550,"font-size":"700%","font-family":"sans-serif","font-weight":"bold","text-anchor":"middle"}),p=e("path",{"class":b,fill:"transparent",stroke:"#666","stroke-width":25,d:d(w,A,A)});var a=t(100,360-Math.abs(A-M)),r=a<=180?0:1,i=e("svg",{viewBox:"0 0 1000 1000","class":k},[e("path",{"class":S,fill:"transparent",stroke:"#eee","stroke-width":20,d:d(w,A,M,r)}),c,p]);n.appendChild(i)}function f(e){var n=i(e,g),a=t(n,360-Math.abs(A-M)),r=a<=180?0:1;y&&(c.textContent=x.call(u,e)),p.setAttribute("d",d(w,A,a+A,r))}u=u||{};var c,p,v,h=a,g=u.max||100,m=r(u.value||0,g),w=u.radius||400,y=u.showValue!==!1,x="function"==typeof u.label?u.label:s,A="undefined"==typeof u.dialStartAngle?135:u.dialStartAngle,M="undefined"==typeof u.dialEndAngle?45:u.dialEndAngle,b="undefined"==typeof u.valueDialClass?"value":u.valueDialClass,C="undefined"==typeof u.valueTextClass?"value-text":u.valueTextClass,S="undefined"==typeof u.dialClass?"dial":u.dialClass,k="undefined"==typeof u.gaugeClass?"gauge":u.gaugeClass;if(A<M){console.log("WARNING! Start angle should be greater than end angle. Swapping");var E=A;A=M,M=E}return v={setMaxValue:function(e){g=e},setValue:function(e){m=r(e,g),f(m)},setValueAnimated:function(e,t){var a=m;m=r(e,g),a!==m&&n({start:a||0,end:m,duration:t||1,step:function(e){f(Math.round(100*e)/100)}})},getValue:function(){return m}},l(h),f(m),v}}();return i});
|