canvas

package
v0.0.0-...-c9a9391 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 17, 2018 License: MIT Imports: 11 Imported by: 0

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

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

func (ax *Axes) BarPlot(X []string, Y []float64) error

BarPlot creates a Bar chart inside Axes with X labels and Y values.

func (*Axes) Bounds

func (p *Axes) Bounds() image.Rectangle

Bounds returns the bounds to be rendered out of a Primitive in pixels.

func (*Axes) Children

func (p *Axes) Children() []Container

Children returns a slice of Container from the children of a Primitive.

func (*Axes) Color

func (p *Axes) Color() color.Color

Color returns the fill color of a Primitive.

func (*Axes) Render

func (ax *Axes) Render(dst draw.Image)

Render draws the Axes' border on top of drawing its contents.

func (*Axes) ScatterPlot

func (ax *Axes) ScatterPlot(X, Y []float64) error

ScatterPlot creates a Scatter chart inside Axes with X and Y values.

func (*Axes) String

func (p *Axes) String() string

func (*Axes) Transform

func (p *Axes) Transform() []*mat.Dense

Transform returns the transformation matrix of the Primitive.

func (*Axes) Vector

func (p *Axes) Vector() mat.Matrix

Vector returns a mat.Matrix with two point coordinates that define the bounding rectangle of the Primitive.

The coordinates system are relative to the Primitive's parent.

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

func (p *Axis) Bounds() image.Rectangle

Bounds returns the bounds to be rendered out of a Primitive in pixels.

func (*Axis) Children

func (p *Axis) Children() []Container

Children returns a slice of Container from the children of a Primitive.

func (*Axis) Color

func (p *Axis) Color() color.Color

Color returns the fill color of a Primitive.

func (*Axis) Labels

func (a *Axis) Labels(X []string, padding float64)

Labels adds X labels to the Axis with regular spacing.

func (*Axis) Render

func (a *Axis) Render(dst draw.Image)

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.

func (*Axis) String

func (p *Axis) String() string

func (*Axis) Transform

func (p *Axis) Transform() []*mat.Dense

Transform returns the transformation matrix of the Primitive.

func (*Axis) Vector

func (p *Axis) Vector() mat.Matrix

Vector returns a mat.Matrix with two point coordinates that define the bounding rectangle of the Primitive.

The coordinates system are relative to the Primitive's parent.

type Container

type Container interface {
	Render(draw.Image)
	Children() []Container
}

Container is an interface that allows access to Render and a Primitive's children.

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 NewFigure

func NewFigure(w, h int) (*Figure, error)

NewFigure creates a new *Figure with width and height in pixels.

func (*Figure) Bounds

func (p *Figure) Bounds() image.Rectangle

Bounds returns the bounds to be rendered out of a Primitive in pixels.

func (*Figure) Children

func (p *Figure) Children() []Container

Children returns a slice of Container from the children of a Primitive.

func (*Figure) Color

func (p *Figure) Color() color.Color

Color returns the fill color of a Primitive.

func (*Figure) NewAxes

func (f *Figure) NewAxes() *Axes

NewAxes attaches a new Axes into the Figure.

func (*Figure) Render

func (p *Figure) Render(dst draw.Image)

Render draws the Primitive into a draw.Image interface.

func (*Figure) Resize

func (f *Figure) Resize(w, h float64)

Resize changes the width and height of the Figure. It also updates the transformation matrix of Figure.

func (*Figure) String

func (p *Figure) String() string

func (*Figure) SubAxes

func (f *Figure) SubAxes(rows, cols int) ([]*Axes, error)

SubAxes attaches multiple Axes defined by the number of rows and columns.

func (*Figure) Transform

func (p *Figure) Transform() []*mat.Dense

Transform returns the transformation matrix of the Primitive.

func (*Figure) Vector

func (p *Figure) Vector() mat.Matrix

Vector returns a mat.Matrix with two point coordinates that define the bounding rectangle of the Primitive.

The coordinates system are relative to the Primitive's parent.

type Label

type Label struct {
	Parent *Axis
	Text   string
	// contains filtered or unexported fields
}

func (*Label) Bounds

func (p *Label) Bounds() image.Rectangle

Bounds returns the bounds to be rendered out of a Primitive in pixels.

func (*Label) Children

func (p *Label) Children() []Container

Children returns a slice of Container from the children of a Primitive.

func (*Label) Color

func (p *Label) Color() color.Color

Color returns the fill color of a Primitive.

func (*Label) Render

func (l *Label) Render(dst draw.Image)

func (*Label) String

func (p *Label) String() string

func (*Label) Transform

func (p *Label) Transform() []*mat.Dense

Transform returns the transformation matrix of the Primitive.

func (*Label) Vector

func (p *Label) Vector() mat.Matrix

Vector returns a mat.Matrix with two point coordinates that define the bounding rectangle of the Primitive.

The coordinates system are relative to the Primitive's parent.

type ScatterPoint

type ScatterPoint struct {
	Parent *Axes
	X, Y   float64
	// contains filtered or unexported fields
}

func NewScatterPoint

func NewScatterPoint(parent *Axes, x, y float64) (*ScatterPoint, error)

func (*ScatterPoint) Bounds

func (p *ScatterPoint) Bounds() image.Rectangle

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.

func (*ScatterPoint) Color

func (p *ScatterPoint) Color() color.Color

Color returns the fill color of a Primitive.

func (*ScatterPoint) Render

func (p *ScatterPoint) Render(dst draw.Image)

Render draws the Primitive into a draw.Image interface.

func (*ScatterPoint) String

func (p *ScatterPoint) String() string

func (*ScatterPoint) Transform

func (p *ScatterPoint) Transform() []*mat.Dense

Transform returns the transformation matrix of the Primitive.

func (*ScatterPoint) Vector

func (p *ScatterPoint) Vector() mat.Matrix

Vector returns a mat.Matrix with two point coordinates that define the bounding rectangle of the Primitive.

The coordinates system are relative to the Primitive's parent.

type Tick

type Tick struct {
	W      int
	Parent *Axis
	// contains filtered or unexported fields
}

Tick represents a tick to be drawn on an Axis

func NewTick

func NewTick(parent *Axis, x, y, l float64, w int) (*Tick, error)

NewTick creates a new Tick linked to an Axis.

func (*Tick) Bounds

func (t *Tick) Bounds() image.Rectangle

Bounds returns a a specific width in pixels.

func (*Tick) Children

func (p *Tick) Children() []Container

Children returns a slice of Container from the children of a Primitive.

func (*Tick) Color

func (p *Tick) Color() color.Color

Color returns the fill color of a Primitive.

func (*Tick) Render

func (t *Tick) Render(dst draw.Image)

Render makes sure Tick's Bounds gets called.

func (*Tick) String

func (p *Tick) String() string

func (*Tick) Transform

func (p *Tick) Transform() []*mat.Dense

Transform returns the transformation matrix of the Primitive.

func (*Tick) Vector

func (p *Tick) Vector() mat.Matrix

Vector returns a mat.Matrix with two point coordinates that define the bounding rectangle of the Primitive.

The coordinates system are relative to the Primitive's parent.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL