feat: limit sparkline bar height to the MaxHeight

This commit is contained in:
Spelchure 2023-08-16 08:42:46 +03:00
parent f976fe697a
commit 780c93dd44
No known key found for this signature in database
GPG Key ID: 3CD6F14FE2A9505E
1 changed files with 4 additions and 1 deletions

View File

@ -17,7 +17,7 @@ type Sparkline struct {
TitleStyle Style TitleStyle Style
LineColor Color LineColor Color
MaxVal float64 MaxVal float64
MaxHeight int // TODO MaxHeight int
} }
// SparklineGroup is a renderable widget which groups together the given sparklines. // SparklineGroup is a renderable widget which groups together the given sparklines.
@ -66,6 +66,9 @@ func (self *SparklineGroup) Draw(buf *Buffer) {
for j := 0; j < len(sl.Data) && j < self.Inner.Dx(); j++ { for j := 0; j < len(sl.Data) && j < self.Inner.Dx(); j++ {
data := sl.Data[j] data := sl.Data[j]
height := int((data / maxVal) * float64(barHeight)) height := int((data / maxVal) * float64(barHeight))
if height > sl.MaxHeight {
height = sl.MaxHeight
}
sparkChar := BARS[len(BARS)-1] sparkChar := BARS[len(BARS)-1]
for k := 0; k < height; k++ { for k := 0; k < height; k++ {
buf.SetCell( buf.SetCell(