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
909fe470
Commit
909fe470
authored
Nov 29, 2018
by
Peter Holmberg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update color on gauge when changing
parent
460d642b
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
43 additions
and
29 deletions
+43
-29
public/app/plugins/panel/gauge/Threshold.test.tsx
+13
-13
public/app/plugins/panel/gauge/Thresholds.tsx
+22
-12
public/app/viz/Gauge.tsx
+8
-4
No files found.
public/app/plugins/panel/gauge/Threshold.test.tsx
View file @
909fe470
...
...
@@ -16,8 +16,8 @@ const setup = (propOverrides?: object) => {
};
const
thresholds
=
[
{
index
:
0
,
label
:
'Min'
,
value
:
0
,
canRemove
:
false
,
color
:
'
#3aa655
'
},
{
index
:
1
,
label
:
''
,
value
:
50
,
canRemove
:
true
,
color
:
'
#ff851b
'
},
{
index
:
0
,
label
:
'Min'
,
value
:
0
,
canRemove
:
false
,
color
:
'
rgba(50, 172, 45, 0.97)
'
},
{
index
:
1
,
label
:
''
,
value
:
50
,
canRemove
:
true
,
color
:
'
rgba(237, 129, 40, 0.89)
'
},
{
index
:
2
,
label
:
'Max'
,
value
:
100
,
canRemove
:
false
},
];
...
...
@@ -28,8 +28,8 @@ describe('Add threshold', () => {
instance
.
onAddThreshold
(
1
);
expect
(
instance
.
state
.
thresholds
).
toEqual
([
{
index
:
0
,
label
:
'Min'
,
value
:
0
,
canRemove
:
false
,
color
:
'
#3aa655
'
},
{
index
:
1
,
label
:
''
,
value
:
50
,
canRemove
:
true
,
color
:
'
#ff851b
'
},
{
index
:
0
,
label
:
'Min'
,
value
:
0
,
canRemove
:
false
,
color
:
'
rgba(50, 172, 45, 0.97)
'
},
{
index
:
1
,
label
:
''
,
value
:
50
,
canRemove
:
true
,
color
:
'
rgba(237, 129, 40, 0.89)
'
},
{
index
:
2
,
label
:
'Max'
,
value
:
100
,
canRemove
:
false
},
]);
});
...
...
@@ -45,9 +45,9 @@ describe('Add threshold', () => {
instance
.
onAddThreshold
(
1
);
expect
(
instance
.
state
.
thresholds
).
toEqual
([
{
index
:
0
,
label
:
'Min'
,
value
:
0
,
canRemove
:
false
,
color
:
'
#3aa655
'
},
{
index
:
1
,
label
:
''
,
value
:
25
,
canRemove
:
true
,
color
:
'
#ff851b
'
},
{
index
:
2
,
label
:
''
,
value
:
50
,
canRemove
:
true
,
color
:
'
#ff851b
'
},
{
index
:
0
,
label
:
'Min'
,
value
:
0
,
canRemove
:
false
,
color
:
'
rgba(50, 172, 45, 0.97)
'
},
{
index
:
1
,
label
:
''
,
value
:
25
,
canRemove
:
true
,
color
:
'
rgba(237, 129, 40, 0.89)
'
},
{
index
:
2
,
label
:
''
,
value
:
50
,
canRemove
:
true
,
color
:
'
rgba(237, 129, 40, 0.89)
'
},
{
index
:
3
,
label
:
'Max'
,
value
:
100
,
canRemove
:
false
},
]);
});
...
...
@@ -116,9 +116,9 @@ describe('change threshold value', () => {
it
(
'should update value and resort rows'
,
()
=>
{
const
instance
=
setup
();
const
mockThresholds
=
[
{
index
:
0
,
label
:
'Min'
,
value
:
0
,
canRemove
:
false
,
color
:
'
#3aa655
'
},
{
index
:
1
,
label
:
''
,
value
:
50
,
canRemove
:
true
,
color
:
'
#ff851b
'
},
{
index
:
2
,
label
:
''
,
value
:
75
,
canRemove
:
true
,
color
:
'
#ff851b
'
},
{
index
:
0
,
label
:
'Min'
,
value
:
0
,
canRemove
:
false
,
color
:
'
rgba(50, 172, 45, 0.97)
'
},
{
index
:
1
,
label
:
''
,
value
:
50
,
canRemove
:
true
,
color
:
'
rgba(237, 129, 40, 0.89)
'
},
{
index
:
2
,
label
:
''
,
value
:
75
,
canRemove
:
true
,
color
:
'
rgba(237, 129, 40, 0.89)
'
},
{
index
:
3
,
label
:
'Max'
,
value
:
100
,
canRemove
:
false
},
];
...
...
@@ -132,9 +132,9 @@ describe('change threshold value', () => {
instance
.
onChangeThresholdValue
(
mockEvent
,
mockThresholds
[
1
]);
expect
(
instance
.
state
.
thresholds
).
toEqual
([
{
index
:
0
,
label
:
'Min'
,
value
:
0
,
canRemove
:
false
,
color
:
'
#3aa655
'
},
{
index
:
1
,
label
:
''
,
value
:
78
,
canRemove
:
true
,
color
:
'
#ff851b
'
},
{
index
:
2
,
label
:
''
,
value
:
75
,
canRemove
:
true
,
color
:
'
#ff851b
'
},
{
index
:
0
,
label
:
'Min'
,
value
:
0
,
canRemove
:
false
,
color
:
'
rgba(50, 172, 45, 0.97)
'
},
{
index
:
1
,
label
:
''
,
value
:
78
,
canRemove
:
true
,
color
:
'
rgba(237, 129, 40, 0.89)
'
},
{
index
:
2
,
label
:
''
,
value
:
75
,
canRemove
:
true
,
color
:
'
rgba(237, 129, 40, 0.89)
'
},
{
index
:
3
,
label
:
'Max'
,
value
:
100
,
canRemove
:
false
},
]);
});
...
...
public/app/plugins/panel/gauge/Thresholds.tsx
View file @
909fe470
...
...
@@ -15,7 +15,7 @@ export default class Thresholds extends PureComponent<PanelOptionsProps<OptionsP
this
.
state
=
{
thresholds
:
this
.
props
.
options
.
thresholds
||
[
{
index
:
0
,
label
:
'Min'
,
value
:
0
,
canRemove
:
false
,
color
:
'
#3aa655
'
},
{
index
:
0
,
label
:
'Min'
,
value
:
0
,
canRemove
:
false
,
color
:
'
rgba(50, 172, 45, 0.97)
'
},
{
index
:
1
,
label
:
'Max'
,
value
:
100
,
canRemove
:
false
},
],
userAddedThresholds
:
0
,
...
...
@@ -35,13 +35,16 @@ export default class Thresholds extends PureComponent<PanelOptionsProps<OptionsP
const
value
=
newThresholds
[
index
].
value
-
(
newThresholds
[
index
].
value
-
newThresholds
[
index
-
1
].
value
)
/
2
;
this
.
setState
(
prevState
=>
({
thresholds
:
this
.
sortThresholds
([
...
newThresholds
,
{
index
:
index
,
label
:
''
,
value
:
value
,
canRemove
:
true
,
color
:
'#ff851b'
},
]),
userAddedThresholds
:
prevState
.
userAddedThresholds
+
1
,
}));
this
.
setState
(
prevState
=>
({
thresholds
:
this
.
sortThresholds
([
...
newThresholds
,
{
index
:
index
,
label
:
''
,
value
:
value
,
canRemove
:
true
,
color
:
'rgba(237, 129, 40, 0.89)'
},
]),
userAddedThresholds
:
prevState
.
userAddedThresholds
+
1
,
}),
()
=>
this
.
updateGauge
()
);
};
onRemoveThreshold
=
threshold
=>
{
...
...
@@ -78,9 +81,12 @@ export default class Thresholds extends PureComponent<PanelOptionsProps<OptionsP
return
currentThreshold
;
});
this
.
setState
({
thresholds
:
newThresholds
,
});
this
.
setState
(
{
thresholds
:
newThresholds
,
},
()
=>
this
.
updateGauge
()
);
};
onBlur
=
()
=>
{
...
...
@@ -88,6 +94,10 @@ export default class Thresholds extends PureComponent<PanelOptionsProps<OptionsP
thresholds
:
this
.
sortThresholds
(
prevState
.
thresholds
),
}));
this
.
updateGauge
();
};
updateGauge
=
()
=>
{
this
.
props
.
onChange
({
...
this
.
props
.
options
,
thresholds
:
this
.
state
.
thresholds
});
};
...
...
@@ -106,7 +116,7 @@ export default class Thresholds extends PureComponent<PanelOptionsProps<OptionsP
return
thresholds
[
index
].
color
;
}
return
'
#d44939
'
;
return
'
rgb(212, 74, 58)
'
;
}
renderNoThresholds
()
{
...
...
public/app/viz/Gauge.tsx
View file @
909fe470
...
...
@@ -20,8 +20,6 @@ interface Props {
suffix
:
string
;
}
const
colors
=
[
'rgba(50, 172, 45, 0.97)'
,
'rgba(237, 129, 40, 0.89)'
,
'rgba(245, 54, 54, 0.9)'
];
export
class
Gauge
extends
PureComponent
<
Props
>
{
canvasElement
:
any
;
...
...
@@ -32,7 +30,10 @@ export class Gauge extends PureComponent<Props> {
showThresholdMarkers
:
true
,
showThresholdLabels
:
false
,
suffix
:
''
,
thresholds
:
[{
label
:
'Min'
,
value
:
0
},
{
label
:
'Max'
,
value
:
100
}],
thresholds
:
[
{
label
:
'Min'
,
value
:
0
,
color
:
'rgba(50, 172, 45, 0.97)'
},
{
label
:
'Max'
,
value
:
100
,
color
:
'rgba(245, 54, 54, 0.9)'
},
],
};
componentDidMount
()
{
...
...
@@ -76,10 +77,13 @@ export class Gauge extends PureComponent<Props> {
const
formattedThresholds
=
thresholds
.
map
((
threshold
,
index
)
=>
{
return
{
value
:
threshold
.
value
,
color
:
colors
[
index
],
// Hacky way to get correct color for threshold.
color
:
index
===
0
?
threshold
.
color
:
thresholds
[
index
-
1
].
color
,
};
});
console
.
log
(
formattedThresholds
);
const
options
=
{
series
:
{
gauges
:
{
...
...
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