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