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
1303a667
Commit
1303a667
authored
Mar 17, 2019
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Great progress on bar gauge look
parent
91ff146d
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
52 additions
and
27 deletions
+52
-27
packages/grafana-ui/src/components/BarGauge/BarGauge.test.tsx
+1
-1
packages/grafana-ui/src/components/BarGauge/BarGauge.tsx
+44
-23
public/app/plugins/panel/bargauge/types.ts
+7
-3
No files found.
packages/grafana-ui/src/components/BarGauge/BarGauge.test.tsx
View file @
1303a667
...
...
@@ -15,7 +15,7 @@ const setup = (propOverrides?: object) => {
minValue
:
0
,
prefix
:
''
,
suffix
:
''
,
displayMode
:
'
simple
'
,
displayMode
:
'
basic
'
,
thresholds
:
[{
index
:
0
,
value
:
-
Infinity
,
color
:
'#7EB26D'
}],
unit
:
'none'
,
height
:
300
,
...
...
packages/grafana-ui/src/components/BarGauge/BarGauge.tsx
View file @
1303a667
...
...
@@ -23,7 +23,7 @@ export interface Props extends Themeable {
prefix
?:
string
;
suffix
?:
string
;
decimals
?:
number
;
displayMode
:
'
simple'
|
'lcd
'
;
displayMode
:
'
basic'
|
'lcd'
|
'gradient
'
;
}
export
class
BarGauge
extends
PureComponent
<
Props
>
{
...
...
@@ -32,7 +32,7 @@ export class BarGauge extends PureComponent<Props> {
minValue
:
0
,
value
:
100
,
unit
:
'none'
,
displayMode
:
'
simple
'
,
displayMode
:
'
basic
'
,
orientation
:
VizOrientation
.
Horizontal
,
thresholds
:
[],
valueMappings
:
[],
...
...
@@ -47,10 +47,13 @@ export class BarGauge extends PureComponent<Props> {
const
formatFunc
=
getValueFormat
(
unit
);
const
valueFormatted
=
formatFunc
(
numericValue
,
decimals
);
if
(
displayMode
===
'lcd'
)
{
return
this
.
renderLcdMode
(
valueFormatted
,
valuePercent
);
}
else
{
return
this
.
renderSimpleMode
(
valueFormatted
,
valuePercent
);
switch
(
displayMode
)
{
case
'lcd'
:
return
this
.
renderRetroBars
(
valueFormatted
,
valuePercent
);
case
'basic'
:
case
'gradient'
:
default
:
return
this
.
renderBasicAndGradientBars
(
valueFormatted
,
valuePercent
);
}
}
...
...
@@ -72,15 +75,15 @@ export class BarGauge extends PureComponent<Props> {
return
{
value
:
color
,
border
:
color
,
ba
r
:
tinycolor
(
color
)
.
setAlpha
(
0.
3
)
ba
ckground
:
tinycolor
(
color
)
.
setAlpha
(
0.
15
)
.
toRgbString
(),
};
}
return
{
value
:
getColorFromHexRgbOrName
(
'gray'
,
theme
.
type
),
ba
r
:
getColorFromHexRgbOrName
(
'gray'
,
theme
.
type
),
ba
ckground
:
getColorFromHexRgbOrName
(
'gray'
,
theme
.
type
),
border
:
getColorFromHexRgbOrName
(
'gray'
,
theme
.
type
),
};
}
...
...
@@ -136,14 +139,15 @@ export class BarGauge extends PureComponent<Props> {
return
gradient
+
')'
;
}
render
SimpleMode
(
valueFormatted
:
string
,
valuePercent
:
number
):
ReactNode
{
const
{
height
,
width
}
=
this
.
props
;
render
BasicAndGradientBars
(
valueFormatted
:
string
,
valuePercent
:
number
):
ReactNode
{
const
{
height
,
width
,
displayMode
}
=
this
.
props
;
const
maxSize
=
this
.
size
*
BAR_SIZE_RATIO
;
const
barSize
=
Math
.
max
(
valuePercent
*
maxSize
,
0
);
const
colors
=
this
.
getValueColors
();
const
spaceForText
=
this
.
isVertical
?
width
:
this
.
size
-
maxSize
;
const
spaceForText
=
this
.
isVertical
?
width
:
Math
.
min
(
this
.
size
-
maxSize
,
height
)
;
const
valueStyles
=
this
.
getValueStyles
(
valueFormatted
,
colors
.
value
,
spaceForText
);
const
isBasic
=
displayMode
===
'basic'
;
const
containerStyles
:
CSSProperties
=
{
width
:
`
${
width
}
px`
,
...
...
@@ -151,26 +155,45 @@ export class BarGauge extends PureComponent<Props> {
display
:
'flex'
,
};
const
barStyles
:
CSSProperties
=
{};
const
barStyles
:
CSSProperties
=
{
borderRadius
:
'3px'
,
};
// Custom styles for vertical orientation
if
(
this
.
isVertical
)
{
// Custom styles for vertical orientation
containerStyles
.
flexDirection
=
'column'
;
containerStyles
.
justifyContent
=
'flex-end'
;
barStyles
.
transition
=
'height 1s'
;
barStyles
.
height
=
`
${
barSize
}
px`
;
barStyles
.
width
=
`
${
width
}
px`
;
// barStyles.borderTop = `1px solid ${colors.border}`;
barStyles
.
background
=
this
.
getBarGradient
(
maxSize
);
if
(
isBasic
)
{
// Basic styles
barStyles
.
background
=
`
${
colors
.
background
}
`
;
barStyles
.
border
=
`1px solid
${
colors
.
border
}
`
;
barStyles
.
boxShadow
=
`0 0 4px
${
colors
.
border
}
`
;
}
else
{
// Gradient styles
barStyles
.
background
=
this
.
getBarGradient
(
maxSize
);
}
}
else
{
// Custom styles for horizontal orientation
containerStyles
.
flexDirection
=
'row-reverse'
;
containerStyles
.
justifyContent
=
'flex-end'
;
containerStyles
.
alignItems
=
'center'
;
barStyles
.
transition
=
'width 1s'
;
barStyles
.
height
=
`
${
height
}
px`
;
barStyles
.
width
=
`
${
barSize
}
px`
;
barStyles
.
marginRight
=
'10px'
;
// barStyles.borderRight = `1px solid ${colors.border}`;
barStyles
.
background
=
this
.
getBarGradient
(
maxSize
);
if
(
isBasic
)
{
// Basic styles
barStyles
.
background
=
`
${
colors
.
background
}
`
;
barStyles
.
border
=
`1px solid
${
colors
.
border
}
`
;
barStyles
.
boxShadow
=
`0 0 4px
${
colors
.
border
}
`
;
}
else
{
// Gradient styles
barStyles
.
background
=
this
.
getBarGradient
(
maxSize
);
}
}
return
(
...
...
@@ -221,7 +244,7 @@ export class BarGauge extends PureComponent<Props> {
};
}
render
LcdMode
(
valueFormatted
:
string
,
valuePercent
:
number
):
ReactNode
{
render
RetroBars
(
valueFormatted
:
string
,
valuePercent
:
number
):
ReactNode
{
const
{
height
,
width
,
maxValue
,
minValue
}
=
this
.
props
;
const
valueRange
=
maxValue
-
minValue
;
...
...
@@ -230,7 +253,7 @@ export class BarGauge extends PureComponent<Props> {
const
cellCount
=
maxSize
/
20
;
const
cellSize
=
(
maxSize
-
cellSpacing
*
cellCount
)
/
cellCount
;
const
colors
=
this
.
getValueColors
();
const
spaceForText
=
this
.
isVertical
?
width
:
this
.
size
-
maxSize
;
const
spaceForText
=
this
.
isVertical
?
width
:
Math
.
min
(
this
.
size
-
maxSize
,
height
)
;
const
valueStyles
=
this
.
getValueStyles
(
valueFormatted
,
colors
.
value
,
spaceForText
);
const
containerStyles
:
CSSProperties
=
{
...
...
@@ -260,8 +283,6 @@ export class BarGauge extends PureComponent<Props> {
if
(
cellColor
.
isLit
)
{
cellStyles
.
boxShadow
=
`0 0 4px
${
cellColor
.
border
}
`
;
// cellStyles.border = `1px solid ${cellColor.border}`;
// cellStyles.background = `${cellColor.backgroundShade}`;
cellStyles
.
backgroundImage
=
`radial-gradient(
${
cellColor
.
background
}
10%,
${
cellColor
.
backgroundShade
}
)`
;
}
else
{
cellStyles
.
backgroundColor
=
cellColor
.
background
;
...
...
@@ -293,7 +314,7 @@ export class BarGauge extends PureComponent<Props> {
interface
BarColors
{
value
:
string
;
ba
r
:
string
;
ba
ckground
:
string
;
border
:
string
;
}
...
...
public/app/plugins/panel/bargauge/types.ts
View file @
1303a667
...
...
@@ -8,7 +8,7 @@ export interface BarGaugeOptions {
valueOptions
:
SingleStatValueOptions
;
valueMappings
:
ValueMapping
[];
thresholds
:
Threshold
[];
displayMode
:
'
simple'
|
'lcd
'
;
displayMode
:
'
basic'
|
'lcd'
|
'gradient
'
;
}
export
const
orientationOptions
:
SelectOptionItem
[]
=
[
...
...
@@ -16,12 +16,16 @@ export const orientationOptions: SelectOptionItem[] = [
{
value
:
VizOrientation
.
Vertical
,
label
:
'Vertical'
},
];
export
const
displayModes
:
SelectOptionItem
[]
=
[{
value
:
'simple'
,
label
:
'Simple'
},
{
value
:
'lcd'
,
label
:
'LCD'
}];
export
const
displayModes
:
SelectOptionItem
[]
=
[
{
value
:
'gradient'
,
label
:
'Gradient'
},
{
value
:
'lcd'
,
label
:
'Retro LCD'
},
{
value
:
'basic'
,
label
:
'Basic'
},
];
export
const
defaults
:
BarGaugeOptions
=
{
minValue
:
0
,
maxValue
:
100
,
displayMode
:
'
simple
'
,
displayMode
:
'
basic
'
,
orientation
:
VizOrientation
.
Horizontal
,
valueOptions
:
{
unit
:
'none'
,
...
...
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