| 150 | } |
| 151 | |
| 152 | func TestBarChart(t *testing.T) { |
| 153 | pt := plot.New() |
| 154 | pt.Title.Text = "Test Bar Chart" |
| 155 | pt.X.Label.Text = "X Axis" |
| 156 | pt.Y.Min = 0 |
| 157 | pt.Y.Max = 100 |
| 158 | pt.Y.Label.Text = "Y Axis" |
| 159 | |
| 160 | data := make(plot.Values, 21) |
| 161 | for i := range data { |
| 162 | x := float32(i % 21) |
| 163 | data[i] = float32(50) + 40*math32.Sin((x/8)*math32.Pi) |
| 164 | } |
| 165 | |
| 166 | cos := make(plot.Values, 21) |
| 167 | for i := range data { |
| 168 | x := float32(i % 21) |
| 169 | cos[i] = float32(50) + 40*math32.Cos((x/8)*math32.Pi) |
| 170 | } |
| 171 | |
| 172 | l1, err := NewBarChart(data, nil) |
| 173 | if err != nil { |
| 174 | t.Error(err.Error()) |
| 175 | } |
| 176 | l1.Color = colors.Uniform(colors.Red) |
| 177 | pt.Add(l1) |
| 178 | pt.Legend.Add("Sine", l1) |
| 179 | |
| 180 | pt.Resize(image.Point{640, 480}) |
| 181 | pt.Draw() |
| 182 | imagex.Assert(t, pt.Pixels, "bar.png") |
| 183 | |
| 184 | l2, err := NewBarChart(cos, nil) |
| 185 | if err != nil { |
| 186 | t.Error(err.Error()) |
| 187 | } |
| 188 | l2.Color = colors.Uniform(colors.Blue) |
| 189 | pt.Legend.Add("Cosine", l2) |
| 190 | |
| 191 | l1.Stride = 2 |
| 192 | l2.Stride = 2 |
| 193 | l2.Offset = 2 |
| 194 | |
| 195 | pt.Add(l2) // note: range updated when added! |
| 196 | pt.Draw() |
| 197 | imagex.Assert(t, pt.Pixels, "bar-cos.png") |
| 198 | } |
| 199 | |
| 200 | func TestBarChartErr(t *testing.T) { |
| 201 | pt := plot.New() |