Skip to content
This repository was archived by the owner on Nov 25, 2021. It is now read-only.

Conversation

sluger
Copy link

@sluger sluger commented Apr 15, 2019

provide option to limit number of decimal digits

Related issue: #37

@sluger sluger requested a review from thinkh April 15, 2019 16:26
@sluger sluger changed the base branch from master to develop April 15, 2019 16:27
Copy link
Member

@thinkh thinkh left a comment

Choose a reason for hiding this comment

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

@sluger Thanks for addressing the issue and adding the new option. In my tests the new config option works well. However, I found one minor issue that you should address before merging.


export function toFixed(value) {
const decimals = this._chart.config.options.tooltipDecimals; // inject number of decimals from config
if (!decimals || typeof decimals !== 'number' || decimals < 0) {
Copy link
Member

@thinkh thinkh Apr 16, 2019

Choose a reason for hiding this comment

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

This doesn't work as expected. !decimals will also be true for tooltipDecimals: 0 and return the full value. As developer I would expect that the function returns an integer.

The fix would be explicitly checking for null and undefined:

if (decimals === null || decimals === undefined || typeof decimals !== 'number' || decimals < 0) {
Copy link
Author

Choose a reason for hiding this comment

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

due to coercion decimals == null will check for both null and undefined

@sluger sluger requested a review from thinkh April 17, 2019 12:29
Copy link
Member

@thinkh thinkh left a comment

Choose a reason for hiding this comment

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

Looks good now!

@thinkh thinkh merged commit e443b9b into develop Apr 18, 2019
@thinkh thinkh deleted the sluger/37_tooltips_decimals branch April 18, 2019 09:25
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
2 participants