Documentation ¶
Overview ¶
Package draw provides types and functions to draw shapes on a vg.Canvas.
Index ¶
- Constants
- func Formats() []string
- func NewFormattedCanvas(w, h vg.Length, format string) (vg.CanvasWriterTo, error)
- func RegisterFormat(name string, fn func(w, h vg.Length) vg.CanvasWriterTo)
- type BoxGlyph
- type Canvas
- func (c *Canvas) Center() vg.Point
- func (c *Canvas) ClipLinesX(lines ...[]vg.Point) (clipped [][]vg.Point)
- func (c *Canvas) ClipLinesXY(lines ...[]vg.Point) [][]vg.Point
- func (c *Canvas) ClipLinesY(lines ...[]vg.Point) (clipped [][]vg.Point)
- func (c *Canvas) ClipPolygonX(pts []vg.Point) []vg.Point
- func (c *Canvas) ClipPolygonXY(pts []vg.Point) []vg.Point
- func (c *Canvas) ClipPolygonY(pts []vg.Point) []vg.Point
- func (c *Canvas) Contains(p vg.Point) bool
- func (c *Canvas) ContainsX(x vg.Length) bool
- func (c *Canvas) ContainsY(y vg.Length) bool
- func (c *Canvas) DrawGlyph(sty GlyphStyle, pt vg.Point)
- func (c *Canvas) DrawGlyphNoClip(sty GlyphStyle, pt vg.Point)
- func (c *Canvas) FillPolygon(clr color.Color, pts []vg.Point)
- func (c *Canvas) FillText(sty TextStyle, pt vg.Point, txt string)
- func (c *Canvas) SetLineStyle(sty LineStyle)
- func (c *Canvas) StrokeLine2(sty LineStyle, x0, y0, x1, y1 vg.Length)
- func (c *Canvas) StrokeLines(sty LineStyle, lines ...[]vg.Point)
- func (c *Canvas) X(x float64) vg.Length
- func (c *Canvas) Y(y float64) vg.Length
- type CircleGlyph
- type CrossGlyph
- type GlyphDrawer
- type GlyphStyle
- type LineStyle
- type PlainTextHandler
- type PlusGlyph
- type PyramidGlyph
- type RingGlyph
- type SquareGlyph
- type TextHandler
- type TextStyle
- type Tiles
- type TriangleGlyph
- type XAlignment
- type YAlignment
Examples ¶
Constants ¶
const ( // XLeft aligns the left edge of the text with the specified location. XLeft = text.XLeft // XCenter aligns the horizontal center of the text with the specified location. XCenter = text.XCenter // XRight aligns the right edge of the text with the specified location. XRight = text.XRight )
const ( // YTop aligns the top of of the text with the specified location. YTop = text.YTop // YCenter aligns the vertical center of the text with the specified location. YCenter = text.YCenter // YBottom aligns the bottom of the text with the specified location. YBottom = text.YBottom )
const ( PosLeft = text.PosLeft PosBottom = text.PosBottom PosCenter = text.PosCenter PosTop = text.PosTop PosRight = text.PosRight )
Position specifies the text position.
Variables ¶
This section is empty.
Functions ¶
func Formats ¶ added in v0.9.0
func Formats() []string
Formats returns the sorted list of registered vg formats.
func NewFormattedCanvas ¶
NewFormattedCanvas creates a new vg.CanvasWriterTo with the specified image format. Supported formats need to be registered by importing one or more of the following packages:
- gonum.org/v1/plot/vg/vgeps: provides eps
- gonum.org/v1/plot/vg/vgimg: provides png, jpg|jpeg, tif|tiff
- gonum.org/v1/plot/vg/vgpdf: provides pdf
- gonum.org/v1/plot/vg/vgsvg: provides svg
- gonum.org/v1/plot/vg/vgtex: provides tex
func RegisterFormat ¶ added in v0.9.0
func RegisterFormat(name string, fn func(w, h vg.Length) vg.CanvasWriterTo)
RegisterFormat registers an image format for use by NewFormattedCanvas. name is the name of the format, like "jpeg" or "png". fn is the construction function to call for the format.
RegisterFormat panics if fn is nil.
Types ¶
type Canvas ¶
A Canvas is a vector graphics canvas along with an associated Rectangle defining a section of the canvas to which drawing should take place.
func Crop ¶
Crop returns a new Canvas corresponding to the Canvas c with the given lengths added to the minimum and maximum x and y values of the Canvas's Rectangle. Note that cropping the right and top sides of the canvas requires specifying negative values of right and top.
Example (SplitHorizontal) ¶
c := draw.New(vgimg.New(vg.Points(10), vg.Points(16))) // Split c along a vertical line centered on the canvas. left, right := SplitHorizontal(c, c.Size().X/2) fmt.Printf("left: %#v\n", left.Rectangle) fmt.Printf("right: %#v\n", right.Rectangle)
Output: left: vg.Rectangle{Min:vg.Point{X:0, Y:0}, Max:vg.Point{X:5, Y:16}} right: vg.Rectangle{Min:vg.Point{X:5, Y:0}, Max:vg.Point{X:10, Y:16}}
Example (SplitVertical) ¶
c := draw.New(vgimg.New(vg.Points(10), vg.Points(16))) // Split c along a horizontal line centered on the canvas. bottom, top := SplitVertical(c, c.Size().Y/2) fmt.Printf("top: %#v\n", top.Rectangle) fmt.Printf("bottom: %#v\n", bottom.Rectangle)
Output: top: vg.Rectangle{Min:vg.Point{X:0, Y:8}, Max:vg.Point{X:10, Y:16}} bottom: vg.Rectangle{Min:vg.Point{X:0, Y:0}, Max:vg.Point{X:10, Y:8}}
func (*Canvas) ClipLinesX ¶
ClipLinesX returns a slice of lines that represent the given line clipped in the X direction.
func (*Canvas) ClipLinesXY ¶
ClipLinesXY returns a slice of lines that represent the given line clipped in both X and Y directions.
func (*Canvas) ClipLinesY ¶
ClipLinesY returns a slice of lines that represent the given line clipped in the Y direction.
func (*Canvas) ClipPolygonX ¶
ClipPolygonX returns a slice of lines that represent the given polygon clipped in the X direction.
func (*Canvas) ClipPolygonXY ¶
ClipPolygonXY returns a slice of lines that represent the given polygon clipped in both X and Y directions.
func (*Canvas) ClipPolygonY ¶
ClipPolygonY returns a slice of lines that represent the given polygon clipped in the Y direction.
func (*Canvas) DrawGlyph ¶
func (c *Canvas) DrawGlyph(sty GlyphStyle, pt vg.Point)
DrawGlyph draws the given glyph to the draw area. If the point is not within the Canvas or the sty.Shape is nil then nothing is drawn.
func (*Canvas) DrawGlyphNoClip ¶
func (c *Canvas) DrawGlyphNoClip(sty GlyphStyle, pt vg.Point)
DrawGlyphNoClip draws the given glyph to the draw area. If the sty.Shape is nil then nothing is drawn.
func (*Canvas) FillPolygon ¶
FillPolygon fills a polygon with the given color.
func (*Canvas) FillText ¶
FillText fills lines of text in the draw area. pt specifies the location where the text is to be drawn.
func (*Canvas) SetLineStyle ¶
SetLineStyle sets the current line style
func (*Canvas) StrokeLine2 ¶
StrokeLine2 draws a line between two points in the given Canvas.
func (*Canvas) StrokeLines ¶
StrokeLines draws a line connecting a set of points in the given Canvas.
type CircleGlyph ¶
type CircleGlyph struct{}
CircleGlyph is a glyph that draws a solid circle.
func (CircleGlyph) DrawGlyph ¶
func (CircleGlyph) DrawGlyph(c *Canvas, sty GlyphStyle, pt vg.Point)
DrawGlyph implements the GlyphDrawer interface.
type CrossGlyph ¶
type CrossGlyph struct{}
CrossGlyph is a glyph that draws a big X.
func (CrossGlyph) DrawGlyph ¶
func (CrossGlyph) DrawGlyph(c *Canvas, sty GlyphStyle, pt vg.Point)
DrawGlyph implements the Glyph interface.
type GlyphDrawer ¶
type GlyphDrawer interface { // DrawGlyph draws the glyph at the given // point, with the given color and radius. DrawGlyph(*Canvas, GlyphStyle, vg.Point) }
A GlyphDrawer wraps the DrawGlyph function.
type GlyphStyle ¶
type GlyphStyle struct { // Color is the color used to draw the glyph. color.Color // Radius specifies the size of the glyph's radius. Radius vg.Length // Shape draws the shape of the glyph. Shape GlyphDrawer }
A GlyphStyle specifies the look of a glyph used to draw a point on a plot.
func (GlyphStyle) Rectangle ¶
func (g GlyphStyle) Rectangle() vg.Rectangle
Rectangle returns the rectangle surrounding this glyph, assuming that it is drawn centered at 0,0
type LineStyle ¶
type LineStyle struct { // Color is the color of the line. Color color.Color // Width is the width of the line. Width vg.Length Dashes []vg.Length DashOffs vg.Length }
LineStyle describes what a line will look like.
type PlainTextHandler ¶ added in v0.8.0
PlainTextHandler is a text/plain handler.
type PyramidGlyph ¶
type PyramidGlyph struct{}
PyramidGlyph is a glyph that draws a filled triangle.
func (PyramidGlyph) DrawGlyph ¶
func (PyramidGlyph) DrawGlyph(c *Canvas, sty GlyphStyle, pt vg.Point)
DrawGlyph implements the Glyph interface.
type SquareGlyph ¶
type SquareGlyph struct{}
SquareGlyph is a glyph that draws the outline of a square.
func (SquareGlyph) DrawGlyph ¶
func (SquareGlyph) DrawGlyph(c *Canvas, sty GlyphStyle, pt vg.Point)
DrawGlyph implements the Glyph interface.
type TextHandler ¶ added in v0.8.0
type Tiles ¶
type Tiles struct {
// Cols and Rows specify the number of rows and columns of tiles.
Cols, Rows int
// PadTop, PadBottom, PadRight, and PadLeft specify the padding
// on the corresponding side of each tile.
PadTop, PadBottom, PadRight, PadLeft vg.Length
// PadX and PadY specify the padding between columns and rows
// of tiles respectively..
PadX, PadY vg.Length
}
Tiles creates regular subcanvases from a Canvas.
type TriangleGlyph ¶
type TriangleGlyph struct{}
TriangleGlyph is a glyph that draws the outline of a triangle.
func (TriangleGlyph) DrawGlyph ¶
func (TriangleGlyph) DrawGlyph(c *Canvas, sty GlyphStyle, pt vg.Point)
DrawGlyph implements the Glyph interface.
type XAlignment ¶
type XAlignment = text.XAlignment
XAlignment specifies text alignment in the X direction. Three preset options are available, but an arbitrary alignment can also be specified using XAlignment(desired number).
type YAlignment ¶
type YAlignment = text.YAlignment
YAlignment specifies text alignment in the Y direction. Three preset options are available, but an arbitrary alignment can also be specified using YAlignment(desired number).