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

Method Plot

plot/plots/barchart.go:148–208  ·  view source on GitHub ↗

Plot implements the plot.Plotter interface.

(plt *plot.Plot)

Source from the content-addressed store, hash-verified

146
147// Plot implements the plot.Plotter interface.
148func (b *BarChart) Plot(plt *plot.Plot) {
149 pc := plt.Paint
150 pc.FillStyle.Color = b.Color
151 b.LineStyle.SetStroke(plt)
152
153 nv := len(b.Values)
154 b.XYs = make(plot.XYs, nv)
155 b.PXYs = make(plot.XYs, nv)
156
157 hw := 0.5 * b.Width
158 ew := b.Width / 3
159 for i, ht := range b.Values {
160 cat := b.Offset + float32(i)*b.Stride
161 var bottom, catVal, catMin, catMax, valMin, valMax float32
162 var box math32.Box2
163 if b.Horizontal {
164 catVal = plt.PY(cat)
165 catMin = plt.PY(cat - hw)
166 catMax = plt.PY(cat + hw)
167 bottom = b.StackedOn.BarHeight(i) // nil safe
168 valMin = plt.PX(bottom)
169 valMax = plt.PX(bottom + ht)
170 b.XYs[i] = math32.Vec2(bottom+ht, cat)
171 b.PXYs[i] = math32.Vec2(valMax, catVal)
172 box.Min.Set(valMin, catMin)
173 box.Max.Set(valMax, catMax)
174 } else {
175 catVal = plt.PX(cat)
176 catMin = plt.PX(cat - hw)
177 catMax = plt.PX(cat + hw)
178 bottom = b.StackedOn.BarHeight(i) // nil safe
179 valMin = plt.PY(bottom)
180 valMax = plt.PY(bottom + ht)
181 b.XYs[i] = math32.Vec2(cat, bottom+ht)
182 b.PXYs[i] = math32.Vec2(catVal, valMax)
183 box.Min.Set(catMin, valMin)
184 box.Max.Set(catMax, valMax)
185 }
186
187 pc.DrawRectangle(box.Min.X, box.Min.Y, box.Size().X, box.Size().Y)
188 pc.FillStrokeClear()
189
190 if i < len(b.Errors) {
191 errval := b.Errors[i]
192 if b.Horizontal {
193 eVal := plt.PX(bottom + ht + math32.Abs(errval))
194 pc.MoveTo(valMax, catVal)
195 pc.LineTo(eVal, catVal)
196 pc.MoveTo(eVal, plt.PY(cat-ew))
197 pc.LineTo(eVal, plt.PY(cat+ew))
198 } else {
199 eVal := plt.PY(bottom + ht + math32.Abs(errval))
200 pc.MoveTo(catVal, valMax)
201 pc.LineTo(catVal, eVal)
202 pc.MoveTo(plt.PX(cat-ew), eVal)
203 pc.LineTo(plt.PX(cat+ew), eVal)
204 }
205 pc.Stroke()

Callers

nothing calls this directly

Calls 13

SizeMethod · 0.95
Vec2Function · 0.92
AbsFunction · 0.92
PYMethod · 0.80
BarHeightMethod · 0.80
PXMethod · 0.80
DrawRectangleMethod · 0.80
FillStrokeClearMethod · 0.80
MoveToMethod · 0.80
LineToMethod · 0.80
StrokeMethod · 0.80
SetMethod · 0.65

Tested by

no test coverage detected