Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/plugins/plugin.legend.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,12 @@ module.exports = function(Chart) {
labelOpts.boxWidth;
}

function getBoxHeight(labelOpts, fontSize) {
return labelOpts.boxHeight ?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we consider 0 a valid height (which I think is), then:

return helpers.isNullOrUndef(options.boxHeight) ? options.boxHeight : fontSize;

else this can be simplified as:

return options.boxHeight || fontSize;

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to handle labelOpts.usePointStyle as in getBoxWidth()? or is it unrelated?

labelOpts.boxHeight :
fontSize;
}

Chart.Legend = Element.extend({

initialize: function(config) {
Expand Down Expand Up @@ -346,6 +352,7 @@ module.exports = function(Chart) {
ctx.font = labelFont;

var boxWidth = getBoxWidth(labelOpts, fontSize);
var boxHeight = getBoxHeight(labelOpts, fontSize);
var hitboxes = me.legendHitBoxes;

// current position
Expand Down Expand Up @@ -381,11 +388,13 @@ module.exports = function(Chart) {
// Draw pointStyle as legend symbol
helpers.canvas.drawPoint(ctx, legendItem.pointStyle, radius, centerX, centerY);
} else {
y += (fontSize - boxHeight) / 2;

// Draw box as legend symbol
if (!isLineWidthZero) {
ctx.strokeRect(x, y, boxWidth, fontSize);
ctx.strokeRect(x, y, boxWidth, boxHeight);
}
ctx.fillRect(x, y, boxWidth, fontSize);
ctx.fillRect(x, y, boxWidth, boxHeight);
}

ctx.restore();
Expand Down