From 426466d05144088c071dead2d38f52b49cd0ddf7 Mon Sep 17 00:00:00 2001 From: nmac143 Date: Tue, 28 Jun 2016 16:33:43 -0400 Subject: [PATCH] Fixed truncation of pie chart borders --- src/controllers/controller.doughnut.js | 19 +++++++++++++++++-- src/core/core.datasetController.js | 4 +++- 2 files changed, 20 insertions(+), 3 deletions(-) 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 -- 2.47.2