mirror of
https://github.com/navidys/tvxwidgets.git
synced 2025-05-11 19:29:26 +08:00
bar chart initial commit
This commit is contained in:
parent
a35531b789
commit
25b7fa382e
1
demos/barchart/README.md
Normal file
1
demos/barchart/README.md
Normal file
@ -0,0 +1 @@
|
||||

|
@ -12,33 +12,14 @@ func main() {
|
||||
barGraph := tgraph.NewBarChart()
|
||||
barGraph.SetRect(0, 0, 50, 20)
|
||||
barGraph.SetBorder(true)
|
||||
barGraph.SetTitle("Bar Graph Demo")
|
||||
barGraph.SetTitle("System Resource Usage")
|
||||
// display system metric usage
|
||||
barGraph.AddBar("cpu", 80, tcell.ColorBlue)
|
||||
barGraph.AddBar("memory", 20, tcell.ColorRed)
|
||||
barGraph.AddBar("mem", 20, tcell.ColorRed)
|
||||
barGraph.AddBar("swap", 40, tcell.ColorGreen)
|
||||
barGraph.AddBar("disk", 40, tcell.ColorOrange)
|
||||
barGraph.SetMaxValue(100)
|
||||
/*
|
||||
update := func() {
|
||||
rand.Seed(time.Now().UnixNano())
|
||||
tick := time.NewTicker(1000 * time.Millisecond)
|
||||
for {
|
||||
select {
|
||||
case <-tick.C:
|
||||
rangeLower := 0
|
||||
rangeUpper := 100
|
||||
randomNum := rangeLower + rand.Intn(rangeUpper-rangeLower+1)
|
||||
barGraph.SetBarValue("cpu", randomNum)
|
||||
randomNum = rangeLower + rand.Intn(rangeUpper-rangeLower+1)
|
||||
barGraph.SetBarValue("memory", randomNum)
|
||||
randomNum = rangeLower + rand.Intn(rangeUpper-rangeLower+1)
|
||||
barGraph.SetBarValue("swap", randomNum)
|
||||
app.Draw()
|
||||
}
|
||||
}
|
||||
}
|
||||
go update()
|
||||
*/
|
||||
|
||||
if err := app.SetRoot(barGraph, false).EnableMouse(true).Run(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
BIN
demos/barchart/screenshot.png
Normal file
BIN
demos/barchart/screenshot.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 8.1 KiB |
51
demos/demo/main.go
Normal file
51
demos/demo/main.go
Normal file
@ -0,0 +1,51 @@
|
||||
// Demo code for the bar chart primitive.
|
||||
package main
|
||||
|
||||
import (
|
||||
"math/rand"
|
||||
"time"
|
||||
|
||||
"github.com/gdamore/tcell/v2"
|
||||
"github.com/navidys/tgraph"
|
||||
"github.com/rivo/tview"
|
||||
)
|
||||
|
||||
func main() {
|
||||
app := tview.NewApplication()
|
||||
barGraph := tgraph.NewBarChart()
|
||||
barGraph.SetRect(0, 0, 50, 20)
|
||||
barGraph.SetBorder(true)
|
||||
barGraph.SetTitle("System Resource Usage")
|
||||
// display system metric usage
|
||||
barGraph.AddBar("cpu", 80, tcell.ColorBlue)
|
||||
barGraph.AddBar("mem", 20, tcell.ColorRed)
|
||||
barGraph.AddBar("swap", 40, tcell.ColorGreen)
|
||||
barGraph.AddBar("disk", 40, tcell.ColorOrange)
|
||||
barGraph.SetMaxValue(100)
|
||||
|
||||
update := func() {
|
||||
rand.Seed(time.Now().UnixNano())
|
||||
tick := time.NewTicker(1000 * time.Millisecond)
|
||||
for {
|
||||
select {
|
||||
case <-tick.C:
|
||||
rangeLower := 0
|
||||
rangeUpper := 100
|
||||
randomNum := rangeLower + rand.Intn(rangeUpper-rangeLower+1)
|
||||
barGraph.SetBarValue("cpu", randomNum)
|
||||
randomNum = rangeLower + rand.Intn(rangeUpper-rangeLower+1)
|
||||
barGraph.SetBarValue("memory", randomNum)
|
||||
randomNum = rangeLower + rand.Intn(rangeUpper-rangeLower+1)
|
||||
barGraph.SetBarValue("swap", randomNum)
|
||||
randomNum = rangeLower + rand.Intn(rangeUpper-rangeLower+1)
|
||||
barGraph.SetBarValue("disk", randomNum)
|
||||
app.Draw()
|
||||
}
|
||||
}
|
||||
}
|
||||
go update()
|
||||
|
||||
if err := app.SetRoot(barGraph, false).EnableMouse(true).Run(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user