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
38ea11d1
Commit
38ea11d1
authored
Jan 21, 2019
by
Hugo Häggmark
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added check for null value in ValueMappings and added tests
parent
96d28703
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
57 additions
and
4 deletions
+57
-4
packages/grafana-ui/src/components/Gauge/Gauge.test.tsx
+39
-0
packages/grafana-ui/src/components/Gauge/Gauge.tsx
+18
-4
No files found.
packages/grafana-ui/src/components/Gauge/Gauge.test.tsx
View file @
38ea11d1
...
...
@@ -135,6 +135,45 @@ describe('Format value with value mappings', () => {
expect
(
result
.
text
).
toEqual
(
'1-20'
);
});
it
(
'should return if value is null and value to text mapping value is null'
,
()
=>
{
const
valueMappings
:
ValueMapping
[]
=
[
{
id
:
0
,
operator
:
''
,
text
:
'1-20'
,
type
:
MappingType
.
RangeToText
,
from
:
'1'
,
to
:
'20'
},
{
id
:
1
,
operator
:
''
,
text
:
'<NULL>'
,
type
:
MappingType
.
ValueToText
,
value
:
'null'
},
];
const
value
=
null
;
const
{
instance
}
=
setup
({
valueMappings
});
const
result
=
instance
.
getFirstFormattedValueMapping
(
valueMappings
,
value
);
expect
(
result
.
text
).
toEqual
(
'<NULL>'
);
});
it
(
'should return if value is null and range to text mapping from is null'
,
()
=>
{
const
valueMappings
:
ValueMapping
[]
=
[
{
id
:
0
,
operator
:
''
,
text
:
'<NULL>'
,
type
:
MappingType
.
RangeToText
,
from
:
'null'
,
to
:
'10'
},
{
id
:
1
,
operator
:
''
,
text
:
'elva'
,
type
:
MappingType
.
ValueToText
,
value
:
'11'
},
];
const
value
=
null
;
const
{
instance
}
=
setup
({
valueMappings
});
const
result
=
instance
.
getFirstFormattedValueMapping
(
valueMappings
,
value
);
expect
(
result
.
text
).
toEqual
(
'<NULL>'
);
});
it
(
'should return if value is null and range to text mapping to is null'
,
()
=>
{
const
valueMappings
:
ValueMapping
[]
=
[
{
id
:
0
,
operator
:
''
,
text
:
'<NULL>'
,
type
:
MappingType
.
RangeToText
,
from
:
'1'
,
to
:
'null'
},
{
id
:
1
,
operator
:
''
,
text
:
'elva'
,
type
:
MappingType
.
ValueToText
,
value
:
'11'
},
];
const
value
=
null
;
const
{
instance
}
=
setup
({
valueMappings
});
const
result
=
instance
.
getFirstFormattedValueMapping
(
valueMappings
,
value
);
expect
(
result
.
text
).
toEqual
(
'<NULL>'
);
});
it
(
'should return rangeToText mapping where value equals to'
,
()
=>
{
const
valueMappings
:
ValueMapping
[]
=
[
{
id
:
0
,
operator
:
''
,
text
:
'1-10'
,
type
:
MappingType
.
RangeToText
,
from
:
'1'
,
to
:
'10'
},
...
...
packages/grafana-ui/src/components/Gauge/Gauge.tsx
View file @
38ea11d1
...
...
@@ -60,10 +60,14 @@ export class Gauge extends PureComponent<Props> {
}
addValueToTextMappingText
(
allValueMappings
:
ValueMapping
[],
valueToTextMapping
:
ValueMap
,
value
:
TimeSeriesValue
)
{
if
(
!
valueToTextMapping
.
value
)
{
if
(
valueToTextMapping
.
value
===
undefined
)
{
return
allValueMappings
;
}
if
(
value
===
null
&&
valueToTextMapping
.
value
&&
valueToTextMapping
.
value
.
toLowerCase
()
===
'null'
)
{
return
allValueMappings
.
concat
(
valueToTextMapping
);
}
const
valueAsNumber
=
parseFloat
(
value
as
string
);
const
valueToTextMappingAsNumber
=
parseFloat
(
valueToTextMapping
.
value
as
string
);
...
...
@@ -79,10 +83,19 @@ export class Gauge extends PureComponent<Props> {
}
addRangeToTextMappingText
(
allValueMappings
:
ValueMapping
[],
rangeToTextMapping
:
RangeMap
,
value
:
TimeSeriesValue
)
{
if
(
!
rangeToTextMapping
.
from
||
!
rangeToTextMapping
.
to
||
!
value
)
{
if
(
rangeToTextMapping
.
from
===
undefined
||
rangeToTextMapping
.
to
===
undefined
||
value
===
undefined
)
{
return
allValueMappings
;
}
if
(
value
===
null
&&
rangeToTextMapping
.
from
&&
rangeToTextMapping
.
to
&&
(
rangeToTextMapping
.
from
.
toLowerCase
()
===
'null'
||
rangeToTextMapping
.
to
.
toLowerCase
()
===
'null'
)
)
{
return
allValueMappings
.
concat
(
rangeToTextMapping
);
}
const
valueAsNumber
=
parseFloat
(
value
as
string
);
const
fromAsNumber
=
parseFloat
(
rangeToTextMapping
.
from
as
string
);
const
toAsNumber
=
parseFloat
(
rangeToTextMapping
.
to
as
string
);
...
...
@@ -139,8 +152,9 @@ export class Gauge extends PureComponent<Props> {
const
formatFunc
=
getValueFormat
(
unit
);
const
formattedValue
=
formatFunc
(
value
as
number
,
decimals
);
const
handleNoValueValue
=
formattedValue
||
'no value'
;
return
`
${
prefix
}
${
formatted
Value
}
${
suffix
}
`
;
return
`
${
prefix
}
${
handleNoValue
Value
}
${
suffix
}
`
;
}
getFontColor
(
value
:
TimeSeriesValue
)
{
...
...
@@ -204,7 +218,7 @@ export class Gauge extends PureComponent<Props> {
if
(
timeSeries
[
0
])
{
value
=
timeSeries
[
0
].
stats
[
stat
];
}
else
{
value
=
'N/A'
;
value
=
null
;
}
const
dimension
=
Math
.
min
(
width
,
height
*
1.3
);
...
...
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