...
1
2
3
4
5 package plotter
6
7 import (
8 "image/color"
9
10 "gonum.org/v1/plot"
11 "gonum.org/v1/plot/palette"
12 "gonum.org/v1/plot/vg"
13 "gonum.org/v1/plot/vg/draw"
14 )
15
16
17
18 func PaletteThumbnailers(p palette.Palette) []plot.Thumbnailer {
19 colors := p.Colors()
20 thumbnailers := make([]plot.Thumbnailer, len(colors))
21 for i, c := range colors {
22 thumbnailers[i] = paletteThumbnailer{color: c}
23 }
24 return thumbnailers
25 }
26
27
28
29 type paletteThumbnailer struct {
30 color color.Color
31 }
32
33
34 func (t paletteThumbnailer) Thumbnail(c *draw.Canvas) {
35 pts := []vg.Point{
36 {X: c.Min.X, Y: c.Min.Y},
37 {X: c.Min.X, Y: c.Max.Y},
38 {X: c.Max.X, Y: c.Max.Y},
39 {X: c.Max.X, Y: c.Min.Y},
40 }
41 poly := c.ClipPolygonY(pts)
42 c.FillPolygon(t.color, poly)
43 }
44
View as plain text