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
32b73bb4
Commit
32b73bb4
authored
Sep 25, 2019
by
Ryan McKinley
Committed by
Torkel Ödegaard
Sep 25, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ValueFormats: check for inf (#19376)
parent
94d7af88
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
0 deletions
+14
-0
packages/grafana-ui/src/utils/valueFormats/valueFormats.test.ts
+8
-0
packages/grafana-ui/src/utils/valueFormats/valueFormats.ts
+6
-0
No files found.
packages/grafana-ui/src/utils/valueFormats/valueFormats.test.ts
View file @
32b73bb4
import
{
toFixed
,
getValueFormat
}
from
'./valueFormats'
;
import
{
toFixed
,
getValueFormat
}
from
'./valueFormats'
;
describe
(
'valueFormats'
,
()
=>
{
describe
(
'valueFormats'
,
()
=>
{
describe
(
'toFixed with edge cases'
,
()
=>
{
it
(
'should handle non number input gracefully'
,
()
=>
{
expect
(
toFixed
(
NaN
)).
toBe
(
'NaN'
);
expect
(
toFixed
(
Number
.
NEGATIVE_INFINITY
)).
toBe
(
'-Inf'
);
expect
(
toFixed
(
Number
.
POSITIVE_INFINITY
)).
toBe
(
'Inf'
);
});
});
describe
(
'toFixed and negative decimals'
,
()
=>
{
describe
(
'toFixed and negative decimals'
,
()
=>
{
it
(
'should treat as zero decimals'
,
()
=>
{
it
(
'should treat as zero decimals'
,
()
=>
{
const
str
=
toFixed
(
186.123
,
-
2
);
const
str
=
toFixed
(
186.123
,
-
2
);
...
...
packages/grafana-ui/src/utils/valueFormats/valueFormats.ts
View file @
32b73bb4
...
@@ -33,6 +33,12 @@ export function toFixed(value: number, decimals?: DecimalCount): string {
...
@@ -33,6 +33,12 @@ export function toFixed(value: number, decimals?: DecimalCount): string {
if
(
value
===
null
)
{
if
(
value
===
null
)
{
return
''
;
return
''
;
}
}
if
(
value
===
Number
.
NEGATIVE_INFINITY
)
{
return
'-Inf'
;
}
if
(
value
===
Number
.
POSITIVE_INFINITY
)
{
return
'Inf'
;
}
const
factor
=
decimals
?
Math
.
pow
(
10
,
Math
.
max
(
0
,
decimals
))
:
1
;
const
factor
=
decimals
?
Math
.
pow
(
10
,
Math
.
max
(
0
,
decimals
))
:
1
;
const
formatted
=
String
(
Math
.
round
(
value
*
factor
)
/
factor
);
const
formatted
=
String
(
Math
.
round
(
value
*
factor
)
/
factor
);
...
...
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