plot

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2026 License: BSD-3-Clause Imports: 9 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package plot renders PlotFeature.

Index

Constants

View Source
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.

func Scale

func Scale(rx, ry float64) *scaleTransformer

Scaley creates a transformer to scale coordinates (x,y) to (rx*x,ry*y).

func Translate

func Translate(dx, dy float64) *translateTransformer

Translate creates a linear transformer to transform coordinates (x,y) to (x+dx,y+dy).

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].

func (*Autoscaler) Scale

func (scaler *Autoscaler) Scale(xmin, xmax float64) (float64, float64)

Scale scales the range of values [xmin,xmax] to include padding.

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.

func (Path) String

func (p Path) String() string

String dumps path as a series of commands, starting with MoveTo command.

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 Percent

type Percent float64

Percent is the per cent value in the range 0 to 1 inclusive.

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 Point

type Point struct {
	X int // X coordinate
	Y int // Y coordinate
}

Point is a point in Cartesian coordinates.

func (Point) String

func (p Point) String() string

String prints the point, suitable for SVG path.d attribute.

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.

func (*ViewBox) String

func (vb *ViewBox) String() string

String dumps the view box in format suitable for svg.viewbox attribute.

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.

type XQuote

type XQuote map[int]*Quote

XQuote is the quote for x coordinate of the line.

Jump to

Keyboard shortcuts

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