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
51509bb2
Unverified
Commit
51509bb2
authored
May 14, 2020
by
Hugo Häggmark
Committed by
GitHub
May 14, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Units: adds scale symbol for currencies with suffixed symbol (#24678)
parent
cfac5912
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
56 additions
and
1 deletions
+56
-1
packages/grafana-data/src/valueFormats/symbolFormatters.test.ts
+55
-0
packages/grafana-data/src/valueFormats/symbolFormatters.ts
+1
-1
No files found.
packages/grafana-data/src/valueFormats/symbolFormatters.test.ts
0 → 100644
View file @
51509bb2
import
{
currency
}
from
'./symbolFormatters'
;
describe
(
'currency'
,
()
=>
{
const
symbol
=
'@'
;
describe
(
'when called without asSuffix'
,
()
=>
{
const
fmtFunc
=
currency
(
symbol
);
it
.
each
`
value | expectedSuffix | expectedText
${
999
}
|
${
''
}
|
${
'999'
}
${
1000
}
|
${
'K'
}
|
${
'1'
}
${
1000000
}
|
${
'M'
}
|
${
'1'
}
${
1000000000
}
|
${
'B'
}
|
${
'1'
}
${
1000000000000
}
|
${
'T'
}
|
${
'1'
}
${
1000000000000000
}
|
${
undefined
}
|
${
'NA'
}
${
-
1000000000000
}
|
${
'T'
}
|
${
'-1'
}
${
-
1000000000
}
|
${
'B'
}
|
${
'-1'
}
${
-
1000000
}
|
${
'M'
}
|
${
'-1'
}
${
-
1000
}
|
${
'K'
}
|
${
'-1'
}
${
-
999
}
|
${
''
}
|
${
'-999'
}
`
(
'when called with value:{$value}'
,
({
value
,
expectedSuffix
,
expectedText
})
=>
{
const
{
prefix
,
suffix
,
text
}
=
fmtFunc
(
value
);
expect
(
prefix
).
toEqual
(
symbol
);
expect
(
suffix
).
toEqual
(
expectedSuffix
);
expect
(
text
).
toEqual
(
expectedText
);
});
});
describe
(
'when called with asSuffix'
,
()
=>
{
const
fmtFunc
=
currency
(
symbol
,
true
);
it
.
each
`
value | expectedSuffix | expectedText
${
999
}
|
${
'@'
}
|
${
'999'
}
${
1000
}
|
${
'K@'
}
|
${
'1'
}
${
1000000
}
|
${
'M@'
}
|
${
'1'
}
${
1000000000
}
|
${
'B@'
}
|
${
'1'
}
${
1000000000000
}
|
${
'T@'
}
|
${
'1'
}
${
1000000000000000
}
|
${
undefined
}
|
${
'NA'
}
${
-
1000000000000
}
|
${
'T@'
}
|
${
'-1'
}
${
-
1000000000
}
|
${
'B@'
}
|
${
'-1'
}
${
-
1000000
}
|
${
'M@'
}
|
${
'-1'
}
${
-
1000
}
|
${
'K@'
}
|
${
'-1'
}
${
-
999
}
|
${
'@'
}
|
${
'-999'
}
`
(
'when called with value:{$value}'
,
({
value
,
expectedSuffix
,
expectedText
})
=>
{
const
{
prefix
,
suffix
,
text
}
=
fmtFunc
(
value
);
expect
(
prefix
).
toEqual
(
undefined
);
expect
(
suffix
).
toEqual
(
expectedSuffix
);
expect
(
text
).
toEqual
(
expectedText
);
});
});
});
packages/grafana-data/src/valueFormats/symbolFormatters.ts
View file @
51509bb2
...
@@ -10,7 +10,7 @@ export function currency(symbol: string, asSuffix?: boolean): ValueFormatter {
...
@@ -10,7 +10,7 @@ export function currency(symbol: string, asSuffix?: boolean): ValueFormatter {
}
}
const
scaled
=
scaler
(
size
,
decimals
,
scaledDecimals
);
const
scaled
=
scaler
(
size
,
decimals
,
scaledDecimals
);
if
(
asSuffix
)
{
if
(
asSuffix
)
{
scaled
.
suffix
=
s
ymbol
;
scaled
.
suffix
=
s
caled
.
suffix
!==
undefined
?
`
${
scaled
.
suffix
}${
symbol
}
`
:
undefined
;
}
else
{
}
else
{
scaled
.
prefix
=
symbol
;
scaled
.
prefix
=
symbol
;
}
}
...
...
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