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