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
533b938f
Commit
533b938f
authored
Jan 17, 2019
by
Hugo Häggmark
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Removed baseColor
parent
e89746c3
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
39 additions
and
39 deletions
+39
-39
packages/grafana-ui/src/components/ThresholdsEditor/ThresholdsEditor.tsx
+13
-8
public/app/plugins/panel/gauge/GaugePanelOptions.tsx
+0
-2
public/app/plugins/panel/gauge/types.ts
+0
-1
public/app/viz/Gauge.test.tsx
+4
-5
public/app/viz/Gauge.tsx
+22
-23
No files found.
packages/grafana-ui/src/components/ThresholdsEditor/ThresholdsEditor.tsx
View file @
533b938f
...
...
@@ -19,9 +19,15 @@ export class ThresholdsEditor extends PureComponent<Props, State> {
constructor
(
props
:
Props
)
{
super
(
props
);
const
thresholds
:
Threshold
[]
=
props
.
thresholds
.
length
>
0
?
props
.
thresholds
:
[{
index
:
0
,
value
:
-
Infinity
,
color
:
colors
[
0
]
}];
const
addDefaultThreshold
=
this
.
props
.
thresholds
.
length
===
0
;
const
thresholds
:
Threshold
[]
=
addDefaultThreshold
?
[{
index
:
0
,
value
:
-
Infinity
,
color
:
colors
[
0
]
}]
:
props
.
thresholds
;
this
.
state
=
{
thresholds
};
if
(
addDefaultThreshold
)
{
this
.
onChange
();
}
}
onAddThreshold
=
(
index
:
number
)
=>
{
...
...
@@ -62,7 +68,7 @@ export class ThresholdsEditor extends PureComponent<Props, State> {
},
]),
},
()
=>
this
.
updateGau
ge
()
()
=>
this
.
onChan
ge
()
);
};
...
...
@@ -85,7 +91,7 @@ export class ThresholdsEditor extends PureComponent<Props, State> {
thresholds
:
newThresholds
.
filter
(
t
=>
t
!==
threshold
),
};
},
()
=>
this
.
updateGau
ge
()
()
=>
this
.
onChan
ge
()
);
};
...
...
@@ -124,11 +130,10 @@ export class ThresholdsEditor extends PureComponent<Props, State> {
{
thresholds
:
newThresholds
,
},
()
=>
this
.
updateGau
ge
()
()
=>
this
.
onChan
ge
()
);
};
onChangeBaseColor
=
(
color
:
string
)
=>
this
.
props
.
onChange
(
this
.
state
.
thresholds
);
onBlur
=
()
=>
{
this
.
setState
(
prevState
=>
{
const
sortThresholds
=
this
.
sortThresholds
([...
prevState
.
thresholds
]);
...
...
@@ -139,10 +144,10 @@ export class ThresholdsEditor extends PureComponent<Props, State> {
return
{
thresholds
:
sortThresholds
};
});
this
.
updateGau
ge
();
this
.
onChan
ge
();
};
updateGau
ge
=
()
=>
{
onChan
ge
=
()
=>
{
this
.
props
.
onChange
(
this
.
state
.
thresholds
);
};
...
...
public/app/plugins/panel/gauge/GaugePanelOptions.tsx
View file @
533b938f
import
React
,
{
PureComponent
}
from
'react'
;
import
{
BasicGaugeColor
,
PanelOptionsProps
,
ThresholdsEditor
,
Threshold
,
...
...
@@ -15,7 +14,6 @@ import { GaugeOptions } from './types';
export
const
defaultProps
=
{
options
:
{
baseColor
:
BasicGaugeColor
.
Green
,
minValue
:
0
,
maxValue
:
100
,
prefix
:
''
,
...
...
public/app/plugins/panel/gauge/types.ts
View file @
533b938f
import
{
Threshold
,
ValueMapping
}
from
'@grafana/ui'
;
export
interface
GaugeOptions
{
baseColor
:
string
;
decimals
:
number
;
valueMappings
:
ValueMapping
[];
maxValue
:
number
;
...
...
public/app/viz/Gauge.test.tsx
View file @
533b938f
import
React
from
'react'
;
import
{
shallow
}
from
'enzyme'
;
import
{
BasicGaugeColor
,
TimeSeriesVMs
}
from
'@grafana/ui'
;
import
{
TimeSeriesVMs
}
from
'@grafana/ui'
;
import
{
Gauge
,
Props
}
from
'./Gauge'
;
...
...
@@ -10,7 +10,6 @@ jest.mock('jquery', () => ({
const
setup
=
(
propOverrides
?:
object
)
=>
{
const
props
:
Props
=
{
baseColor
:
BasicGaugeColor
.
Green
,
maxValue
:
100
,
valueMappings
:
[],
minValue
:
0
,
...
...
@@ -18,7 +17,7 @@ const setup = (propOverrides?: object) => {
showThresholdMarkers
:
true
,
showThresholdLabels
:
false
,
suffix
:
''
,
thresholds
:
[],
thresholds
:
[
{
index
:
0
,
value
:
-
Infinity
,
color
:
'#7EB26D'
}
],
unit
:
'none'
,
stat
:
'avg'
,
height
:
300
,
...
...
@@ -42,12 +41,12 @@ describe('Get font color', () => {
it
(
'should get base color if no threshold'
,
()
=>
{
const
{
instance
}
=
setup
();
expect
(
instance
.
getFontColor
(
40
)).
toEqual
(
BasicGaugeColor
.
Green
);
expect
(
instance
.
getFontColor
(
40
)).
toEqual
(
'#7EB26D'
);
});
it
(
'should be f2f2f2'
,
()
=>
{
const
{
instance
}
=
setup
({
thresholds
:
[{
value
:
59
,
color
:
'#f2f2f2'
}],
thresholds
:
[{
index
:
0
,
value
:
-
Infinity
,
color
:
'#7EB26D'
},
{
index
:
1
,
value
:
59
,
color
:
'#f2f2f2'
}],
});
expect
(
instance
.
getFontColor
(
58
)).
toEqual
(
'#f2f2f2'
);
...
...
public/app/viz/Gauge.tsx
View file @
533b938f
...
...
@@ -6,7 +6,6 @@ import config from '../core/config';
import
kbn
from
'../core/utils/kbn'
;
export
interface
Props
{
baseColor
:
string
;
decimals
:
number
;
height
:
number
;
valueMappings
:
ValueMapping
[];
...
...
@@ -27,7 +26,6 @@ export class Gauge extends PureComponent<Props> {
canvasElement
:
any
;
static
defaultProps
=
{
baseColor
:
BasicGaugeColor
.
Green
,
maxValue
:
100
,
valueMappings
:
[],
minValue
:
0
,
...
...
@@ -91,24 +89,25 @@ export class Gauge extends PureComponent<Props> {
}
getFontColor
(
value
)
{
const
{
baseColor
,
maxValue
,
thresholds
}
=
this
.
props
;
const
{
maxValue
,
thresholds
}
=
this
.
props
;
if
(
thresholds
.
length
>
0
)
{
const
atThreshold
=
thresholds
.
filter
(
threshold
=>
value
<=
threshold
.
value
);
if
(
thresholds
.
length
===
1
)
{
return
thresholds
[
0
].
color
;
}
if
(
atThreshold
.
length
>
0
)
{
return
atThreshold
[
0
].
color
;
}
else
if
(
value
<=
maxValue
)
{
return
BasicGaugeColor
.
Red
;
}
const
atThreshold
=
thresholds
.
filter
(
threshold
=>
value
<
threshold
.
value
);
if
(
atThreshold
.
length
>
0
)
{
return
atThreshold
[
0
].
color
;
}
else
if
(
value
<=
maxValue
)
{
return
BasicGaugeColor
.
Red
;
}
return
baseColor
;
return
''
;
}
draw
()
{
const
{
baseColor
,
maxValue
,
minValue
,
timeSeries
,
...
...
@@ -137,16 +136,16 @@ export class Gauge extends PureComponent<Props> {
const
thresholdMarkersWidth
=
gaugeWidth
/
5
;
const
thresholdLabelFontSize
=
fontSize
/
2.5
;
const
formattedThresholds
=
[
{
value
:
minValue
,
color
:
BasicGaugeColor
.
Green
},
...
thresholds
.
map
((
threshold
,
index
)
=>
{
return
{
value
:
threshold
.
value
,
color
:
index
===
0
?
threshold
.
color
:
thresholds
[
index
].
color
,
};
}),
{
value
:
maxValue
,
color
:
thresholds
.
length
>
0
?
BasicGaugeColor
.
Red
:
baseColor
},
];
//
const formattedThresholds = [
//
{ value: minValue, color: BasicGaugeColor.Green },
//
...thresholds.map((threshold, index) => {
//
return {
//
value: threshold.value,
//
color: index === 0 ? threshold.color : thresholds[index].color,
//
};
//
}),
//
{ value: maxValue, color: thresholds.length > 0 ? BasicGaugeColor.Red : baseColor },
//
];
const
options
=
{
series
:
{
...
...
@@ -164,7 +163,7 @@ export class Gauge extends PureComponent<Props> {
layout
:
{
margin
:
0
,
thresholdWidth
:
0
},
cell
:
{
border
:
{
width
:
0
}
},
threshold
:
{
values
:
formattedT
hresholds
,
values
:
t
hresholds
,
label
:
{
show
:
showThresholdLabels
,
margin
:
thresholdMarkersWidth
+
1
,
...
...
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