Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nexpie-grafana-theme
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kornkitt Poolsup
nexpie-grafana-theme
Commits
c1b70787
Unverified
Commit
c1b70787
authored
Jan 02, 2020
by
Ryan McKinley
Committed by
GitHub
Jan 02, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Units: support dynamic count and currency units (#21279)
parent
1764c241
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
1 deletions
+15
-1
packages/grafana-data/src/valueFormats/valueFormats.test.ts
+8
-0
packages/grafana-data/src/valueFormats/valueFormats.ts
+7
-1
No files found.
packages/grafana-data/src/valueFormats/valueFormats.test.ts
View file @
c1b70787
...
...
@@ -53,6 +53,14 @@ const formatTests: ValueFormatTest[] = [
{
id
:
'si:µF'
,
value
:
1234000000
,
decimals
:
2
,
result
:
'1.23 kF'
},
{
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
{
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'
},
...
...
packages/grafana-data/src/valueFormats/valueFormats.ts
View file @
c1b70787
import
{
getCategories
}
from
'./categories'
;
import
{
DecimalCount
}
from
'../types/displayValue'
;
import
{
toDateTimeValueFormatter
}
from
'./dateTimeFormatters'
;
import
{
getOffsetFromSIPrefix
,
decimalSIPrefix
}
from
'./symbolFormatters'
;
import
{
getOffsetFromSIPrefix
,
decimalSIPrefix
,
currency
}
from
'./symbolFormatters'
;
export
interface
FormattedValue
{
text
:
string
;
...
...
@@ -197,6 +197,12 @@ export function getValueFormat(id: string): ValueFormatter {
const unit = offset === 0 ? sub : sub.substring(1);
return decimalSIPrefix(unit, offset);
}
if (key === 'count') {
return simpleCountUnit(sub);
}
if (key === 'currency') {
return currency(sub);
}
}
return toFixedUnit(id);
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment