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

Function TestLabels

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

Source from the content-addressed store, hash-verified

113}
114
115func 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
152func TestBarChart(t *testing.T) {
153 pt := plot.New()

Callers

nothing calls this directly

Calls 10

NewFunction · 0.92
SinFunction · 0.92
AssertFunction · 0.92
NewLinePointsFunction · 0.85
NewLabelsFunction · 0.85
ErrorMethod · 0.65
AddMethod · 0.65
DrawMethod · 0.65
DpMethod · 0.45
ResizeMethod · 0.45

Tested by

no test coverage detected