MCPcopy Create free account
hub / github.com/cogentcore/core / TestBarChart

Function TestBarChart

plot/plots/plot_test.go:152–198  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

150}
151
152func 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
200func TestBarChartErr(t *testing.T) {
201 pt := plot.New()

Callers

nothing calls this directly

Calls 10

NewFunction · 0.92
SinFunction · 0.92
CosFunction · 0.92
UniformFunction · 0.92
AssertFunction · 0.92
NewBarChartFunction · 0.85
ErrorMethod · 0.65
AddMethod · 0.65
DrawMethod · 0.65
ResizeMethod · 0.45

Tested by

no test coverage detected