From 618a2299ddbb0daa2d52881af7ded185391a0d28 Mon Sep 17 00:00:00 2001 From: Antonio De Lucreziis Date: Sat, 9 Jul 2022 19:19:45 +0200 Subject: [PATCH] Better label positioning on pie chart --- _frontend/src/components/charts/PieChart.jsx | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/_frontend/src/components/charts/PieChart.jsx b/_frontend/src/components/charts/PieChart.jsx index 6a1030c..d1efd9e 100644 --- a/_frontend/src/components/charts/PieChart.jsx +++ b/_frontend/src/components/charts/PieChart.jsx @@ -66,16 +66,11 @@ export const PieChart = ({ parts, labels, total, totalLabel }) => { g.lineTo(0, 0) g.stroke() - const { width: w } = g.measureText(label) - const textRadius = Math.sqrt(w ** 2 + 16 ** 2) / 2 - g.fillStyle = `hsl(${((hashCode(`${i} ${seed}`) % 0xff) * 360) / 0xff}, 80%, 15%)` g.fillText( label, - Math.cos(acc + angle / 2 - 0.5 * Math.PI) * - (width * 0.5 * 0.85 + textRadius * 0.8), - Math.sin(acc + angle / 2 - 0.5 * Math.PI) * - (width * 0.5 * 0.85 + textRadius * 0.8) + Math.cos(acc + angle / 2 - 0.5 * Math.PI) * (width * 0.5 * 0.9125), + Math.sin(acc + angle / 2 - 0.5 * Math.PI) * (width * 0.5 * 0.9125) ) acc += angle