func plotSparks(xys plotter.XYs) (image.Image, error) { border := 4 if optRows == 1 { border = 1 } else if optRows == 2 { border = 2 } height := optCharHeight * optRows width := (optCharWidth * 2) + (optCharWidth * len(xys)) img := image.NewRGBA(image.Rect(0, 0, width, height)) _, _, ymin, ymax := plotter.XYRange(xys) ymin = 0 for i, xy := range xys { //xf := (xy.X - xmin) / xmax yf := (xy.Y - ymin) / ymax hm := height - int(float64(height-(border*2))*yf) - border h0 := height - border w := ((i + 1) * optCharWidth) for h := h0; h >= hm; h = h - 2 { var c color.RGBA if h == hm || h == hm+1 { c = color.RGBA{0, 255, 0, 255} } else if h == h0 { c = color.RGBA{0, 128, 0, 255} } else { p := float64(h-hm)/float64(h0-hm)*0.5 + 0.3 g := uint8(float64(255) - (p * float64(255))) c = color.RGBA{0, g, 0, 255} } for j := 0; j < (optCharWidth - 2); j++ { img.SetRGBA(w+j, h, c) } } } return img, nil }
func (cg *ColorGrid) DataRange() (xmin, xmax, ymin, ymax float64) { // we use the XYRange function from the plotter package // to compute the minimum and maximum X and Y values. return plotter.XYRange(plotter.XYValues{cg.XYZs}) }
func (s *SparkLines) DataRange() (xmin, xmax, ymin, ymax float64) { return plotter.XYRange(s.XYs) }