},
calculateTotal: function() {
+ var dataset = this.getDataset();
var meta = this.getMeta();
var total = 0;
+ var value;
- this.getDataset().data.forEach(function(value, index) {
- if (!isNaN(value) && !meta.data[index].hidden) {
+ helpers.each(meta.data, function(element, index) {
+ value = dataset.data[index];
+ if (!isNaN(value) && !element.hidden) {
total += Math.abs(value);
}
});
},
update: function update(reset) {
+ var meta = this.getMeta();
var minSize = Math.min(this.chart.chartArea.right - this.chart.chartArea.left, this.chart.chartArea.bottom - this.chart.chartArea.top);
this.chart.outerRadius = Math.max((minSize - this.chart.options.elements.arc.borderWidth / 2) / 2, 0);
this.chart.innerRadius = Math.max(this.chart.options.cutoutPercentage ? (this.chart.outerRadius / 100) * (this.chart.options.cutoutPercentage) : 1, 0);
this.outerRadius = this.chart.outerRadius - (this.chart.radiusLength * this.index);
this.innerRadius = this.outerRadius - this.chart.radiusLength;
- helpers.each(this.getMeta().data, function(arc, index) {
+ meta.count = this.countVisibleElements();
+
+ helpers.each(meta.data, function(arc, index) {
this.updateElement(arc, index, reset);
}, this);
},
arc._model.borderWidth = arc.custom && arc.custom.borderWidth ? arc.custom.borderWidth : helpers.getValueAtIndexOrDefault(this.getDataset().borderWidth, index, this.chart.options.elements.arc.borderWidth);
},
- calculateCircumference: function(value) {
- if (isNaN(value)) {
- return 0;
- }
-
- // Count the number of "visible"" values
+ countVisibleElements: function() {
+ var dataset = this.getDataset();
var meta = this.getMeta();
var count = 0;
- this.getDataset().data.forEach(function(value, index) {
- if (!isNaN(value) && !meta.data[index].hidden) {
+ helpers.each(meta.data, function(element, index) {
+ if (!isNaN(dataset.data[index]) && !element.hidden) {
count++;
}
});
- return (2 * Math.PI) / count;
+ return count;
+ },
+
+ calculateCircumference: function(value) {
+ var count = this.getMeta().count;
+ if (count > 0 && !isNaN(value)) {
+ return (2 * Math.PI) / count;
+ } else {
+ return 0;
+ }
}
});
-
};