1(function($) { 2 $.easyPieChart = function(el, options) { 3 var addScaleLine, animateLine, drawLine, easeInOutQuad, rAF, renderBackground, renderScale, renderTrack, _this = this; 4 this.el = el; 5 this.$el = $(el); 6 this.$el.data("easyPieChart", this); 7 this.init = function() { 8 var percent, scaleBy; 9 _this.options = $.extend({}, $.easyPieChart.defaultOptions, options); 10 percent = parseInt(_this.$el.data('percent'), 10); 11 _this.percentage = 0; 12 _this.canvas = $("<canvas width='" + _this.options.size + "' height='" + _this.options.size + "'></canvas>").get(0); 13 _this.$el.append(_this.canvas); 14 if (typeof G_vmlCanvasManager !== "undefined" && G_vmlCanvasManager !== null) { 15 G_vmlCanvasManager.initElement(_this.canvas); 16 } 17 _this.ctx = _this.canvas.getContext('2d'); 18 if (window.devicePixelRatio > 1) { 19 scaleBy = window.devicePixelRatio; 20 $(_this.canvas).css({ 21 width: _this.options.size, 22 height: _this.options.size 23 }); 24 _this.canvas.width *= scaleBy; 25 _this.canvas.height *= scaleBy; 26 _this.ctx.scale(scaleBy, scaleBy); 27 } 28 _this.ctx.translate(_this.options.size / 2, _this.options.size / 2); 29 _this.ctx.rotate(_this.options.rotate * Math.PI / 180); 30 _this.$el.addClass('easyPieChart'); 31 _this.$el.css({ 32 width: _this.options.size, 33 height: _this.options.size, 34 lineHeight: "" + _this.options.size + "px" 35 }); 36 _this.update(percent); 37 return _this; 38 }; 39 this.update = function(percent) { 40 percent = parseFloat(percent) || 0; 41 if (_this.options.animate === false) { 42 drawLine(percent); 43 } else { 44 animateLine(_this.percentage, percent); 45 } 46 return _this; 47 }; 48 renderScale = function() { 49 var i, _i, _results; 50 _this.ctx.fillStyle = _this.options.scaleColor; 51 _this.ctx.lineWidth = 1; 52 _results = []; 53 for (i = _i = 0; _i <= 24; i = ++_i) { 54 _results.push(addScaleLine(i)); 55 } 56 return _results; 57 }; 58 addScaleLine = function(i) { 59 var offset; 60 offset = i % 6 === 0 ? 0 : _this.options.size * 0.017; 61 _this.ctx.save(); 62 _this.ctx.rotate(i * Math.PI / 12); 63 _this.ctx.fillRect(_this.options.size / 2 - offset, 0, -_this.options.size * 0.05 + offset, 1); 64 _this.ctx.restore(); 65 }; 66 renderTrack = function() { 67 var offset; 68 offset = _this.options.size / 2 - _this.options.lineWidth / 2; 69 if (_this.options.scaleColor !== false) { 70 offset -= _this.options.size * 0.08; 71 } 72 _this.ctx.beginPath(); 73 _this.ctx.arc(0, 0, offset, 0, Math.PI * 2, true); 74 _this.ctx.closePath(); 75 _this.ctx.strokeStyle = _this.options.trackColor; 76 _this.ctx.lineWidth = _this.options.lineWidth; 77 _this.ctx.stroke(); 78 }; 79 renderBackground = function() { 80 if (_this.options.scaleColor !== false) { 81 renderScale(); 82 } 83 if (_this.options.trackColor !== false) { 84 renderTrack(); 85 } 86 }; 87 drawLine = function(percent) { 88 var offset; 89 renderBackground(); 90 _this.ctx.strokeStyle = $.isFunction(_this.options.barColor) ? _this.options.barColor(percent) : _this.options.barColor; 91 _this.ctx.lineCap = _this.options.lineCap; 92 _this.ctx.lineWidth = _this.options.lineWidth; 93 offset = _this.options.size / 2 - _this.options.lineWidth / 2; 94 if (_this.options.scaleColor !== false) { 95 offset -= _this.options.size * 0.08; 96 } 97 _this.ctx.save(); 98 _this.ctx.rotate(-Math.PI / 2); 99 _this.ctx.beginPath(); 100 _this.ctx.arc(0, 0, offset, 0, Math.PI * 2 * percent / 100, false); 101 _this.ctx.stroke();
102 _this.ctx.restore(); 103 }; 104 rAF = (function() { 105 return window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || function(callback) { 106 return window.setTimeout(callback, 1000 / 60); 107 }; 108 })(); 109 animateLine = function(from, to) { 110 var anim, startTime; 111 _this.options.onStart.call(_this); 112 _this.percentage = to; 113 startTime = Date.now(); 114 anim = function() { 115 var currentValue, process; 116 process = Date.now() - startTime; 117 if (process < _this.options.animate) { 118 rAF(anim); 119 } 120 _this.ctx.clearRect(-_this.options.size / 2, -_this.options.size / 2, _this.options.size, _this.options.size); 121 renderBackground.call(_this); 122 currentValue = [easeInOutQuad(process, from, to - from, _this.options.animate)]; 123 _this.options.onStep.call(_this, currentValue); 124 drawLine.call(_this, currentValue); 125 if (process >= _this.options.animate) { 126 return _this.options.onStop.call(_this); 127 } 128 }; 129 rAF(anim); 130 }; 131 easeInOutQuad = function(t, b, c, d) { 132 var easeIn, easing; 133 easeIn = function(t) { 134 return Math.pow(t, 2); 135 }; 136 easing = function(t) { 137 if (t < 1) { 138 return easeIn(t); 139 } else { 140 return 2 - easeIn((t / 2) * -2 + 2); 141 } 142 }; 143 t /= d / 2; 144 return c / 2 * easing(t) + b; 145 }; 146 return this.init(); 147 }; 148 $.easyPieChart.defaultOptions = { 149 barColor: '#ef1e25', 150 trackColor: '#f2f2f2', 151 scaleColor: '#dfe0e0', 152 lineCap: 'round', 153 rotate: 0, 154 size: 110, 155 lineWidth: 3, 156 animate: false, 157 onStart: $.noop, 158 onStop: $.noop, 159 onStep: $.noop 160 }; 161 $.fn.easyPieChart = function(options) { 162 return $.each(this, function(i, el) { 163 var $el, instanceOptions; 164 $el = $(el); 165 if (!$el.data('easyPieChart')) { 166 instanceOptions = $.extend({}, options, $el.data()); 167 return $el.data('easyPieChart', new $.easyPieChart(el, instanceOptions)); 168 } 169 }); 170 }; 171 return void 0; 172})(jQuery);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.