Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 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
2 changes: 1 addition & 1 deletion docs/configuration/legend.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ The legend label configuration is nested below the legend configuration using th
| `padding` | `Number` | `10` | Padding between rows of colored boxes.
| `generateLabels` | `Function` | | Generates legend items for each thing in the legend. Default implementation returns the text + styling for the color box. See [Legend Item](#legend-item-interface) for details.
| `filter` | `Function` | `null` | Filters legend items out of the legend. Receives 2 parameters, a [Legend Item](#legend-item-interface) and the chart data.
| `usePointStyle` | `Boolean` | `false` | Label style will match corresponding point style (size is based on fontSize, boxWidth is not used in this case).
| `usePointStyle` | `Boolean` | `false` | Label box style will match corresponding point style (size is based on mimimum value between boxWidth and fontSize).

## Legend Item Interface

Expand Down
12 changes: 6 additions & 6 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 ?
fontSize * Math.SQRT2 :
return labelOpts.usePointStyle && labelOpts.boxWidth > fontSize ?
fontSize :
labelOpts.boxWidth;
}

Expand Down Expand Up @@ -369,10 +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 = fontSize * Math.SQRT2 / 2;
var offSet = radius / Math.SQRT2;
var centerX = x + offSet;
var centerY = y + offSet;
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