Skip to content

Commit

Permalink
Calculate the maximum height instead of adjusting initial column heights
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan Tagscherer committed Oct 20, 2018
1 parent e8f9c50 commit 7a58896
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/plugins/plugin.legend.js
Expand Up @@ -272,21 +272,22 @@ 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) {
var boxWidth = getBoxWidth(labelOpts, fontSize);
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
Expand Down

0 comments on commit 7a58896

Please sign in to comment.