From 7a5889691c2c9d177c24ea8fa96f5fb3d9b5a394 Mon Sep 17 00:00:00 2001 From: Jan Tagscherer Date: Sat, 20 Oct 2018 13:56:18 +0200 Subject: [PATCH] Calculate the maximum height instead of adjusting initial column heights --- src/plugins/plugin.legend.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/plugins/plugin.legend.js b/src/plugins/plugin.legend.js index 78a944739c6..1ff4c89a46d 100644 --- a/src/plugins/plugin.legend.js +++ b/src/plugins/plugin.legend.js @@ -272,8 +272,9 @@ var Legend = Element.extend({ var vPadding = labelOpts.padding; var columnWidths = me.columnWidths = []; var totalWidth = labelOpts.padding; + var maxHeight = minSize.height - vPadding; var currentColWidth = 0; - var currentColHeight = vPadding; + var currentColHeight = 0; var itemHeight = fontSize + vPadding; helpers.each(me.legendItems, function(legendItem, i) { @@ -281,12 +282,12 @@ var Legend = Element.extend({ var itemWidth = boxWidth + (fontSize / 2) + ctx.measureText(legendItem.text).width; // If too tall, go to new column - if (currentColHeight + itemHeight > minSize.height) { + if (currentColHeight + itemHeight > maxHeight) { totalWidth += currentColWidth + labelOpts.padding; columnWidths.push(currentColWidth); // previous column width currentColWidth = 0; - currentColHeight = vPadding; + currentColHeight = 0; } // Get max width