| 113 | } |
| 114 | |
| 115 | func TestLabels(t *testing.T) { |
| 116 | pt := plot.New() |
| 117 | pt.Title.Text = "Test Labels" |
| 118 | pt.X.Label.Text = "X Axis" |
| 119 | pt.Y.Label.Text = "Y Axis" |
| 120 | |
| 121 | // note: making two overlapping series |
| 122 | data := make(plot.XYs, 12) |
| 123 | labels := make([]string, 12) |
| 124 | for i := range data { |
| 125 | x := float32(i % 21) |
| 126 | data[i].X = x * 5 |
| 127 | data[i].Y = float32(50) + 40*math32.Sin((x/8)*math32.Pi) |
| 128 | labels[i] = fmt.Sprintf("%7.4g", data[i].Y) |
| 129 | } |
| 130 | |
| 131 | l1, sc, err := NewLinePoints(data) |
| 132 | if err != nil { |
| 133 | t.Error(err.Error()) |
| 134 | } |
| 135 | pt.Add(l1) |
| 136 | pt.Add(sc) |
| 137 | pt.Legend.Add("Sine", l1, sc) |
| 138 | |
| 139 | l2, err := NewLabels(XYLabels{XYs: data, Labels: labels}) |
| 140 | if err != nil { |
| 141 | t.Error(err.Error()) |
| 142 | } |
| 143 | l2.Offset.X.Dp(6) |
| 144 | l2.Offset.Y.Dp(-6) |
| 145 | pt.Add(l2) |
| 146 | |
| 147 | pt.Resize(image.Point{640, 480}) |
| 148 | pt.Draw() |
| 149 | imagex.Assert(t, pt.Pixels, "labels.png") |
| 150 | } |
| 151 | |
| 152 | func TestBarChart(t *testing.T) { |
| 153 | pt := plot.New() |