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
368f1f67
Commit
368f1f67
authored
Dec 07, 2018
by
Peter Holmberg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
render a value mapping row
parent
4f39df90
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
165 additions
and
61 deletions
+165
-61
public/app/plugins/panel/gauge/MappingRow.tsx
+141
-0
public/app/plugins/panel/gauge/ValueMappings.tsx
+22
-61
public/app/plugins/panel/gauge/module.tsx
+2
-0
No files found.
public/app/plugins/panel/gauge/MappingRow.tsx
0 → 100644
View file @
368f1f67
import
React
,
{
PureComponent
}
from
'react'
;
import
{
Label
}
from
'app/core/components/Label/Label'
;
import
ToggleButtonGroup
,
{
ToggleButton
}
from
'app/core/components/ToggleButtonGroup/ToggleButtonGroup'
;
import
{
RangeMap
,
ValueMap
}
from
'app/types'
;
enum
MappingType
{
ValueToText
=
1
,
RangeToText
=
2
,
}
interface
Props
{
mapping
:
ValueMap
|
RangeMap
;
updateMapping
:
(
mapping
)
=>
void
;
}
interface
State
{
mapping
:
ValueMap
|
RangeMap
;
mappingType
:
MappingType
;
}
export
default
class
MappingRow
extends
PureComponent
<
Props
,
State
>
{
constructor
(
props
)
{
super
(
props
);
this
.
state
=
{
mappingType
:
MappingType
.
ValueToText
,
mapping
:
props
.
mapping
,
};
}
onMappingValueChange
=
event
=>
{
const
{
mapping
}
=
this
.
state
;
const
updatedMapping
=
{
...
mapping
,
value
:
event
.
target
.
value
};
this
.
setState
({
mapping
:
updatedMapping
});
};
onMappingFromChange
=
event
=>
{
const
{
mapping
}
=
this
.
state
;
const
updatedMapping
=
{
...
mapping
,
from
:
event
.
target
.
value
};
this
.
setState
({
mapping
:
updatedMapping
});
};
onMappingToChange
=
event
=>
{
const
{
mapping
}
=
this
.
state
;
const
updatedMapping
=
{
...
mapping
,
to
:
event
.
target
.
value
};
this
.
setState
({
mapping
:
updatedMapping
});
};
onMappingTextChange
=
event
=>
{
const
{
mapping
}
=
this
.
state
;
const
updatedMapping
=
{
...
mapping
,
text
:
event
.
target
.
value
};
this
.
setState
({
mapping
:
updatedMapping
});
};
onMappingTypeChange
=
mappingType
=>
this
.
setState
({
mappingType
});
renderRow
()
{
const
{
mapping
,
mappingType
}
=
this
.
state
;
if
(
mappingType
===
MappingType
.
RangeToText
)
{
const
rangeMap
=
mapping
as
RangeMap
;
return
(
<
div
className=
"gf-form-inline"
>
<
div
className=
"gf-form-group"
>
<
Label
>
From
</
Label
>
<
input
value=
{
rangeMap
.
from
}
onChange=
{
this
.
onMappingFromChange
}
/>
</
div
>
<
div
className=
"gf-form-group"
>
<
Label
>
To
</
Label
>
<
input
value=
{
rangeMap
.
to
}
onChange=
{
this
.
onMappingToChange
}
/>
</
div
>
<
div
className=
"gf-form-group"
>
<
Label
>
Text
</
Label
>
<
input
value=
{
rangeMap
.
text
}
onChange=
{
this
.
onMappingTextChange
}
/>
</
div
>
</
div
>
);
}
const
valueMap
=
mapping
as
ValueMap
;
return
(
<
div
className=
"gf-form-inline"
>
<
div
className=
"gf-form-inline"
>
<
Label
width=
{
4
}
>
Value
</
Label
>
<
input
className=
"gf-form-input"
onChange=
{
this
.
onMappingValueChange
}
value=
{
valueMap
.
value
}
/>
</
div
>
<
div
className=
"gf-form-inline"
>
<
Label
width=
{
4
}
>
Text
</
Label
>
<
input
className=
"gf-form-input"
value=
{
valueMap
.
text
}
onChange=
{
this
.
onMappingTextChange
}
/>
</
div
>
</
div
>
);
}
render
()
{
const
{
mappingType
}
=
this
.
state
;
return
(
<
div
>
<
div
className=
"gf-form-inline"
>
<
ToggleButtonGroup
label=
"Mapping type"
onChange=
{
mappingType
=>
this
.
onMappingTypeChange
(
mappingType
)
}
render=
{
({
selectedValue
,
onChange
})
=>
{
return
[
<
ToggleButton
className=
"btn-small"
key=
"value"
onChange=
{
onChange
}
selected=
{
selectedValue
===
mappingType
}
value=
"Value"
>
Value
</
ToggleButton
>,
<
ToggleButton
className=
"btn-small"
key=
"range"
onChange=
{
onChange
}
selected=
{
selectedValue
===
mappingType
}
value=
"Range"
>
Range
</
ToggleButton
>,
];
}
}
/>
<
div
>
{
this
.
renderRow
()
}
</
div
>
</
div
>
</
div
>
);
}
}
public/app/plugins/panel/gauge/ValueMappings.tsx
View file @
368f1f67
import
React
,
{
PureComponent
}
from
'react'
;
import
React
,
{
PureComponent
}
from
'react'
;
import
{
Label
}
from
'app/core/components/Label/Label'
;
import
MappingRow
from
'./MappingRow'
;
import
SimplePicker
from
'app/core/components/Picker/SimplePicker'
;
import
{
OptionModuleProps
}
from
'./module'
;
import
{
OptionModuleProps
}
from
'./module'
;
import
{
RangeMap
,
ValueMap
}
from
'app/types'
;
import
{
RangeMap
,
ValueMap
}
from
'app/types'
;
interface
State
{
interface
State
{
combinedMappings
:
any
[];
valueMaps
:
ValueMap
[];
valueMaps
:
ValueMap
[];
rangeMaps
:
RangeMap
[];
rangeMaps
:
RangeMap
[];
}
}
enum
MappingType
{
ValueToText
=
1
,
RangeToText
=
2
,
}
const
mappingOptions
=
[
{
name
:
'Value to text'
,
value
:
MappingType
.
ValueToText
},
{
name
:
'Range to text'
,
value
:
MappingType
.
RangeToText
},
];
export
default
class
ValueMappings
extends
PureComponent
<
OptionModuleProps
,
State
>
{
export
default
class
ValueMappings
extends
PureComponent
<
OptionModuleProps
,
State
>
{
constructor
(
props
)
{
constructor
(
props
)
{
super
(
props
);
super
(
props
);
this
.
state
=
{
this
.
state
=
{
valueMaps
:
props
.
options
.
valueMaps
,
combinedMappings
:
props
.
options
.
valueMaps
.
concat
(
props
.
options
.
rangeMaps
)
,
rangeMaps
:
props
.
options
.
rangeMaps
,
rangeMaps
:
props
.
options
.
rangeMaps
,
valueMaps
:
props
.
options
.
valueMaps
,
};
};
}
}
onMappingTypeChange
=
option
=>
this
.
props
.
onChange
({
...
this
.
props
.
options
,
mappingType
:
option
.
value
});
add
ValueMap
=
()
=>
add
Mapping
=
()
=>
this
.
setState
(
prevState
=>
({
this
.
setState
(
prevState
=>
({
valueMaps
:
[...
prevState
.
valueMap
s
,
{
op
:
''
,
value
:
''
,
text
:
''
}],
combinedMappings
:
[...
prevState
.
combinedMapping
s
,
{
op
:
''
,
value
:
''
,
text
:
''
}],
}));
}));
addRangeMap
=
()
=>
{
updateGauge
=
mapping
=>
{
this
.
setState
=
()
=>
this
.
setState
(
prevState
=>
({
this
.
setState
(
prevState
=>
({
valueMaps
:
[...
prevState
.
valueMaps
,
{
op
:
''
,
value
:
''
,
text
:
''
,
from
:
''
,
to
:
''
}],
combinedMappings
:
prevState
.
combinedMappings
.
map
(
m
=>
{
}));
if
(
m
===
mapping
)
{
};
return
{
...
mapping
};
updateGauge
=
()
=>
{};
renderValueMapList
()
{
const
{
mappingType
,
rangeMaps
,
valueMaps
}
=
this
.
props
.
options
;
if
(
mappingType
===
MappingType
.
RangeToText
)
{
return
(
<
div
>
{
rangeMaps
.
length
>
0
?
rangeMaps
.
map
((
range
,
index
)
=>
{
return
<
div
>
{
`${range.from}-${range.to}`
}
</
div
>;
})
:
'aint no ranges, add one?'
}
</
div
>
);
}
}
return
(
return
m
;
<
div
>
}),
{
valueMaps
.
length
>
0
}));
?
valueMaps
.
map
((
value
,
index
)
=>
{
};
return
<
div
>
{
`${value}`
}
</
div
>;
})
:
'aint no values, add one?'
}
</
div
>
);
}
render
()
{
render
()
{
const
{
mappingType
}
=
this
.
props
.
options
;
const
{
combinedMappings
}
=
this
.
state
;
return
(
return
(
<
div
className=
"gf-form-group"
>
<
div
className=
"
section
gf-form-group"
>
<
div
className=
"gf-form"
>
<
div
className=
"gf-form"
>
<
Label
width=
{
5
}
>
Type
</
Label
>
<
div
className=
"mappings"
>
<
SimplePicker
{
combinedMappings
.
length
>
0
&&
options=
{
mappingOptions
}
combinedMappings
.
map
((
mapping
,
index
)
=>
{
defaultValue=
{
MappingType
.
ValueToText
}
return
<
MappingRow
key=
{
index
}
mapping=
{
mapping
}
updateMapping=
{
this
.
updateGauge
}
/>;
getOptionLabel=
{
i
=>
i
.
name
}
})
}
onSelected=
{
option
=>
this
.
onMappingTypeChange
(
option
)
}
width=
{
5
}
value=
{
mappingType
}
/>
</
div
>
</
div
>
<
div
className=
"section gf-form-group"
>
<
div
onClick=
{
this
.
addMapping
}
>
Add mapping
</
div
>
<
h5
className=
"page-heading"
>
Set value mappings
</
h5
>
<
div
className=
"gf-form"
>
{
this
.
renderValueMapList
()
}
</
div
>
</
div
>
</
div
>
</
div
>
</
div
>
);
);
...
...
public/app/plugins/panel/gauge/module.tsx
View file @
368f1f67
...
@@ -34,6 +34,8 @@ export const defaultProps = {
...
@@ -34,6 +34,8 @@ export const defaultProps = {
showThresholdMarkers
:
true
,
showThresholdMarkers
:
true
,
showThresholdLabels
:
false
,
showThresholdLabels
:
false
,
suffix
:
''
,
suffix
:
''
,
valueMaps
:
[],
rangeMaps
:
[],
},
},
};
};
...
...
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