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
abe96f4f
Unverified
Commit
abe96f4f
authored
Nov 05, 2020
by
Marcus Andersson
Committed by
GitHub
Nov 05, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Units: added support to handle negative fractional numbers. (#28849)
parent
e54fc474
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
2 deletions
+20
-2
packages/grafana-data/src/field/displayProcessor.test.ts
+19
-1
packages/grafana-data/src/field/displayProcessor.ts
+1
-1
No files found.
packages/grafana-data/src/field/displayProcessor.test.ts
View file @
abe96f4f
import
{
getDisplayProcessor
,
getRawDisplayProcessor
}
from
'./displayProcessor'
;
import
{
getD
ecimalsForValue
,
getD
isplayProcessor
,
getRawDisplayProcessor
}
from
'./displayProcessor'
;
import
{
DisplayProcessor
,
DisplayValue
}
from
'../types/displayValue'
;
import
{
MappingType
,
ValueMapping
}
from
'../types/valueMapping'
;
import
{
FieldConfig
,
FieldType
,
ThresholdsMode
}
from
'../types'
;
...
...
@@ -329,3 +329,21 @@ describe('getRawDisplayProcessor', () => {
expect
(
result
).
toEqual
({
text
:
expected
,
numeric
:
null
});
});
});
describe
(
'getDecimalsForValue'
,
()
=>
{
it
.
each
`
value | expected
${
0
}
|
${
0
}
${
13.37
}
|
${
0
}
${
-
13.37
}
|
${
0
}
${
12679.3712345811212
}
|
${
0
}
${
-
12679.3712345811212
}
|
${
0
}
${
0.3712345
}
|
${
2
}
${
-
0.37123458
}
|
${
2
}
${
-
0.04671994403853774
}
|
${
3
}
${
0.04671994403853774
}
|
${
3
}
`
(
'should return correct suggested decimal count'
,
({
value
,
expected
})
=>
{
const
result
=
getDecimalsForValue
(
value
);
expect
(
result
.
decimals
).
toEqual
(
expected
);
});
});
packages/grafana-data/src/field/displayProcessor.ts
View file @
abe96f4f
...
...
@@ -143,7 +143,7 @@ export function getDecimalsForValue(value: number, decimalOverride?: DecimalCoun
return
{
decimals
:
decimalOverride
,
scaledDecimals
:
null
};
}
let
dec
=
-
Math
.
floor
(
Math
.
log
(
value
)
/
Math
.
LN10
)
+
1
;
let
dec
=
-
Math
.
floor
(
Math
.
log
(
Math
.
abs
(
value
)
)
/
Math
.
LN10
)
+
1
;
const
magn
=
Math
.
pow
(
10
,
-
dec
);
const
norm
=
value
/
magn
;
// norm is between 1.0 and 10.0
let
size
;
...
...
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