mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Units: support dynamic count and currency units (#21279)
This commit is contained in:
@@ -53,6 +53,14 @@ const formatTests: ValueFormatTest[] = [
|
|||||||
{ id: 'si:µF', value: 1234000000, decimals: 2, result: '1.23 kF' },
|
{ id: 'si:µF', value: 1234000000, decimals: 2, result: '1.23 kF' },
|
||||||
{ id: 'si:µF', value: 1234000000000000, decimals: 2, result: '1.23 GF' },
|
{ id: 'si:µF', value: 1234000000000000, decimals: 2, result: '1.23 GF' },
|
||||||
|
|
||||||
|
// Counts (suffix)
|
||||||
|
{ id: 'count:xpm', value: 1234567, decimals: 2, result: '1.23M xpm' },
|
||||||
|
{ id: 'count:x/min', value: 1234, decimals: 2, result: '1.23K x/min' },
|
||||||
|
|
||||||
|
// Currency (prefix)
|
||||||
|
{ id: 'currency:@', value: 1234567, decimals: 2, result: '@1.23M' },
|
||||||
|
{ id: 'currency:@', value: 1234, decimals: 2, result: '@1.23K' },
|
||||||
|
|
||||||
// Time format
|
// Time format
|
||||||
{ id: 'time:YYYY', decimals: 0, value: dateTime(new Date(1999, 6, 2)).valueOf(), result: '1999' },
|
{ id: 'time:YYYY', decimals: 0, value: dateTime(new Date(1999, 6, 2)).valueOf(), result: '1999' },
|
||||||
{ id: 'time:YYYY.MM', decimals: 0, value: dateTime(new Date(2010, 6, 2)).valueOf(), result: '2010.07' },
|
{ id: 'time:YYYY.MM', decimals: 0, value: dateTime(new Date(2010, 6, 2)).valueOf(), result: '2010.07' },
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
import { getCategories } from './categories';
|
import { getCategories } from './categories';
|
||||||
import { DecimalCount } from '../types/displayValue';
|
import { DecimalCount } from '../types/displayValue';
|
||||||
import { toDateTimeValueFormatter } from './dateTimeFormatters';
|
import { toDateTimeValueFormatter } from './dateTimeFormatters';
|
||||||
import { getOffsetFromSIPrefix, decimalSIPrefix } from './symbolFormatters';
|
import { getOffsetFromSIPrefix, decimalSIPrefix, currency } from './symbolFormatters';
|
||||||
|
|
||||||
export interface FormattedValue {
|
export interface FormattedValue {
|
||||||
text: string;
|
text: string;
|
||||||
@@ -197,6 +197,12 @@ export function getValueFormat(id: string): ValueFormatter {
|
|||||||
const unit = offset === 0 ? sub : sub.substring(1);
|
const unit = offset === 0 ? sub : sub.substring(1);
|
||||||
return decimalSIPrefix(unit, offset);
|
return decimalSIPrefix(unit, offset);
|
||||||
}
|
}
|
||||||
|
if (key === 'count') {
|
||||||
|
return simpleCountUnit(sub);
|
||||||
|
}
|
||||||
|
if (key === 'currency') {
|
||||||
|
return currency(sub);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return toFixedUnit(id);
|
return toFixedUnit(id);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user