]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Fix mismatch between hit boxes and drawn items in legend plugin (#11352)
authorstockiNail <stocki.nail@gmail.com>
Tue, 20 Jun 2023 16:20:12 +0000 (18:20 +0200)
committerGitHub <noreply@github.com>
Tue, 20 Jun 2023 16:20:12 +0000 (18:20 +0200)
* Fix mismatch between hit boxes and drawn items in legend plugin

* fixes padding calculation

src/plugins/plugin.legend.js
test/fixtures/plugin.legend/legend-doughnut-right-center-mulitiline-labels.png

index 8d8264d637ff006669b1e7736b478ef16339121f..6ed994135360be517ffe1fc62909999f1039f531 100644 (file)
@@ -428,7 +428,7 @@ export class Legend extends Element {
         cursor.x += width + padding;
       } else if (typeof legendItem.text !== 'string') {
         const fontLineHeight = labelFont.lineHeight;
-        cursor.y += calculateLegendItemHeight(legendItem, fontLineHeight);
+        cursor.y += calculateLegendItemHeight(legendItem, fontLineHeight) + padding;
       } else {
         cursor.y += lineHeight;
       }
@@ -575,7 +575,7 @@ function calculateItemHeight(_itemHeight, legendItem, fontLineHeight) {
 }
 
 function calculateLegendItemHeight(legendItem, fontLineHeight) {
-  const labelHeight = legendItem.text ? legendItem.text.length + 0.5 : 0;
+  const labelHeight = legendItem.text ? legendItem.text.length : 0;
   return fontLineHeight * labelHeight;
 }
 
index 6be697361c33d6dd05ea90f567448b0ac06d95de..1e92045fc0655ded2b44d3ec101e307989cd2496 100644 (file)
Binary files a/test/fixtures/plugin.legend/legend-doughnut-right-center-mulitiline-labels.png and b/test/fixtures/plugin.legend/legend-doughnut-right-center-mulitiline-labels.png differ