Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions src/controllers/controller.polarArea.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,16 +146,19 @@ module.exports = function(Chart) {
var animationOpts = opts.animation;
var scale = chart.scale;
var labels = chart.data.labels;
var customAngles = opts.customAngles;

var circumference = me.calculateCircumference(dataset.data[index]);
var circumference = me.calculateCircumference(dataset.data[index], index);
var centerX = scale.xCenter;
var centerY = scale.yCenter;

// If there is NaN data before us, we need to calculate the starting angle correctly.
// We could be way more efficient here, but its unlikely that the polar area chart will have a lot of data
var previousAngle = 0;
var visibleCount = 0;
var meta = me.getMeta();
for (var i = 0; i < index; ++i) {
previousAngle += customAngles[visibleCount];
if (!isNaN(dataset.data[i]) && !meta.data[i].hidden) {
++visibleCount;
}
Expand All @@ -164,7 +167,7 @@ module.exports = function(Chart) {
// var negHalfPI = -0.5 * Math.PI;
var datasetStartAngle = opts.startAngle;
var distance = arc.hidden ? 0 : scale.getDistanceFromCenterForValue(dataset.data[index]);
var startAngle = datasetStartAngle + (circumference * visibleCount);
var startAngle = datasetStartAngle + previousAngle;
var endAngle = startAngle + (arc.hidden ? 0 : circumference);

var resetRadius = animationOpts.animateScale ? 0 : scale.getDistanceFromCenterForValue(dataset.data[index]);
Expand Down Expand Up @@ -211,10 +214,14 @@ module.exports = function(Chart) {
return count;
},

calculateCircumference: function(value) {
calculateCircumference: function(value, index) {
var me = this;
var chart = me.chart;
var opts = chart.options;
var customAngles = opts.customAngles;
var count = this.getMeta().count;
if (count > 0 && !isNaN(value)) {
return (2 * Math.PI) / count;
return count === 1 ? 2 * Math.PI : customAngles[index];
}
return 0;
}
Expand Down