Skip to content
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Fix using custom point size in legend
Takes min value from boxSize and fontSize when using point styles for legend boxes, and correctly displays them on the screen.
  • Loading branch information
Alfie Hopkin authored Jan 25, 2019
commit ceb5b2050490282fba6015e44da6fb7c98d641c0
11 changes: 6 additions & 5 deletions src/plugins/plugin.legend.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ defaults._set('global', {
* @return {Number} width of the color box area
*/
function getBoxWidth(labelOpts, fontSize) {
return labelOpts.usePointStyle ?
labelOpts.pointSize || fontSize * Math.SQRT2 :
return labelOpts.usePointStyle && labelOpts.boxWidth > fontSize ?
fontSize * Math.SQRT2 :
labelOpts.boxWidth;
}

Expand Down Expand Up @@ -369,9 +369,10 @@ var Legend = Element.extend({
if (opts.labels && opts.labels.usePointStyle) {
// Recalculate x and y for drawPoint() because its expecting
// x and y to be center of figure (instead of top left)
var radius = boxWidth * Math.SQRT2 / 2;
var centerX = x + (fontSize / 2);
var centerY = y + (fontSize / 2);
var pointWidth = Math.min(boxWidth, fontSize);
var radius = pointWidth * Math.SQRT2 / 2;
var centerX = x + pointWidth / 2;
var centerY = y + fontSize / 2;

// Draw pointStyle as legend symbol
helpers.canvas.drawPoint(ctx, legendItem.pointStyle, radius, centerX, centerY);
Expand Down