Пример #1
0
// 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.Pt(xmin, ymin))
		outline := da.ClipLinesY(pts)
		da.StrokeLines(b.LineStyle, outline...)
	}
}
Пример #2
0
// Plot implements the plot.Plotter interface.
func (cg *ColorGrid) Plot(da plot.DrawArea, plt *plot.Plot) {
	trX, trY := plt.Transforms(&da)
	for i, d := range cg.XYZs {
		if i%cg.Ny != cg.Ny-1 && i < cg.Nx*cg.Ny-cg.Ny {
			pts := []plot.Point{
				{trX(d.X), trY(d.Y)},
				{trX(cg.XYZs[i+cg.Ny].X), trY(cg.XYZs[i+cg.Ny].Y)},
				{trX(cg.XYZs[i+cg.Ny+1].X), trY(cg.XYZs[i+cg.Ny+1].Y)},
				{trX(cg.XYZs[i+1].X), trY(cg.XYZs[i+1].Y)},
			}
			da.FillPolygon(color.Gray{uint8((d.Z - cg.MinZ) / math.Abs(cg.MaxZ-cg.MinZ) * 255.0)}, pts)
		}
	}
}
Пример #3
0
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.Pt(da.Min.X, da.Min.Y))
	outline := da.ClipLinesY(pts)
	da.StrokeLines(b.LineStyle, outline...)
}
Пример #4
0
// Plot implements the Plotter interface, drawing a line
// that connects each point in the Line.
func (h *Histogram) Plot(da plot.DrawArea, p *plot.Plot) {
	trX, trY := p.Transforms(&da)

	for _, bin := range h.Bins {
		pts := []plot.Point{
			{trX(bin.Min), trY(0)},
			{trX(bin.Max), trY(0)},
			{trX(bin.Max), trY(bin.Weight)},
			{trX(bin.Min), trY(bin.Weight)},
		}
		if h.FillColor != nil {
			da.FillPolygon(h.FillColor, da.ClipPolygonXY(pts))
		}
		pts = append(pts, plot.Pt(trX(bin.Min), trY(0)))
		da.StrokeLines(h.LineStyle, da.ClipLinesXY(pts)...)
	}
}
Пример #5
0
// Thumbnail the thumbnail for the Line,
// implementing the plot.Thumbnailer interface.
func (pts *Line) Thumbnail(da *plot.DrawArea) {
	if pts.ShadeColor != nil {
		points := []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(points)
		da.FillPolygon(*pts.ShadeColor, poly)

		points = append(points, plot.Pt(da.Min.X, da.Min.Y))
	} else {
		y := da.Center().Y
		da.StrokeLine2(pts.LineStyle, da.Min.X, y, da.Max().X, y)
	}
}