Plot implements the Plot method of the plot.Plotter interface.
(c draw.Canvas, p *plot.Plot)
| 53 | |
| 54 | // Plot implements the Plot method of the plot.Plotter interface. |
| 55 | func (l *ColorBar) Plot(c draw.Canvas, p *plot.Plot) { |
| 56 | l.check() |
| 57 | colors := l.colors(c) |
| 58 | var pImg *Image |
| 59 | delta := (l.ColorMap.Max() - l.ColorMap.Min()) / float64(colors) |
| 60 | if l.Vertical { |
| 61 | img := image.NewNRGBA64(image.Rectangle{ |
| 62 | Min: image.Point{X: 0, Y: 0}, |
| 63 | Max: image.Point{X: 1, Y: colors}, |
| 64 | }) |
| 65 | for i := range colors { |
| 66 | color, err := l.ColorMap.At(l.ColorMap.Min() + delta*float64(i)) |
| 67 | if err != nil { |
| 68 | panic(err) |
| 69 | } |
| 70 | img.Set(0, colors-1-i, color) |
| 71 | } |
| 72 | pImg = NewImage(img, 0, l.ColorMap.Min(), 1, l.ColorMap.Max()) |
| 73 | } else { |
| 74 | img := image.NewNRGBA64(image.Rectangle{ |
| 75 | Min: image.Point{X: 0, Y: 0}, |
| 76 | Max: image.Point{X: colors, Y: 1}, |
| 77 | }) |
| 78 | for i := range colors { |
| 79 | color, err := l.ColorMap.At(l.ColorMap.Min() + delta*float64(i)) |
| 80 | if err != nil { |
| 81 | panic(err) |
| 82 | } |
| 83 | img.Set(i, 0, color) |
| 84 | } |
| 85 | pImg = NewImage(img, l.ColorMap.Min(), 0, l.ColorMap.Max(), 1) |
| 86 | } |
| 87 | pImg.Plot(c, p) |
| 88 | } |
| 89 | |
| 90 | // DataRange implements the DataRange method |
| 91 | // of the plot.DataRanger interface. |