Documentation
¶
Overview ¶
Package plot renders PlotFeature.
Index ¶
- Constants
- func NewPlotter(tr Transformer) *plotter
- func NewRenderer(msg *pb.PlotFeature) *renderer
- func Scale(rx, ry float64) *scaleTransformer
- func Translate(dx, dy float64) *translateTransformer
- type Autoscaler
- type AxesConfig
- type Axis
- type AxisConfig
- type Graph
- type HTMLTemplateData
- type JSTemplateData
- type Path
- type PathCommand
- type PathLineCommand
- type PathMoveCommand
- type Percent
- type PlotConfig
- type PlotInfo
- type Point
- type Quote
- type TemplateData
- type Text
- type Transformer
- type ViewBox
- type ViewBoxConfig
- type XQuote
Constants ¶
const PlotPaddingPercent = 0.02
PlotPaddingPercent is the padding size to be added to the plot as per cent of the plot's y-range, the distance between the plot's max and minimum values.
Variables ¶
This section is empty.
Functions ¶
func NewPlotter ¶
func NewPlotter(tr Transformer) *plotter
NewPlotter creates a plotter to plot quotes in the virtual coordinates box from (0,0) to (1,1) and translate the coordinates using tr translator.
func NewRenderer ¶
func NewRenderer(msg *pb.PlotFeature) *renderer
NewRenderer creates a renderer for PlotFeature.
Types ¶
type Autoscaler ¶
type Autoscaler struct {
// Padding is the per cent of the range width of [xmin,max].
Padding Percent
}
Autoscaler adds padding to the range [xmin,xmax].
type AxesConfig ¶
type AxesConfig struct {
// X is the x-axis configuration.
X AxisConfig
// Y is the y-axis configuration.
Y AxisConfig
}
AxesConfig configurations for x- and y- axes.
type Axis ¶
type Axis struct {
// Line draws the axis line.
Line *Path
// Guides is a set of the axis guide lines.
Guides *Path
// Labels are axis values for guides.
Labels []Text
}
Axis describes a single axis.
type AxisConfig ¶
type AxisConfig struct {
// X is the x-coordinate of the axis
X int
// Y is the y-coordinate of the axis
Y int
// Width of the axis, excluding the offset.
Width int
// Height of the axis, excluding the offset.
Height int
// Padding is the axis offset from the plot to make axes stand out.
Padding int
// TickWidth is the tick width of the axis.
TickWidth int
}
AxisConfig configures an axis.
type Graph ¶
type Graph struct {
// X is the x-coordinate of the top-left corner.
X int
// Y is the y-coordinate of the top-left corner.
Y int
// Width is the width of the graph area.
Width int
// Height is the height of the graph area.
Height int
}
Graph defines properties of the graph area in the plot.
type HTMLTemplateData ¶
type HTMLTemplateData struct {
// ViewBox defines visiple part of the user space in SVG.
ViewBox *ViewBox
// X defines x-axis.
X *Axis
// Y defines y-axis.
Y *Axis
// Path is the plotted line of the quotes.
Path *Path
// Graph describes the main area in the plot with graph.
Graph *Graph
// Title is the name of the plot.
Title string
}
HTMLTemplateData is the input data to HTML template.
type JSTemplateData ¶
type JSTemplateData struct {
// Quotes associates actual data (Quote) with plot x coordinates.
Quotes XQuote
}
JSTemplateData is the input data to JS template.
type Path ¶
type Path struct {
// Commands are path.d commands.
Commands []PathCommand
}
Path is the SVG path.d attribute.
type PathCommand ¶
type PathCommand interface {
// contains filtered or unexported methods
}
PathCommand restricts the types of path commands.
type PathLineCommand ¶
type PathLineCommand struct {
// Point is the destination to draw a line to.
Point
// contains filtered or unexported fields
}
PathLineCommand is the LineTo command of SVG path. It translates to "L X Y".
func (PathLineCommand) String ¶
func (cmd PathLineCommand) String() string
String prints the line command.
type PathMoveCommand ¶
type PathMoveCommand struct {
// Point is the destination to move to.
Point
// contains filtered or unexported fields
}
PathMoveCommand is the MoveTo command of SVG path. It translates to "M X Y".
func (PathMoveCommand) String ¶
func (cmd PathMoveCommand) String() string
String prints the move command.
type PlotConfig ¶
type PlotConfig struct {
// ViewBox is the configuration for SVG view box.
ViewBox ViewBoxConfig
// Axes holds configuration for x- and y- axes.
Axes AxesConfig
}
PlotConfig defines configuration for the plot in SVG araea.
type PlotInfo ¶
type PlotInfo struct {
// Path is the plot line.
Path *Path
// Quotes are plot data points.
Quotes XQuote
// Ymin is the minimum range of the axis.
Ymin float64
// Ymax is the maximum range of the axis.
Ymax float64
}
PlotInfo holds generated plot.
type Quote ¶
type Quote struct {
// UnixTime is the number of seconds since Jan 1, 1970 UTC.
// See [time.Time.Unix].
UnixTime int64
// Cents is the quote value on the date.
Cents int32
}
Quote is a data point on the graph. It has a date and the value.
type TemplateData ¶
type TemplateData struct {
// contains filtered or unexported fields
}
TemplateData holds data for HTML and JS templates.
type Text ¶
type Text struct {
// Val is the text value.
Val string
// X is the text x-coordinate.
X int
// Y is the text y-coordinate.
Y int
}
Text represents an SVG text element.
type Transformer ¶
type Transformer interface {
// Transform transforms coordinates (x,y) in some way.
Transform(x, y float64) (newx, newy float64)
}
Transformer performs cartesian coordinates transformation.
func WithTransformer ¶
func WithTransformer(t Transformer, opts ...Transformer) Transformer
WithTransformer creates a chain of transformers starting with t.
type ViewBox ¶
type ViewBox struct {
// Point is the origin of the view box.
Point
// Width of the view box.
Width int
// Height of the view box.
Height int
}
ViewBox is the SVG viewbox attribute. It defines the visible region of the user space, shown in the user-agent.
type ViewBoxConfig ¶
type ViewBoxConfig struct {
// Width is the width of the view box.
Width int
// Height is the height of the view box.
Height int
}
ViewBoxConfig defines the SVG's view box.