Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance legend label color point when usePointStyle is true #6006

Merged
merged 10 commits into from Feb 10, 2019
11 changes: 6 additions & 5 deletions src/plugins/plugin.legend.js
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 :
alfiehopkin marked this conversation as resolved.
Show resolved Hide resolved
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);
alfiehopkin marked this conversation as resolved.
Show resolved Hide resolved
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