...
1
2
3
4
5 package vg_test
6
7 import (
8 "image/color"
9 "math"
10 "reflect"
11 "testing"
12
13 "gonum.org/v1/plot"
14 "gonum.org/v1/plot/plotter"
15 "gonum.org/v1/plot/plotutil"
16 "gonum.org/v1/plot/vg"
17 "gonum.org/v1/plot/vg/draw"
18 "gonum.org/v1/plot/vg/recorder"
19 )
20
21 func TestMultiCanvas(t *testing.T) {
22 p := plot.New()
23 p.Title.Text = "Title"
24 p.X.Label.Text = "x"
25 p.Y.Label.Text = "y"
26 p.X.Min = -2 * math.Pi
27 p.X.Max = +2 * math.Pi
28
29 sin := plotter.NewFunction(math.Sin)
30 sin.LineStyle.Color = color.RGBA{R: 255, A: 255}
31 sin.LineStyle.Dashes = plotutil.Dashes(1)
32
33 cos := plotter.NewFunction(math.Cos)
34 cos.LineStyle.Color = color.RGBA{B: 255, A: 255}
35 cos.LineStyle.Dashes = plotutil.Dashes(2)
36
37 p.Add(sin, cos, plotter.NewGrid())
38
39 c1 := new(recorder.Canvas)
40 c2 := new(recorder.Canvas)
41
42 const (
43 width = 10 * vg.Centimeter
44 height = 10 * vg.Centimeter
45 )
46
47 p.Draw(draw.NewCanvas(
48 vg.MultiCanvas(c1, c2, vg.MultiCanvas()),
49 width, height,
50 ))
51
52 if !reflect.DeepEqual(c1, c2) {
53 t.Fatalf("tee canvas failed to replicate drawing calls")
54 }
55 }
56
View as plain text