mirror of https://github.com/gizak/termui.git
feat: limit sparkline bar height to the MaxHeight
This commit is contained in:
parent
f976fe697a
commit
780c93dd44
|
@ -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(
|
||||||
|
|
Loading…
Reference in New Issue