Documentation
¶
Index ¶
- Variables
- func CheckFloats(fs ...float64) error
- func CheckNaNs(fs ...float64) bool
- func DrawBox(pc *paint.Painter, pos math32.Vector2, size float32)
- func DrawCircle(pc *paint.Painter, pos math32.Vector2, size float32)
- func DrawCross(pc *paint.Painter, pos math32.Vector2, size float32)
- func DrawPlus(pc *paint.Painter, pos math32.Vector2, size float32)
- func DrawPyramid(pc *paint.Painter, pos math32.Vector2, size float32)
- func DrawRing(pc *paint.Painter, pos math32.Vector2, size float32)
- func DrawSquare(pc *paint.Painter, pos math32.Vector2, size float32)
- func DrawTriangle(pc *paint.Painter, pos math32.Vector2, size float32)
- func PlotX(plt *Plot, data Valuer) []float32
- func PlotY(plt *Plot, data Valuer) []float32
- func PlotYR(plt *Plot, data Valuer) []float32
- func Range(data Valuer, rng *minmax.F64)
- func RangeClamp(data Valuer, axisRng *minmax.F64, styleRng *minmax.Range64)
- func RegisterPlotter(name, doc string, required, optional []Roles, ...)
- func SetFirstStyler(obj any, f func(s *Style))
- func SetStyler(obj any, st ...func(s *Style))
- func Styler(obj any, f func(s *Style))
- func UnixTimeIn(loc *time.Location) func(t float64) time.Time
- type Axis
- type AxisScales
- func (i AxisScales) Desc() string
- func (i AxisScales) Int64() int64
- func (i AxisScales) MarshalText() ([]byte, error)
- func (i *AxisScales) SetInt64(in int64)
- func (i *AxisScales) SetString(s string) error
- func (i AxisScales) String() string
- func (i *AxisScales) UnmarshalText(text []byte) error
- func (i AxisScales) Values() []enums.Enum
- type AxisStyle
- func (ax *AxisStyle) Defaults()
- func (t *AxisStyle) SetLine(v LineStyle) *AxisStyle
- func (t *AxisStyle) SetNTicks(v int) *AxisStyle
- func (t *AxisStyle) SetOn(v bool) *AxisStyle
- func (t *AxisStyle) SetPadding(v units.Value) *AxisStyle
- func (t *AxisStyle) SetScale(v AxisScales) *AxisStyle
- func (t *AxisStyle) SetText(v TextStyle) *AxisStyle
- func (t *AxisStyle) SetTickLength(v units.Value) *AxisStyle
- func (t *AxisStyle) SetTickLine(v LineStyle) *AxisStyle
- func (t *AxisStyle) SetTickText(v TextStyle) *AxisStyle
- type ConstantTicks
- type Data
- type DefaultOffOn
- func (i DefaultOffOn) Desc() string
- func (i DefaultOffOn) Int64() int64
- func (i DefaultOffOn) MarshalText() ([]byte, error)
- func (i *DefaultOffOn) SetInt64(in int64)
- func (i *DefaultOffOn) SetString(s string) error
- func (i DefaultOffOn) String() string
- func (i *DefaultOffOn) UnmarshalText(text []byte) error
- func (i DefaultOffOn) Values() []enums.Enum
- type DefaultTicks
- type InvertedScale
- type Labels
- type Legend
- type LegendEntry
- type LegendPosition
- type LegendStyle
- func (ls *LegendStyle) Defaults()
- func (t *LegendStyle) SetColumn(v string) *LegendStyle
- func (t *LegendStyle) SetFill(v image.Image) *LegendStyle
- func (t *LegendStyle) SetPosition(v LegendPosition) *LegendStyle
- func (t *LegendStyle) SetText(v TextStyle) *LegendStyle
- func (t *LegendStyle) SetThumbnailWidth(v units.Value) *LegendStyle
- type LineStyle
- func (ls *LineStyle) Defaults()
- func (ls *LineStyle) Draw(pt *Plot, start, end math32.Vector2) bool
- func (ls *LineStyle) HasFill() bool
- func (t *LineStyle) SetColor(v image.Image) *LineStyle
- func (t *LineStyle) SetDashes(v ...float32) *LineStyle
- func (t *LineStyle) SetFill(v image.Image) *LineStyle
- func (t *LineStyle) SetNegativeX(v bool) *LineStyle
- func (t *LineStyle) SetOn(v DefaultOffOn) *LineStyle
- func (t *LineStyle) SetStep(v StepKind) *LineStyle
- func (ls *LineStyle) SetStroke(pt *Plot) bool
- func (t *LineStyle) SetWidth(v units.Value) *LineStyle
- func (ls *LineStyle) SpacedColor(idx int)
- func (ls *LineStyle) SpacedFill(idx int)
- type LinearScale
- type LogScale
- type LogTicks
- type Normalizer
- type PanZoom
- type Plot
- func (pt *Plot) Add(ps ...Plotter)
- func (pt *Plot) ClosestDataToPixel(px, py int) (plt Plotter, plotterIndex, pointIndex int, dist float32, pixel math32.Vector2, ...)
- func (pt *Plot) CurBounds() image.Rectangle
- func (pt *Plot) Defaults()
- func (pt *Plot) Draw(pc *paint.Painter) *paint.Painter
- func (pt *Plot) HideAxes()
- func (pt *Plot) HideX()
- func (pt *Plot) HideY()
- func (pt *Plot) HideYR()
- func (pt *Plot) NominalX(names ...string)
- func (pt *Plot) NominalY(names ...string)
- func (pt *Plot) PX(v float64) float32
- func (pt *Plot) PY(v float64) float32
- func (pt *Plot) PYR(v float64) float32
- func (pt *Plot) PushBounds(tb image.Rectangle)
- func (pt *Plot) RenderImage() image.Image
- func (pt *Plot) RenderSVG() []byte
- func (pt *Plot) SaveImage(fname string) error
- func (pt *Plot) SaveSVG(fname string) error
- func (pt *Plot) SetSize(sz image.Point)
- func (pt *Plot) UnitContext() *units.Context
- func (pt *Plot) UpdateRange()
- type PlotStyle
- func (ps *PlotStyle) Defaults()
- func (t *PlotStyle) SetAxis(v AxisStyle) *PlotStyle
- func (t *PlotStyle) SetBackground(v image.Image) *PlotStyle
- func (t *PlotStyle) SetBarWidth(v float64) *PlotStyle
- func (ps *PlotStyle) SetElementStyle(es *Style)
- func (t *PlotStyle) SetLabelSize(v units.Value) *PlotStyle
- func (t *PlotStyle) SetLegend(v LegendStyle) *PlotStyle
- func (t *PlotStyle) SetLineWidth(v units.Value) *PlotStyle
- func (t *PlotStyle) SetLinesOn(v DefaultOffOn) *PlotStyle
- func (t *PlotStyle) SetPointSize(v units.Value) *PlotStyle
- func (t *PlotStyle) SetPointsOn(v DefaultOffOn) *PlotStyle
- func (t *PlotStyle) SetScale(v float32) *PlotStyle
- func (t *PlotStyle) SetShowErrors(v bool) *PlotStyle
- func (t *PlotStyle) SetTitle(v string) *PlotStyle
- func (t *PlotStyle) SetTitleStyle(v TextStyle) *PlotStyle
- func (t *PlotStyle) SetXAxis(v XAxisStyle) *PlotStyle
- func (t *PlotStyle) SetYAxisLabel(v string) *PlotStyle
- type Plotter
- type PlotterName
- type PlotterType
- type PointStyle
- func (ps *PointStyle) Defaults()
- func (ps *PointStyle) DrawShape(pc *paint.Painter, pos math32.Vector2)
- func (ps *PointStyle) IsOn(pt *Plot) bool
- func (t *PointStyle) SetColor(v image.Image) *PointStyle
- func (t *PointStyle) SetFill(v image.Image) *PointStyle
- func (t *PointStyle) SetOn(v DefaultOffOn) *PointStyle
- func (t *PointStyle) SetShape(v Shapes) *PointStyle
- func (t *PointStyle) SetSize(v units.Value) *PointStyle
- func (ps *PointStyle) SetStroke(pt *Plot) bool
- func (t *PointStyle) SetWidth(v units.Value) *PointStyle
- func (ps *PointStyle) SpacedColor(idx int)
- type Roles
- type Shapes
- func (i Shapes) Desc() string
- func (i Shapes) Int64() int64
- func (i Shapes) MarshalText() ([]byte, error)
- func (i *Shapes) SetInt64(in int64)
- func (i *Shapes) SetString(s string) error
- func (i Shapes) String() string
- func (i *Shapes) UnmarshalText(text []byte) error
- func (i Shapes) Values() []enums.Enum
- type StepKind
- func (i StepKind) Desc() string
- func (i StepKind) Int64() int64
- func (i StepKind) MarshalText() ([]byte, error)
- func (i *StepKind) SetInt64(in int64)
- func (i *StepKind) SetString(s string) error
- func (i StepKind) String() string
- func (i *StepKind) UnmarshalText(text []byte) error
- func (i StepKind) Values() []enums.Enum
- type Style
- func (st *Style) Defaults()
- func (t *Style) SetGroup(v string) *Style
- func (t *Style) SetLabel(v string) *Style
- func (t *Style) SetLabelSkip(v int) *Style
- func (t *Style) SetLine(v LineStyle) *Style
- func (t *Style) SetNTicks(v int) *Style
- func (t *Style) SetNoLegend(v bool) *Style
- func (t *Style) SetOn(v bool) *Style
- func (t *Style) SetPlot(v PlotStyle) *Style
- func (t *Style) SetPlotter(v PlotterName) *Style
- func (t *Style) SetPoint(v PointStyle) *Style
- func (t *Style) SetRange(v minmax.Range64) *Style
- func (t *Style) SetRightY(v bool) *Style
- func (t *Style) SetRole(v Roles) *Style
- func (t *Style) SetText(v TextStyle) *Style
- func (t *Style) SetWidth(v WidthStyle) *Style
- type Stylers
- type Text
- type TextStyle
- func (ts *TextStyle) Defaults()
- func (t *TextStyle) SetAlign(v styles.Aligns) *TextStyle
- func (t *TextStyle) SetColor(v image.Image) *TextStyle
- func (t *TextStyle) SetFamily(v rich.Family) *TextStyle
- func (t *TextStyle) SetOffset(v units.XY) *TextStyle
- func (t *TextStyle) SetPadding(v units.Value) *TextStyle
- func (t *TextStyle) SetRotation(v float32) *TextStyle
- func (t *TextStyle) SetSize(v units.Value) *TextStyle
- type Thumbnailer
- type Tick
- type Ticker
- type TimeTicks
- type Valuer
- type Values
- type WidthStyle
- type XAxisStyle
Constants ¶
This section is empty.
Variables ¶
var ( ErrInfinity = errors.New("plotter: infinite data point") ErrNoData = errors.New("plotter: no data points") )
var DefaultFontFamily = rich.SansSerif
DefaultFontFamily specifies a default font family for plotting. if not set, the standard Cogent Core default font is used.
var Plotters = map[string]PlotterType{}
Plotters is the registry of Plotter types.
var UTCUnixTime = UnixTimeIn(time.UTC)
UTCUnixTime is the default time conversion for TimeTicks.
Functions ¶
func CheckFloats ¶
CheckFloats returns an error if any of the arguments are Infinity. or if there are no non-NaN data points available for plotting.
func PlotYR ¶ added in v0.1.1
PlotYR returns plot pixel YR right axis coordinate values for given data.
func RangeClamp ¶
RangeClamp updates the given axis Min, Max range values based on the range of values in the given Data, and the given style range.
func RegisterPlotter ¶
func RegisterPlotter(name, doc string, required, optional []Roles, newFun func(plt *Plot, data Data) Plotter)
RegisterPlotter registers a plotter type.
func SetFirstStyler ¶
SetFirstStyler sets the Styler function into given object's metadata, only if there are no other stylers present. This is important for cases where code may be run multiple times on the same object, and you don't want to add multiple redundant style functions (and [plotcore.Editor] is being used).
func SetStyler ¶
SetStyler sets the Stylers function(s) into given object's metadata. This overwrites any existing styler functions. The [plotcore.Editor] depends on adding a styler function on top of any existing ones, so it is better to use [SetFirstStyle] if that is being used.
Types ¶
type Axis ¶
type Axis struct {
// Range has the Min, Max range of values for the axis (in raw data units.)
Range minmax.F64
// specifies which axis this is: X, Y or Z.
Axis math32.Dims
// For a Y axis, this puts the axis on the right (i.e., the second Y axis).
RightY bool
// Label for the axis.
Label Text
// Style has the style parameters for the Axis.
Style AxisStyle
// TickText is used for rendering the tick text labels.
TickText Text
// Ticker generates the tick marks. Any tick marks
// returned by the Marker function that are not in
// range of the axis are not drawn.
Ticker Ticker
// 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 Normalizer
// AutoRescale enables an axis to automatically adapt its minimum
// and maximum boundaries, according to its underlying Ticker.
AutoRescale bool
// contains filtered or unexported fields
}
Axis represents either a horizontal or vertical axis of a plot. This is the "internal" data structure and should not be used for styling.
func (*Axis) Defaults ¶
Sets Defaults, range is (∞, ∞), and thus any finite value is less than Min and greater than Max.
func (*Axis) Norm ¶
Norm returns the value of x, given in the data coordinate system, normalized to its distance as a fraction of the range of this axis. For example, if x is a.Min then the return value is 0, and if x is a.Max then the return value is 1.
func (*Axis) SanitizeRange ¶
func (ax *Axis) SanitizeRange()
SanitizeRange ensures that the range of the axis makes sense.
type AxisScales ¶
type AxisScales int32 //enums:enum
AxisScales are the scaling options for how values are distributed along an axis: Linear, Log, etc.
const ( // Linear is a linear axis scale. Linear AxisScales = iota // Log is a Logarithmic axis scale. Log // InverseLinear is an inverted linear axis scale. InverseLinear // InverseLog is an inverted log axis scale. InverseLog )
const AxisScalesN AxisScales = 4
AxisScalesN is the highest valid value for type AxisScales, plus one.
func AxisScalesValues ¶
func AxisScalesValues() []AxisScales
AxisScalesValues returns all possible values for the type AxisScales.
func (AxisScales) Desc ¶
func (i AxisScales) Desc() string
Desc returns the description of the AxisScales value.
func (AxisScales) Int64 ¶
func (i AxisScales) Int64() int64
Int64 returns the AxisScales value as an int64.
func (AxisScales) MarshalText ¶
func (i AxisScales) MarshalText() ([]byte, error)
MarshalText implements the encoding.TextMarshaler interface.
func (*AxisScales) SetInt64 ¶
func (i *AxisScales) SetInt64(in int64)
SetInt64 sets the AxisScales value from an int64.
func (*AxisScales) SetString ¶
func (i *AxisScales) SetString(s string) error
SetString sets the AxisScales value from its string representation, and returns an error if the string is invalid.
func (AxisScales) String ¶
func (i AxisScales) String() string
String returns the string representation of this AxisScales value.
func (*AxisScales) UnmarshalText ¶
func (i *AxisScales) UnmarshalText(text []byte) error
UnmarshalText implements the encoding.TextUnmarshaler interface.
func (AxisScales) Values ¶
func (i AxisScales) Values() []enums.Enum
Values returns all possible values for the type AxisScales.
type AxisStyle ¶
type AxisStyle struct {
// On determines whether the axis is rendered.
On bool
// Text has the text style parameters for the text label.
Text TextStyle
// Line has styling properties for the axis line.
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 units.Value
// NTicks is the desired number of ticks (actual likely
// will be different). If < 2 then the axis will not be drawn.
NTicks int
// Scale specifies how values are scaled along the axis:
// Linear, Log, Inverted
Scale AxisScales
// TickText has the text style for rendering tick labels,
// and is shared for actual rendering.
TickText TextStyle
// TickLine has line style for drawing tick lines.
TickLine LineStyle
// TickLength is the length of tick lines.
TickLength units.Value
}
AxisStyle has style properties for the axis.
func (*AxisStyle) SetLine ¶
SetLine sets the [AxisStyle.Line]: Line has styling properties for the axis line.
func (*AxisStyle) SetNTicks ¶
SetNTicks sets the [AxisStyle.NTicks]: NTicks is the desired number of ticks (actual likely will be different). If < 2 then the axis will not be drawn.
func (*AxisStyle) SetOn ¶
SetOn sets the [AxisStyle.On]: On determines whether the axis is rendered.
func (*AxisStyle) SetPadding ¶
SetPadding sets the [AxisStyle.Padding]: 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.
func (*AxisStyle) SetScale ¶
func (t *AxisStyle) SetScale(v AxisScales) *AxisStyle
SetScale sets the [AxisStyle.Scale]: Scale specifies how values are scaled along the axis: Linear, Log, Inverted
func (*AxisStyle) SetText ¶
SetText sets the [AxisStyle.Text]: Text has the text style parameters for the text label.
func (*AxisStyle) SetTickLength ¶
SetTickLength sets the [AxisStyle.TickLength]: TickLength is the length of tick lines.
func (*AxisStyle) SetTickLine ¶
SetTickLine sets the [AxisStyle.TickLine]: TickLine has line style for drawing tick lines.
func (*AxisStyle) SetTickText ¶
SetTickText sets the [AxisStyle.TickText]: TickText has the text style for rendering tick labels, and is shared for actual rendering.
type ConstantTicks ¶
type ConstantTicks []Tick
ConstantTicks is suitable for the Ticker field of an Axis. This function returns the given set of ticks.
type Data ¶
Data is a map of Roles and Data for that Role, providing the primary way of passing data to a Plotter
func DataOrValuer ¶
DataOrValuer processes the given argument which can be either a Data or a Valuer. If the latter, it is returned as a Data with the given Role. This is used for New Plotter methods that can take the default required Valuer, or a Data with roles explicitly defined. If the arg is neither, an error is returned.
func (Data) CheckLengths ¶
CheckLengths checks that all the data elements have the same length. Logs and returns an error if not.
type DefaultOffOn ¶
type DefaultOffOn int32 //enums:enum
DefaultOffOn specifies whether to use the default value for a bool option, or to override the default and set Off or On.
const ( // Default means use the default value. Default DefaultOffOn = iota // Off means to override the default and turn Off. Off // On means to override the default and turn On. On )
const DefaultOffOnN DefaultOffOn = 3
DefaultOffOnN is the highest valid value for type DefaultOffOn, plus one.
func DefaultOffOnValues ¶
func DefaultOffOnValues() []DefaultOffOn
DefaultOffOnValues returns all possible values for the type DefaultOffOn.
func (DefaultOffOn) Desc ¶
func (i DefaultOffOn) Desc() string
Desc returns the description of the DefaultOffOn value.
func (DefaultOffOn) Int64 ¶
func (i DefaultOffOn) Int64() int64
Int64 returns the DefaultOffOn value as an int64.
func (DefaultOffOn) MarshalText ¶
func (i DefaultOffOn) MarshalText() ([]byte, error)
MarshalText implements the encoding.TextMarshaler interface.
func (*DefaultOffOn) SetInt64 ¶
func (i *DefaultOffOn) SetInt64(in int64)
SetInt64 sets the DefaultOffOn value from an int64.
func (*DefaultOffOn) SetString ¶
func (i *DefaultOffOn) SetString(s string) error
SetString sets the DefaultOffOn value from its string representation, and returns an error if the string is invalid.
func (DefaultOffOn) String ¶
func (i DefaultOffOn) String() string
String returns the string representation of this DefaultOffOn value.
func (*DefaultOffOn) UnmarshalText ¶
func (i *DefaultOffOn) UnmarshalText(text []byte) error
UnmarshalText implements the encoding.TextUnmarshaler interface.
func (DefaultOffOn) Values ¶
func (i DefaultOffOn) Values() []enums.Enum
Values returns all possible values for the type DefaultOffOn.
type DefaultTicks ¶
type DefaultTicks struct{}
DefaultTicks is suitable for the Ticker field of an Axis, it returns a reasonable default set of tick marks.
type InvertedScale ¶
type InvertedScale struct{ Normalizer }
InvertedScale can be used as the value of an Axis.Scale function to invert the axis using any Normalizer.
func (InvertedScale) Normalize ¶
func (is InvertedScale) Normalize(min, max, x float64) float64
Normalize returns a normalized [0, 1] value for the position of x.
type Labels ¶
type Labels []string
Labels provides a minimal implementation of the Data interface using a slice of string. It always returns 0 for Float1D.
type Legend ¶
type Legend struct {
// Style has the legend styling parameters.
Style LegendStyle
// Entries are all of the LegendEntries described by this legend.
Entries []LegendEntry
}
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 (lg *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.
func (*Legend) LegendForPlotter ¶
LegendForPlotter returns the legend Text for given plotter, if it exists as a Thumbnailer in the legend entries. Otherwise returns empty string.
type LegendEntry ¶
type LegendEntry struct {
// text is the text associated with this entry.
Text string
// thumbs is a slice of all of the thumbnails styles
Thumbs []Thumbnailer
}
A LegendEntry represents a single line of a legend, it has a name and an icon.
type LegendPosition ¶
type LegendPosition struct {
// Top and Left specify the location of the legend.
Top, Left bool
// XOffs and YOffs are added to the legend's final position,
// relative to the relevant anchor position
XOffs, YOffs units.Value
}
LegendPosition specifies where to put the legend
func (*LegendPosition) Defaults ¶
func (lg *LegendPosition) Defaults()
type LegendStyle ¶
type LegendStyle struct {
// Column is for table-based plotting, specifying the column with legend values.
Column string
// Text is the style given to the legend entry texts.
Text TextStyle `display:"add-fields"`
// position of the legend
Position LegendPosition `display:"inline"`
// ThumbnailWidth is the width of legend thumbnails.
ThumbnailWidth units.Value `display:"inline"`
// Fill specifies the background fill color for the legend box,
// if non-nil.
Fill image.Image
}
LegendStyle has the styling properties for the Legend.
func (*LegendStyle) Defaults ¶
func (ls *LegendStyle) Defaults()
func (*LegendStyle) SetColumn ¶
func (t *LegendStyle) SetColumn(v string) *LegendStyle
SetColumn sets the [LegendStyle.Column]: Column is for table-based plotting, specifying the column with legend values.
func (*LegendStyle) SetFill ¶
func (t *LegendStyle) SetFill(v image.Image) *LegendStyle
SetFill sets the [LegendStyle.Fill]: Fill specifies the background fill color for the legend box, if non-nil.
func (*LegendStyle) SetPosition ¶
func (t *LegendStyle) SetPosition(v LegendPosition) *LegendStyle
SetPosition sets the [LegendStyle.Position]: position of the legend
func (*LegendStyle) SetText ¶
func (t *LegendStyle) SetText(v TextStyle) *LegendStyle
SetText sets the [LegendStyle.Text]: Text is the style given to the legend entry texts.
func (*LegendStyle) SetThumbnailWidth ¶
func (t *LegendStyle) SetThumbnailWidth(v units.Value) *LegendStyle
SetThumbnailWidth sets the [LegendStyle.ThumbnailWidth]: ThumbnailWidth is the width of legend thumbnails.
type LineStyle ¶
type LineStyle struct {
// On indicates whether to plot lines.
On DefaultOffOn
// Color is the stroke color image specification.
// Setting to nil turns line off.
Color image.Image
// Width is the line width, with a default of 1 Pt (point).
// Setting to 0 turns line off.
Width units.Value
// Dashes are the dashes of the stroke. Each pair of values specifies
// the amount to paint and then the amount to skip.
Dashes []float32
// Fill is the color to fill solid regions, in a plot-specific
// way (e.g., the area below a Line plot, the bar color).
// Use nil to disable filling.
Fill image.Image
// NegativeX specifies whether to draw lines that connect points with a negative
// X-axis direction; otherwise there is a break in the line.
// default is false, so that repeated series of data across the X axis
// are plotted separately.
NegativeX bool
// Step specifies how to step the line between points.
Step StepKind
}
LineStyle has style properties for drawing lines.
func (*LineStyle) Draw ¶
Draw draws a line between given coordinates, setting the stroke style to current parameters. Returns false if either Width = 0 or Color = nil
func (*LineStyle) SetColor ¶
SetColor sets the [LineStyle.Color]: Color is the stroke color image specification. Setting to nil turns line off.
func (*LineStyle) SetDashes ¶
SetDashes sets the [LineStyle.Dashes]: Dashes are the dashes of the stroke. Each pair of values specifies the amount to paint and then the amount to skip.
func (*LineStyle) SetFill ¶
SetFill sets the [LineStyle.Fill]: Fill is the color to fill solid regions, in a plot-specific way (e.g., the area below a Line plot, the bar color). Use nil to disable filling.
func (*LineStyle) SetNegativeX ¶
SetNegativeX sets the [LineStyle.NegativeX]: NegativeX specifies whether to draw lines that connect points with a negative X-axis direction; otherwise there is a break in the line. default is false, so that repeated series of data across the X axis are plotted separately.
func (*LineStyle) SetOn ¶
func (t *LineStyle) SetOn(v DefaultOffOn) *LineStyle
SetOn sets the [LineStyle.On]: On indicates whether to plot lines.
func (*LineStyle) SetStep ¶
SetStep sets the [LineStyle.Step]: Step specifies how to step the line between points.
func (*LineStyle) SetStroke ¶
SetStroke sets the stroke style in plot paint to current line style. returns false if either the Width = 0 or Color is nil
func (*LineStyle) SetWidth ¶
SetWidth sets the [LineStyle.Width]: Width is the line width, with a default of 1 Pt (point). Setting to 0 turns line off.
func (*LineStyle) SpacedColor ¶
SpacedColor sets the Color to a default spaced color based on index, if it still has the initial OnSurface default.
func (*LineStyle) SpacedFill ¶
SpacedFill sets the Fill to a default spaced color based on index, if it still has the initial nil default.
type LinearScale ¶
type LinearScale struct{}
LinearScale an be used as the value of an Axis.Scale function to set the axis to a standard linear scale.
func (LinearScale) Normalize ¶
func (LinearScale) Normalize(min, max, x float64) float64
Normalize returns the fractional distance of x between min and max.
type LogScale ¶
type LogScale struct{}
LogScale can be used as the value of an Axis.Scale function to set the axis to a log scale.
type LogTicks ¶
type LogTicks struct {
// Prec specifies the precision of tick rendering
// according to the documentation for strconv.FormatFloat.
Prec int
}
LogTicks is suitable for the Ticker field of an Axis, it returns tick marks suitable for a log-scale axis.
type Normalizer ¶
type Normalizer interface {
// Normalize transforms a value x in the data coordinate system to
// the normalized coordinate system.
Normalize(min, max, x float64) float64
}
Normalizer rescales values from the data coordinate system to the normalized coordinate system.
type PanZoom ¶
type PanZoom struct {
// XOffset adds offset to X range (pan).
XOffset float64
// XScale multiplies X range (zoom).
XScale float64
// YOffset adds offset to Y range (pan).
YOffset float64
// YScale multiplies Y range (zoom).
YScale float64
}
PanZoom provides post-styling pan and zoom range manipulation.
type Plot ¶
type Plot struct {
// Title of the plot
Title Text
// Style has the styling properties for the plot.
// All end-user configuration should be put in here,
// rather than modifying other fields directly on the plot.
Style PlotStyle
// standard text style with default options
StandardTextStyle text.Style
// X, Y, YR, and Z are the horizontal, vertical, right vertical, and depth axes
// of the plot respectively. These are the actual compiled
// state data and should not be used for styling: use Style.
X, Y, YR, Z Axis
// Legend is the plot's legend.
Legend Legend
// Plotters are drawn by calling their Plot method after the axes are drawn.
Plotters []Plotter
// PanZoom provides post-styling pan and zoom range factors.
PanZoom PanZoom
// HighlightPlotter is the Plotter to highlight. Used for mouse hovering for example.
// It is the responsibility of the Plotter Plot function to implement highlighting.
HighlightPlotter Plotter
// HighlightIndex is the index of the data point to highlight, for HighlightPlotter.
HighlightIndex int
// TextShaper for shaping text. Can set to a shared external one,
// or else the shared plotShaper is used under a mutex lock during Render.
TextShaper shaped.Shaper
// PaintBox is the bounding box for the plot within the Paint.
// For standalone, it is the size of the image.
PaintBox image.Rectangle
// Current local plot bounding box in image coordinates, for computing
// plotting coordinates.
PlotBox math32.Box2
// Painter is the current painter being used,
// which is only valid during rendering, and is set by Draw function.
// It needs to be exported for different plot types in other packages.
Painter *paint.Painter
// contains filtered or unexported fields
}
Plot is the basic type representing a plot. It renders into its own image.RGBA Pixels image, and can also save a corresponding SVG version.
func NewTablePlot ¶
NewTablePlot returns a new Plot with all configuration based on given table.Table set of columns and associated metadata, which must have Stylers functions set (e.g., [SetStylersTo]) that at least set basic table parameters, including:
- On: Set the main (typically Role = Y) column On to include in plot.
- Role: Set the appropriate Roles role for this column (Y, X, etc).
- Group: Multiple columns used for a given Plotter type must be grouped together with a common name (typically the name of the main Y axis), e.g., for Low, High error bars, Size, Color, etc. If only one On column, then Group can be empty and all other such columns will be grouped.
- Plotter: Determines the type of Plotter element to use, which in turn determines the additional Roles that can be used within a Group.
Returns nil if no valid plot elements were present.
func (*Plot) Add ¶
Add adds Plotter element(s) to the plot. When drawing the plot, Plotters are drawn in the order in which they were added to the plot.
func (*Plot) ClosestDataToPixel ¶
func (pt *Plot) ClosestDataToPixel(px, py int) (plt Plotter, plotterIndex, pointIndex int, dist float32, pixel math32.Vector2, data Data, legend string)
ClosestDataToPixel returns the Plotter data point closest to given pixel point, in the Pixels image.
func (*Plot) Draw ¶
Draw draws the plot to a core paint.Painter, which then can be used with a core render.Renderer to generate an image or SVG document, etc. If painter is nil, then one is created. See Plot.RenderImage and Plot.RenderSVG for convenience methods. Plotters are drawn in the order in which they were added to the plot.
func (*Plot) HideX ¶
func (pt *Plot) HideX()
HideX configures the X axis so that it will not be drawn.
func (*Plot) HideY ¶
func (pt *Plot) HideY()
HideY configures the Y axis so that it will not be drawn.
func (*Plot) HideYR ¶ added in v0.1.1
func (pt *Plot) HideYR()
HideYR configures the YR 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.
func (*Plot) PX ¶
PX returns the X-axis plotting coordinate for given raw data value using the current plot bounding region
func (*Plot) PYR ¶ added in v0.1.1
PYR returns the Y-axis plotting coordinate for given raw data value
func (*Plot) PushBounds ¶ added in v0.1.1
PushBounds returns the current render bounds from Paint
func (*Plot) RenderImage ¶ added in v0.1.1
RenderImage renders the plot to an image and returns it.
func (*Plot) RenderSVG ¶ added in v0.1.1
RenderSVG renders the plot to an SVG document and returns it.
func (*Plot) SaveImage ¶
SaveImage renders the plot to an image and saves it to given filename, using the filename extension to determine the file type.
func (*Plot) SaveSVG ¶ added in v0.1.1
SaveSVG renders the plot to an SVG document and saves it to given filename.
func (*Plot) SetSize ¶ added in v0.1.1
SetSize sets the size of the plot, typically in terms of actual device pixels (dots).
func (*Plot) UnitContext ¶ added in v0.1.1
UnitContext returns the units.Context to use for styling. This includes the scaling factor.
func (*Plot) UpdateRange ¶
func (pt *Plot) UpdateRange()
UpdateRange updates the axis range values based on current Plot values. This first resets the range so any fixed additional range values should be set after this point.
type PlotStyle ¶
type PlotStyle struct {
// Title is the overall title of the plot.
Title string
// TitleStyle is the text styling parameters for the title.
TitleStyle TextStyle
// Background is the background of the plot.
// The default is [colors.Scheme.Surface].
Background image.Image
// Scale multiplies the plot DPI value, to change the overall scale
// of the rendered plot. Larger numbers produce larger scaling.
// Typically use larger numbers when generating plots for inclusion in
// documents or other cases where the overall plot size will be small.
Scale float32 `default:"1,2"`
// Legend has the styling properties for the Legend.
Legend LegendStyle `display:"add-fields"`
// Axis has the styling properties for the Axis associated with this Data.
Axis AxisStyle `display:"add-fields"`
// XAxis has plot-level properties specific to the XAxis.
XAxis XAxisStyle `display:"add-fields"`
// YAxisLabel is the optional label to use for the YAxis instead of the default.
YAxisLabel string
// LinesOn determines whether lines are plotted by default at the overall,
// Plot level, for elements that plot lines (e.g., plots.XY).
LinesOn DefaultOffOn
// LineWidth sets the default line width for data plotting lines at the
// overall Plot level.
LineWidth units.Value
// PointsOn determines whether points are plotted by default at the
// overall Plot level, for elements that plot points (e.g., plots.XY).
PointsOn DefaultOffOn
// PointSize sets the default point size at the overall Plot level.
PointSize units.Value
// LabelSize sets the default label text size at the overall Plot level.
LabelSize units.Value
// BarWidth for Bar plot sets the default width of the bars,
// which should be less than the Stride (1 typically) to prevent
// bar overlap. Defaults to .8.
BarWidth float64
// ShowErrors can be set to have Plot configuration errors reported.
// This is particularly important for table-driven plots (e.g., [plotcore.Editor]),
// but it is not on by default because often there are transitional states
// with known errors that can lead to false alarms.
ShowErrors bool
}
PlotStyle has overall plot level styling properties. Some properties provide defaults for individual elements, which can then be overwritten by element-level properties.
func (*PlotStyle) SetAxis ¶
SetAxis sets the [PlotStyle.Axis]: Axis has the styling properties for the Axis associated with this Data.
func (*PlotStyle) SetBackground ¶
SetBackground sets the [PlotStyle.Background]: Background is the background of the plot. The default is colors.Scheme.Surface.
func (*PlotStyle) SetBarWidth ¶
SetBarWidth sets the [PlotStyle.BarWidth]: BarWidth for Bar plot sets the default width of the bars, which should be less than the Stride (1 typically) to prevent bar overlap. Defaults to .8.
func (*PlotStyle) SetElementStyle ¶
SetElementStyle sets the properties for given element's style based on the global default settings in this PlotStyle.
func (*PlotStyle) SetLabelSize ¶
SetLabelSize sets the [PlotStyle.LabelSize]: LabelSize sets the default label text size at the overall Plot level.
func (*PlotStyle) SetLegend ¶
func (t *PlotStyle) SetLegend(v LegendStyle) *PlotStyle
SetLegend sets the [PlotStyle.Legend]: Legend has the styling properties for the Legend.
func (*PlotStyle) SetLineWidth ¶
SetLineWidth sets the [PlotStyle.LineWidth]: LineWidth sets the default line width for data plotting lines at the overall Plot level.
func (*PlotStyle) SetLinesOn ¶
func (t *PlotStyle) SetLinesOn(v DefaultOffOn) *PlotStyle
SetLinesOn sets the [PlotStyle.LinesOn]: LinesOn determines whether lines are plotted by default at the overall, Plot level, for elements that plot lines (e.g., plots.XY).
func (*PlotStyle) SetPointSize ¶
SetPointSize sets the [PlotStyle.PointSize]: PointSize sets the default point size at the overall Plot level.
func (*PlotStyle) SetPointsOn ¶
func (t *PlotStyle) SetPointsOn(v DefaultOffOn) *PlotStyle
SetPointsOn sets the [PlotStyle.PointsOn]: PointsOn determines whether points are plotted by default at the overall Plot level, for elements that plot points (e.g., plots.XY).
func (*PlotStyle) SetScale ¶
SetScale sets the [PlotStyle.Scale]: Scale multiplies the plot DPI value, to change the overall scale of the rendered plot. Larger numbers produce larger scaling. Typically use larger numbers when generating plots for inclusion in documents or other cases where the overall plot size will be small.
func (*PlotStyle) SetShowErrors ¶ added in v0.1.1
SetShowErrors sets the [PlotStyle.ShowErrors]: ShowErrors can be set to have Plot configuration errors reported. This is particularly important for table-driven plots (e.g., [plotcore.Editor]), but it is not on by default because often there are transitional states with known errors that can lead to false alarms.
func (*PlotStyle) SetTitle ¶
SetTitle sets the [PlotStyle.Title]: Title is the overall title of the plot.
func (*PlotStyle) SetTitleStyle ¶
SetTitleStyle sets the [PlotStyle.TitleStyle]: TitleStyle is the text styling parameters for the title.
func (*PlotStyle) SetXAxis ¶
func (t *PlotStyle) SetXAxis(v XAxisStyle) *PlotStyle
SetXAxis sets the [PlotStyle.XAxis]: XAxis has plot-level properties specific to the XAxis.
func (*PlotStyle) SetYAxisLabel ¶
SetYAxisLabel sets the [PlotStyle.YAxisLabel]: YAxisLabel is the optional label to use for the YAxis instead of the default.
type Plotter ¶
type Plotter interface {
// Plot draws the data to the Plot Paint.
Plot(pt *Plot)
// UpdateRange updates the given ranges.
UpdateRange(plt *Plot, x, y, yr, z *minmax.F64)
// Data returns the data by roles for this plot, for both the original
// data and the pixel-transformed X,Y coordinates for that data.
// This allows a GUI interface to inspect data etc.
Data() (data Data, pixX, pixY []float32)
// Stylers returns the styler functions for this element.
Stylers() *Stylers
// ApplyStyle applies any stylers to this element,
// first initializing from the given global plot style, which has
// already been styled with defaults and all the plot element stylers.
ApplyStyle(plotStyle *PlotStyle, idx int)
}
Plotter is an interface that wraps the Plot method. Standard implementations of Plotter are in the [plots] package.
func NewPlotter ¶
NewPlotter returns a new plotter of given type, e.g., "XY", "Bar" etc, for given data roles (which must include Required roles, and may include Optional ones). Logs an error and returns nil if type name is not a registered type.
type PlotterType ¶
type PlotterType struct {
// Name of the plot type.
Name string
// Doc is the documentation for this Plotter.
Doc string
// Required Data roles for this plot. Data for these Roles must be provided.
Required []Roles
// Optional Data roles for this plot.
Optional []Roles
// New returns a new plotter of this type with given data in given roles.
New func(plt *Plot, data Data) Plotter
}
PlotterType registers a Plotter so that it can be created with appropriate data.
func PlotterByType ¶
func PlotterByType(typeName string) (*PlotterType, error)
PlotterByType returns PlotterType info for a registered Plotter of given type name, e.g., "XY", "Bar" etc, Returns an error and nil if type name is not a registered type.
type PointStyle ¶
type PointStyle struct {
// On indicates whether to plot points.
On DefaultOffOn
// Shape to draw.
Shape Shapes
// Color is the stroke color image specification.
// Setting to nil turns line off.
Color image.Image
// Fill is the color to fill solid regions, in a plot-specific
// way (e.g., the area below a Line plot, the bar color).
// Use nil to disable filling.
Fill image.Image
// Width is the line width for point glyphs, with a default of 1 Pt (point).
// Setting to 0 turns line off.
Width units.Value
// Size of shape to draw for each point.
// Defaults to 3 Pt (point).
Size units.Value
}
PointStyle has style properties for drawing points as different shapes.
func (*PointStyle) Defaults ¶
func (ps *PointStyle) Defaults()
func (*PointStyle) DrawShape ¶
func (ps *PointStyle) DrawShape(pc *paint.Painter, pos math32.Vector2)
DrawShape draws the given shape
func (*PointStyle) IsOn ¶ added in v0.1.1
func (ps *PointStyle) IsOn(pt *Plot) bool
IsOn returns true if points are to be drawn. Also computes the dots sizes at this point.
func (*PointStyle) SetColor ¶
func (t *PointStyle) SetColor(v image.Image) *PointStyle
SetColor sets the [PointStyle.Color]: Color is the stroke color image specification. Setting to nil turns line off.
func (*PointStyle) SetFill ¶
func (t *PointStyle) SetFill(v image.Image) *PointStyle
SetFill sets the [PointStyle.Fill]: Fill is the color to fill solid regions, in a plot-specific way (e.g., the area below a Line plot, the bar color). Use nil to disable filling.
func (*PointStyle) SetOn ¶
func (t *PointStyle) SetOn(v DefaultOffOn) *PointStyle
SetOn sets the [PointStyle.On]: On indicates whether to plot points.
func (*PointStyle) SetShape ¶
func (t *PointStyle) SetShape(v Shapes) *PointStyle
SetShape sets the [PointStyle.Shape]: Shape to draw.
func (*PointStyle) SetSize ¶
func (t *PointStyle) SetSize(v units.Value) *PointStyle
SetSize sets the [PointStyle.Size]: Size of shape to draw for each point. Defaults to 3 Pt (point).
func (*PointStyle) SetStroke ¶
func (ps *PointStyle) SetStroke(pt *Plot) bool
SetStroke sets the stroke style in plot paint to current line style. returns false if either the Width = 0 or Color is nil
func (*PointStyle) SetWidth ¶
func (t *PointStyle) SetWidth(v units.Value) *PointStyle
SetWidth sets the [PointStyle.Width]: Width is the line width for point glyphs, with a default of 1 Pt (point). Setting to 0 turns line off.
func (*PointStyle) SpacedColor ¶
func (ps *PointStyle) SpacedColor(idx int)
SpacedColor sets the Color to a default spaced color based on index, if it still has the initial OnSurface default.
type Roles ¶
type Roles int32 //enums:enum
Roles are the roles that a given set of data values can play, designed to be sufficiently generalizable across all different types of plots, even if sometimes it is a bit of a stretch.
const ( // NoRole is the default no-role specified case. NoRole Roles = iota // X axis X // Y axis Y // Z axis Z // U is the X component of a vector or first quartile in Box plot, etc. U // V is the Y component of a vector or third quartile in a Box plot, etc. V // W is the Z component of a vector W // Low is a lower error bar or region. Low // High is an upper error bar or region. High // Size controls the size of points etc. Size // Color controls the color of points or other elements. Color // Label renders a label, typically from string data, // but can also be used for values. Label // Split is a special role for table-based plots. The // unique values of this data are used to split the other // plot data into groups, with each group added to the legend. // A different default color will be used for each such group. Split )
const RolesN Roles = 13
RolesN is the highest valid value for type Roles, plus one.
func RolesValues ¶
func RolesValues() []Roles
RolesValues returns all possible values for the type Roles.
func (Roles) MarshalText ¶
MarshalText implements the encoding.TextMarshaler interface.
func (*Roles) SetString ¶
SetString sets the Roles value from its string representation, and returns an error if the string is invalid.
func (*Roles) UnmarshalText ¶
UnmarshalText implements the encoding.TextUnmarshaler interface.
type Shapes ¶
type Shapes int32 //enums:enum
Shapes has the options for how to draw points in the plot.
const ( // Circle is a solid circle Circle Shapes = iota // Box is a filled square Box // Pyramid is a filled triangle Pyramid // Plus is a plus sign Plus // Cross is a big X Cross // Ring is the outline of a circle Ring // Square is the outline of a square Square // Triangle is the outline of a triangle Triangle )
const ShapesN Shapes = 8
ShapesN is the highest valid value for type Shapes, plus one.
func ShapesValues ¶
func ShapesValues() []Shapes
ShapesValues returns all possible values for the type Shapes.
func (Shapes) MarshalText ¶
MarshalText implements the encoding.TextMarshaler interface.
func (*Shapes) SetString ¶
SetString sets the Shapes value from its string representation, and returns an error if the string is invalid.
func (*Shapes) UnmarshalText ¶
UnmarshalText implements the encoding.TextUnmarshaler interface.
type StepKind ¶
type StepKind int32 //enums:enum
StepKind specifies a form of a connection of two consecutive points.
const ( // NoStep connects two points by simple line. NoStep StepKind = iota // PreStep connects two points by following lines: vertical, horizontal. PreStep // MidStep connects two points by following lines: horizontal, vertical, horizontal. // Vertical line is placed in the middle of the interval. MidStep // PostStep connects two points by following lines: horizontal, vertical. PostStep )
const StepKindN StepKind = 4
StepKindN is the highest valid value for type StepKind, plus one.
func StepKindValues ¶
func StepKindValues() []StepKind
StepKindValues returns all possible values for the type StepKind.
func (StepKind) MarshalText ¶
MarshalText implements the encoding.TextMarshaler interface.
func (*StepKind) SetString ¶
SetString sets the StepKind value from its string representation, and returns an error if the string is invalid.
func (*StepKind) UnmarshalText ¶
UnmarshalText implements the encoding.TextUnmarshaler interface.
type Style ¶
type Style struct {
// Plot has overall plot-level properties, which can be set by any
// plot element, and are updated first, before applying element-wise styles.
Plot PlotStyle `display:"-"`
// On specifies whether to plot this item, for table-based plots.
On bool
// Plotter is the type of plotter to use in plotting this data,
// for [plot.NewTablePlot] [table.Table] driven plots.
// Blank means use default ([plots.XY] is overall default).
Plotter PlotterName
// Role specifies how a particular column of data should be used,
// for [plot.NewTablePlot] [table.Table] driven plots.
Role Roles
// Group specifies a group of related data items,
// for [plot.NewTablePlot] [table.Table] driven plots,
// where different columns of data within the same Group play different Roles.
Group string
// Range is the effective range of data to plot, where either end can be fixed.
Range minmax.Range64 `display:"inline"`
// Label provides an alternative label to use for axis, if set.
Label string
// NoLegend excludes this item from the legend when it otherwise would be included,
// for [plot.NewTablePlot] [table.Table] driven plots.
// Role = Y values are included in the Legend by default.
NoLegend bool
// RightY specifies that this should use the right-side alternate Y axis.
RightY bool
// NTicks sets the desired number of ticks for the axis, if > 0.
NTicks int
// LabelSkip is the number of data points to skip between Labels.
// 0 means plot the Label at every point.
LabelSkip int
// Line has style properties for drawing lines.
Line LineStyle `display:"add-fields"`
// Point has style properties for drawing points.
Point PointStyle `display:"add-fields"`
// Text has style properties for rendering text.
Text TextStyle `display:"add-fields"`
// Width has various plot width properties.
Width WidthStyle `display:"inline"`
}
Style contains the plot styling properties relevant across most plot types. These properties apply to individual plot elements while the Plot properties applies to the overall plot itself.
func (*Style) SetGroup ¶
SetGroup sets the [Style.Group]: Group specifies a group of related data items, for plot.NewTablePlot table.Table driven plots, where different columns of data within the same Group play different Roles.
func (*Style) SetLabel ¶
SetLabel sets the [Style.Label]: Label provides an alternative label to use for axis, if set.
func (*Style) SetLabelSkip ¶
SetLabelSkip sets the [Style.LabelSkip]: LabelSkip is the number of data points to skip between Labels. 0 means plot the Label at every point.
func (*Style) SetNTicks ¶
SetNTicks sets the [Style.NTicks]: NTicks sets the desired number of ticks for the axis, if > 0.
func (*Style) SetNoLegend ¶
SetNoLegend sets the [Style.NoLegend]: NoLegend excludes this item from the legend when it otherwise would be included, for plot.NewTablePlot table.Table driven plots. Role = Y values are included in the Legend by default.
func (*Style) SetOn ¶
SetOn sets the [Style.On]: On specifies whether to plot this item, for table-based plots.
func (*Style) SetPlot ¶
SetPlot sets the [Style.Plot]: Plot has overall plot-level properties, which can be set by any plot element, and are updated first, before applying element-wise styles.
func (*Style) SetPlotter ¶
func (t *Style) SetPlotter(v PlotterName) *Style
SetPlotter sets the [Style.Plotter]: Plotter is the type of plotter to use in plotting this data, for plot.NewTablePlot table.Table driven plots. Blank means use default ([plots.XY] is overall default).
func (*Style) SetPoint ¶
func (t *Style) SetPoint(v PointStyle) *Style
SetPoint sets the [Style.Point]: Point has style properties for drawing points.
func (*Style) SetRange ¶
SetRange sets the [Style.Range]: Range is the effective range of data to plot, where either end can be fixed.
func (*Style) SetRightY ¶ added in v0.1.1
SetRightY sets the [Style.RightY]: RightY specifies that this should use the right-side alternate Y axis.
func (*Style) SetRole ¶
SetRole sets the [Style.Role]: Role specifies how a particular column of data should be used, for plot.NewTablePlot table.Table driven plots.
func (*Style) SetText ¶
SetText sets the [Style.Text]: Text has style properties for rendering text.
func (*Style) SetWidth ¶
func (t *Style) SetWidth(v WidthStyle) *Style
SetWidth sets the [Style.Width]: Width has various plot width properties.
type Stylers ¶
type Stylers []func(s *Style)
Stylers is a list of styling functions that set Style properties. These are called in the order added.
func GetStylers ¶
GetStylers returns Stylers functions from given object's metadata. Returns nil if none or no metadata.
func GetStylersFromData ¶
GetStylersFromData returns Stylers from given role in given Data. nil if not present. Mostly used internally for Plotters implementations.
type Text ¶
type Text struct {
// text string, which can use HTML formatting
Text string
// styling for this text element
Style TextStyle
// PaintText is the [shaped.Lines] for painting the text.
PaintText *shaped.Lines
// contains filtered or unexported fields
}
Text specifies a single text element in a plot
func (*Text) PosX ¶
PosX returns the starting position for a horizontally-aligned text element, based on given width. Text must have been config'd already.
func (*Text) PosY ¶
PosY returns the starting position for a vertically-rotated text element, based on given height. Text must have been config'd already.
type TextStyle ¶
type TextStyle struct {
// Size of font to render. Default is 16dp
Size units.Value
// Family name for font (inherited): ordered list of comma-separated names
// from more general to more specific to use. Use split on, to parse.
Family rich.Family
// Color of text.
Color image.Image
// Align specifies how to align text along the relevant
// dimension for the text element.
Align styles.Aligns
// Padding is used in a case-dependent manner to add
// space around text elements.
Padding units.Value
// Rotation of the text, in degrees.
Rotation float32
// Offset is added directly to the final label location.
Offset units.XY
}
TextStyle specifies styling parameters for Text elements.
func (*TextStyle) SetAlign ¶
SetAlign sets the [TextStyle.Align]: Align specifies how to align text along the relevant dimension for the text element.
func (*TextStyle) SetFamily ¶
SetFamily sets the [TextStyle.Family]: Family name for font (inherited): ordered list of comma-separated names from more general to more specific to use. Use split on, to parse.
func (*TextStyle) SetOffset ¶
SetOffset sets the [TextStyle.Offset]: Offset is added directly to the final label location.
func (*TextStyle) SetPadding ¶
SetPadding sets the [TextStyle.Padding]: Padding is used in a case-dependent manner to add space around text elements.
func (*TextStyle) SetRotation ¶
SetRotation sets the [TextStyle.Rotation]: Rotation of the text, in degrees.
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(pt *Plot)
}
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.
type Ticker ¶
type Ticker interface {
// Ticks returns Ticks in a specified range, with desired number of ticks,
// which can be ignored depending on the ticker type.
Ticks(mn, mx float64, nticks int) []Tick
}
Ticker creates Ticks in a specified range
type TimeTicks ¶
type TimeTicks struct {
// Ticker is used to generate a set of ticks.
// If nil, DefaultTicks will be used.
Ticker Ticker
// Format is the textual representation of the time value.
// If empty, time.RFC3339 will be used
Format string
// Time takes a float32 value and converts it into a time.Time.
// If nil, UTCUnixTime is used.
Time func(t float64) time.Time
}
TimeTicks is suitable for axes representing time values.
type Valuer ¶
type Valuer interface {
// Len returns the number of values.
Len() int
// Float1D(i int) returns float64 value at given index.
Float1D(i int) float64
// String1D(i int) returns string value at given index.
String1D(i int) string
}
Valuer is the data interface for plotting, supporting either float64 or string representations. It is satisfied by the tensor.Tensor interface, so a tensor can be used directly for plot Data.
type Values ¶
type Values []float64
Values provides a minimal implementation of the Data interface using a slice of float64.
func CopyRole ¶
CopyRole returns Values copy of given role from given data map, returning nil if role not present.
func CopyValues ¶
CopyValues returns a Values that is a copy of the values from Data, or an error if there are no values, or if one of the copied values is a Infinity. NaN values are skipped in the copying process.
func MustCopyRole ¶
MustCopyRole returns Values copy of given role from given data map, logging an error and returning nil if not present.
type WidthStyle ¶
type WidthStyle struct {
// Cap is the width of the caps drawn at the top of error bars.
// The default is 10dp
Cap units.Value
// Offset for Bar plot is the offset added to each X axis value
// relative to the Stride computed value (X = offset + index * Stride)
// Defaults to 0.
Offset float64
// Stride for Bar plot is distance between bars. Defaults to 1.
Stride float64
// Width for Bar plot is the width of the bars, as a fraction of the Stride,
// to prevent bar overlap. Defaults to .8.
Width float64 `min:"0.01" max:"1" default:"0.8"`
// Pad for Bar plot is additional space at start / end of data range,
// to keep bars from overflowing ends. This amount is subtracted from Offset
// and added to (len(Values)-1)*Stride -- no other accommodation for bar
// width is provided, so that should be built into this value as well.
// Defaults to 1.
Pad float64
}
WidthStyle contains various plot width properties relevant across different plot types.
func (*WidthStyle) Defaults ¶
func (ws *WidthStyle) Defaults()
func (*WidthStyle) SetCap ¶
func (t *WidthStyle) SetCap(v units.Value) *WidthStyle
SetCap sets the [WidthStyle.Cap]: Cap is the width of the caps drawn at the top of error bars. The default is 10dp
func (*WidthStyle) SetOffset ¶
func (t *WidthStyle) SetOffset(v float64) *WidthStyle
SetOffset sets the [WidthStyle.Offset]: Offset for Bar plot is the offset added to each X axis value relative to the Stride computed value (X = offset + index * Stride) Defaults to 0.
func (*WidthStyle) SetPad ¶
func (t *WidthStyle) SetPad(v float64) *WidthStyle
SetPad sets the [WidthStyle.Pad]: Pad for Bar plot is additional space at start / end of data range, to keep bars from overflowing ends. This amount is subtracted from Offset and added to (len(Values)-1)*Stride -- no other accommodation for bar width is provided, so that should be built into this value as well. Defaults to 1.
func (*WidthStyle) SetStride ¶
func (t *WidthStyle) SetStride(v float64) *WidthStyle
SetStride sets the [WidthStyle.Stride]: Stride for Bar plot is distance between bars. Defaults to 1.
func (*WidthStyle) SetWidth ¶
func (t *WidthStyle) SetWidth(v float64) *WidthStyle
SetWidth sets the [WidthStyle.Width]: Width for Bar plot is the width of the bars, as a fraction of the Stride, to prevent bar overlap. Defaults to .8.
type XAxisStyle ¶
type XAxisStyle struct {
// Column specifies the column to use for the common X axis,
// for [plot.NewTablePlot] [table.Table] driven plots.
// If empty, standard Group-based role binding is used: the last column
// within the same group with Role=X is used.
Column string
// Rotation is the rotation of the X Axis labels, in degrees.
Rotation float32
// Label is the optional label to use for the XAxis instead of the default.
Label string
// Range is the effective range of XAxis data to plot, where either end can be fixed.
Range minmax.Range64 `display:"inline"`
// Scale specifies how values are scaled along the X axis:
// Linear, Log, Inverted
Scale AxisScales
}
XAxisStyle has overall plot level styling properties for the XAxis.
func (*XAxisStyle) SetColumn ¶
func (t *XAxisStyle) SetColumn(v string) *XAxisStyle
SetColumn sets the [XAxisStyle.Column]: Column specifies the column to use for the common X axis, for plot.NewTablePlot table.Table driven plots. If empty, standard Group-based role binding is used: the last column within the same group with Role=X is used.
func (*XAxisStyle) SetLabel ¶
func (t *XAxisStyle) SetLabel(v string) *XAxisStyle
SetLabel sets the [XAxisStyle.Label]: Label is the optional label to use for the XAxis instead of the default.
func (*XAxisStyle) SetRange ¶
func (t *XAxisStyle) SetRange(v minmax.Range64) *XAxisStyle
SetRange sets the [XAxisStyle.Range]: Range is the effective range of XAxis data to plot, where either end can be fixed.
func (*XAxisStyle) SetRotation ¶
func (t *XAxisStyle) SetRotation(v float32) *XAxisStyle
SetRotation sets the [XAxisStyle.Rotation]: Rotation is the rotation of the X Axis labels, in degrees.
func (*XAxisStyle) SetScale ¶
func (t *XAxisStyle) SetScale(v AxisScales) *XAxisStyle
SetScale sets the [XAxisStyle.Scale]: Scale specifies how values are scaled along the X axis: Linear, Log, Inverted