1// Generated by CoffeeScript 1.4.0 2 3/* 4Easy pie chart is a jquery plugin to display simple animated pie charts for only one value 5 6Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) 7and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses. 8 9Built on top of the jQuery library (http://jquery.com) 10 11@source: http://github.com/rendro/easy-pie-chart/ 12@autor: Robert Fleischmann 13@version: 1.0.1 14 15Inspired by: http://dribbble.com/shots/631074-Simple-Pie-Charts-II?list=popular&offset=210 16Thanks to Philip Thrasher for the jquery plugin boilerplate for coffee script 17*/ 18 19 20(function() { 21 22 (function($) { 23 $.easyPieChart = function(el, options) { 24 var addScaleLine, animateLine, drawLine, easeInOutQuad, renderBackground, renderScale, renderTrack, 25 _this = this; 26 this.el = el; 27 this.$el = $(el); 28 this.$el.data("easyPieChart", this); 29 this.init = function() { 30 var percent; 31 _this.options = $.extend({}, $.easyPieChart.defaultOptions, options); 32 percent = parseInt(_this.$el.data('percent'), 10); 33 _this.percentage = 0; 34 _this.canvas = $("<canvas width='" + _this.options.size + "' height='" + _this.options.size + "'></canvas>").get(0); 35 _this.$el.append(_this.canvas); 36 if (typeof G_vmlCanvasManager !== "undefined" && G_vmlCanvasManager !== null) { 37 G_vmlCanvasManager.initElement(_this.canvas); 38 } 39 _this.ctx = _this.canvas.getContext('2d'); 40 if (window.devicePixelRatio > 1.5) { 41 $(_this.canvas).css({ 42 width: _this.options.size, 43 height: _this.options.size 44 }); 45 _this.canvas.width *= 2; 46 _this.canvas.height *= 2; 47 _this.ctx.scale(2, 2); 48 } 49 _this.ctx.translate(_this.options.size / 2, _this.options.size / 2); 50 _this.$el.addClass('easyPieChart'); 51 _this.$el.css({ 52 width: _this.options.size, 53 height: _this.options.size, 54 lineHeight: "" + _this.options.size + "px" 55 }); 56 _this.update(percent); 57 return _this; 58 }; 59 this.update = function(percent) { 60 if (_this.options.animate === false) { 61 return drawLine(percent); 62 } else { 63 return animateLine(_this.percentage, percent); 64 } 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 return _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 return _this.ctx.stroke(); 96 }; 97 renderBackground = function() { 98 if (_this.options.scaleColor !== false) { 99 renderScale(); 100 } 101 if (_this.options.trackColor !== false) { 102 return 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 return _this.ctx.restore(); 121 }; 122 animateLine = function(from, to) { 123 var currentStep, fps, steps; 124 fps = 30; 125 steps = fps * _this.options.animate / 1000; 126 currentStep = 0; 127 _this.options.onStart.call(_this); 128 _this.percentage = to; 129 if (_this.animation) { 130 clearInterval(_this.animation); 131 _this.animation = false; 132 } 133 return _this.animation = setInterval(function() { 134 _this.ctx.clearRect(-_this.options.size / 2, -_this.options.size / 2, _this.options.size, _this.options.size); 135 renderBackground.call(_this); 136 drawLine.call(_this, [easeInOutQuad(currentStep, from, to - from, steps)]); 137 currentStep++; 138 if ((currentStep / steps) > 1) { 139 clearInterval(_this.animation); 140 _this.animation = false; 141 return _this.options.onStop.call(_this); 142 } 143 }, 1000 / fps); 144 }; 145 easeInOutQuad = function(t, b, c, d) { 146 var easeIn, easing; 147 easeIn = function(t) { 148 return Math.pow(t, 2); 149 }; 150 easing = function(t) { 151 if (t < 1) { 152 return easeIn(t); 153 } else { 154 return 2 - easeIn((t / 2) * -2 + 2); 155 } 156 }; 157 t /= d / 2; 158 return c / 2 * easing(t) + b; 159 }; 160 return this.init(); 161 }; 162 $.easyPieChart.defaultOptions = { 163 barColor: '#ef1e25', 164 trackColor: '#f2f2f2', 165 scaleColor: '#dfe0e0', 166 lineCap: 'round', 167 size: 110, 168 lineWidth: 3, 169 animate: false, 170 onStart: $.noop, 171 onStop: $.noop 172 }; 173 $.fn.easyPieChart = function(options) { 174 return $.each(this, function(i, el) { 175 var $el; 176 $el = $(el); 177 if (!$el.data('easyPieChart')) { 178 return $el.data('easyPieChart', new $.easyPieChart(el, options)); 179 } 180 }); 181 }; 182 return void 0; 183 })(jQuery); 184 185}).call(this);
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.