PageSourceSearch

http://bayalagbuteegch.mn/js/jquery.easy-pie-chart.js

js bayalagbuteegch.mn collected 2026-10-04 13:28:40 UTC 6,563 bytes, 193 lines download raw bytes

1/*
2Easy pie chart is a jquery plugin to display simple animated pie charts for only one value
3
4Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php)
5and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
6
7Built on top of the jQuery library (http://jquery.com)
8
9@source: http://github.com/rendro/easy-pie-chart/
10@autor: Robert Fleischmann
11@version: 1.2.3
12
13Inspired by: http://dribbble.com/shots/631074-Simple-Pie-Charts-II?list=popular&offset=210
14Thanks to Philip Thrasher for the jquery plugin boilerplate for coffee script
15*/
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      Date.now || (Date.now = function() {
132        return +(new Date);
133      });
134      startTime = Date.now();
135      anim = function() {
136        var currentValue, process;
137        process = Date.now() - startTime;
138        if (process < _this.options.animate) {
139          rAF(anim);
140        }
141        _this.ctx.clearRect(-_this.options.size / 2, -_this.options.size / 2, _this.options.size, _this.options.size);
142        renderBackground.call(_this);
143        currentValue = [easeInOutQuad(process, from, to - from, _this.options.animate)];
144        _this.options.onStep.call(_this, currentValue);
145        drawLine.call(_this, currentValue);
146        if (process >= _this.options.animate) {
147          return _this.options.onStop.call(_this, currentValue, to);
148        }
149      };
150      rAF(anim);
151    };
152    easeInOutQuad = function(t, b, c, d) {
153      var easeIn, easing;
154      easeIn = function(t) {
155        return Math.pow(t, 2);
156      };
157      easing = function(t) {
158        if (t < 1) {
159          return easeIn(t);
160        } else {
161          return 2 - easeIn((t / 2) * -2 + 2);
162        }
163      };
164      t /= d / 2;
165      return c / 2 * easing(t) + b;
166    };
167    return this.init();
168  };
169  $.easyPieChart.defaultOptions = {
170    barColor: '#ef1e25',
171    trackColor: '#f2f2f2',
172    scaleColor: '#dfe0e0',
173    lineCap: 'round',
174    rotate: 0,
175    size: 110,
176    lineWidth: 3,
177    animate: false,
178    onStart: $.noop,
179    onStop: $.noop,
180    onStep: $.noop
181  };
182  $.fn.easyPieChart = function(options) {
183    return $.each(this, function(i, el) {
184      var $el, instanceOptions;
185      $el = $(el);
186      if (!$el.data('easyPieChart')) {
187        instanceOptions = $.extend({}, options, $el.data());
188        return $el.data('easyPieChart', new $.easyPieChart(el, instanceOptions));
189      }
190    });
191  };
192  return void 0;
193})(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.