Example #1
0
// DrawGlyph implements the Glyph interface.
func (BoxGlyph) DrawGlyph(da *DrawArea, sty GlyphStyle, pt Point) {
	x := (sty.Radius-sty.Radius*cosπover4)/2 + sty.Radius*cosπover4
	var p vg.Path
	p.Move(pt.X-x, pt.Y-x)
	p.Line(pt.X+x, pt.Y-x)
	p.Line(pt.X+x, pt.Y+x)
	p.Line(pt.X-x, pt.Y+x)
	p.Close()
	da.Fill(p)
}
Example #2
0
// DrawGlyph implements the Glyph interface.
func (SquareGlyph) DrawGlyph(da *DrawArea, sty GlyphStyle, pt Point) {
	da.setLineStyle(LineStyle{Color: sty.Color, Width: vg.Points(0.5)})
	x := (sty.Radius-sty.Radius*cosπover4)/2 + sty.Radius*cosπover4
	var p vg.Path
	p.Move(pt.X-x, pt.Y-x)
	p.Line(pt.X+x, pt.Y-x)
	p.Line(pt.X+x, pt.Y+x)
	p.Line(pt.X-x, pt.Y+x)
	p.Close()
	da.Stroke(p)
}
Example #3
0
// DrawGlyph implements the Glyph interface.
func (CrossGlyph) DrawGlyph(da *DrawArea, sty GlyphStyle, pt Point) {
	da.setLineStyle(LineStyle{Color: sty.Color, Width: vg.Points(0.5)})
	r := sty.Radius * cosπover4
	var p vg.Path
	p.Move(pt.X-r, pt.Y-r)
	p.Line(pt.X+r, pt.Y+r)
	da.Stroke(p)
	p = vg.Path{}
	p.Move(pt.X-r, pt.Y+r)
	p.Line(pt.X+r, pt.Y-r)
	da.Stroke(p)
}
Example #4
0
// 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)
}
Example #5
0
// 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)
}
Example #6
0
// StrokeLines draws a line connecting a set of points
// in the given DrawArea.
func (da *DrawArea) StrokeLines(sty LineStyle, lines ...[]Point) {
	if len(lines) == 0 {
		return
	}

	da.setLineStyle(sty)

	for _, l := range lines {
		if len(l) == 0 {
			continue
		}
		var p vg.Path
		p.Move(l[0].X, l[0].Y)
		for _, pt := range l[1:] {
			p.Line(pt.X, pt.Y)
		}
		da.Stroke(p)
	}
}
Example #7
0
// DrawGlyph implements the Glyph interface.
func (PyramidGlyph) DrawGlyph(da *DrawArea, sty GlyphStyle, pt Point) {
	r := sty.Radius + (sty.Radius-sty.Radius*sinπover6)/2
	var p vg.Path
	p.Move(pt.X, pt.Y+r)
	p.Line(pt.X-r*cosπover6, pt.Y-r*sinπover6)
	p.Line(pt.X+r*cosπover6, pt.Y-r*sinπover6)
	p.Close()
	da.Fill(p)
}
Example #8
0
// DrawGlyph implements the Glyph interface.
func (TriangleGlyph) DrawGlyph(da *DrawArea, sty GlyphStyle, pt Point) {
	da.setLineStyle(LineStyle{Color: sty.Color, Width: vg.Points(0.5)})
	r := sty.Radius + (sty.Radius-sty.Radius*sinπover6)/2
	var p vg.Path
	p.Move(pt.X, pt.Y+r)
	p.Line(pt.X-r*cosπover6, pt.Y-r*sinπover6)
	p.Line(pt.X+r*cosπover6, pt.Y-r*sinπover6)
	p.Close()
	da.Stroke(p)
}
Example #9
0
// FillPolygon fills a polygon with the given color.
func (da *DrawArea) FillPolygon(clr color.Color, pts []Point) {
	if len(pts) == 0 {
		return
	}

	da.SetColor(clr)
	var p vg.Path
	p.Move(pts[0].X, pts[0].Y)
	for _, pt := range pts[1:] {
		p.Line(pt.X, pt.Y)
	}
	p.Close()
	da.Fill(p)
}
Example #10
0
// 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)
	}
}