1
0
mirror of https://github.com/mum4k/termdash.git synced 2025-04-27 13:48:49 +08:00

Undo the experiments in the LineChart demo.

This commit is contained in:
Jakub Sobon 2019-02-18 18:50:55 -05:00
parent 38ec4a9e1b
commit 5b89dbc1a0
No known key found for this signature in database
GPG Key ID: F2451A77FB05D3B7

View File

@ -44,38 +44,28 @@ func sineInputs() []float64 {
// playLineChart continuously adds values to the LineChart, once every delay.
// Exits when the context expires.
func playLineChart(ctx context.Context, lc *linechart.LineChart, delay time.Duration) {
//inputs := sineInputs()
var inputs []float64
inputs := sineInputs()
ticker := time.NewTicker(delay)
defer ticker.Stop()
for i := 0; ; {
select {
case <-ticker.C:
//i = (i + 1) % len(inputs)
inputs = append(inputs, float64(i%30))
if err := lc.Series("first", inputs,
i = (i + 1) % len(inputs)
rotated := append(inputs[i:], inputs[:i]...)
if err := lc.Series("first", rotated,
linechart.SeriesCellOpts(cell.FgColor(cell.ColorBlue)),
linechart.SeriesXLabels(map[int]string{
0: "zero",
}),
); err != nil {
panic(err)
}
i++
/*
rotated := append(inputs[i:], inputs[:i]...)
if err := lc.Series("first", rotated,
linechart.SeriesCellOpts(cell.FgColor(cell.ColorBlue)),
linechart.SeriesXLabels(map[int]string{
0: "zero",
}),
); err != nil {
panic(err)
}
i2 := (i + 100) % len(inputs)
rotated2 := append(inputs[i2:], inputs[:i2]...)
if err := lc.Series("second", rotated2, linechart.SeriesCellOpts(cell.FgColor(cell.ColorWhite))); err != nil {
panic(err)
}*/
i2 := (i + 100) % len(inputs)
rotated2 := append(inputs[i2:], inputs[:i2]...)
if err := lc.Series("second", rotated2, linechart.SeriesCellOpts(cell.FgColor(cell.ColorWhite))); err != nil {
panic(err)
}
case <-ctx.Done():
return
@ -96,12 +86,11 @@ func main() {
linechart.AxesCellOpts(cell.FgColor(cell.ColorRed)),
linechart.YLabelCellOpts(cell.FgColor(cell.ColorGreen)),
linechart.XLabelCellOpts(cell.FgColor(cell.ColorCyan)),
//linechart.XAxisUnscaled(),
)
if err != nil {
panic(err)
}
go playLineChart(ctx, lc, redrawInterval/10)
go playLineChart(ctx, lc, redrawInterval/3)
c, err := container.New(
t,
container.Border(draw.LineStyleLight),