From e7b0ca3897d124d3b58ed0f9cdb05258c2670b5e Mon Sep 17 00:00:00 2001 From: stockiNail Date: Mon, 4 Nov 2024 18:58:38 +0100 Subject: [PATCH 1/2] Fix spacing applied to doughnut label --- src/types/doughnutLabel.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/types/doughnutLabel.js b/src/types/doughnutLabel.js index 0f2891db..9fe5749b 100644 --- a/src/types/doughnutLabel.js +++ b/src/types/doughnutLabel.js @@ -136,7 +136,7 @@ function getControllerMeta({chartArea}, options, meta) { y: (square.top + square.bottom) / 2 }; const space = options.spacing + options.borderWidth / 2; - const _radius = innerRadius - space; + const _radius = Math.max(innerRadius - space, 0); const _counterclockwise = point.y > y; const side = _counterclockwise ? top + space : bottom - space; const angles = getAngles(side, x, y, _radius); @@ -150,7 +150,7 @@ function getControllerMeta({chartArea}, options, meta) { return { controllerMeta, point, - radius: Math.min(innerRadius, Math.min(square.right - square.left, square.bottom - square.top) / 2) + radius: Math.min(_radius, Math.min(square.right - square.left, square.bottom - square.top) / 2) }; } From ab70b6885790938d1d27f00e1493608ea9650cd8 Mon Sep 17 00:00:00 2001 From: stockiNail Date: Mon, 4 Nov 2024 19:03:35 +0100 Subject: [PATCH 2/2] use Math.hypot --- src/types/doughnutLabel.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/types/doughnutLabel.js b/src/types/doughnutLabel.js index 9fe5749b..d95cc1dd 100644 --- a/src/types/doughnutLabel.js +++ b/src/types/doughnutLabel.js @@ -154,10 +154,9 @@ function getControllerMeta({chartArea}, options, meta) { }; } -function getFitRatio({width, height}, radius) { - const hypo = Math.sqrt(Math.pow(width, 2) + Math.pow(height, 2)); - return (radius * 2) / hypo; -} +function getFitRatio({width, height}, radius) { + return (radius * 2) / Math.hypot(width, height); +} function getAngles(y, centerX, centerY, radius) { const yk2 = Math.pow(centerY - y, 2);