mirror of
https://github.com/chartjs/Chart.js.git
synced 2025-12-08 20:36:08 +00:00
Fixed truncation of pie chart borders
This commit is contained in:
parent
266df5e877
commit
426466d051
@ -166,8 +166,9 @@ module.exports = function(Chart) {
|
||||
minSize = Math.min(availableWidth / size.width, availableHeight / size.height);
|
||||
offset = {x: (max.x + min.x) * -0.5, y: (max.y + min.y) * -0.5};
|
||||
}
|
||||
chart.borderWidth = me.getMaxBorderWidth(meta.data);
|
||||
|
||||
chart.outerRadius = Math.max(minSize / 2, 0);
|
||||
chart.outerRadius = Math.max((minSize - chart.borderWidth) / 2, 0);
|
||||
chart.innerRadius = Math.max(cutoutPercentage ? (chart.outerRadius / 100) * (cutoutPercentage) : 1, 0);
|
||||
chart.radiusLength = (chart.outerRadius - chart.innerRadius) / chart.getVisibleDatasetCount();
|
||||
chart.offsetX = offset.x * chart.outerRadius;
|
||||
@ -262,6 +263,20 @@ module.exports = function(Chart) {
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
//gets the max border or hover width to properly scale pie charts
|
||||
getMaxBorderWidth: function (elements) {
|
||||
var max = 0;
|
||||
|
||||
for (var i = 0; i < elements.length; i++) {
|
||||
var borderWidth = elements[i]._model ? elements[i]._model.borderWidth : 0,
|
||||
hoverWidth = elements[i]._chart ? elements[i]._chart.config.data.datasets[this.index].hoverBorderWidth : 0;
|
||||
|
||||
max = borderWidth > max ? borderWidth : max;
|
||||
max = hoverWidth > max ? hoverWidth : max;
|
||||
}
|
||||
return max;
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
@ -157,7 +157,9 @@ module.exports = function(Chart) {
|
||||
model.borderColor = custom.hoverBorderColor ? custom.hoverBorderColor : valueOrDefault(dataset.hoverBorderColor, index, getHoverColor(model.borderColor));
|
||||
model.borderWidth = custom.hoverBorderWidth ? custom.hoverBorderWidth : valueOrDefault(dataset.hoverBorderWidth, index, model.borderWidth);
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
Chart.DatasetController.extend = helpers.inherits;
|
||||
};
|
||||
Loading…
x
Reference in New Issue
Block a user