// Plot implements the plot.Plotter interface. func (b *BarChart) Plot(da plot.DrawArea, plt *plot.Plot) { trX, trY := plt.Transforms(&da) for i, ht := range b.Values { x := b.XMin + float64(i) xmin := trX(float64(x)) if !da.ContainsX(xmin) { continue } xmin = xmin - b.Width/2 + b.Offset xmax := xmin + b.Width bottom := b.stackedOn.BarHeight(i) ymin := trY(bottom) ymax := trY(bottom + ht) pts := []plot.Point{ {xmin, ymin}, {xmin, ymax}, {xmax, ymax}, {xmax, ymin}, } poly := da.ClipPolygonY(pts) da.FillPolygon(b.Color, poly) pts = append(pts, plot.Point{xmin, ymin}) outline := da.ClipLinesY(pts) da.StrokeLines(b.LineStyle, outline...) } }
func (b *BarChart) Thumbnail(da *plot.DrawArea) { pts := []plot.Point{ {da.Min.X, da.Min.Y}, {da.Min.X, da.Max().Y}, {da.Max().X, da.Max().Y}, {da.Max().X, da.Min.Y}, } poly := da.ClipPolygonY(pts) da.FillPolygon(b.Color, poly) pts = append(pts, plot.Point{da.Min.X, da.Min.Y}) outline := da.ClipLinesY(pts) da.StrokeLines(b.LineStyle, outline...) }