sparkline gradient colors improvements
This commit is contained in:
parent
df18d0fb89
commit
061d77c76a
|
@ -19,7 +19,7 @@ type SparkLine struct {
|
|||
maxValue float64
|
||||
minValue float64
|
||||
scale int
|
||||
color ui.Color
|
||||
gradient []ui.Color
|
||||
palette console.Palette
|
||||
}
|
||||
|
||||
|
@ -30,7 +30,7 @@ func NewSparkLine(c config.SparkLineConfig, palette console.Palette) *SparkLine
|
|||
Consumer: data.NewConsumer(),
|
||||
values: []float64{},
|
||||
scale: *c.Scale,
|
||||
color: *c.Item.Color,
|
||||
gradient: *c.Gradient,
|
||||
palette: palette,
|
||||
}
|
||||
|
||||
|
@ -112,7 +112,7 @@ func (s *SparkLine) Draw(buffer *ui.Buffer) {
|
|||
}
|
||||
|
||||
for j := 1; j <= top; 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))
|
||||
buffer.SetCell(ui.NewCell(console.SymbolVerticalBar, ui.NewStyle(console.GetGradientColor(s.gradient, 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))
|
||||
|
|
|
@ -55,8 +55,9 @@ type GaugeConfig struct {
|
|||
|
||||
type SparkLineConfig struct {
|
||||
ComponentConfig `yaml:",inline"`
|
||||
Scale *int `yaml:"scale,omitempty"`
|
||||
Item Item `yaml:",inline"`
|
||||
Scale *int `yaml:"scale,omitempty"`
|
||||
Item Item `yaml:",inline"`
|
||||
Gradient *[]ui.Color `yaml:",omitempty"`
|
||||
}
|
||||
|
||||
type BarChartConfig struct {
|
||||
|
|
|
@ -173,10 +173,8 @@ func (c *Config) setDefaultColors() {
|
|||
}
|
||||
|
||||
for i, s := range c.SparkLines {
|
||||
if s.Item.Color == nil {
|
||||
s.Item.Color = &palette.ContentColors[i%colorsCount]
|
||||
c.SparkLines[i] = s
|
||||
}
|
||||
s.Gradient = &palette.GradientColors[i%(len(palette.GradientColors))]
|
||||
c.SparkLines[i] = s
|
||||
}
|
||||
|
||||
for i, g := range c.Gauges {
|
||||
|
|
|
@ -37,7 +37,7 @@ const (
|
|||
|
||||
type Palette struct {
|
||||
ContentColors []ui.Color
|
||||
GradientColors []ui.Color
|
||||
GradientColors [][]ui.Color
|
||||
BaseColor ui.Color
|
||||
MediumColor ui.Color
|
||||
ReverseColor ui.Color
|
||||
|
@ -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, 209, 203, 198, 196, 125},
|
||||
GradientColors: [][]ui.Color{{39, 33, 62, 93, 164, 161}, {95, 138, 180, 179, 178, 178}},
|
||||
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, 16},
|
||||
GradientColors: [][]ui.Color{{250, 248, 246, 244, 242, 240, 238, 236, 234, 232, 16}},
|
||||
BaseColor: ColorBlack,
|
||||
MediumColor: ColorLightGrey,
|
||||
ReverseColor: ColorWhite,
|
||||
|
@ -66,8 +66,7 @@ func GetPalette(theme Theme) Palette {
|
|||
}
|
||||
}
|
||||
|
||||
// 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))]
|
||||
func GetGradientColor(gradient []ui.Color, cur int, max int) ui.Color {
|
||||
ratio := float64(len(gradient)) / float64(max)
|
||||
return gradient[int(ratio*float64(cur))]
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue