Add option to allow square legend symbols at different sizes#4890
Add option to allow square legend symbols at different sizes#4890soniiic wants to merge 3 commits intochartjs:masterfrom
Conversation
If the useSquareBox option is set to true, the height is set to the same as the boxWidth option. It places it vertically central to the label. It also ensures the legend symbol never exceeds the size of the font size.
|
@soniiic thanks for PR this. I haven't looked too deeply yet. Would it be easier to simply create a @simonbrunel thoughts? |
|
Thanks for your consideration. My requirement was that it was square but I agree that adding boxHeight would allow more general usage. I have updated the code to allow the user to assign boxHeight in the label options Demo updated: https://codepen.io/soniiic/pen/zEgrGb |
etimberg
left a comment
There was a problem hiding this comment.
Thanks for updating to a boxHeight option! Is it possible to add unit tests for this? Also, could you update the docs in https://github.com/chartjs/Chart.js/blob/master/docs/configuration/legend.md
|
Ok, I'll have a go at those |
| } | ||
|
|
||
| function getBoxHeight(labelOpts, fontSize) { | ||
| return labelOpts.boxHeight ? |
There was a problem hiding this comment.
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;There was a problem hiding this comment.
Do we need to handle labelOpts.usePointStyle as in getBoxWidth()? or is it unrelated?
|
@dan-schoolcomms will you be able to address Simon's comments? |
|
@benmccann Sorry for not keeping on top of this. Adding the unit tests would require me getting a development environment set up which at the moment I do not have as I have just made the edit within github itself. At the moment I don't have the time to do this, but I will see if I can get an hour or two to start it to see how far I get. |
|
Closing due to inactivity |
If the useSquareBox option is set to true, the height is set to the same as the boxWidth option. It places it vertically central to the label. It also ensures the legend symbol never exceeds the size of the font size.
Demo: https://codepen.io/soniiic/pen/zEgrGb