Documentation ¶
Overview ¶
Package canvas holds all the components required to plot a chart.
All canvas elements except Figure depend on a parent. To create a figure, use the method:
fig, err := canvas.NewFigure(w, h) if err != nil { panic(err) }
All other elements should be created from a parent as shown in this family tree:
Figure |- Axes (figure.NewAxes(), figure.SubAxes(c, r)) |- Bar Chart (axes.BarPlot(X, Y)) |- Scatter Point Chart (axes.ScatterPlot(X, Y))
Canvas uses a primitive as the building block of the plotter. A primitive implements Container and holds all the information necessary to draw an element into an image. Most elements used on the plotter are derivatives from primitive. For that reason, they also implement Container.
Any primitive can contain other primitives as a slice of Container in children.
Index ¶
- type Alignment
- type Axes
- func (ax *Axes) BarPlot(X []string, Y []float64) error
- func (p *Axes) Bounds() image.Rectangle
- func (p *Axes) Children() []Container
- func (p *Axes) Color() color.Color
- func (ax *Axes) Render(dst draw.Image)
- func (ax *Axes) ScatterPlot(X, Y []float64) error
- func (p *Axes) String() string
- func (p *Axes) Transform() []*mat.Dense
- func (p *Axes) Vector() mat.Matrix
- type Axis
- func (p *Axis) Bounds() image.Rectangle
- func (p *Axis) Children() []Container
- func (p *Axis) Color() color.Color
- func (a *Axis) Labels(X []string, padding float64)
- func (a *Axis) Render(dst draw.Image)
- func (p *Axis) String() string
- func (p *Axis) Transform() []*mat.Dense
- func (p *Axis) Vector() mat.Matrix
- type Container
- type Figure
- func (p *Figure) Bounds() image.Rectangle
- func (p *Figure) Children() []Container
- func (p *Figure) Color() color.Color
- func (f *Figure) NewAxes() *Axes
- func (p *Figure) Render(dst draw.Image)
- func (f *Figure) Resize(w, h float64)
- func (p *Figure) String() string
- func (f *Figure) SubAxes(rows, cols int) ([]*Axes, error)
- func (p *Figure) Transform() []*mat.Dense
- func (p *Figure) Vector() mat.Matrix
- type Label
- type ScatterPoint
- func (p *ScatterPoint) Bounds() image.Rectangle
- func (p *ScatterPoint) Children() []Container
- func (p *ScatterPoint) Color() color.Color
- func (p *ScatterPoint) Render(dst draw.Image)
- func (p *ScatterPoint) String() string
- func (p *ScatterPoint) Transform() []*mat.Dense
- func (p *ScatterPoint) Vector() mat.Matrix
- type Tick
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Alignment ¶
type Alignment byte
Alignment defines how to draw each element of the plot.
const ( BottomAxis Alignment = 0 LeftAxis Alignment = 1 TopAxis Alignment = 2 RightAxis Alignment = 3 )
Constants used to define the location of an Axis primitive.
const ( // Used for X alignment LeftAlign Alignment = 0 // Used for Y alignment BottomAlign Alignment = 0 // Used for X and Y alignment CenterAlign Alignment = 1 // Used for X alignment RightAlign Alignment = 2 // Used for Y alignment TopAlign Alignment = 2 )
Constants used to align a Container's side to its origin point.
type Axes ¶
type Axes struct { Parent *Figure // contains filtered or unexported fields }
Axes represents a Primitive with Figure as its parent.
func (*Axes) Children ¶
func (p *Axes) Children() []Container
Children returns a slice of Container from the children of a Primitive.
func (*Axes) ScatterPlot ¶
ScatterPlot creates a Scatter chart inside Axes with X and Y values.
type Axis ¶
type Axis struct {
Min, Max float64
Loc Alignment
Parent *Axes
Typer *fontType
// contains filtered or unexported fields
}
Axis represents a Primitive for horizontal and vertical axes with Axes as its parent.
func (*Axis) Children ¶
func (p *Axis) Children() []Container
Children returns a slice of Container from the children of a Primitive.
func (*Axis) Render ¶
Render creates a Typer to be used by the children Labels. The size of Typer is calculated whenever Axis is requested to render. This ensures the size is updated on any parent's change.
type Figure ¶
type Figure struct {
// contains filtered or unexported fields
}
Figure defines the basic area to draw all the elements of the plot. This is the top parent container.
func (*Figure) Children ¶
func (p *Figure) Children() []Container
Children returns a slice of Container from the children of a Primitive.
func (*Figure) Resize ¶
Resize changes the width and height of the Figure. It also updates the transformation matrix of Figure.
type Label ¶
func (*Label) Children ¶
func (p *Label) Children() []Container
Children returns a slice of Container from the children of a Primitive.
type ScatterPoint ¶
func NewScatterPoint ¶
func NewScatterPoint(parent *Axes, x, y float64) (*ScatterPoint, error)
func (*ScatterPoint) Bounds ¶
Bounds returns the bounds to be rendered out of a Primitive in pixels.
func (*ScatterPoint) Children ¶
func (p *ScatterPoint) Children() []Container
Children returns a slice of Container from the children of a Primitive.
type Tick ¶
Tick represents a tick to be drawn on an Axis
func (*Tick) Children ¶
func (p *Tick) Children() []Container
Children returns a slice of Container from the children of a Primitive.