(t *testing.T)
| 131 | } |
| 132 | |
| 133 | func TestDrawGlyphBoxes(t *testing.T) { |
| 134 | cmpimg.CheckPlot(func() { |
| 135 | p := plot.New() |
| 136 | |
| 137 | p.Title.Text = "My very very very\nlong Title" |
| 138 | p.X.Min = 0 |
| 139 | p.X.Max = 10 |
| 140 | p.Y.Min = 0 |
| 141 | p.Y.Max = 10 |
| 142 | |
| 143 | p.X.Label.Text = "X-axis" |
| 144 | p.Y.Label.Text = "Y-axis" |
| 145 | |
| 146 | f1 := plotter.NewFunction(func(x float64) float64 { return 5 }) |
| 147 | f1.LineStyle.Color = color.RGBA{R: 255, A: 255} |
| 148 | |
| 149 | f2 := plotter.NewFunction(func(x float64) float64 { return 6 }) |
| 150 | f2.LineStyle.Color = color.RGBA{B: 255, A: 255} |
| 151 | |
| 152 | labels, err := plotter.NewLabels(plotter.XYLabels{ |
| 153 | XYs: []plotter.XY{ |
| 154 | {X: 2.5, Y: 2.5}, |
| 155 | {X: 7.5, Y: 2.5}, |
| 156 | {X: 7.5, Y: 7.5}, |
| 157 | {X: 2.5, Y: 7.5}, |
| 158 | }, |
| 159 | Labels: []string{"Agg", "Bgg", "Cgg", "Dgg"}, |
| 160 | }) |
| 161 | if err != nil { |
| 162 | t.Fatalf("could not creates labels plotter: %+v", err) |
| 163 | } |
| 164 | |
| 165 | p.Add(f1, f2, labels) |
| 166 | p.Add(plotter.NewGrid()) |
| 167 | |
| 168 | p.Legend.Add("fg1", f1) |
| 169 | p.Legend.Add("fg2", f2) |
| 170 | p.Legend.Top = true |
| 171 | |
| 172 | c := vgimg.PngCanvas{ |
| 173 | Canvas: vgimg.New(20*vg.Centimeter, 15*vg.Centimeter), |
| 174 | } |
| 175 | |
| 176 | d := draw.New(c) |
| 177 | p.Draw(d) |
| 178 | p.DrawGlyphBoxes(d) |
| 179 | |
| 180 | buf := new(bytes.Buffer) |
| 181 | _, err = c.WriteTo(buf) |
| 182 | if err != nil { |
| 183 | t.Fatalf("error: %+v", err) |
| 184 | } |
| 185 | |
| 186 | err = os.WriteFile("testdata/glyphbox_"+runtime.GOARCH+".png", buf.Bytes(), 0644) |
| 187 | if err != nil { |
| 188 | t.Fatalf("could not save plot: %+v", err) |
| 189 | } |
| 190 | }, t, "glyphbox_"+runtime.GOARCH+".png") |
nothing calls this directly
no test coverage detected