From: nmac143 Date: Tue, 28 Jun 2016 20:33:43 +0000 (-0400) Subject: Fixed truncation of pie chart borders X-Git-Tag: v2.2.0-rc.1~22^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F2865%2Fhead;p=thirdparty%2FChart.js.git Fixed truncation of pie chart borders --- diff --git a/src/controllers/controller.doughnut.js b/src/controllers/controller.doughnut.js index 159f40b3d..d073e0afc 100644 --- a/src/controllers/controller.doughnut.js +++ b/src/controllers/controller.doughnut.js @@ -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; + } }); }; diff --git a/src/core/core.datasetController.js b/src/core/core.datasetController.js index e9cda32a6..02af1471d 100644 --- a/src/core/core.datasetController.js +++ b/src/core/core.datasetController.js @@ -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; }; \ No newline at end of file