blob: f011239928a732dd2cacebb6efebe916bbabaeff (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
package termui
import (
"fmt"
)
// BarChart creates multiple bars in a widget:
type List struct {
*Block
TextColor Color
Data []int
DataLabels []string
Threshold int
}
// NewBarChart returns a new *BarChart with current theme.
func NewList() *List {
return &List{
Block: NewBlock(),
TextColor: Theme.Fg,
}
}
// Buffer implements Bufferer interface.
func (bc *List) Buffer() *Buffer {
buf := bc.Block.Buffer()
for y, text := range bc.DataLabels {
if y+1 > bc.Y {
break
}
fg := Theme.TempLow
if bc.Data[y] >= bc.Threshold {
fg = Theme.TempHigh
}
r := MaxString(text, (bc.X - 4))
buf.SetString(1, y+1, r, Theme.Fg, bc.Bg)
buf.SetString(bc.X-2, y+1, fmt.Sprintf("%dC", bc.Data[y]), fg, bc.Bg)
}
return buf
}
|