forked from atsaki/termeter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbarchart.go
48 lines (38 loc) · 1.01 KB
/
barchart.go
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
43
44
45
46
47
48
package termeter
import "gopkg.in/gizak/termui.v1"
type BarChartWidget struct {
BarChart *termui.BarChart
}
func NewBarChartWidget() *BarChartWidget {
return &BarChartWidget{
BarChart: termui.NewBarChart(),
}
}
func (bc *BarChartWidget) SetX(x int) {
bc.BarChart.X = x
}
func (bc *BarChartWidget) SetY(y int) {
bc.BarChart.Y = y
}
func (bc *BarChartWidget) SetWidth(w int) {
bc.BarChart.Width = w
}
func (bc *BarChartWidget) SetHeight(h int) {
bc.BarChart.Height = h
}
func (bc *BarChartWidget) Buffer() []termui.Point {
defer func() {
recover()
}()
return bc.BarChart.Buffer()
}
func (bc *BarChartWidget) Add(label string, freq int) {
bc.BarChart.Data = append(bc.BarChart.Data, freq)
bc.BarChart.DataLabels = append(bc.BarChart.DataLabels, label)
}
func (bc *BarChartWidget) Update(labels []string, freqs []int) {
bc.BarChart.Data = make([]int, len(freqs), len(freqs))
bc.BarChart.DataLabels = make([]string, len(labels), len(labels))
copy(bc.BarChart.Data, freqs)
copy(bc.BarChart.DataLabels, labels)
}