Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
malwaredllc
GitHub Repository: malwaredllc/byob
Path: blob/master/web-gui/buildyourownbotnet/assets/js/easy-pie-chart/src/easypiechart.js
1293 views
1
var EasyPieChart = function(el, opts) {
2
var defaultOptions = {
3
barColor: '#ef1e25',
4
trackColor: '#f9f9f9',
5
scaleColor: '#dfe0e0',
6
scaleLength: 5,
7
lineCap: 'round',
8
lineWidth: 3,
9
trackWidth: undefined,
10
size: 110,
11
rotate: 0,
12
animate: {
13
duration: 1000,
14
enabled: true
15
},
16
easing: function (x, t, b, c, d) { // more can be found here: http://gsgd.co.uk/sandbox/jquery/easing/
17
t = t / (d/2);
18
if (t < 1) {
19
return c / 2 * t * t + b;
20
}
21
return -c/2 * ((--t)*(t-2) - 1) + b;
22
},
23
onStart: function(from, to) {
24
return;
25
},
26
onStep: function(from, to, currentValue) {
27
return;
28
},
29
onStop: function(from, to) {
30
return;
31
}
32
};
33
34
// detect present renderer
35
if (typeof(CanvasRenderer) !== 'undefined') {
36
defaultOptions.renderer = CanvasRenderer;
37
} else if (typeof(SVGRenderer) !== 'undefined') {
38
defaultOptions.renderer = SVGRenderer;
39
} else {
40
throw new Error('Please load either the SVG- or the CanvasRenderer');
41
}
42
43
var options = {};
44
var currentValue = 0;
45
46
/**
47
* Initialize the plugin by creating the options object and initialize rendering
48
*/
49
var init = function() {
50
this.el = el;
51
this.options = options;
52
53
// merge user options into default options
54
for (var i in defaultOptions) {
55
if (defaultOptions.hasOwnProperty(i)) {
56
options[i] = opts && typeof(opts[i]) !== 'undefined' ? opts[i] : defaultOptions[i];
57
if (typeof(options[i]) === 'function') {
58
options[i] = options[i].bind(this);
59
}
60
}
61
}
62
63
// check for jQuery easing
64
if (typeof(options.easing) === 'string' && typeof(jQuery) !== 'undefined' && jQuery.isFunction(jQuery.easing[options.easing])) {
65
options.easing = jQuery.easing[options.easing];
66
} else {
67
options.easing = defaultOptions.easing;
68
}
69
70
// process earlier animate option to avoid bc breaks
71
if (typeof(options.animate) === 'number') {
72
options.animate = {
73
duration: options.animate,
74
enabled: true
75
};
76
}
77
78
if (typeof(options.animate) === 'boolean' && !options.animate) {
79
options.animate = {
80
duration: 1000,
81
enabled: options.animate
82
};
83
}
84
85
// create renderer
86
this.renderer = new options.renderer(el, options);
87
88
// initial draw
89
this.renderer.draw(currentValue);
90
91
// initial update
92
if (el.dataset && el.dataset.percent) {
93
this.update(parseFloat(el.dataset.percent));
94
} else if (el.getAttribute && el.getAttribute('data-percent')) {
95
this.update(parseFloat(el.getAttribute('data-percent')));
96
}
97
}.bind(this);
98
99
/**
100
* Update the value of the chart
101
* @param {number} newValue Number between 0 and 100
102
* @return {object} Instance of the plugin for method chaining
103
*/
104
this.update = function(newValue) {
105
newValue = parseFloat(newValue);
106
if (options.animate.enabled) {
107
this.renderer.animate(currentValue, newValue);
108
} else {
109
this.renderer.draw(newValue);
110
}
111
currentValue = newValue;
112
return this;
113
}.bind(this);
114
115
/**
116
* Disable animation
117
* @return {object} Instance of the plugin for method chaining
118
*/
119
this.disableAnimation = function() {
120
options.animate.enabled = false;
121
return this;
122
};
123
124
/**
125
* Enable animation
126
* @return {object} Instance of the plugin for method chaining
127
*/
128
this.enableAnimation = function() {
129
options.animate.enabled = true;
130
return this;
131
};
132
133
init();
134
};
135
136