Path: blob/master/web-gui/buildyourownbotnet/assets/js/easy-pie-chart/src/easypiechart.js
1293 views
var EasyPieChart = function(el, opts) {1var defaultOptions = {2barColor: '#ef1e25',3trackColor: '#f9f9f9',4scaleColor: '#dfe0e0',5scaleLength: 5,6lineCap: 'round',7lineWidth: 3,8trackWidth: undefined,9size: 110,10rotate: 0,11animate: {12duration: 1000,13enabled: true14},15easing: function (x, t, b, c, d) { // more can be found here: http://gsgd.co.uk/sandbox/jquery/easing/16t = t / (d/2);17if (t < 1) {18return c / 2 * t * t + b;19}20return -c/2 * ((--t)*(t-2) - 1) + b;21},22onStart: function(from, to) {23return;24},25onStep: function(from, to, currentValue) {26return;27},28onStop: function(from, to) {29return;30}31};3233// detect present renderer34if (typeof(CanvasRenderer) !== 'undefined') {35defaultOptions.renderer = CanvasRenderer;36} else if (typeof(SVGRenderer) !== 'undefined') {37defaultOptions.renderer = SVGRenderer;38} else {39throw new Error('Please load either the SVG- or the CanvasRenderer');40}4142var options = {};43var currentValue = 0;4445/**46* Initialize the plugin by creating the options object and initialize rendering47*/48var init = function() {49this.el = el;50this.options = options;5152// merge user options into default options53for (var i in defaultOptions) {54if (defaultOptions.hasOwnProperty(i)) {55options[i] = opts && typeof(opts[i]) !== 'undefined' ? opts[i] : defaultOptions[i];56if (typeof(options[i]) === 'function') {57options[i] = options[i].bind(this);58}59}60}6162// check for jQuery easing63if (typeof(options.easing) === 'string' && typeof(jQuery) !== 'undefined' && jQuery.isFunction(jQuery.easing[options.easing])) {64options.easing = jQuery.easing[options.easing];65} else {66options.easing = defaultOptions.easing;67}6869// process earlier animate option to avoid bc breaks70if (typeof(options.animate) === 'number') {71options.animate = {72duration: options.animate,73enabled: true74};75}7677if (typeof(options.animate) === 'boolean' && !options.animate) {78options.animate = {79duration: 1000,80enabled: options.animate81};82}8384// create renderer85this.renderer = new options.renderer(el, options);8687// initial draw88this.renderer.draw(currentValue);8990// initial update91if (el.dataset && el.dataset.percent) {92this.update(parseFloat(el.dataset.percent));93} else if (el.getAttribute && el.getAttribute('data-percent')) {94this.update(parseFloat(el.getAttribute('data-percent')));95}96}.bind(this);9798/**99* Update the value of the chart100* @param {number} newValue Number between 0 and 100101* @return {object} Instance of the plugin for method chaining102*/103this.update = function(newValue) {104newValue = parseFloat(newValue);105if (options.animate.enabled) {106this.renderer.animate(currentValue, newValue);107} else {108this.renderer.draw(newValue);109}110currentValue = newValue;111return this;112}.bind(this);113114/**115* Disable animation116* @return {object} Instance of the plugin for method chaining117*/118this.disableAnimation = function() {119options.animate.enabled = false;120return this;121};122123/**124* Enable animation125* @return {object} Instance of the plugin for method chaining126*/127this.enableAnimation = function() {128options.animate.enabled = true;129return this;130};131132init();133};134135136