Example #1
0
func TestSmall(t *testing.T) {
	t.Parallel()
	gray := color.RGBA{R: 0x88, G: 0x88, B: 0x88, A: 0xFF}
	s := sparkline.New(10, gray, trafficLights)
	for _, n := range []float32{
		1000,
		800,
		751,
		454,
		300,
		599,
		564,
		901,
		1500,
		1300,
		500,
		270,
	} {
		s.Add(n)
	}
	bounds := image.Rect(0, 0, 100, 32)
	// trigger false assumptions about 0,0 origin
	bounds = bounds.Add(image.Point{X: 10000, Y: 10000})
	img := image.NewRGBA(bounds)
	s.Draw(img)
	if err := approve.Image(img); err != nil {
		t.Fatalf("not approved: %v", err)
	}
}
Example #2
0
// New returns a new instance of the plugin.
func (Swap) New(state *quobar.State) (quobar.Drawer, error) {
	p := &swap{
		state: state,
		chart: sparkline.New(limit, state.Config.Foreground, trafficLights),
	}
	// TODO give sparkline a way to set min/max, init to 0..100
	// TODO shutdown mechanism
	go p.update()
	return p, nil
}
Example #3
0
// New returns a new instance of the plugin.
func (DiskFree) New(state *quobar.State) (quobar.Drawer, error) {
	path := os.Getenv("HOME")
	if path == "" {
		return nil, errors.New("HOME not set in environment")
	}
	p := &diskFree{
		state: state,
		path:  path,
		chart: sparkline.New(limit, state.Config.Foreground, trafficLights),
	}
	// seed with a baseline so the graph draws high, to begin with
	p.chart.Add(0.0)
	// TODO shutdown mechanism
	go p.update()
	return p, nil
}