mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-11-21 14:44:00 +00:00
app/vmui: do not round the number in formatPrettyNumber() if the range isn't set
This commit is contained in:
parent
006af394ff
commit
c94020f7dc
2 changed files with 13 additions and 2 deletions
|
@ -40,7 +40,7 @@ const Index: FC = () => {
|
|||
const getQueryStatsTitle = (key: keyof TopQueryStats) => {
|
||||
if (!data) return key;
|
||||
const value = data[key];
|
||||
if (typeof value === "number") return formatPrettyNumber(value, 0, value);
|
||||
if (typeof value === "number") return formatPrettyNumber(value);
|
||||
return value || key;
|
||||
};
|
||||
|
||||
|
|
|
@ -37,7 +37,18 @@ export const formatPrettyNumber = (n: number | null | undefined, min = 0, max =
|
|||
if (n === undefined || n === null) {
|
||||
return "";
|
||||
}
|
||||
let digits = 3 + Math.floor(1 + Math.log10(Math.max(Math.abs(min), Math.abs(max))) - Math.log10(Math.abs(min - max)));
|
||||
const range = Math.abs(max - min);
|
||||
if (isNaN(range) || range == 0) {
|
||||
// Return the constant number as is if the range isn't set of it is too small.
|
||||
if (Math.abs(n) >= 1000) {
|
||||
return n.toLocaleString("en-US");
|
||||
}
|
||||
return n.toString();
|
||||
}
|
||||
// Make sure n has 3 significant digits on the given range.
|
||||
// This precision should be enough for most UX cases,
|
||||
// since the remaining digits are usually a white noise.
|
||||
let digits = 3 + Math.floor(1 + Math.log10(Math.max(Math.abs(min), Math.abs(max))) - Math.log10(range));
|
||||
if (isNaN(digits) || digits > 20) {
|
||||
digits = 20;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue