Files
Roshan476 bf823cb44e update
2026-01-08 15:17:00 +05:45

8 lines
7.3 KiB
JavaScript

/**!
* easy-pie-chart
* Lightweight plugin to render simple, animated and retina optimized pie charts
*
* @license
* @author Robert Fleischmann <rendro87@gmail.com> (http://robert-fleischmann.de)
* @version 2.1.7
**/ !function(e,t){"function"==typeof define&&define.amd?define(["jquery"],function(e){return t(e)}):"object"==typeof exports?module.exports=t(require("jquery")):t(jQuery)}(this,function(e){var t=function(e,t){var n,i=document.createElement("canvas");e.appendChild(i),"object"==typeof G_vmlCanvasManager&&G_vmlCanvasManager.initElement(i);var a=i.getContext("2d");i.width=i.height=t.size;var r=1;window.devicePixelRatio>1&&(r=window.devicePixelRatio,i.style.width=i.style.height=[t.size,"px"].join(""),i.width=i.height=t.size*r,a.scale(r,r)),a.translate(t.size/2,t.size/2),a.rotate((-.5+t.rotate/180)*Math.PI);var o=(t.size-t.lineWidth)/2;t.scaleColor&&t.scaleLength&&(o-=t.scaleLength+2),Date.now=Date.now||function(){return+new Date};var s=function(e,t,n){var i=0>=(n=Math.min(Math.max(-1,n||0),1));a.beginPath(),a.arc(0,0,o,0,2*Math.PI*n,i),a.strokeStyle=e,a.lineWidth=t,a.stroke()},d=function(){var e,n;a.lineWidth=1,a.fillStyle=t.scaleColor,a.save();for(var i=24;i>0;--i)i%6==0?(n=t.scaleLength,e=0):(n=.6*t.scaleLength,e=t.scaleLength-n),a.fillRect(-t.size/2+e,0,n,1),a.rotate(Math.PI/12);a.restore()},l=window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||function(e){window.setTimeout(e,1e3/60)},h=function(){t.scaleColor&&d(),t.trackColor&&s(t.trackColor,t.trackWidth||t.lineWidth,1)};this.getCanvas=function(){return i},this.getCtx=function(){return a},this.clear=function(){a.clearRect(-(t.size/2),-(t.size/2),t.size,t.size)},this.draw=(function(e){var i;t.scaleColor||t.trackColor?a.getImageData&&a.putImageData?n?a.putImageData(n,0,0):(h(),n=a.getImageData(0,0,t.size*r,t.size*r)):(this.clear(),h()):this.clear(),a.lineCap=t.lineCap,s(i="function"==typeof t.barColor?t.barColor(e):t.barColor,t.lineWidth,e/100)}).bind(this),this.animate=(function(e,n){var i=Date.now();t.onStart(e,n);var a=(function(){var r=Math.min(Date.now()-i,t.animate.duration),o=t.easing(this,r,e,n-e,t.animate.duration);this.draw(o),t.onStep(e,n,o),r>=t.animate.duration?t.onStop(e,n):l(a)}).bind(this);l(a)}).bind(this)},n=function(e,n){var i={barColor:"#ef1e25",trackColor:"#f9f9f9",scaleColor:"#dfe0e0",scaleLength:5,lineCap:"round",lineWidth:3,trackWidth:void 0,size:110,rotate:0,animate:{duration:1e3,enabled:!0},easing:function(e,t,n,i,a){return 1>(t/=a/2)?i/2*t*t+n:-i/2*(--t*(t-2)-1)+n},onStart:function(e,t){},onStep:function(e,t,n){},onStop:function(e,t){}};if(void 0!==t)i.renderer=t;else{if("undefined"==typeof SVGRenderer)throw Error("Please load either the SVG- or the CanvasRenderer");i.renderer=SVGRenderer}var a={},r=0,o=(function(){for(var t in this.el=e,this.options=a,i)i.hasOwnProperty(t)&&(a[t]=n&&void 0!==n[t]?n[t]:i[t],"function"==typeof a[t]&&(a[t]=a[t].bind(this)));"string"==typeof a.easing&&"undefined"!=typeof jQuery&&jQuery.isFunction(jQuery.easing[a.easing])?a.easing=jQuery.easing[a.easing]:a.easing=i.easing,"number"==typeof a.animate&&(a.animate={duration:a.animate,enabled:!0}),"boolean"!=typeof a.animate||a.animate||(a.animate={duration:1e3,enabled:a.animate}),this.renderer=new a.renderer(e,a),this.renderer.draw(r),e.dataset&&e.dataset.percent?this.update(parseFloat(e.dataset.percent)):e.getAttribute&&e.getAttribute("data-percent")&&this.update(parseFloat(e.getAttribute("data-percent")))}).bind(this);this.update=(function(e){return e=parseFloat(e),a.animate.enabled?this.renderer.animate(r,e):this.renderer.draw(e),r=e,this}).bind(this),this.disableAnimation=function(){return a.animate.enabled=!1,this},this.enableAnimation=function(){return a.animate.enabled=!0,this},o()};e.fn.easyPieChart=function(t){return this.each(function(){var i;e.data(this,"easyPieChart")||(i=e.extend({},t,e(this).data()),e.data(this,"easyPieChart",new n(this,i)))})}}),function(e,t){"object"==typeof exports?module.exports=t():"function"==typeof define&&define.amd?define("EasyPieChart",[],t):e.EasyPieChart=t()}(this,function(){var e=function(e,t){var n,i=document.createElement("canvas");e.appendChild(i),"undefined"!=typeof G_vmlCanvasManager&&G_vmlCanvasManager.initElement(i);var a=i.getContext("2d");i.width=i.height=t.size;var r=1;window.devicePixelRatio>1&&(r=window.devicePixelRatio,i.style.width=i.style.height=[t.size,"px"].join(""),i.width=i.height=t.size*r,a.scale(r,r)),a.translate(t.size/2,t.size/2),a.rotate((-.5+t.rotate/180)*Math.PI);var o=(t.size-t.lineWidth)/2;t.scaleColor&&t.scaleLength&&(o-=t.scaleLength+2),Date.now=Date.now||function(){return+new Date};var s=function(e,t,n){var i=(n=Math.min(Math.max(-1,n||0),1))<=0;a.beginPath(),a.arc(0,0,o,0,2*Math.PI*n,i),a.strokeStyle=e,a.lineWidth=t,a.stroke()},d=function(){a.lineWidth=1,a.fillStyle=t.scaleColor,a.save();for(var e,n,i=24;i>0;--i)i%6==0?(n=t.scaleLength,e=0):(n=.6*t.scaleLength,e=t.scaleLength-n),a.fillRect(-t.size/2+e,0,n,1),a.rotate(Math.PI/12);a.restore()},l=window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||function(e){window.setTimeout(e,1e3/60)},h=function(){t.scaleColor&&d(),t.trackColor&&s(t.trackColor,t.lineWidth,1)};this.canvas=function(){return i},this.ctx=function(){return a},this.clear=function(){a.clearRect(-(t.size/2),-(t.size/2),t.size,t.size)},this.draw=(function(e){var i;t.scaleColor||t.trackColor?a.getImageData&&a.putImageData?n?a.putImageData(n,0,0):(h(),n=a.getImageData(0,0,t.size*r,t.size*r)):(this.clear(),h()):this.clear(),a.lineCap=t.lineCap,s(i="function"==typeof t.barColor?t.barColor(e):t.barColor,t.lineWidth,e/100)}).bind(this),this.animate=(function(e,n){var i=Date.now();t.onStart(e,n);var a=(function(){var r=Math.min(Date.now()-i,t.animate.duration),o=t.easing(this,r,e,n-e,t.animate.duration);this.draw(o),t.onStep(e,n,o),r>=t.animate.duration?t.onStop(e,n):l(a)}).bind(this);l(a)}).bind(this)};return function(t,n){var i={barColor:"#ef1e25",trackColor:"#f9f9f9",scaleColor:"#dfe0e0",scaleLength:5,lineCap:"round",lineWidth:3,size:110,rotate:0,animate:{duration:1e3,enabled:!0},easing:function(e,t,n,i,a){return(t/=a/2)<1?i/2*t*t+n:-i/2*(--t*(t-2)-1)+n},onStart:function(e,t){},onStep:function(e,t,n){},onStop:function(e,t){}};if(void 0!==e)i.renderer=e;else if("undefined"!=typeof SVGRenderer)i.renderer=SVGRenderer;else throw Error("Please load either the SVG- or the CanvasRenderer");var a={},r=0,o=(function(){for(var e in this.el=t,this.options=a,i)i.hasOwnProperty(e)&&(a[e]=n&&void 0!==n[e]?n[e]:i[e],"function"==typeof a[e]&&(a[e]=a[e].bind(this)));"string"==typeof a.easing&&"undefined"!=typeof jQuery&&jQuery.isFunction(jQuery.easing[a.easing])?a.easing=jQuery.easing[a.easing]:a.easing=i.easing,"number"==typeof a.animate&&(a.animate={duration:a.animate,enabled:!0}),"boolean"!=typeof a.animate||a.animate||(a.animate={duration:1e3,enabled:a.animate}),this.renderer=new a.renderer(t,a),this.renderer.draw(r),t.dataset&&t.dataset.percent?this.update(parseFloat(t.dataset.percent)):t.getAttribute&&t.getAttribute("data-percent")&&this.update(parseFloat(t.getAttribute("data-percent")))}).bind(this);this.update=(function(e){return e=parseFloat(e),a.animate.enabled?this.renderer.animate(r,e):this.renderer.draw(e),r=e,this}).bind(this),this.disableAnimation=function(){return a.animate.enabled=!1,this},this.enableAnimation=function(){return a.animate.enabled=!0,this},o()}});