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
52c39904
Unverified
Commit
52c39904
authored
Apr 09, 2019
by
Torkel Ödegaard
Committed by
GitHub
Apr 09, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Graph: Fixed auto decimals in legend values (#16455)
Fixes #16448
parent
a96194fa
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
28 deletions
+35
-28
packages/grafana-ui/src/utils/valueFormats/valueFormats.test.ts
+28
-19
packages/grafana-ui/src/utils/valueFormats/valueFormats.ts
+7
-9
No files found.
packages/grafana-ui/src/utils/valueFormats/valueFormats.test.ts
View file @
52c39904
import
{
toFixed
,
getValueFormat
}
from
'./valueFormats'
;
describe
(
'kbn.toFixed and negative decimals'
,
()
=>
{
it
(
'should treat as zero decimals'
,
()
=>
{
const
str
=
toFixed
(
186.123
,
-
2
);
expect
(
str
).
toBe
(
'186'
);
describe
(
'valueFormats'
,
()
=>
{
describe
(
'toFixed and negative decimals'
,
()
=>
{
it
(
'should treat as zero decimals'
,
()
=>
{
const
str
=
toFixed
(
186.123
,
-
2
);
expect
(
str
).
toBe
(
'186'
);
});
});
});
describe
(
'kbn ms format when scaled decimals is null do not use it'
,
()
=>
{
it
(
'should use specified decimals'
,
()
=>
{
const
str
=
getValueFormat
(
'ms'
)(
10000086.123
,
1
,
null
);
expect
(
str
).
toBe
(
'2.8 hour'
);
describe
(
'ms format when scaled decimals is null do not use it'
,
()
=>
{
it
(
'should use specified decimals'
,
()
=>
{
const
str
=
getValueFormat
(
'ms'
)(
10000086.123
,
1
,
null
);
expect
(
str
).
toBe
(
'2.8 hour'
);
});
});
});
describe
(
'kbn kbytes format when scaled decimals is null do not use it'
,
()
=>
{
it
(
'should use specified decimals'
,
()
=>
{
const
str
=
getValueFormat
(
'kbytes'
)(
10000000
,
3
,
null
);
expect
(
str
).
toBe
(
'9.537 GiB'
);
describe
(
'kbytes format when scaled decimals is null do not use it'
,
()
=>
{
it
(
'should use specified decimals'
,
()
=>
{
const
str
=
getValueFormat
(
'kbytes'
)(
10000000
,
3
,
null
);
expect
(
str
).
toBe
(
'9.537 GiB'
);
});
});
describe
(
'deckbytes format when scaled decimals is null do not use it'
,
()
=>
{
it
(
'should use specified decimals'
,
()
=>
{
const
str
=
getValueFormat
(
'deckbytes'
)(
10000000
,
3
,
null
);
expect
(
str
).
toBe
(
'10.000 GB'
);
});
});
});
describe
(
'kbn deckbytes format when scaled decimals is null do not use it'
,
()
=>
{
it
(
'should use specified decimals'
,
()
=>
{
const
str
=
getValueFormat
(
'deckbytes'
)(
10000000
,
3
,
null
);
expect
(
str
).
toBe
(
'10.000 GB'
);
describe
(
'ms format when scaled decimals is 0'
,
()
=>
{
it
(
'should use scaledDecimals and add 3'
,
()
=>
{
const
str
=
getValueFormat
(
'ms'
)(
1200
,
0
,
0
);
expect
(
str
).
toBe
(
'1.200 s'
);
});
});
});
packages/grafana-ui/src/utils/valueFormats/valueFormats.ts
View file @
52c39904
...
...
@@ -56,17 +56,15 @@ export function toFixed(value: number, decimals?: DecimalCount): string {
export
function
toFixedScaled
(
value
:
number
,
decimals
?
:
DecimalCount
,
scaledDecimals
?
:
DecimalCount
,
additionalDecimals
?:
DecimalCount
,
decimals
:
DecimalCount
,
scaledDecimals
:
DecimalCount
,
additionalDecimals
:
number
,
ext
?:
string
)
{
if
(
scaledDecimals
)
{
if
(
additionalDecimals
)
{
return
toFixed
(
value
,
scaledDecimals
+
additionalDecimals
)
+
ext
;
}
else
{
return
toFixed
(
value
,
scaledDecimals
)
+
ext
;
}
if
(
scaledDecimals
===
null
||
scaledDecimals
===
undefined
)
{
return
toFixed
(
value
,
decimals
)
+
ext
;
}
else
{
return
toFixed
(
value
,
scaledDecimals
+
additionalDecimals
)
+
ext
;
}
return
toFixed
(
value
,
decimals
)
+
ext
;
...
...
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