Documentation
¶
Overview ¶
Package spark prints real time data as sparklines in your terminal.
Index ¶
Examples ¶
Constants ¶
const (
// Bytes is a predefined unit type, will pretty print using humanized values.
Bytes = "bytes"
)
Variables ¶
This section is empty.
Functions ¶
func Reader ¶
Reader wraps the reads of r with a SparkStream. The stream will have Bytes units and refresh every 33ms.
It will stop printing when the reader returns an error.
func ReaderOut ¶
ReaderOut wraps the reads of r with a SparkStream. The stream will have Bytes units and refresh every 33ms.
It will stop printing when the reader returns an error.
func WriteSeeker ¶
func WriteSeeker(ws io.WriteSeeker) (io.WriteSeeker, func())
WriteSeeker wraps the writes to w with a SparkStream. The stream will have Bytes units and refresh every 33ms.
It will stop printing when the writer returns an error.
Types ¶
type SparkStream ¶
SparkStream prints sparklines for values it receives in real time. It scales up and down the visible window of values and prints the average values per second it has observed in recent history.
func Spark ¶
func Spark(resolution time.Duration) *SparkStream
Spark creates a stream of sparklines that will print every lines bucketize with the given resolution.
By default, it prints to os.Stdout and is unitless.
Example (Random) ¶
package main import ( "github.com/aybabtme/uniplot/spark" "log" "math/rand" "os" "time" ) func main() { sprk := spark.Spark(time.Millisecond * 30) sprk.Out = os.Stderr sprk.Units = spark.Bytes sprk.Start() timeout := time.NewTicker(time.Second * 5) loop: for { select { case <-time.After(time.Millisecond * 20): sprk.Add(float64(rand.Intn(10000000000))) case <-timeout.C: log.Printf("DONE!") break loop } } sprk.Stop() }
Output:
Example (Saw) ¶
package main import ( "github.com/aybabtme/uniplot/spark" "log" "os" "time" ) func main() { sprk := spark.Spark(time.Millisecond * 60) sprk.Out = os.Stderr sprk.Units = spark.Bytes sprk.Start() timeout := time.NewTicker(time.Second * 15) x := 0.0 loop: for { select { case <-time.After(time.Millisecond * 60): x += 0.1 sprk.Add(x) if x >= 1.0 { x = 0.0 } case <-timeout.C: log.Printf("DONE!") break loop } } sprk.Stop() }
Output:
Example (Sine) ¶
package main import ( "github.com/aybabtme/uniplot/spark" "log" "math" "os" "time" ) func main() { sprk := spark.Spark(time.Millisecond * 60) sprk.Out = os.Stderr sprk.Units = spark.Bytes sprk.Start() timeout := time.NewTicker(time.Second * 15) x := 0.0 loop: for { select { case <-time.After(time.Millisecond * 60): y := math.Sin(x) x += 0.1 sprk.Add(y) case <-timeout.C: log.Printf("DONE!") break loop } } sprk.Stop() }
Output:
func (*SparkStream) Add ¶
func (s *SparkStream) Add(v float64)
Add puts the value in the current bucket of sparklines. The value will appear part of the next update of the spark stream.