1
0
mirror of https://github.com/gizak/termui.git synced 2025-04-24 13:48:50 +08:00

Merge pull request #327 from Spelchure/master

feat: limit sparkline bar height to the MaxHeight #211
This commit is contained in:
Zack Guo 2023-11-11 16:00:52 +08:00 committed by GitHub
commit b3569a6cd5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -17,7 +17,7 @@ type Sparkline struct {
TitleStyle Style
LineColor Color
MaxVal float64
MaxHeight int // TODO
MaxHeight int
}
// 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++ {
data := sl.Data[j]
height := int((data / maxVal) * float64(barHeight))
if height > sl.MaxHeight {
height = sl.MaxHeight
}
sparkChar := BARS[len(BARS)-1]
for k := 0; k < height; k++ {
buf.SetCell(