Documentation

Index

Examples

Constants

View Source
const (
	PosLeft   = -1
	PosBottom = -1
	PosCenter = 0
	PosTop    = +1
	PosRight  = +1
)

    Position specifies the text position.

    Variables

    This section is empty.

    Functions

    func NewFormattedCanvas

    func NewFormattedCanvas(w, h vg.Length, format string) (vg.CanvasWriterTo, error)

      NewFormattedCanvas creates a new vg.CanvasWriterTo with the specified image format.

      Supported formats are:

      eps, jpg|jpeg, pdf, png, svg, tex and tif|tiff.
      

      Types

      type BoxGlyph

      type BoxGlyph struct{}

        BoxGlyph is a glyph that draws a filled square.

        func (BoxGlyph) DrawGlyph

        func (BoxGlyph) DrawGlyph(c *Canvas, sty GlyphStyle, pt vg.Point)

          DrawGlyph implements the Glyph interface.

          type Canvas

          type Canvas struct {
          	vg.Canvas
          	vg.Rectangle
          }

            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

            func Crop(c Canvas, left, right, bottom, top vg.Length) Canvas

              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)
              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)
              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 New

              func New(c vg.CanvasSizer) Canvas

                New returns a new (bounded) draw.Canvas.

                func NewCanvas

                func NewCanvas(c vg.Canvas, w, h vg.Length) Canvas

                  NewCanvas returns a new (bounded) draw.Canvas of the given size.

                  func (*Canvas) Center

                  func (c *Canvas) Center() vg.Point

                    Center returns the center point of the area

                    func (*Canvas) ClipLinesX

                    func (c *Canvas) ClipLinesX(lines ...[]vg.Point) (clipped [][]vg.Point)

                      ClipLinesX returns a slice of lines that represent the given line clipped in the X direction.

                      func (*Canvas) ClipLinesXY

                      func (c *Canvas) ClipLinesXY(lines ...[]vg.Point) [][]vg.Point

                        ClipLinesXY returns a slice of lines that represent the given line clipped in both X and Y directions.

                        func (*Canvas) ClipLinesY

                        func (c *Canvas) ClipLinesY(lines ...[]vg.Point) (clipped [][]vg.Point)

                          ClipLinesY returns a slice of lines that represent the given line clipped in the Y direction.

                          func (*Canvas) ClipPolygonX

                          func (c *Canvas) ClipPolygonX(pts []vg.Point) []vg.Point

                            ClipPolygonX returns a slice of lines that represent the given polygon clipped in the X direction.

                            func (*Canvas) ClipPolygonXY

                            func (c *Canvas) ClipPolygonXY(pts []vg.Point) []vg.Point

                              ClipPolygonXY returns a slice of lines that represent the given polygon clipped in both X and Y directions.

                              func (*Canvas) ClipPolygonY

                              func (c *Canvas) ClipPolygonY(pts []vg.Point) []vg.Point

                                ClipPolygonY returns a slice of lines that represent the given polygon clipped in the Y direction.

                                func (*Canvas) Contains

                                func (c *Canvas) Contains(p vg.Point) bool

                                  Contains returns true if the Canvas contains the point.

                                  func (*Canvas) ContainsX

                                  func (c *Canvas) ContainsX(x vg.Length) bool

                                    ContainsX returns true if the Canvas contains the x coordinate.

                                    func (*Canvas) ContainsY

                                    func (c *Canvas) ContainsY(y vg.Length) bool

                                      ContainsY returns true if the Canvas contains the y coordinate.

                                      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

                                          func (c *Canvas) FillPolygon(clr color.Color, pts []vg.Point)

                                            FillPolygon fills a polygon with the given color.

                                            func (*Canvas) FillText

                                            func (c *Canvas) FillText(sty TextStyle, pt vg.Point, txt string)

                                              FillText fills lines of text in the draw area. pt specifies the location where the text is to be drawn.

                                              func (*Canvas) SetLineStyle

                                              func (c *Canvas) SetLineStyle(sty LineStyle)

                                                SetLineStyle sets the current line style

                                                func (*Canvas) StrokeLine2

                                                func (c *Canvas) StrokeLine2(sty LineStyle, x0, y0, x1, y1 vg.Length)

                                                  StrokeLine2 draws a line between two points in the given Canvas.

                                                  func (*Canvas) StrokeLines

                                                  func (c *Canvas) StrokeLines(sty LineStyle, lines ...[]vg.Point)

                                                    StrokeLines draws a line connecting a set of points in the given Canvas.

                                                    func (*Canvas) X

                                                    func (c *Canvas) X(x float64) vg.Length

                                                      X returns the value of x, given in the unit range, in the drawing coordinates of this draw area. A value of 0, for example, will return the minimum x value of the draw area and a value of 1 will return the maximum.

                                                      func (*Canvas) Y

                                                      func (c *Canvas) Y(y float64) vg.Length

                                                        Y returns the value of x, given in the unit range, in the drawing coordinates of this draw area. A value of 0, for example, will return the minimum y value of the draw area and a value of 1 will return the maximum.

                                                        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

                                                                        type PlainTextHandler struct{}

                                                                          PlainTextHandler is a text/plain handler.

                                                                          func (PlainTextHandler) Box

                                                                          func (hdlr PlainTextHandler) Box(txt string, fnt vg.Font) (width, height, depth vg.Length)

                                                                            Box returns the bounding box of the given text where:

                                                                            - width is the horizontal space from the origin.
                                                                            - height is the vertical space above the baseline.
                                                                            - depth is the vertical space below the baseline, a negative number.
                                                                            

                                                                            func (PlainTextHandler) Draw

                                                                            func (hdlr PlainTextHandler) Draw(c *Canvas, txt string, sty TextStyle, pt vg.Point)

                                                                              Draw renders the given text with the provided style and position on the canvas.

                                                                              type PlusGlyph

                                                                              type PlusGlyph struct{}

                                                                                PlusGlyph is a glyph that draws a plus sign

                                                                                func (PlusGlyph) DrawGlyph

                                                                                func (PlusGlyph) DrawGlyph(c *Canvas, sty GlyphStyle, pt vg.Point)

                                                                                  DrawGlyph implements the Glyph interface.

                                                                                  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 RingGlyph

                                                                                      type RingGlyph struct{}

                                                                                        RingGlyph is a glyph that draws the outline of a circle.

                                                                                        func (RingGlyph) DrawGlyph

                                                                                        func (RingGlyph) 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

                                                                                              type TextHandler interface {
                                                                                              	// Box returns the bounding box of the given text where:
                                                                                              	//  - width is the horizontal space from the origin.
                                                                                              	//  - height is the vertical space above the baseline.
                                                                                              	//  - depth is the vertical space below the baseline, a negative number.
                                                                                              	Box(txt string, fnt vg.Font) (width, height, depth vg.Length)
                                                                                              
                                                                                              	// Draw renders the given text with the provided style and position
                                                                                              	// on the canvas.
                                                                                              	Draw(c *Canvas, txt string, sty TextStyle, pt vg.Point)
                                                                                              }

                                                                                                TextHandler parses, formats and renders text.

                                                                                                type TextStyle

                                                                                                type TextStyle struct {
                                                                                                	// Color is the text color.
                                                                                                	Color color.Color
                                                                                                
                                                                                                	// Font is the font description.
                                                                                                	Font vg.Font
                                                                                                
                                                                                                	// Rotation is the text rotation in radians, performed around the axis
                                                                                                	// defined by XAlign and YAlign.
                                                                                                	Rotation float64
                                                                                                
                                                                                                	// XAlign and YAlign specify the alignment of the text.
                                                                                                	XAlign XAlignment
                                                                                                	YAlign YAlignment
                                                                                                
                                                                                                	// TextHandler parses and formats text according to a given
                                                                                                	// dialect (Markdown, LaTeX, plain, ...)
                                                                                                	// The default is a plain text handler.
                                                                                                	Handler TextHandler
                                                                                                }

                                                                                                  TextStyle describes what text will look like.

                                                                                                  func (TextStyle) Height

                                                                                                  func (sty TextStyle) Height(txt string) vg.Length

                                                                                                    Height returns the height of the text when using the given font before any text rotation is applied.

                                                                                                    func (TextStyle) Rectangle

                                                                                                    func (sty TextStyle) Rectangle(txt string) vg.Rectangle

                                                                                                      Rectangle returns a rectangle giving the bounds of this text assuming that it is drawn at (0, 0).

                                                                                                      func (TextStyle) Width

                                                                                                      func (sty TextStyle) Width(txt string) (max vg.Length)

                                                                                                        Width returns the width of lines of text when using the given font before any text rotation is applied.

                                                                                                        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.

                                                                                                          func (Tiles) At

                                                                                                          func (ts Tiles) At(c Canvas, x, y int) Canvas

                                                                                                            At returns the subcanvas within c that corresponds to the tile at column x, row y.

                                                                                                            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 float64

                                                                                                                  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).

                                                                                                                  const (
                                                                                                                  	// XLeft aligns the left edge of the text with the specified location.
                                                                                                                  	XLeft XAlignment = 0
                                                                                                                  	// XCenter aligns the horizontal center of the text with the specified location.
                                                                                                                  	XCenter XAlignment = -0.5
                                                                                                                  	// XRight aligns the right edge of the text with the specified location.
                                                                                                                  	XRight XAlignment = -1
                                                                                                                  )

                                                                                                                  type YAlignment

                                                                                                                  type YAlignment float64

                                                                                                                    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).

                                                                                                                    const (
                                                                                                                    	// YTop aligns the top of of the text with the specified location.
                                                                                                                    	YTop YAlignment = -1
                                                                                                                    	// YCenter aligns the vertical center of the text with the specified location.
                                                                                                                    	YCenter YAlignment = -0.5
                                                                                                                    	// YBottom aligns the bottom of the text with the specified location.
                                                                                                                    	YBottom YAlignment = 0
                                                                                                                    )