geom

package
v0.0.0-...-42b5f6e Latest Latest
Warning

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

Go to latest
Published: Dec 22, 2020 License: BSD-3-Clause Imports: 11 Imported by: 0

Documentation

Overview

Package geom provides basic geometric objects to display data in a plot.

The overall concept is loosely based in ggplot2's geoms. Each geom has some required aesthetics, typically an (x,y) coordinate and may provide the ability to optionally map other aestetics like line or fill color or size.

The required aestethics are a field like XY in the various geoms while the optional aestehtics are mapped through optional (Discrete)Aesthetics functions which provide a (discrete) value for a data point.

The different geoms have singular names like Rectangle or Point even if they may draw several rectangles or points to match the naming in ggplot2.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CanonicRectangle

func CanonicRectangle(r vg.Rectangle) vg.Rectangle

CanonicRectangle returns the canonical form of r, i.e. its Min points having smaller coordinates than its Max point.

func CopyAesthetics

func CopyAesthetics(dst, src interface{}, index func(int) int)

CopyAesthetics copies the non-nil aesthetics from src to dst. The destination must be a pointer to a struct, the source may be a struct or a pointer to one. The index function can be used to reindex the aestetics functions between src and dst.

func UpdateAestheticsRanges

func UpdateAestheticsRanges(dr *facet.DataRanges, n int,
	alpha Aesthetic,
	color Aesthetic,
	fill Aesthetic,
	shape DiscreteAesthetic,
	size Aesthetic,
	stroke DiscreteAesthetic)

UpdateAestheticsRanges is a helper to update the data ranges dr based on the non-nil aesthetics functions evaluated for all n data points.

Types

type Aesthetic

type Aesthetic func(i int) float64

Aestetic is a function mapping a certain data point to an aestehtic.

type Bar

type Bar struct {
	XY plotter.XYer

	Alpha  Aesthetic
	Color  Aesthetic
	Fill   Aesthetic
	Size   Aesthetic
	Stroke DiscreteAesthetic

	Position string  // "stack" (default), "dogde" or "fill"
	GGap     float64 // Gap between groups as fraction of sample distance.
	BGap     float64 // Gap inside a group as fraction of sample distance.

	Default BoxStyle
}

Bar draws rectangles standing/hanging from y=0.

func (Bar) DataRange

func (b Bar) DataRange() facet.DataRanges

func (Bar) Draw

func (b Bar) Draw(p *facet.Panel)

Draw implements facet.Geom.Draw.

type BarGroups

type BarGroups struct {
	Group    map[float64][]int
	Position string  // "dodge" or something else
	Ggap     float64 // between groups
	Dgap     float64 // between bars inside a group if dodged
	Same     bool    // Same width for all bars?
	// contains filtered or unexported fields
}

func NewBarGroups

func NewBarGroups(position string, groupGap, barGap float64, sameWidth bool) *BarGroups

NewBarGroups creates a BarGroups for dodged bar positioning with sensible gaps between bars.

func (*BarGroups) MaxGroupSize

func (bg *BarGroups) MaxGroupSize() int

MaxGroupSize determines the maximum number of values recorded per x-values.

func (*BarGroups) MinDelta

func (bg *BarGroups) MinDelta() float64

MinDelta returns the smallest difference between recorded x-values.

func (*BarGroups) Record

func (bg *BarGroups) Record(x float64, i int)

Record the point i with the given x coordinate.

func (*BarGroups) Width

func (bg *BarGroups) Width(x float64, i int) (center float64, halfwidth float64)

Bar returns the center and the halfwidth for the bar i at x.

func (*BarGroups) XRange

func (bg *BarGroups) XRange() (xmin float64, xmax float64)

func (*BarGroups) Xs

func (bg *BarGroups) Xs() []float64

Xs returns the sorted list of recorded x values.

type BoxStyle

type BoxStyle struct {
	Fill   color.Color
	Border draw.LineStyle
}

BoxStyle combines a line style (for the border with a fill color for the interior of a geom. TODO: add the rest like size, symbol too?

type Boxplot

type Boxplot struct {
	Boxplot data.Boxplotter

	Alpha  Aesthetic
	Color  Aesthetic
	Fill   Aesthetic
	Shape  DiscreteAesthetic
	Size   Aesthetic
	Stroke DiscreteAesthetic

	Position     string
	Default      BoxStyle
	DefaultPoint draw.GlyphStyle
	GGap, BGap   float64
}

Boxplot draws rectangles. The coordinates are the outside coordinates, i.e. if the border is drawn for the rectangle then this border is drawn inside the rectangle given by the coordinates.

func (Boxplot) DataRange

func (b Boxplot) DataRange() facet.DataRanges

func (Boxplot) Draw

func (b Boxplot) Draw(panel *facet.Panel)

Draw implements facet.Geom.Draw.

type DiscreteAesthetic

type DiscreteAesthetic func(i int) int

DiscreteAestetic is a function mapping a certain data point to a discrete aesthetic like Shape or Stroke.

type HLine

type HLine struct {
	Y plotter.Valuer

	Alpha  Aesthetic
	Color  Aesthetic
	Size   Aesthetic
	Stroke DiscreteAesthetic

	Default draw.LineStyle
}

HLine draws horizontal reference (or rule) lines at the given Y values.

func (HLine) DataRange

func (h HLine) DataRange() facet.DataRanges

func (HLine) Draw

func (h HLine) Draw(panel *facet.Panel)

type Line

type Line struct {
	XY plotter.XYer

	Alpha  Aesthetic
	Color  Aesthetic
	Size   Aesthetic
	Stroke DiscreteAesthetic

	Default draw.LineStyle
}

Line connects the given points in order of the x values by straight line segments. The aestetics map the individual line segments based on their first point.

(To draw them in data order see Path.)

func (Line) DataRange

func (l Line) DataRange() facet.DataRanges

func (Line) Draw

func (l Line) Draw(panel *facet.Panel)

type Path

type Path struct {
	XY plotter.XYer

	Alpha  Aesthetic
	Color  Aesthetic
	Size   Aesthetic
	Stroke DiscreteAesthetic

	Default draw.LineStyle
}

Path connects the given points in data order through straight line segments. The aestetics map the individual line segments based on their first point.

(To draw them in order of x values see Line.)

func (Path) DataRange

func (p Path) DataRange() facet.DataRanges

func (Path) Draw

func (p Path) Draw(panel *facet.Panel)

type Point

type Point struct {
	XY plotter.XYer

	Alpha Aesthetic
	Color Aesthetic
	Shape DiscreteAesthetic
	Size  Aesthetic

	Default draw.GlyphStyle
}

Point draws points / symbols.

func (Point) DataRange

func (p Point) DataRange() facet.DataRanges

func (Point) Draw

func (p Point) Draw(panel *facet.Panel)

type Rectangle

type Rectangle struct {
	XYUV data.XYUVer

	Alpha  Aesthetic
	Color  Aesthetic
	Fill   Aesthetic
	Size   Aesthetic
	Stroke DiscreteAesthetic

	Default BoxStyle
}

Rectangle draws rectangles. The coordinates are the outside coordinates, i.e. if the border is drawn for the rectangle then this border is drawn inside the rectangle given by the coordinates.

func (Rectangle) DataRange

func (r Rectangle) DataRange() facet.DataRanges

func (Rectangle) Draw

func (r Rectangle) Draw(panel *facet.Panel)

Draw implements facet.Geom.Draw.

type Segment

type Segment struct {
	XYUV data.XYUVer

	Alpha  Aesthetic
	Color  Aesthetic
	Size   Aesthetic
	Stroke DiscreteAesthetic

	Default draw.LineStyle
}

Segment draws line segments between two points (X,Y) and (U,V).

func (Segment) DataRange

func (s Segment) DataRange() facet.DataRanges

func (Segment) Draw

func (s Segment) Draw(panel *facet.Panel)

type Step

type Step struct {
	XY plotter.XYer

	Alpha  Aesthetic
	Color  Aesthetic
	Size   Aesthetic
	Stroke DiscreteAesthetic

	// Vertical changes the step to "vertical then horizontal".
	Vertical bool

	Default draw.LineStyle
}

Step produces a stairstep plot of the given data.

func (Step) DataRange

func (s Step) DataRange() facet.DataRanges

func (Step) Draw

func (s Step) Draw(panel *facet.Panel)

type Text

type Text struct {
	XYText data.XYTexter

	Alpha Aesthetic
	Color Aesthetic
	Size  Aesthetic

	Default draw.TextStyle
}

Text draws points / symbols.

func (Text) DataRange

func (t Text) DataRange() facet.DataRanges

func (Text) Draw

func (t Text) Draw(panel *facet.Panel)

type VLine

type VLine struct {
	X plotter.Valuer

	Alpha  Aesthetic
	Color  Aesthetic
	Size   Aesthetic
	Stroke DiscreteAesthetic

	Default draw.LineStyle
}

VLine draws vertical reference (or rule) lines at the given X values.

func (VLine) DataRange

func (v VLine) DataRange() facet.DataRanges

func (VLine) Draw

func (v VLine) Draw(panel *facet.Panel)

Jump to

Keyboard shortcuts

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