gradient selection

This commit is contained in:
sqshq 2019-03-31 23:02:58 -04:00
parent 393556a265
commit df18d0fb89
4 changed files with 13 additions and 8 deletions

View File

@ -87,8 +87,8 @@ func (s *SparkLine) consumeSample(sample *data.Sample) {
func (s *SparkLine) Draw(buffer *ui.Buffer) {
textStyle := ui.NewStyle(s.palette.BaseColor)
lineStyle := ui.NewStyle(s.color)
height := s.Dy() - 2
minValue := util.FormatValue(s.minValue, s.scale)
maxValue := util.FormatValue(s.maxValue, s.scale)
curValue := util.FormatValue(s.values[len(s.values)-1], s.scale)
@ -105,14 +105,14 @@ func (s *SparkLine) Draw(buffer *ui.Buffer) {
break
}
top := int((s.values[i] / s.maxValue) * float64(s.Dy()-2))
top := int((s.values[i] / s.maxValue) * float64(height))
if top == 0 {
top = 1
}
for j := 1; j <= top; j++ {
buffer.SetCell(ui.NewCell(console.SymbolSquare, lineStyle), image.Pt(s.Inner.Max.X-n-indent, s.Inner.Max.Y-j))
buffer.SetCell(ui.NewCell(console.SymbolVerticalBar, ui.NewStyle(s.palette.GetGradientColor(j-1, height))), image.Pt(s.Inner.Max.X-n-indent, s.Inner.Max.Y-j))
if i == len(s.values)-1 && j == top {
buffer.SetString(curValue, textStyle, image.Pt(s.Inner.Max.X-n-indent+2, s.Inner.Max.Y-j))
buffer.SetString(minValue, textStyle, image.Pt(s.Inner.Max.X-n-indent+2, s.Max.Y-2))

View File

@ -85,10 +85,10 @@ asciiboxes:
font: 3d
sparklines:
- title: CPU usage
position: [[27, 17], [25, 5]]
position: [[27, 22], [25, 7]]
scale: 0
value: ps -A -o %cpu | awk '{s+=$1} END {print s}'
- title: Memory pages free
position: [[27, 22], [25, 7]]
position: [[27, 17], [25, 5]]
scale: 0
value: memory_pressure | grep 'Pages free' | awk '{print $3}'

View File

@ -48,7 +48,7 @@ func GetPalette(theme Theme) Palette {
case ThemeDark:
return Palette{
ContentColors: []ui.Color{ColorOlive, ColorDeepSkyBlue, ColorDeepPink, ColorWhite, ColorGrey, ColorGreen, ColorOrange, ColorCian, ColorPurple},
GradientColors: []ui.Color{39, 44, 47, 82, 148, 185, 208, 203, 198, 196},
GradientColors: []ui.Color{39, 44, 47, 82, 148, 185, 209, 203, 198, 196, 125},
BaseColor: ColorWhite,
MediumColor: ColorDarkGrey,
ReverseColor: ColorBlack,
@ -56,7 +56,7 @@ func GetPalette(theme Theme) Palette {
case ThemeLight:
return Palette{
ContentColors: []ui.Color{ColorBlack, ColorDarkRed, ColorBlueViolet, ColorGrey, ColorGreen},
GradientColors: []ui.Color{250, 248, 246, 244, 242, 240, 238, 236, 234, 232},
GradientColors: []ui.Color{250, 248, 246, 244, 242, 240, 238, 236, 234, 232, 16},
BaseColor: ColorBlack,
MediumColor: ColorLightGrey,
ReverseColor: ColorWhite,
@ -65,3 +65,9 @@ func GetPalette(theme Theme) Palette {
panic(fmt.Sprintf("Following theme is not supported: %v", theme))
}
}
// selects gradient color for cur item (out of max items)
func (palette *Palette) GetGradientColor(cur int, max int) ui.Color {
ratio := float64(len(palette.GradientColors)) / float64(max)
return palette.GradientColors[int(ratio*float64(cur))]
}

View File

@ -4,5 +4,4 @@ const (
SymbolSelection rune = '▲'
SymbolVerticalBar rune = '▎'
SymbolHorizontalBar rune = '═'
SymbolSquare rune = '■'
)