// DrawGlyph implements the GlyphDrawer interface. func (c CircleGlyph) DrawGlyph(da *DrawArea, sty GlyphStyle, pt Point) { var p vg.Path p.Move(pt.X+sty.Radius, pt.Y) p.Arc(pt.X, pt.Y, sty.Radius, 0, 2*math.Pi) p.Close() da.Fill(p) }
func (pt *Dots) Plot(da plot.DrawArea, plt *plot.Plot) { trX, trY := plt.Transforms(&da) da.SetColor(pt.Color) for i := range pt.Y { // Transform the data x, y coordinate of this bubble // to the corresponding drawing coordinate. x := trX(pt.X[i]) y := trY(pt.Y[i]) // Get the radius of this bubble. The radius // is specified in drawing units (i.e., its size // is given as the final size at which it will // be drawn) so it does not need to be transformed. rad := vg.Length(2) // Fill a circle centered at x,y on the draw area. var p vg.Path p.Move(x+rad, y) p.Arc(x, y, rad, 0, 2*math.Pi) p.Close() da.Fill(p) } }
// DrawGlyph implements the Glyph interface. func (RingGlyph) DrawGlyph(da *DrawArea, sty GlyphStyle, pt Point) { da.SetLineStyle(LineStyle{Color: sty.Color, Width: vg.Points(0.5)}) var p vg.Path p.Move(pt.X+sty.Radius, pt.Y) p.Arc(pt.X, pt.Y, sty.Radius, 0, 2*math.Pi) p.Close() da.Stroke(p) }
// Plot implements the Plot method of the plot.Plotter interface. func (bs *Bubbles) Plot(da plot.DrawArea, plt *plot.Plot) { trX, trY := plt.Transforms(&da) da.SetColor(bs.Color) for _, d := range bs.XYZs { x := trX(d.X) y := trY(d.Y) if !da.Contains(plot.Point{x, y}) { continue } rad := bs.radius(d.Z) // draw a circle centered at x, y var p vg.Path p.Move(x+rad, y) p.Arc(x, y, rad, 0, 2*math.Pi) p.Close() da.Fill(p) } }
// DrawArcs draws some arcs to the canvas. // The canvas is assumed to be 4 inches square. func DrawArcs(c vg.Canvas) { green := color.RGBA{G: 255, A: 255} var p vg.Path p.Move(vg.Inches(3), vg.Inches(2)) p.Arc(vg.Inches(2), vg.Inches(2), vg.Inches(1), 0, 2*math.Pi) c.SetColor(color.RGBA{B: 255, A: 255}) c.Fill(p) p = vg.Path{} p.Move(vg.Inches(4), vg.Inches(2)) p.Line(vg.Inches(3), vg.Inches(2)) p.Arc(vg.Inches(2), vg.Inches(2), vg.Inches(1), 0, 5*math.Pi/2) p.Line(vg.Inches(2), vg.Inches(4)) c.SetColor(color.RGBA{R: 255, A: 255}) c.SetLineWidth(vg.Points(3)) c.Stroke(p) p = vg.Path{} p.Move(vg.Inches(0), vg.Inches(2)) p.Line(vg.Inches(1), vg.Inches(2)) p.Arc(vg.Inches(2), vg.Inches(2), vg.Inches(1), math.Pi, -7*math.Pi/2) p.Line(vg.Inches(2), vg.Inches(0)) c.SetColor(color.Black) c.SetLineWidth(vg.Points(1)) c.Stroke(p) p = vg.Path{} p.Move(vg.Inches(0), vg.Inches(1)) p.Arc(vg.Inches(1), vg.Inches(1), vg.Inches(1), math.Pi, math.Pi/2) c.SetLineWidth(vg.Points(3)) c.SetColor(green) c.Stroke(p) p = vg.Path{} p.Move(vg.Inches(1), vg.Inches(0)) p.Arc(vg.Inches(1), vg.Inches(1), vg.Inches(1), 3*math.Pi/2, -math.Pi/2) c.SetLineWidth(vg.Points(1)) c.SetColor(color.Black) c.Stroke(p) p = vg.Path{} p.Move(vg.Inches(3), vg.Inches(2)) p.Arc(vg.Inches(3), vg.Inches(3), vg.Inches(1), 3*math.Pi/2, 3*math.Pi/2) c.SetLineWidth(vg.Points(3)) c.SetColor(green) c.Stroke(p) p = vg.Path{} p.Move(vg.Inches(2), vg.Inches(3)) p.Arc(vg.Inches(3), vg.Inches(3), vg.Inches(1), math.Pi, -3*math.Pi/2) c.SetLineWidth(vg.Points(1)) c.SetColor(color.Black) c.Stroke(p) }