| 23 | } |
| 24 | |
| 25 | func TestLine(t *testing.T) { |
| 26 | pt := plot.New() |
| 27 | pt.Title.Text = "Test Line" |
| 28 | pt.X.Min = 0 |
| 29 | pt.X.Max = 100 |
| 30 | pt.X.Label.Text = "X Axis" |
| 31 | pt.Y.Min = 0 |
| 32 | pt.Y.Max = 100 |
| 33 | pt.Y.Label.Text = "Y Axis" |
| 34 | |
| 35 | // note: making two overlapping series |
| 36 | data := make(plot.XYs, 42) |
| 37 | for i := range data { |
| 38 | x := float32(i % 21) |
| 39 | data[i].X = x * 5 |
| 40 | if i < 21 { |
| 41 | data[i].Y = float32(50) + 40*math32.Sin((x/8)*math32.Pi) |
| 42 | } else { |
| 43 | data[i].Y = float32(50) + 40*math32.Cos((x/8)*math32.Pi) |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | l1, err := NewLine(data) |
| 48 | if err != nil { |
| 49 | t.Error(err.Error()) |
| 50 | } |
| 51 | pt.Add(l1) |
| 52 | pt.Legend.Add("Sine", l1) |
| 53 | pt.Legend.Add("Cos", l1) |
| 54 | |
| 55 | pt.Resize(image.Point{640, 480}) |
| 56 | pt.Draw() |
| 57 | imagex.Assert(t, pt.Pixels, "line.png") |
| 58 | |
| 59 | l1.Fill = colors.Uniform(colors.Yellow) |
| 60 | pt.Draw() |
| 61 | imagex.Assert(t, pt.Pixels, "line-fill.png") |
| 62 | |
| 63 | l1.StepStyle = PreStep |
| 64 | pt.Draw() |
| 65 | imagex.Assert(t, pt.Pixels, "line-prestep.png") |
| 66 | |
| 67 | l1.StepStyle = MidStep |
| 68 | pt.Draw() |
| 69 | imagex.Assert(t, pt.Pixels, "line-midstep.png") |
| 70 | |
| 71 | l1.StepStyle = PostStep |
| 72 | pt.Draw() |
| 73 | imagex.Assert(t, pt.Pixels, "line-poststep.png") |
| 74 | |
| 75 | l1.StepStyle = NoStep |
| 76 | l1.Fill = nil |
| 77 | l1.NegativeXDraw = true |
| 78 | pt.Draw() |
| 79 | imagex.Assert(t, pt.Pixels, "line-negx.png") |
| 80 | |
| 81 | } |
| 82 | |