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
f06fd5bc
Unverified
Commit
f06fd5bc
authored
Sep 25, 2019
by
Ryan McKinley
Committed by
GitHub
Sep 25, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
DisplayFormat: use toLocaleString for infinity
parent
0b85e34b
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
10 deletions
+20
-10
packages/grafana-ui/src/utils/valueFormats/valueFormats.test.ts
+15
-5
packages/grafana-ui/src/utils/valueFormats/valueFormats.ts
+5
-5
No files found.
packages/grafana-ui/src/utils/valueFormats/valueFormats.test.ts
View file @
f06fd5bc
import
{
toFixed
,
getValueFormat
}
from
'./valueFormats'
;
import
{
toFixed
,
getValueFormat
,
scaledUnits
}
from
'./valueFormats'
;
describe
(
'valueFormats'
,
()
=>
{
describe
(
'toFixed with edge cases'
,
()
=>
{
it
(
'should handle non number input gracefully'
,
()
=>
{
describe
(
'format edge cases'
,
()
=>
{
const
negInf
=
Number
.
NEGATIVE_INFINITY
.
toLocaleString
();
const
posInf
=
Number
.
POSITIVE_INFINITY
.
toLocaleString
();
it
(
'toFixed 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'
);
expect
(
toFixed
(
Number
.
NEGATIVE_INFINITY
)).
toBe
(
negInf
);
expect
(
toFixed
(
Number
.
POSITIVE_INFINITY
)).
toBe
(
posInf
);
});
it
(
'scaledUnits should handle non number input gracefully'
,
()
=>
{
const
disp
=
scaledUnits
(
5
,
[
'a'
,
'b'
,
'c'
]);
expect
(
disp
(
NaN
)).
toBe
(
'NaN'
);
expect
(
disp
(
Number
.
NEGATIVE_INFINITY
)).
toBe
(
negInf
);
expect
(
disp
(
Number
.
POSITIVE_INFINITY
)).
toBe
(
posInf
);
});
});
...
...
packages/grafana-ui/src/utils/valueFormats/valueFormats.ts
View file @
f06fd5bc
...
...
@@ -33,11 +33,8 @@ export function toFixed(value: number, decimals?: DecimalCount): string {
if
(
value
===
null
)
{
return
''
;
}
if
(
value
===
Number
.
NEGATIVE_INFINITY
)
{
return
'-Inf'
;
}
if
(
value
===
Number
.
POSITIVE_INFINITY
)
{
return
'Inf'
;
if
(
value
===
Number
.
NEGATIVE_INFINITY
||
value
===
Number
.
POSITIVE_INFINITY
)
{
return
value
.
toLocaleString
();
}
const
factor
=
decimals
?
Math
.
pow
(
10
,
Math
.
max
(
0
,
decimals
))
:
1
;
...
...
@@ -94,6 +91,9 @@ export function scaledUnits(factor: number, extArray: string[]) {
if
(
size
===
null
)
{
return
''
;
}
if
(
size
===
Number
.
NEGATIVE_INFINITY
||
size
===
Number
.
POSITIVE_INFINITY
||
isNaN
(
size
))
{
return
size
.
toLocaleString
();
}
let
steps
=
0
;
const
limit
=
extArray
.
length
;
...
...
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