1// Generated by CoffeeScript 1.6.3 2/* 3Easy pie chart is a jquery plugin to display simple animated pie charts for only one value 4 5Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) 6and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses. 7 8Built on top of the jQuery library (http://jquery.com) 9 10@source: http://github.com/rendro/easy-pie-chart/ 11@autor: Robert Fleischmann 12@version: 1.2.2 13 14Inspired by: http://dribbble.com/shots/631074-Simple-Pie-Charts-II?list=popular&offset=210 15Thanks to Philip Thrasher for the jquery plugin boilerplate for coffee script 16*/ 17 18(function($) { 19 $.easyPieChart = function(el, options) { 20 var addScaleLine, animateLine, drawLine, easeInOutQuad, rAF, renderBackground, renderScale, renderTrack, 21 _this = this; 22 this.el = el; 23 this.$el = $(el); 24 this.$el.data("easyPieChart", this); 25 this.init = function() { 26 var percent, scaleBy; 27 _this.options = $.extend({}, $.easyPieChart.defaultOptions, options); 28 percent = parseInt(_this.$el.data('percent'), 10); 29 _this.percentage = 0; 30 _this.canvas = $("<canvas width='" + _this.options.size + "' height='" + _this.options.size + "'></canvas>").get(0); 31 _this.$el.append(_this.canvas); 32 if (typeof G_vmlCanvasManager !== "undefined" && G_vmlCanvasManager !== null) { 33 G_vmlCanvasManager.initElement(_this.canvas); 34 } 35 _this.ctx = _this.canvas.getContext('2d'); 36 if (window.devicePixelRatio > 1) { 37 scaleBy = window.devicePixelRatio; 38 $(_this.canvas).css({ 39 width: _this.options.size, 40 height: _this.options.size 41 }); 42 _this.canvas.width *= scaleBy; 43 _this.canvas.height *= scaleBy; 44 _this.ctx.scale(scaleBy, scaleBy); 45 } 46 _this.ctx.translate(_this.options.size / 2, _this.options.size / 2); 47 _this.ctx.rotate(_this.options.rotate * Math.PI / 180); 48 _this.$el.addClass('easyPieChart'); 49 _this.$el.css({ 50 width: _this.options.size, 51 height: _this.options.size, 52 lineHeight: "" + _this.options.size + "px" 53 }); 54 _this.update(percent); 55 return _this; 56 }; 57 this.update = function(percent) { 58 percent = parseFloat(percent) || 0; 59 if (_this.options.animate === false) { 60 drawLine(percent); 61 } else { 62 animateLine(_this.percentage, percent); 63 } 64 return _this; 65 }; 66 renderScale = function() { 67 var i, _i, _results; 68 _this.ctx.fillStyle = _this.options.scaleColor; 69 _this.ctx.lineWidth = 1; 70 _results = []; 71 for (i = _i = 0; _i <= 24; i = ++_i) { 72 _results.push(addScaleLine(i)); 73 } 74 return _results; 75 }; 76 addScaleLine = function(i) { 77 var offset; 78 offset = i % 6 === 0 ? 0 : _this.options.size * 0.017; 79 _this.ctx.save(); 80 _this.ctx.rotate(i * Math.PI / 12); 81 _this.ctx.fillRect(_this.options.size / 2 - offset, 0, -_this.options.size * 0.05 + offset, 1); 82 _this.ctx.restore(); 83 }; 84 renderTrack = function() { 85 var offset; 86 offset = _this.options.size / 2 - _this.options.lineWidth / 2; 87 if (_this.options.scaleColor !== false) { 88 offset -= _this.options.size * 0.08; 89 } 90 _this.ctx.beginPath(); 91 _this.ctx.arc(0, 0, offset, 0, Math.PI * 2, true); 92 _this.ctx.closePath(); 93 _this.ctx.strokeStyle = _this.options.trackColor; 94 _this.ctx.lineWidth = _this.options.lineWidth; 95 _this.ctx.stroke(); 96 }; 97 renderBackground = function() { 98 if (_this.options.scaleColor !== false) { 99 renderScale(); 100 } 101 if (_this.options.trackColor !== false) { 102 renderTrack(); 103 } 104 }; 105 drawLine = function(percent) { 106 var offset; 107 renderBackground(); 108 _this.ctx.strokeStyle = $.isFunction(_this.options.barColor) ? _this.options.barColor(percent) : _this.options.barColor; 109 _this.ctx.lineCap = _this.options.lineCap; 110 _this.ctx.lineWidth = _this.options.lineWidth; 111 offset = _this.options.size / 2 - _this.options.lineWidth / 2; 112 if (_this.options.scaleColor !== false) { 113 offset -= _this.options.size * 0.08; 114 } 115 _this.ctx.save(); 116 _this.ctx.rotate(-Math.PI / 2); 117 _this.ctx.beginPath(); 118 _this.ctx.arc(0, 0, offset, 0, Math.PI * 2 * percent / 100, false); 119 _this.ctx.stroke();
120 _this.ctx.restore(); 121 }; 122 rAF = (function() { 123 return window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || function(callback) { 124 return window.setTimeout(callback, 1000 / 60); 125 }; 126 })(); 127 animateLine = function(from, to) { 128 var anim, startTime; 129 _this.options.onStart.call(_this); 130 _this.percentage = to; 131 startTime = Date.now(); 132 anim = function() { 133 var currentValue, process; 134 process = Date.now() - startTime; 135 if (process < _this.options.animate) { 136 rAF(anim); 137 } 138 _this.ctx.clearRect(-_this.options.size / 2, -_this.options.size / 2, _this.options.size, _this.options.size); 139 renderBackground.call(_this); 140 currentValue = [easeInOutQuad(process, from, to - from, _this.options.animate)]; 141 _this.options.onStep.call(_this, currentValue); 142 drawLine.call(_this, currentValue); 143 if (process >= _this.options.animate) { 144 return _this.options.onStop.call(_this, currentValue, to); 145 } 146 }; 147 rAF(anim); 148 }; 149 easeInOutQuad = function(t, b, c, d) { 150 var easeIn, easing; 151 easeIn = function(t) { 152 return Math.pow(t, 2); 153 }; 154 easing = function(t) { 155 if (t < 1) { 156 return easeIn(t); 157 } else { 158 return 2 - easeIn((t / 2) * -2 + 2); 159 } 160 }; 161 t /= d / 2; 162 return c / 2 * easing(t) + b; 163 }; 164 return this.init(); 165 }; 166 $.easyPieChart.defaultOptions = { 167 barColor: '#ef1e25', 168 trackColor: '#f2f2f2', 169 scaleColor: '#dfe0e0', 170 lineCap: 'round', 171 rotate: 0, 172 size: 110, 173 lineWidth: 3, 174 animate: false, 175 onStart: $.noop, 176 onStop: $.noop, 177 onStep: $.noop 178 }; 179 $.fn.easyPieChart = function(options) { 180 return $.each(this, function(i, el) { 181 var $el, instanceOptions; 182 $el = $(el); 183 if (!$el.data('easyPieChart')) { 184 instanceOptions = $.extend({}, options, $el.data()); 185 return $el.data('easyPieChart', new $.easyPieChart(el, instanceOptions)); 186 } 187 }); 188 }; 189 return void 0; 190})(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.