Documentation ¶
Overview ¶
plot provides an API for setting up plots, and primitives for drawing on plots.
Plot is the basic type for creating a plot, setting the title, axis labels, legend, tick marks, etc. Types implementing the Plotter interface can draw to the data area of a plot using the primitives made available by this package. Some standard implementations of the Plotter interface can be found in the code.google.com/p/plotinum/plotter package which is documented here: http://godoc.org/code.google.com/p/plotinum/plotter
Index ¶
- func ConstantTicks(ts []Tick) func(float64, float64) []Tick
- func LinearScale(min, max, x float64) float64
- func LogScale(min, max, x float64) float64
- type Axis
- type BoxGlyph
- type CircleGlyph
- type CrossGlyph
- type DataRanger
- type DrawArea
- func (da *DrawArea) Center() Point
- func (da *DrawArea) ClipLinesX(lines ...[]Point) (clipped [][]Point)
- func (da *DrawArea) ClipLinesXY(lines ...[]Point) [][]Point
- func (da *DrawArea) ClipLinesY(lines ...[]Point) (clipped [][]Point)
- func (da *DrawArea) ClipPolygonX(pts []Point) []Point
- func (da *DrawArea) ClipPolygonXY(pts []Point) []Point
- func (da *DrawArea) ClipPolygonY(pts []Point) []Point
- func (da *DrawArea) Contains(p Point) bool
- func (da *DrawArea) ContainsX(x vg.Length) bool
- func (da *DrawArea) ContainsY(y vg.Length) bool
- func (da *DrawArea) DrawGlyph(sty GlyphStyle, pt Point)
- func (da *DrawArea) DrawGlyphNoClip(sty GlyphStyle, pt Point)
- func (da *DrawArea) FillPolygon(clr color.Color, pts []Point)
- func (da *DrawArea) FillText(sty TextStyle, x, y vg.Length, xalign, yalign float64, txt string)
- func (da *DrawArea) SetLineStyle(sty LineStyle)
- func (da *DrawArea) StrokeLine2(sty LineStyle, x0, y0, x1, y1 vg.Length)
- func (da *DrawArea) StrokeLines(sty LineStyle, lines ...[]Point)
- func (da *DrawArea) X(x float64) vg.Length
- func (da *DrawArea) Y(y float64) vg.Length
- type GlyphBox
- type GlyphBoxer
- type GlyphDrawer
- type GlyphStyle
- type Legend
- type LineStyle
- type Plot
- func (p *Plot) Add(ps ...Plotter)
- func (p *Plot) DataDrawArea(da DrawArea) DrawArea
- func (p *Plot) Draw(da DrawArea)
- func (p *Plot) DrawGlyphBoxes(da *DrawArea)
- func (p *Plot) GlyphBoxes(*Plot) (boxes []GlyphBox)
- func (p *Plot) HideAxes()
- func (p *Plot) HideX()
- func (p *Plot) HideY()
- func (p *Plot) NominalX(names ...string)
- func (p *Plot) NominalY(names ...string)
- func (p *Plot) Save(width, height float64, file string) (err error)
- func (p *Plot) Transforms(da *DrawArea) (x, y func(float64) vg.Length)
- type Plotter
- type PlusGlyph
- type Point
- type PyramidGlyph
- type Rect
- type RingGlyph
- type SquareGlyph
- type TextStyle
- type Thumbnailer
- type Tick
- type TriangleGlyph
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ConstantTicks ¶
ConstantTicks returns a function suitable for the Tick.Marker field of an Axis. This function returns the given set of ticks.
func LinearScale ¶
LinearScale an be used as the value of an Axis.Scale function to set the axis to a standard linear scale.
Types ¶
type Axis ¶
type Axis struct {
// Min and Max are the minimum and maximum data
// values represented by the axis.
Min, Max float64
Label struct {
// Text is the axis label string.
Text string
// TextStyle is the style of the axis label text.
TextStyle
}
// LineStyle is the style of the axis line.
LineStyle
// Padding between the axis line and the data. Having
// non-zero padding ensures that the data is never drawn
// on the axis, thus making it easier to see.
Padding vg.Length
Tick struct {
// Label is the TextStyle on the tick labels.
Label TextStyle
// LineStyle is the LineStyle of the tick lines.
LineStyle
// Length is the length of a major tick mark.
// Minor tick marks are half of the length of major
// tick marks.
Length vg.Length
// Marker returns the tick marks. Any tick marks
// returned by the Marker function that are not in
// range of the axis are not drawn.
Marker func(min, max float64) []Tick
}
// Scale transforms a value given in the data coordinate system
// to the normalized coordinate system of the axis—its distance
// along the axis as a fraction of the axis range.
Scale func(min, max, x float64) float64
}
An Axis represents either a horizontal or vertical axis of a plot.
type CircleGlyph ¶
type CircleGlyph struct{}
CircleGlyph is a glyph that draws a solid circle.
func (CircleGlyph) DrawGlyph ¶
func (c CircleGlyph) DrawGlyph(da *DrawArea, sty GlyphStyle, pt 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(da *DrawArea, sty GlyphStyle, pt Point)
DrawGlyph implements the Glyph interface.
type DataRanger ¶
type DataRanger interface { // DataRange returns the range of X and Y values. DataRange() (xmin, xmax, ymin, ymax float64) }
DataRanger wraps the DataRange method.
type DrawArea ¶
A DrawArea is a vector graphics canvas along with an associated Rect defining a section of the canvas to which drawing should take place.
func MakeDrawArea ¶
MakeDrawArea returns a new DrawArea for a canvas with a Size method.
func MakeDrawAreaSize ¶
MakeDrawAreaSize returns a new DrawArea of the given size for a canvas.
func (*DrawArea) ClipLinesX ¶
ClipLineX returns a slice of lines that represent the given line clipped in the X direction.
func (*DrawArea) ClipLinesXY ¶
ClipLineXY returns a slice of lines that represent the given line clipped in both X and Y directions.
func (*DrawArea) ClipLinesY ¶
ClipLineY returns a slice of lines that represent the given line clipped in the Y direction.
func (*DrawArea) ClipPolygonX ¶
ClipPolygonX returns a slice of lines that represent the given polygon clipped in the X direction.
func (*DrawArea) ClipPolygonXY ¶
ClipPolygonXY returns a slice of lines that represent the given polygon clipped in both X and Y directions.
func (*DrawArea) ClipPolygonY ¶
ClipPolygonY returns a slice of lines that represent the given polygon clipped in the Y direction.
func (*DrawArea) DrawGlyph ¶
func (da *DrawArea) DrawGlyph(sty GlyphStyle, pt Point)
DrawGlyph draws the given glyph to the draw area. If the point is not within the DrawArea or the sty.Shape is nil then nothing is drawn.
func (*DrawArea) DrawGlyphNoClip ¶
func (da *DrawArea) DrawGlyphNoClip(sty GlyphStyle, pt Point)
DrawGlyphNoClip draws the given glyph to the draw area. If the sty.Shape is nil then nothing is drawn.
func (*DrawArea) FillPolygon ¶
FillPolygon fills a polygon with the given color.
func (*DrawArea) FillText ¶
FillText fills lines of text in the draw area. The text is offset by its width times xalign and its height times yalign. x and y give the bottom left corner of the text befor e it is offset.
func (*DrawArea) SetLineStyle ¶
SetLineStyle sets the current line style
func (*DrawArea) StrokeLine2 ¶
StrokeLine2 draws a line between two points in the given DrawArea.
func (*DrawArea) StrokeLines ¶
StrokeLines draws a line connecting a set of points in the given DrawArea.
type GlyphBox ¶
type GlyphBox struct {
// The glyph location in normalized coordinates.
X, Y float64
// Rect is the offset of the glyph's minimum drawing
// point relative to the glyph location and its size.
Rect
}
A GlyphBox describes the location of a glyph and the offset/size of its bounding box.
If the Rect.Size.X is non-positive (<= 0) then the GlyphBox is ignored when computing the horizontal padding, and likewise with Rect.Size.Y and the vertical padding.
type GlyphBoxer ¶
GlyphBoxer wraps the GlyphBoxes method. It should be implemented by things that meet the Plotter interface that draw glyphs so that their glyphs are not clipped if drawn near the edge of the DrawArea.
When computing padding, the plot ignores GlyphBoxes as follows: If the Size.X > 0 and the X value is not in range of the X axis then the box is ignored. If Size.Y > 0 and the Y value is not in range of the Y axis then the box is ignored.
Also, GlyphBoxes with Size.X <= 0 are ignored when computing horizontal padding and GlyphBoxes with Size.Y <= 0 are ignored when computing vertical padding. This is useful for things like box plots and bar charts where the boxes and bars are considered to be glyphs in the X direction (and thus need padding), but may be clipped in the Y direction (and do not need padding).
type GlyphDrawer ¶
type GlyphDrawer interface { // DrawGlyph draws the glyph at the given // point, with the given color and radius. DrawGlyph(*DrawArea, GlyphStyle, 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) Rect ¶
func (g GlyphStyle) Rect() Rect
Rect returns the rectangle surrounding this glyph, assuming that it is drawn centered at 0,0
type Legend ¶
type Legend struct { // TextStyle is the style given to the legend // entry texts. TextStyle // Padding is the amount of padding to add // betweeneach entry of the legend. If Padding // is zero then entries are spaced based on the // font size. Padding vg.Length // Top and Left specify the location of the legend. // If Top is true the legend is located along the top // edge of the plot, otherwise it is located along // the bottom edge. If Left is true then the legend // is located along the left edge of the plot, and the // text is positioned after the icons, otherwise it is // located along the right edge and the text is // positioned before the icons. Top, Left bool // XOffs and YOffs are added to the legend's // final position. XOffs, YOffs vg.Length // ThumbnailWidth is the width of legend thumbnails. ThumbnailWidth vg.Length // contains filtered or unexported fields }
A Legend gives a description of the meaning of different data elements of the plot. Each legend entry has a name and a thumbnail, where the thumbnail shows a small sample of the display style of the corresponding data.
func (*Legend) Add ¶
func (l *Legend) Add(name string, thumbs ...Thumbnailer)
Add adds an entry to the legend with the given name. The entry's thumbnail is drawn as the composite of all of the thumbnails.
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 Plot ¶
type Plot struct { Title struct { // Text is the text of the plot title. If // Text is the empty string then the plot // will not have a title. Text string // Padding is the amount of padding // between the bottom of the title and // the top of the plot. Padding vg.Length TextStyle } // BackgroundColor is the background color of the plot. // The default is White. BackgroundColor color.Color // X and Y are the horizontal and vertical axes // of the plot respectively. X, Y Axis // Legend is the plot's legend. Legend Legend // contains filtered or unexported fields }
Plot is the basic type representing a plot.
func (*Plot) Add ¶
Add adds a Plotters to the plot.
If the plotters implements DataRanger then the minimum and maximum values of the X and Y axes are changed if necessary to fit the range of the data.
When drawing the plot, Plotters are drawn in the order in which they were added to the plot.
func (*Plot) DataDrawArea ¶
DataDrawArea returns a new DrawArea that is the subset of the given draw area into which the plot data will be drawn.
func (*Plot) Draw ¶
Draw draws a plot to a DrawArea.
Plotters are drawn in the order in which they were added to the plot. Plotters that implement the GlyphBoxer interface will have their GlyphBoxes taken into account when padding the plot so that none of their glyphs are clipped.
func (*Plot) DrawGlyphBoxes ¶
DrawGlyphBoxes draws red outlines around the plot's GlyphBoxes. This is intended for debugging.
func (*Plot) GlyphBoxes ¶
GlyphBoxes returns the GlyphBoxes for all plot data that meet the GlyphBoxer interface.
func (*Plot) HideX ¶
func (p *Plot) HideX()
HideX configures the X axis so that it will not be drawn.
func (*Plot) HideY ¶
func (p *Plot) HideY()
HideY configures the Y axis so that it will not be drawn.
func (*Plot) NominalX ¶
NominalX configures the plot to have a nominal X axis—an X axis with names instead of numbers. The X location corresponding to each name are the integers, e.g., the x value 0 is centered above the first name and 1 is above the second name, etc. Labels for x values that do not end up in range of the X axis will not have tick marks.
type Plotter ¶
Plotter is an interface that wraps the Plot method. Some standard implementations of Plotter can be found in the code.google.com/p/plotinum/plotter package, documented here: http://go.pkgdoc.org/code.google.com/p/plotinum/plotter
type Point ¶
A Point is a location in 2d space.
Points are used for drawing, not for data. For data, see the XYer interface.
type PyramidGlyph ¶
type PyramidGlyph struct{}
PyramidGlyph is a glyph that draws a filled triangle.
func (PyramidGlyph) DrawGlyph ¶
func (PyramidGlyph) DrawGlyph(da *DrawArea, sty GlyphStyle, pt Point)
DrawGlyph implements the Glyph interface.
type Rect ¶
type Rect struct {
Min, Size Point
}
A Rect represents a Rectangular region of 2d space.
type SquareGlyph ¶
type SquareGlyph struct{}
SquareGlyph is a glyph that draws the outline of a square.
func (SquareGlyph) DrawGlyph ¶
func (SquareGlyph) DrawGlyph(da *DrawArea, sty GlyphStyle, pt Point)
DrawGlyph implements the Glyph interface.
type TextStyle ¶
type TextStyle struct { // Color is the text color. Color color.Color // Font is the font description. Font vg.Font }
TextStyle describes what text will look like.
type Thumbnailer ¶
type Thumbnailer interface { // Thumbnail draws an thumbnail representing // a legend entry. The thumbnail will usually show // a smaller representation of the style used // to plot the corresponding data. Thumbnail(da *DrawArea) }
Thumbnailer wraps the Thumbnail method, which draws the small image in a legend representing the style of data.
type Tick ¶
type Tick struct { // Value is the data value marked by this Tick. Value float64 // Label is the text to display at the tick mark. // If Label is an empty string then this is a minor // tick mark. Label string }
A Tick is a single tick mark on an axis.
func DefaultTicks ¶
DefaultTicks is suitable for the Tick.Marker field of an Axis, it returns a resonable default set of tick marks.
type TriangleGlyph ¶
type TriangleGlyph struct{}
TriangleGlyph is a glyph that draws the outline of a triangle.
func (TriangleGlyph) DrawGlyph ¶
func (TriangleGlyph) DrawGlyph(da *DrawArea, sty GlyphStyle, pt Point)
DrawGlyph implements the Glyph interface.