-
Notifications
You must be signed in to change notification settings - Fork 66
[FIX] charts: correctly humanize decimal numbers #7287
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
base: 19.0
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import { toNumber } from "../../functions/helpers"; | ||
import { toNumber, tryToNumber } from "../../functions/helpers"; | ||
import { _t } from "../../translation"; | ||
import { | ||
CellValue, | ||
|
@@ -682,14 +682,18 @@ function _roundFormat<T extends InternalFormat>(internalFormat: T): T { | |
} | ||
|
||
export function humanizeNumber({ value, format }: FunctionResultObject, locale: Locale): string { | ||
const numberFormat = formatLargeNumber( | ||
{ | ||
value, | ||
format, | ||
}, | ||
undefined, | ||
locale | ||
); | ||
const numberValue = tryToNumber(value, locale); | ||
if (numberValue === undefined) { | ||
return ""; | ||
} | ||
let numberFormat: Format | undefined = format; | ||
if (Math.abs(numberValue) < 1000) { | ||
const hasDecimal = numberValue % 1 !== 0; | ||
numberFormat = !format && hasDecimal ? "0.####" : format; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure we need to have 4 decimals, I would have gone to 2, but why not :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ideally it's dependant on the number of digit before the comma (123.4, 12.34, 123.4). And ideally, we should also probably handle the different formats (a formatLargeNumber function, but for small ones) Not sure it's worth tho, I went with the fast & dumb approach. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
} else { | ||
numberFormat = formatLargeNumber({ value, format }, undefined, locale); | ||
} | ||
|
||
return formatValue(value, { format: numberFormat, locale }); | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not needed here, it's already in the
ChartWithAxisDesignPanel.components
:)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
up