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
50cd8d99
Commit
50cd8d99
authored
Dec 12, 2018
by
Peter Holmberg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
display value map or range map
parent
f7cb5a1f
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
36 additions
and
3 deletions
+36
-3
public/app/viz/Gauge.tsx
+36
-3
No files found.
public/app/viz/Gauge.tsx
View file @
50cd8d99
import
React
,
{
PureComponent
}
from
'react'
;
import
$
from
'jquery'
;
import
{
RangeMap
,
Threshold
,
TimeSeriesVMs
,
ValueMap
}
from
'app/types'
;
import
{
MappingType
,
RangeMap
,
Threshold
,
TimeSeriesVMs
,
ValueMap
}
from
'app/types'
;
import
config
from
'../core/config'
;
import
kbn
from
'../core/utils/kbn'
;
...
...
@@ -47,16 +47,49 @@ export class Gauge extends PureComponent<Props> {
this
.
draw
();
}
formatWithMappings
(
mappings
,
value
)
{
const
valueMaps
=
mappings
.
filter
(
m
=>
m
.
type
===
MappingType
.
ValueToText
);
const
rangeMaps
=
mappings
.
filter
(
m
=>
m
.
type
===
MappingType
.
RangeToText
);
const
valueMap
=
valueMaps
.
map
(
mapping
=>
{
if
(
mapping
.
value
&&
value
===
mapping
.
value
)
{
return
mapping
.
text
;
}
})[
0
];
const
rangeMap
=
rangeMaps
.
map
(
mapping
=>
{
if
(
mapping
.
from
&&
mapping
.
to
&&
value
>
mapping
.
from
&&
value
<
mapping
.
to
)
{
return
mapping
.
text
;
}
})[
0
];
return
{
rangeMap
,
valueMap
,
};
}
formatValue
(
value
)
{
const
{
decimals
,
prefix
,
suffix
,
unit
}
=
this
.
props
;
const
{
decimals
,
mappings
,
prefix
,
suffix
,
unit
}
=
this
.
props
;
const
formatFunc
=
kbn
.
valueFormats
[
unit
];
const
formattedValue
=
formatFunc
(
value
,
decimals
);
if
(
mappings
.
length
>
0
)
{
const
{
rangeMap
,
valueMap
}
=
this
.
formatWithMappings
(
mappings
,
formattedValue
);
if
(
valueMap
)
{
return
valueMap
;
}
else
if
(
rangeMap
)
{
return
rangeMap
;
}
}
if
(
isNaN
(
value
))
{
return
'-'
;
}
return
`
${
prefix
}
${
format
Func
(
value
,
decimals
)
}
${
suffix
}
`
;
return
`
${
prefix
}
${
format
tedValue
}
${
suffix
}
`
;
}
draw
()
{
...
...
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