chart

package module
v2.5.2 Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2021 License: MIT Imports: 20 Imported by: 0

README

go-charts

This is a fork of https://github.com/wcharczuk/go-chart with various patches that's used by userstyles.world.

Documentation

Index

Constants

View Source
const (
	// DefaultChartHeight is the default chart height.
	DefaultChartHeight = 400
	// DefaultChartWidth is the default chart width.
	DefaultChartWidth = 1024
	// DefaultStrokeWidth is the default chart stroke width.
	DefaultStrokeWidth = 0.0
	// DefaultDotWidth is the default chart dot width.
	DefaultDotWidth = 0.0
	// DefaultSeriesLineWidth is the default line width.
	DefaultSeriesLineWidth = 1.0
	// DefaultAxisLineWidth is the line width of the axis lines.
	DefaultAxisLineWidth = 1.0
	// DefaultDPI is the default dots per inch for the chart.
	DefaultDPI = 92.0
	// DefaultMinimumFontSize is the default minimum font size.
	DefaultMinimumFontSize = 8.0
	// DefaultFontSize is the default font size.
	DefaultFontSize = 10.0
	// DefaultTitleFontSize is the default title font size.
	DefaultTitleFontSize = 18.0
	// DefaultAnnotationDeltaWidth is the width of the left triangle out of annotations.
	DefaultAnnotationDeltaWidth = 10
	// DefaultAnnotationFontSize is the font size of annotations.
	DefaultAnnotationFontSize = 10.0
	// DefaultAxisFontSize is the font size of the axis labels.
	DefaultAxisFontSize = 10.0
	// DefaultTitleTop is the default distance from the top of the chart to put the title.
	DefaultTitleTop = 10

	// DefaultBackgroundStrokeWidth is the default stroke on the chart background.
	DefaultBackgroundStrokeWidth = 0.0
	// DefaultCanvasStrokeWidth is the default stroke on the chart canvas.
	DefaultCanvasStrokeWidth = 0.0

	// DefaultLineSpacing is the default vertical distance between lines of text.
	DefaultLineSpacing = 5

	// DefaultYAxisMargin is the default distance from the right of the canvas to the y axis labels.
	DefaultYAxisMargin = 10
	// DefaultXAxisMargin is the default distance from bottom of the canvas to the x axis labels.
	DefaultXAxisMargin = 10

	// DefaultVerticalTickHeight is half the margin.
	DefaultVerticalTickHeight = DefaultXAxisMargin >> 1
	// DefaultHorizontalTickWidth is half the margin.
	DefaultHorizontalTickWidth = DefaultYAxisMargin >> 1

	// DefaultTickCount is the default number of ticks to show
	DefaultTickCount = 10
	// DefaultTickCountSanityCheck is a hard limit on number of ticks to prevent infinite loops.
	DefaultTickCountSanityCheck = 1 << 10 // 1024

	// DefaultMinimumTickHorizontalSpacing is the minimum distance between horizontal ticks.
	DefaultMinimumTickHorizontalSpacing = 20
	// DefaultMinimumTickVerticalSpacing is the minimum distance between vertical ticks.
	DefaultMinimumTickVerticalSpacing = 20

	// DefaultDateFormat is the default date format.
	DefaultDateFormat = "2006-01-02"
	// DefaultDateHourFormat is the date format for hour timestamp formats.
	DefaultDateHourFormat = "01-02 3PM"
	// DefaultDateMinuteFormat is the date format for minute range timestamp formats.
	DefaultDateMinuteFormat = "01-02 3:04PM"
	// DefaultFloatFormat is the default float format.
	DefaultFloatFormat = "%.2f"
	// DefaultPercentValueFormat is the default percent format.
	DefaultPercentValueFormat = "%0.2f%%"

	// DefaultBarSpacing is the default pixel spacing between bars.
	DefaultBarSpacing = 100
	// DefaultBarWidth is the default pixel width of bars in a bar chart.
	DefaultBarWidth = 50
)
View Source
const (
	// ContentTypePNG is the png mime type.
	ContentTypePNG = "image/png"

	// ContentTypeSVG is the svg mime type.
	ContentTypeSVG = "image/svg+xml"
)
View Source
const (
	SecondsPerHour = 60 * 60
	SecondsPerDay  = 60 * 60 * 24
)

SecondsPerXYZ

View Source
const (
	// Disabled indicates if the value should be interpreted as set intentionally to zero.
	// this is because golang optionals aren't here yet.
	Disabled = -1
)

Variables

View Source
var (
	// ColorWhite is white.
	ColorWhite = drawing.Color{R: 255, G: 255, B: 255, A: 255}
	// ColorBlue is the basic theme blue color.
	ColorBlue = drawing.Color{R: 0, G: 116, B: 217, A: 255}
	// ColorCyan is the basic theme cyan color.
	ColorCyan = drawing.Color{R: 0, G: 217, B: 210, A: 255}
	// ColorGreen is the basic theme green color.
	ColorGreen = drawing.Color{R: 0, G: 217, B: 101, A: 255}
	// ColorRed is the basic theme red color.
	ColorRed = drawing.Color{R: 217, G: 0, B: 116, A: 255}
	// ColorOrange is the basic theme orange color.
	ColorOrange = drawing.Color{R: 217, G: 101, B: 0, A: 255}
	// ColorYellow is the basic theme yellow color.
	ColorYellow = drawing.Color{R: 217, G: 210, B: 0, A: 255}
	// ColorBlack is the basic theme black color.
	ColorBlack = drawing.Color{R: 51, G: 51, B: 51, A: 255}
	// ColorLightGray is the basic theme light gray color.
	ColorLightGray = drawing.Color{R: 239, G: 239, B: 239, A: 255}

	// ColorAlternateBlue is a alternate theme color.
	ColorAlternateBlue = drawing.Color{R: 106, G: 195, B: 203, A: 255}
	// ColorAlternateGreen is a alternate theme color.
	ColorAlternateGreen = drawing.Color{R: 42, G: 190, B: 137, A: 255}
	// ColorAlternateGray is a alternate theme color.
	ColorAlternateGray = drawing.Color{R: 110, G: 128, B: 139, A: 255}
	// ColorAlternateYellow is a alternate theme color.
	ColorAlternateYellow = drawing.Color{R: 240, G: 174, B: 90, A: 255}
	// ColorAlternateLightGray is a alternate theme color.
	ColorAlternateLightGray = drawing.Color{R: 187, G: 190, B: 191, A: 255}

	// ColorTransparent is a transparent (alpha zero) color.
	ColorTransparent = drawing.Color{R: 1, G: 1, B: 1, A: 0}
)
View Source
var (
	// DefaultBackgroundColor is the default chart background color.
	// It is equivalent to css color:white.
	DefaultBackgroundColor = ColorWhite
	// DefaultBackgroundStrokeColor is the default chart border color.
	// It is equivalent to color:white.
	DefaultBackgroundStrokeColor = ColorWhite
	// DefaultCanvasColor is the default chart canvas color.
	// It is equivalent to css color:white.
	DefaultCanvasColor = ColorWhite
	// DefaultCanvasStrokeColor is the default chart canvas stroke color.
	// It is equivalent to css color:white.
	DefaultCanvasStrokeColor = ColorWhite
	// DefaultTextColor is the default chart text color.
	// It is equivalent to #333333.
	DefaultTextColor = ColorBlack
	// DefaultAxisColor is the default chart axis line color.
	// It is equivalent to #333333.
	DefaultAxisColor = ColorBlack
	// DefaultStrokeColor is the default chart border color.
	// It is equivalent to #efefef.
	DefaultStrokeColor = ColorLightGray
	// DefaultFillColor is the default fill color.
	// It is equivalent to #0074d9.
	DefaultFillColor = ColorBlue
	// DefaultAnnotationFillColor is the default annotation background color.
	DefaultAnnotationFillColor = ColorWhite
	// DefaultGridLineColor is the default grid line color.
	DefaultGridLineColor = ColorLightGray
)
View Source
var (
	// DefaultColors are a couple default series colors.
	DefaultColors = []drawing.Color{
		ColorBlue,
		ColorGreen,
		ColorRed,
		ColorCyan,
		ColorOrange,
	}

	// DefaultAlternateColors are a couple alternate colors.
	DefaultAlternateColors = []drawing.Color{
		ColorAlternateBlue,
		ColorAlternateGreen,
		ColorAlternateGray,
		ColorAlternateYellow,
		ColorBlue,
		ColorGreen,
		ColorRed,
		ColorCyan,
		ColorOrange,
	}
)
View Source
var (
	// DashArrayDots is a dash array that represents '....' style stroke dashes.
	DashArrayDots = []int{1, 1}
	// DashArrayDashesSmall is a dash array that represents '- - -' style stroke dashes.
	DashArrayDashesSmall = []int{3, 3}
	// DashArrayDashesMedium is a dash array that represents '-- -- --' style stroke dashes.
	DashArrayDashesMedium = []int{5, 5}
	// DashArrayDashesLarge is a dash array that represents '----- ----- -----' style stroke dashes.
	DashArrayDashesLarge = []int{10, 10}
)
View Source
var (
	// DefaultAnnotationPadding is the padding around an annotation.
	DefaultAnnotationPadding = Box{Top: 5, Left: 5, Right: 5, Bottom: 5}

	// DefaultBackgroundPadding is the default canvas padding config.
	DefaultBackgroundPadding = Box{Top: 5, Left: 5, Right: 5, Bottom: 5}
)
View Source
var AlternateColorPalette alternateColorPalette

AlternateColorPalette represents the default palatte.

View Source
var (
	// BoxZero is a preset box that represents an intentional zero value.
	BoxZero = Box{IsSet: true}
)
View Source
var DefaultColorPalette defaultColorPalette

DefaultColorPalette represents the default palatte.

View Source
var (
	// Draw contains helpers for drawing common objects.
	Draw = &draw{}
)
View Source
var (
	// Text contains utilities for text.
	Text = &text{}
)

Functions

func AbsInt

func AbsInt(value int) int

AbsInt returns the absolute value of an int.

func AbsWithBranch added in v2.4.0

func AbsWithBranch(n int64) int64

func CirclePoint

func CirclePoint(cx, cy int, radius, thetaRadians float64) (x, y int)

CirclePoint returns the absolute position of a circle diameter point given by the radius and the theta.

func Days

func Days(days int) []time.Time

Days generates a seq of timestamps by day, from -days to today.

func Debug

func Debug(log Logger, arguments ...interface{})

Debug logs an debug message if the logger is set.

func Debugf

func Debugf(log Logger, format string, arguments ...interface{})

Debugf logs an debug message if the logger is set.

func DegreesAdd

func DegreesAdd(baseDegrees, deltaDegrees float64) float64

DegreesAdd adds a delta to a base in radians.

func DegreesToCompass

func DegreesToCompass(deg float64) float64

DegreesToCompass returns the degree value in compass / clock orientation.

func DegreesToRadians

func DegreesToRadians(degrees float64) float64

DegreesToRadians returns degrees as radians.

func DiffHours

func DiffHours(t1, t2 time.Time) (hours int)

DiffHours returns the difference in hours between two times.

func FloatValueFormatter

func FloatValueFormatter(v interface{}) string

FloatValueFormatter is a ValueFormatter for float64.

func FloatValueFormatterWithFormat

func FloatValueFormatterWithFormat(v interface{}, floatFormat string) string

FloatValueFormatterWithFormat is a ValueFormatter for float64 with a given format.

func GetAlternateColor

func GetAlternateColor(index int) drawing.Color

GetAlternateColor returns a color from the default list by index. NOTE: the index will wrap around (using a modulo).

func GetDefaultColor

func GetDefaultColor(index int) drawing.Color

GetDefaultColor returns a color from the default list by index. NOTE: the index will wrap around (using a modulo).

func GetDefaultFont

func GetDefaultFont() (*truetype.Font, error)

GetDefaultFont returns the default font (Roboto-Medium).

func GetRoundToForDelta

func GetRoundToForDelta(delta float64) float64

GetRoundToForDelta returns a `roundTo` value for a given delta.

func Hours

func Hours(start time.Time, totalHours int) []time.Time

Hours returns a sequence of times by the hour for a given number of hours after a given start.

func HoursFilled

func HoursFilled(xdata []time.Time, ydata []float64) ([]time.Time, []float64)

HoursFilled adds zero values for the data bounded by the start and end of the xdata array.

func Info

func Info(log Logger, arguments ...interface{})

Info logs an info message if the logger is set.

func Infof

func Infof(log Logger, format string, arguments ...interface{})

Infof logs an info message if the logger is set.

func IntValueFormatter

func IntValueFormatter(v interface{}) string

IntValueFormatter is a ValueFormatter for float64.

func LinearRange

func LinearRange(start, end float64) []float64

LinearRange returns an array of values representing the range from start to end, incremented by 1.0.

func LinearRangeWithStep

func LinearRangeWithStep(start, end, step float64) []float64

LinearRangeWithStep returns the array values of a linear seq with a given start, end and optional step.

func MaxInt

func MaxInt(values ...int) (max int)

MaxInt returns the maximum int.

func Mean

func Mean(values ...float64) float64

Mean returns the mean of a set of values

func MeanInt

func MeanInt(values ...int) int

MeanInt returns the mean of a set of integer values.

func MinInt

func MinInt(values ...int) (min int)

MinInt returns the minimum int.

func MinInt2 added in v2.5.2

func MinInt2(a, b int) int

MinInt2 returns the minum int between two values.

func MinMax

func MinMax(values ...float64) (min, max float64)

MinMax returns the minimum and maximum of a given set of values.

func Normalize

func Normalize(values ...float64) []float64

Normalize returns a set of numbers on the interval [0,1] for a given set of inputs. An example: 4,3,2,1 => 0.4, 0.3, 0.2, 0.1 Caveat; the total may be < 1.0; there are going to be issues with irrational numbers etc.

func ParseFloats

func ParseFloats(values ...string) ([]float64, error)

ParseFloats parses a list of floats.

func ParseTimes

func ParseTimes(layout string, values ...string) ([]time.Time, error)

ParseTimes parses a list of times with a given format.

func PercentDifference

func PercentDifference(v1, v2 float64) float64

PercentDifference computes the percentage difference between two values. The formula is (v2-v1)/v1.

func PercentToRadians

func PercentToRadians(pct float64) float64

PercentToRadians converts a normalized value (0,1) to radians.

func PercentValueFormatter

func PercentValueFormatter(v interface{}) string

PercentValueFormatter is a formatter for percent values. NOTE: it normalizes the values, i.e. multiplies by 100.0.

func RadianAdd

func RadianAdd(base, delta float64) float64

RadianAdd adds a delta to a base in radians.

func RadiansToDegrees

func RadiansToDegrees(value float64) float64

RadiansToDegrees translates a radian value to a degree value.

func RandomValues

func RandomValues(count int) []float64

RandomValues returns an array of random values.

func RandomValuesWithMax

func RandomValuesWithMax(count int, max float64) []float64

RandomValuesWithMax returns an array of random values with a given average.

func RotateCoordinate

func RotateCoordinate(cx, cy, x, y int, thetaRadians float64) (rx, ry int)

RotateCoordinate rotates a coordinate around a given center by a theta in radians.

func RoundDown

func RoundDown(value, roundTo float64) float64

RoundDown rounds down to a given roundTo value.

func RoundPlaces

func RoundPlaces(input float64, places int) (rounded float64)

RoundPlaces rounds an input to a given places.

func RoundUp

func RoundUp(value, roundTo float64) float64

RoundUp rounds up to a given roundTo value.

func SVGWithCSS

func SVGWithCSS(css string, nonce string) func(width, height int) (Renderer, error)

SVGWithCSS returns a new png/raster renderer with attached custom CSS The optional nonce argument sets a CSP nonce.

func SplitCSV

func SplitCSV(text string) (output []string)

SplitCSV splits a corpus by the `,`, dropping leading or trailing whitespace unless quoted.

func Sum

func Sum(values ...float64) float64

Sum sums a set of values.

func SumInt

func SumInt(values ...int) int

SumInt sums a set of values.

func TimeDateValueFormatter

func TimeDateValueFormatter(v interface{}) string

TimeDateValueFormatter is a ValueFormatter for timestamps.

func TimeFromFloat64

func TimeFromFloat64(tf float64) time.Time

TimeFromFloat64 returns a time from a float64.

func TimeHourValueFormatter

func TimeHourValueFormatter(v interface{}) string

TimeHourValueFormatter is a ValueFormatter for timestamps.

func TimeMax

func TimeMax(times ...time.Time) (max time.Time)

TimeMax returns the minimum and maximum times in a given range.

func TimeMillis

func TimeMillis(d time.Duration) float64

TimeMillis returns a duration as a float millis.

func TimeMin

func TimeMin(times ...time.Time) (min time.Time)

TimeMin returns the minimum and maximum times in a given range.

func TimeMinMax

func TimeMinMax(times ...time.Time) (min, max time.Time)

TimeMinMax returns the minimum and maximum times in a given range.

func TimeMinuteValueFormatter

func TimeMinuteValueFormatter(v interface{}) string

TimeMinuteValueFormatter is a ValueFormatter for timestamps.

func TimeToFloat64

func TimeToFloat64(t time.Time) float64

TimeToFloat64 returns a float64 representation of a time.

func TimeValueFormatter

func TimeValueFormatter(v interface{}) string

TimeValueFormatter is a ValueFormatter for timestamps.

func ToFloat64

func ToFloat64(t time.Time) float64

ToFloat64 returns a float64 representation of a time.

Types

type Array

type Array []float64

Array is a wrapper for an array of floats that implements `ValuesProvider`.

func NewArray

func NewArray(values ...float64) Array

NewArray returns a new array from a given set of values. Array implements Sequence, which allows it to be used with the sequence helpers.

func (Array) GetValue

func (a Array) GetValue(index int) float64

GetValue returns the value at a given index.

func (Array) Len

func (a Array) Len() int

Len returns the value provider length.

type Axis

type Axis interface {
	GetName() string
	SetName(name string)

	GetStyle() Style
	SetStyle(style Style)

	GetTicks() []Tick
	GenerateTicks(r Renderer, ra Range, vf ValueFormatter) []Tick

	// GenerateGridLines returns the gridlines for the axis.
	GetGridLines(ticks []Tick) []GridLine

	// Measure should return an absolute box for the axis.
	// This is used when auto-fitting the canvas to the background.
	Measure(r Renderer, canvasBox Box, ra Range, style Style, ticks []Tick) Box

	// Render renders the axis.
	Render(r Renderer, canvasBox Box, ra Range, style Style, ticks []Tick)
}

Axis is a chart feature detailing what values happen where.

type BarChart

type BarChart struct {
	Title      string
	TitleStyle Style

	ColorPalette ColorPalette

	Width  int
	Height int
	DPI    float64

	BarWidth int

	Background Style
	Canvas     Style

	XAxis Style
	YAxis YAxis

	BarSpacing int

	UseBaseValue bool
	BaseValue    float64

	Font *truetype.Font

	Bars     []Value
	Elements []Renderable
	// contains filtered or unexported fields
}

BarChart is a chart that draws bars on a range.

func (BarChart) GetBarSpacing

func (bc BarChart) GetBarSpacing() int

GetBarSpacing returns the spacing between bars.

func (BarChart) GetBarWidth

func (bc BarChart) GetBarWidth() int

GetBarWidth returns the default bar width.

func (BarChart) GetColorPalette

func (bc BarChart) GetColorPalette() ColorPalette

GetColorPalette returns the color palette for the chart.

func (BarChart) GetDPI

func (bc BarChart) GetDPI() float64

GetDPI returns the dpi for the chart.

func (BarChart) GetFont

func (bc BarChart) GetFont() *truetype.Font

GetFont returns the text font.

func (BarChart) GetHeight

func (bc BarChart) GetHeight() int

GetHeight returns the chart height or the default value.

func (BarChart) GetWidth

func (bc BarChart) GetWidth() int

GetWidth returns the chart width or the default value.

func (BarChart) Render

func (bc BarChart) Render(rp RendererProvider, w io.Writer) error

Render renders the chart with the given renderer to the given io.Writer.

func (BarChart) StyleDefaultsTitle added in v2.4.0

func (bc BarChart) StyleDefaultsTitle() Style

type BoundedLastValuesProvider

type BoundedLastValuesProvider interface {
	GetBoundedLastValues() (x, y1, y2 float64)
}

BoundedLastValuesProvider is a special type of value provider that can return it's (potentially computed) bounded last value.

type BoundedValuesProvider

type BoundedValuesProvider interface {
	Len() int
	GetBoundedValues(index int) (x, y1, y2 float64)
}

BoundedValuesProvider allows series to return a range.

type Box

type Box struct {
	Top    int
	Left   int
	Right  int
	Bottom int
	IsSet  bool
}

Box represents the main 4 dimensions of a box.

func NewBox

func NewBox(top, left, right, bottom int) Box

NewBox returns a new (set) box.

func (Box) Aspect

func (b Box) Aspect() float64

Aspect returns the aspect ratio of the box.

func (Box) Center

func (b Box) Center() (x, y int)

Center returns the center of the box

func (Box) Clone

func (b Box) Clone() Box

Clone returns a new copy of the box.

func (Box) Constrain

func (b Box) Constrain(other Box) Box

Constrain is similar to `Fit` except that it will work more literally like the opposite of grow.

func (Box) Corners

func (b Box) Corners() BoxCorners

Corners returns the box as a set of corners.

func (Box) Equals

func (b Box) Equals(other Box) bool

Equals returns if the box equals another box.

func (Box) Fit

func (b Box) Fit(other Box) Box

Fit is functionally the inverse of grow. Fit maintains the original aspect ratio of the `other` box, but constrains it to the bounds of the target box.

func (Box) GetBottom

func (b Box) GetBottom(defaults ...int) int

GetBottom returns a coalesced value with a default.

func (Box) GetLeft

func (b Box) GetLeft(defaults ...int) int

GetLeft returns a coalesced value with a default.

func (Box) GetRight

func (b Box) GetRight(defaults ...int) int

GetRight returns a coalesced value with a default.

func (Box) GetTop

func (b Box) GetTop(defaults ...int) int

GetTop returns a coalesced value with a default.

func (Box) Grow

func (b Box) Grow(other Box) Box

Grow grows a box based on another box.

func (Box) Height

func (b Box) Height() int

Height returns the height

func (Box) IsBiggerThan

func (b Box) IsBiggerThan(other Box) bool

IsBiggerThan returns if a box is bigger than another box.

func (Box) IsSmallerThan

func (b Box) IsSmallerThan(other Box) bool

IsSmallerThan returns if a box is smaller than another box.

func (Box) IsZero

func (b Box) IsZero() bool

IsZero returns if the box is set or not.

func (Box) OuterConstrain

func (b Box) OuterConstrain(bounds, other Box) Box

OuterConstrain is similar to `Constraint` with the difference that it applies corrections

func (Box) Shift

func (b Box) Shift(x, y int) Box

Shift pushes a box by x,y.

func (Box) String

func (b Box) String() string

String returns a string representation of the box.

func (Box) Width

func (b Box) Width() int

Width returns the width

type BoxCorners

type BoxCorners struct {
	TopLeft, TopRight, BottomRight, BottomLeft Point
}

BoxCorners is a box with independent corners.

func (BoxCorners) Box

func (bc BoxCorners) Box() Box

Box return the BoxCorners as a regular box.

func (BoxCorners) Center

func (bc BoxCorners) Center() (x, y int)

Center returns the center of the box

func (BoxCorners) Equals

func (bc BoxCorners) Equals(other BoxCorners) bool

Equals returns if the box equals another box.

func (BoxCorners) Height

func (bc BoxCorners) Height() int

Height returns the height

func (BoxCorners) Rotate

func (bc BoxCorners) Rotate(thetaDegrees float64) BoxCorners

Rotate rotates the box.

func (BoxCorners) String

func (bc BoxCorners) String() string

func (BoxCorners) Width

func (bc BoxCorners) Width() int

Width returns the width

type Chart

type Chart struct {
	Title      string
	TitleStyle Style

	ColorPalette ColorPalette

	Width  int
	Height int
	DPI    float64

	Background Style
	Canvas     Style

	XAxis          XAxis
	YAxis          YAxis
	YAxisSecondary YAxis

	Font *truetype.Font

	Series   []Series
	Elements []Renderable

	Log Logger
	// contains filtered or unexported fields
}

Chart is what we're drawing.

func (Chart) Box

func (c Chart) Box() Box

Box returns the chart bounds as a box.

func (Chart) GetColorPalette

func (c Chart) GetColorPalette() ColorPalette

GetColorPalette returns the color palette for the chart.

func (Chart) GetDPI

func (c Chart) GetDPI(defaults ...float64) float64

GetDPI returns the dpi for the chart.

func (Chart) GetFont

func (c Chart) GetFont() *truetype.Font

GetFont returns the text font.

func (Chart) GetHeight

func (c Chart) GetHeight() int

GetHeight returns the chart height or the default value.

func (Chart) GetWidth

func (c Chart) GetWidth() int

GetWidth returns the chart width or the default value.

func (Chart) Render

func (c Chart) Render(rp RendererProvider, w io.Writer) error

Render renders the chart with the given renderer to the given io.Writer.

type ColorPalette

type ColorPalette interface {
	BackgroundColor() drawing.Color
	BackgroundStrokeColor() drawing.Color
	CanvasColor() drawing.Color
	CanvasStrokeColor() drawing.Color
	AxisStrokeColor() drawing.Color
	TextColor() drawing.Color
	GetSeriesColor(index int) drawing.Color
}

ColorPalette is a set of colors that.

type ColorProvider

type ColorProvider func(v, vmin, vmax float64) drawing.Color

ColorProvider is a general provider for color ranges based on values.

type ConcatSeries

type ConcatSeries []Series

ConcatSeries is a special type of series that concatenates its `InnerSeries`.

func (ConcatSeries) GetValue

func (cs ConcatSeries) GetValue(index int) (x, y float64)

GetValue returns the value at the (meta) index (i.e 0 => totalLen-1)

func (ConcatSeries) Len

func (cs ConcatSeries) Len() int

Len returns the length of the concatenated set of series.

func (ConcatSeries) Validate

func (cs ConcatSeries) Validate() error

Validate validates the series.

type ContinuousRange

type ContinuousRange struct {
	Min        float64
	Max        float64
	Domain     int
	Descending bool
}

ContinuousRange represents a boundary for a set of numbers.

func (ContinuousRange) GetDelta

func (r ContinuousRange) GetDelta() float64

GetDelta returns the difference between the min and max value.

func (ContinuousRange) GetDomain

func (r ContinuousRange) GetDomain() int

GetDomain returns the range domain.

func (ContinuousRange) GetMax

func (r ContinuousRange) GetMax() float64

GetMax returns the max value for the continuous range.

func (ContinuousRange) GetMin

func (r ContinuousRange) GetMin() float64

GetMin gets the min value for the continuous range.

func (ContinuousRange) IsDescending

func (r ContinuousRange) IsDescending() bool

IsDescending returns if the range is descending.

func (ContinuousRange) IsZero

func (r ContinuousRange) IsZero() bool

IsZero returns if the ContinuousRange has been set or not.

func (*ContinuousRange) SetDomain

func (r *ContinuousRange) SetDomain(domain int)

SetDomain sets the range domain.

func (*ContinuousRange) SetMax

func (r *ContinuousRange) SetMax(max float64)

SetMax sets the max value for the continuous range.

func (*ContinuousRange) SetMin

func (r *ContinuousRange) SetMin(min float64)

SetMin sets the min value for the continuous range.

func (ContinuousRange) String

func (r ContinuousRange) String() string

String returns a simple string for the ContinuousRange.

func (ContinuousRange) Translate

func (r ContinuousRange) Translate(value float64) int

Translate maps a given value into the ContinuousRange space.

type ContinuousSeries

type ContinuousSeries struct {
	Name  string
	Style Style

	YAxis YAxisType

	XValueFormatter ValueFormatter
	YValueFormatter ValueFormatter

	XValues []float64
	YValues []float64
}

ContinuousSeries represents a line on a chart.

func (ContinuousSeries) GetFirstValues

func (cs ContinuousSeries) GetFirstValues() (x, y float64)

GetFirstValues gets the first x,y values.

func (ContinuousSeries) GetLastValues

func (cs ContinuousSeries) GetLastValues() (x, y float64)

GetLastValues gets the last x,y values.

func (ContinuousSeries) GetName

func (cs ContinuousSeries) GetName() string

GetName returns the name of the time series.

func (ContinuousSeries) GetStyle

func (cs ContinuousSeries) GetStyle() Style

GetStyle returns the line style.

func (ContinuousSeries) GetValueFormatters

func (cs ContinuousSeries) GetValueFormatters() (x, y ValueFormatter)

GetValueFormatters returns value formatter defaults for the series.

func (ContinuousSeries) GetValues

func (cs ContinuousSeries) GetValues(index int) (x, y float64)

GetValues gets the x,y values at a given index.

func (ContinuousSeries) GetYAxis

func (cs ContinuousSeries) GetYAxis() YAxisType

GetYAxis returns which YAxis the series draws on.

func (ContinuousSeries) Len

func (cs ContinuousSeries) Len() int

Len returns the number of elements in the series.

func (ContinuousSeries) Render

func (cs ContinuousSeries) Render(r Renderer, canvasBox Box, xrange, yrange Range, defaults Style)

Render renders the series.

func (ContinuousSeries) Validate

func (cs ContinuousSeries) Validate() error

Validate validates the series.

type DotColorProvider

type DotColorProvider func(xrange, yrange Range, index int, x, y float64) drawing.Color

DotColorProvider is a provider for dot color.

type FirstValuesProvider

type FirstValuesProvider interface {
	GetFirstValues() (x, y float64)
}

FirstValuesProvider is a special type of value provider that can return it's (potentially computed) first value.

type FullBoundedValuesProvider

type FullBoundedValuesProvider interface {
	BoundedValuesProvider
	BoundedLastValuesProvider
}

FullBoundedValuesProvider is an interface that combines `BoundedValuesProvider` and `BoundedLastValuesProvider`

type FullValuesProvider

type FullValuesProvider interface {
	ValuesProvider
	LastValuesProvider
}

FullValuesProvider is an interface that combines `ValuesProvider` and `LastValuesProvider`

type GridLine

type GridLine struct {
	IsMinor bool
	Style   Style
	Value   float64
}

GridLine is a line on a graph canvas.

func GenerateGridLines

func GenerateGridLines(ticks []Tick, majorStyle, minorStyle Style) []GridLine

GenerateGridLines generates grid lines.

func (GridLine) Major

func (gl GridLine) Major() bool

Major returns if the gridline is a `major` line.

func (GridLine) Minor

func (gl GridLine) Minor() bool

Minor returns if the gridline is a `minor` line.

func (GridLine) Render

func (gl GridLine) Render(r Renderer, canvasBox Box, ra Range, isVertical bool, defaults Style)

Render renders the gridline

type GridLineProvider

type GridLineProvider interface {
	GetGridLines(ticks []Tick, isVertical bool, majorStyle, minorStyle Style) []GridLine
}

GridLineProvider is a type that provides grid lines.

type ImageWriter

type ImageWriter struct {
	// contains filtered or unexported fields
}

ImageWriter is a special type of io.Writer that produces a final image.

func (*ImageWriter) Image

func (ir *ImageWriter) Image() (image.Image, error)

Image returns an *image.Image for the result.

func (*ImageWriter) SetRGBA

func (ir *ImageWriter) SetRGBA(i *image.RGBA)

SetRGBA sets a raw version of the image.

func (*ImageWriter) Write

func (ir *ImageWriter) Write(buffer []byte) (int, error)

type IsZeroable

type IsZeroable interface {
	IsZero() bool
}

IsZeroable is a type that returns if it's been set or not.

type LastValuesProvider

type LastValuesProvider interface {
	GetLastValues() (x, y float64)
}

LastValuesProvider is a special type of value provider that can return it's (potentially computed) last value.

type LinearCoefficientProvider

type LinearCoefficientProvider interface {
	Coefficients() (m, b, stdev, avg float64)
}

LinearCoefficientProvider is a type that returns linear cofficients.

type LinearCoefficientSet

type LinearCoefficientSet struct {
	M      float64
	B      float64
	StdDev float64
	Avg    float64
}

LinearCoefficientSet is the m and b values for the linear equation in the form: y = (m*x) + b

func LinearCoefficients

func LinearCoefficients(m, b float64) LinearCoefficientSet

LinearCoefficients returns a fixed linear coefficient pair.

func NormalizedLinearCoefficients

func NormalizedLinearCoefficients(m, b, stdev, avg float64) LinearCoefficientSet

NormalizedLinearCoefficients returns a fixed linear coefficient pair.

func (LinearCoefficientSet) Coefficients

func (lcs LinearCoefficientSet) Coefficients() (m, b, stdev, avg float64)

Coefficients returns the coefficients.

type LinearRegressionSeries

type LinearRegressionSeries struct {
	Name  string
	Style Style
	YAxis YAxisType

	Limit       int
	Offset      int
	InnerSeries ValuesProvider
	// contains filtered or unexported fields
}

LinearRegressionSeries is a series that plots the n-nearest neighbors linear regression for the values.

func (LinearRegressionSeries) Coefficients

func (lrs LinearRegressionSeries) Coefficients() (m, b, stdev, avg float64)

Coefficients returns the linear coefficients for the series.

func (LinearRegressionSeries) GetEndIndex

func (lrs LinearRegressionSeries) GetEndIndex() int

GetEndIndex returns the effective limit end.

func (*LinearRegressionSeries) GetFirstValues

func (lrs *LinearRegressionSeries) GetFirstValues() (x, y float64)

GetFirstValues computes the first linear regression value.

func (*LinearRegressionSeries) GetLastValues

func (lrs *LinearRegressionSeries) GetLastValues() (x, y float64)

GetLastValues computes the last linear regression value.

func (LinearRegressionSeries) GetLimit

func (lrs LinearRegressionSeries) GetLimit() int

GetLimit returns the window size.

func (LinearRegressionSeries) GetName

func (lrs LinearRegressionSeries) GetName() string

GetName returns the name of the time series.

func (LinearRegressionSeries) GetOffset

func (lrs LinearRegressionSeries) GetOffset() int

GetOffset returns the data offset.

func (LinearRegressionSeries) GetStyle

func (lrs LinearRegressionSeries) GetStyle() Style

GetStyle returns the line style.

func (*LinearRegressionSeries) GetValues

func (lrs *LinearRegressionSeries) GetValues(index int) (x, y float64)

GetValues gets a value at a given index.

func (LinearRegressionSeries) GetYAxis

func (lrs LinearRegressionSeries) GetYAxis() YAxisType

GetYAxis returns which YAxis the series draws on.

func (*LinearRegressionSeries) IsZero

func (lrs *LinearRegressionSeries) IsZero() bool

IsZero returns if we've computed the coefficients or not.

func (LinearRegressionSeries) Len

func (lrs LinearRegressionSeries) Len() int

Len returns the number of elements in the series.

func (*LinearRegressionSeries) Render

func (lrs *LinearRegressionSeries) Render(r Renderer, canvasBox Box, xrange, yrange Range, defaults Style)

Render renders the series.

func (*LinearRegressionSeries) Validate

func (lrs *LinearRegressionSeries) Validate() error

Validate validates the series.

type LinearSeq

type LinearSeq struct {
	// contains filtered or unexported fields
}

LinearSeq is a stepwise generator.

func NewLinearSequence

func NewLinearSequence() *LinearSeq

NewLinearSequence returns a new linear generator.

func (LinearSeq) End

func (lg LinearSeq) End() float64

End returns the end value.

func (LinearSeq) GetValue

func (lg LinearSeq) GetValue(index int) float64

GetValue returns the value at a given index.

func (LinearSeq) Len

func (lg LinearSeq) Len() int

Len returns the number of elements in the seq.

func (LinearSeq) Start

func (lg LinearSeq) Start() float64

Start returns the start value.

func (LinearSeq) Step

func (lg LinearSeq) Step() float64

Step returns the step value.

func (*LinearSeq) WithEnd

func (lg *LinearSeq) WithEnd(end float64) *LinearSeq

WithEnd sets the end and returns the linear generator.

func (*LinearSeq) WithStart

func (lg *LinearSeq) WithStart(start float64) *LinearSeq

WithStart sets the start and returns the linear generator.

func (*LinearSeq) WithStep

func (lg *LinearSeq) WithStep(step float64) *LinearSeq

WithStep sets the step and returns the linear generator.

type LinearSeries

type LinearSeries struct {
	Name  string
	Style Style
	YAxis YAxisType

	XValues     []float64
	InnerSeries LinearCoefficientProvider
	// contains filtered or unexported fields
}

LinearSeries is a series that plots a line in a given domain.

func (LinearSeries) GetEndIndex

func (ls LinearSeries) GetEndIndex() int

GetEndIndex returns the effective limit end.

func (*LinearSeries) GetFirstValues

func (ls *LinearSeries) GetFirstValues() (x, y float64)

GetFirstValues computes the first linear regression value.

func (*LinearSeries) GetLastValues

func (ls *LinearSeries) GetLastValues() (x, y float64)

GetLastValues computes the last linear regression value.

func (LinearSeries) GetName

func (ls LinearSeries) GetName() string

GetName returns the name of the time series.

func (LinearSeries) GetStyle

func (ls LinearSeries) GetStyle() Style

GetStyle returns the line style.

func (*LinearSeries) GetValues

func (ls *LinearSeries) GetValues(index int) (x, y float64)

GetValues gets a value at a given index.

func (LinearSeries) GetYAxis

func (ls LinearSeries) GetYAxis() YAxisType

GetYAxis returns which YAxis the series draws on.

func (LinearSeries) IsZero

func (ls LinearSeries) IsZero() bool

IsZero returns if the linear series has computed coefficients or not.

func (LinearSeries) Len

func (ls LinearSeries) Len() int

Len returns the number of elements in the series.

func (*LinearSeries) Render

func (ls *LinearSeries) Render(r Renderer, canvasBox Box, xrange, yrange Range, defaults Style)

Render renders the series.

func (LinearSeries) Validate

func (ls LinearSeries) Validate() error

Validate validates the series.

type Logger

type Logger interface {
	Info(...interface{})
	Infof(string, ...interface{})
	Debug(...interface{})
	Debugf(string, ...interface{})
	Err(error)
	FatalErr(error)
	Error(...interface{})
	Errorf(string, ...interface{})
}

Logger is a type that implements the logging interface.

func NewLogger

func NewLogger(options ...LoggerOption) Logger

NewLogger returns a new logger.

type LoggerOption

type LoggerOption = func(*StdoutLogger)

LoggerOption mutates a stdout logger.

func OptLoggerStderr

func OptLoggerStderr(wr io.Writer) LoggerOption

OptLoggerStderr sets the Stdout writer.

func OptLoggerStdout

func OptLoggerStdout(wr io.Writer) LoggerOption

OptLoggerStdout sets the Stdout writer.

type NameProvider

type NameProvider interface {
	GetName() string
}

NameProvider is a type that returns a name.

type Point

type Point struct {
	X, Y int
}

Point is an X,Y pair

func (Point) DistanceTo

func (p Point) DistanceTo(other Point) float64

DistanceTo calculates the distance to another point.

func (Point) Equals

func (p Point) Equals(other Point) bool

Equals returns if a point equals another point.

func (Point) String

func (p Point) String() string

String returns a string representation of the point.

type RGBACollector

type RGBACollector interface {
	SetRGBA(i *image.RGBA)
}

RGBACollector is a render target for a chart.

type RandomSeq

type RandomSeq struct {
	// contains filtered or unexported fields
}

RandomSeq is a random number seq generator.

func NewRandomSequence

func NewRandomSequence() *RandomSeq

NewRandomSequence creates a new random seq.

func (*RandomSeq) GetValue

func (r *RandomSeq) GetValue(_ int) float64

GetValue returns the value.

func (*RandomSeq) Len

func (r *RandomSeq) Len() int

Len returns the number of elements that will be generated.

func (RandomSeq) Max

func (r RandomSeq) Max() *float64

Max returns the maximum value.

func (RandomSeq) Min

func (r RandomSeq) Min() *float64

Min returns the minimum value.

func (*RandomSeq) WithLen

func (r *RandomSeq) WithLen(length int) *RandomSeq

WithLen sets a maximum len

func (*RandomSeq) WithMax

func (r *RandomSeq) WithMax(max float64) *RandomSeq

WithMax sets the average and returns the Random.

func (*RandomSeq) WithMin

func (r *RandomSeq) WithMin(min float64) *RandomSeq

WithMin sets the scale and returns the Random.

type Range

type Range interface {
	Stringable
	IsZeroable

	GetMin() float64
	SetMin(min float64)

	GetMax() float64
	SetMax(max float64)

	GetDelta() float64

	GetDomain() int
	SetDomain(domain int)

	IsDescending() bool

	// Translate the range to the domain.
	Translate(value float64) int
}

Range is a common interface for a range of values.

type Renderable

type Renderable func(r Renderer, canvasBox Box, defaults Style)

Renderable is a function that can be called to render custom elements on the chart.

func Legend

func Legend(c *Chart, userDefaults ...Style) Renderable

Legend returns a legend renderable function.

func LegendLeft

func LegendLeft(c *Chart, userDefaults ...Style) Renderable

LegendLeft is a legend that is designed for longer series lists.

func LegendThin

func LegendThin(c *Chart, userDefaults ...Style) Renderable

LegendThin is a legend that doesn't obscure the chart area.

type Renderer

type Renderer interface {
	// ResetStyle should reset any style related settings on the renderer.
	ResetStyle()

	// GetDPI gets the DPI for the renderer.
	GetDPI() float64

	// SetDPI sets the DPI for the renderer.
	SetDPI(dpi float64)

	// SetClassName sets the current class name.
	SetClassName(string)

	// SetStrokeColor sets the current stroke color.
	SetStrokeColor(drawing.Color)

	// SetFillColor sets the current fill color.
	SetFillColor(drawing.Color)

	// SetStrokeWidth sets the stroke width.
	SetStrokeWidth(width float64)

	// SetStrokeDashArray sets the stroke dash array.
	SetStrokeDashArray(dashArray []float64)

	// MoveTo moves the cursor to a given point.
	MoveTo(x, y int)

	// LineTo both starts a shape and draws a line to a given point
	// from the previous point.
	LineTo(x, y int)

	// QuadCurveTo draws a quad curve.
	// cx and cy represent the bezier "control points".
	QuadCurveTo(cx, cy, x, y int)

	// Close finalizes a shape as drawn by LineTo.
	Close()

	// Stroke strokes the path.
	Stroke()

	// Fill fills the path, but does not stroke.
	Fill()

	// FillStroke fills and strokes a path.
	FillStroke()

	// Circle draws a circle at the given coords with a given radius.
	Circle(radius float64, x, y int)

	// SetFont sets a font for a text field.
	SetFont(*truetype.Font)

	// SetFontColor sets a font's color
	SetFontColor(drawing.Color)

	// SetFontSize sets the font size for a text field.
	SetFontSize(size float64)

	// Text draws a text blob.
	Text(body string, x, y int)

	// MeasureText measures text.
	MeasureText(body string) Box

	// SetTextRotatation sets a rotation for drawing elements.
	SetTextRotation(radians float64)

	// ClearTextRotation clears rotation.
	ClearTextRotation()

	// Save writes the image to the given writer.
	Save(w io.Writer) error
}

Renderer represents the basic methods required to draw a chart.

func PNG

func PNG(width, height int) (Renderer, error)

PNG returns a new png/raster renderer.

func SVG

func SVG(width, height int) (Renderer, error)

SVG returns a new png/raster renderer.

type RendererProvider

type RendererProvider func(int, int) (Renderer, error)

RendererProvider is a function that returns a renderer.

type Seq

type Seq struct {
	Sequence
}

Seq is a utility wrapper for seq providers.

func ValueSequence

func ValueSequence(values ...float64) Seq

ValueSequence returns a sequence for a given values set.

func (Seq) Average

func (s Seq) Average() float64

Average returns the float average of the values in the buffer.

func (Seq) Each

func (s Seq) Each(mapfn func(int, float64))

Each applies the `mapfn` to all values in the value provider.

func (Seq) FoldLeft

func (s Seq) FoldLeft(mapfn func(i int, v0, v float64) float64) (v0 float64)

FoldLeft collapses a seq from left to right.

func (Seq) FoldRight

func (s Seq) FoldRight(mapfn func(i int, v0, v float64) float64) (v0 float64)

FoldRight collapses a seq from right to left.

func (Seq) Map

func (s Seq) Map(mapfn func(i int, v float64) float64) Seq

Map applies the `mapfn` to all values in the value provider, returning a new seq.

func (Seq) Max

func (s Seq) Max() float64

Max returns the maximum value in the seq.

func (Seq) Median

func (s Seq) Median() (median float64)

Median returns the median or middle value in the sorted seq.

func (Seq) Min

func (s Seq) Min() float64

Min returns the minimum value in the seq.

func (Seq) MinMax

func (s Seq) MinMax() (min, max float64)

MinMax returns the minimum and the maximum in one pass.

func (Seq) Normalize

func (s Seq) Normalize() Seq

Normalize maps every value to the interval [0, 1.0].

func (Seq) Percentile

func (s Seq) Percentile(percent float64) (percentile float64)

Percentile finds the relative standing in a slice of floats. `percent` should be given on the interval [0,1.0).

func (Seq) Reverse

func (s Seq) Reverse() Seq

Reverse reverses the sequence

func (Seq) Sort

func (s Seq) Sort() Seq

Sort returns the seq sorted in ascending order. This fully enumerates the seq.

func (Seq) StdDev

func (s Seq) StdDev() float64

StdDev returns the standard deviation.

func (Seq) Sum

func (s Seq) Sum() (accum float64)

Sum adds all the elements of a series together.

func (Seq) Values

func (s Seq) Values() (output []float64)

Values enumerates the seq into a slice.

func (Seq) Variance

func (s Seq) Variance() float64

Variance computes the variance of the buffer.

type Sequence

type Sequence interface {
	Len() int
	GetValue(int) float64
}

Sequence is a provider for values for a seq.

type Series

type Series interface {
	GetName() string
	GetYAxis() YAxisType
	GetStyle() Style
	Validate() error
	Render(r Renderer, canvasBox Box, xrange, yrange Range, s Style)
}

Series is an alias to Renderable.

type SizeProvider

type SizeProvider func(xrange, yrange Range, index int, x, y float64) float64

SizeProvider is a provider for integer size.

type StdoutLogger

type StdoutLogger struct {
	TimeFormat string
	Stdout     io.Writer
	Stderr     io.Writer
}

StdoutLogger is a basic logger.

func (*StdoutLogger) Debug

func (l *StdoutLogger) Debug(arguments ...interface{})

Debug writes an debug message.

func (*StdoutLogger) Debugf

func (l *StdoutLogger) Debugf(format string, arguments ...interface{})

Debugf writes an debug message.

func (*StdoutLogger) Err

func (l *StdoutLogger) Err(err error)

Err writes an error message.

func (*StdoutLogger) Error

func (l *StdoutLogger) Error(arguments ...interface{})

Error writes an error message.

func (*StdoutLogger) Errorf

func (l *StdoutLogger) Errorf(format string, arguments ...interface{})

Errorf writes an error message.

func (*StdoutLogger) Errorln

func (l *StdoutLogger) Errorln(arguments ...interface{})

Errorln prints a new message.

func (*StdoutLogger) FatalErr

func (l *StdoutLogger) FatalErr(err error)

FatalErr writes an error message and exits.

func (*StdoutLogger) Info

func (l *StdoutLogger) Info(arguments ...interface{})

Info writes an info message.

func (*StdoutLogger) Infof

func (l *StdoutLogger) Infof(format string, arguments ...interface{})

Infof writes an info message.

func (*StdoutLogger) Println

func (l *StdoutLogger) Println(arguments ...interface{})

Println prints a new message.

type Stringable

type Stringable interface {
	String() string
}

Stringable is a type that has a string representation.

type Style

type Style struct {
	Hidden  bool
	Padding Box

	ClassName string

	StrokeWidth     float64
	StrokeColor     drawing.Color
	StrokeDashArray []float64

	DotColor drawing.Color
	DotWidth float64

	DotWidthProvider SizeProvider
	DotColorProvider DotColorProvider

	FillColor drawing.Color

	FontSize  float64
	FontColor drawing.Color
	Font      *truetype.Font

	TextHorizontalAlign TextHorizontalAlign
	TextVerticalAlign   TextVerticalAlign
	TextWrap            TextWrap
	TextLineSpacing     int
	TextRotationDegrees float64 // 0 is unset or normal
}

Style is a simple style set.

func Hidden

func Hidden() Style

Hidden is a prebuilt style with the `Hidden` property set to true.

func Shown

func Shown() Style

Shown is a prebuilt style with the `Hidden` property set to false. You can also think of this as the default.

func StyleTextDefaults

func StyleTextDefaults() Style

StyleTextDefaults returns a style for drawing outside a chart context.

func (Style) GetClassName

func (s Style) GetClassName(defaults ...string) string

GetClassName returns the class name or a default.

func (Style) GetDotColor

func (s Style) GetDotColor(defaults ...drawing.Color) drawing.Color

GetDotColor returns the stroke color.

func (Style) GetDotOptions

func (s Style) GetDotOptions() Style

GetDotOptions returns the dot components.

func (Style) GetDotWidth

func (s Style) GetDotWidth(defaults ...float64) float64

GetDotWidth returns the dot width for scatter plots.

func (Style) GetFillAndStrokeOptions

func (s Style) GetFillAndStrokeOptions() Style

GetFillAndStrokeOptions returns the fill and stroke components.

func (Style) GetFillColor

func (s Style) GetFillColor(defaults ...drawing.Color) drawing.Color

GetFillColor returns the fill color.

func (Style) GetFillOptions

func (s Style) GetFillOptions() Style

GetFillOptions returns the fill components.

func (Style) GetFont

func (s Style) GetFont(defaults ...*truetype.Font) *truetype.Font

GetFont returns the font face.

func (Style) GetFontColor

func (s Style) GetFontColor(defaults ...drawing.Color) drawing.Color

GetFontColor gets the font size.

func (Style) GetFontSize

func (s Style) GetFontSize(defaults ...float64) float64

GetFontSize gets the font size.

func (Style) GetPadding

func (s Style) GetPadding(defaults ...Box) Box

GetPadding returns the padding.

func (Style) GetStrokeColor

func (s Style) GetStrokeColor(defaults ...drawing.Color) drawing.Color

GetStrokeColor returns the stroke color.

func (Style) GetStrokeDashArray

func (s Style) GetStrokeDashArray(defaults ...[]float64) []float64

GetStrokeDashArray returns the stroke dash array.

func (Style) GetStrokeOptions

func (s Style) GetStrokeOptions() Style

GetStrokeOptions returns the stroke components.

func (Style) GetStrokeWidth

func (s Style) GetStrokeWidth(defaults ...float64) float64

GetStrokeWidth returns the stroke width.

func (Style) GetTextHorizontalAlign

func (s Style) GetTextHorizontalAlign(defaults ...TextHorizontalAlign) TextHorizontalAlign

GetTextHorizontalAlign returns the horizontal alignment.

func (Style) GetTextLineSpacing

func (s Style) GetTextLineSpacing(defaults ...int) int

GetTextLineSpacing returns the spacing in pixels between lines of text (vertically).

func (Style) GetTextOptions

func (s Style) GetTextOptions() Style

GetTextOptions returns just the text components of the style.

func (Style) GetTextRotationDegrees

func (s Style) GetTextRotationDegrees(defaults ...float64) float64

GetTextRotationDegrees returns the text rotation in degrees.

func (Style) GetTextVerticalAlign

func (s Style) GetTextVerticalAlign(defaults ...TextVerticalAlign) TextVerticalAlign

GetTextVerticalAlign returns the vertical alignment.

func (Style) GetTextWrap

func (s Style) GetTextWrap(defaults ...TextWrap) TextWrap

GetTextWrap returns the word wrap.

func (Style) InheritFrom

func (s Style) InheritFrom(defaults Style) (final Style)

InheritFrom coalesces two styles into a new style.

func (Style) IsZero

func (s Style) IsZero() bool

IsZero returns if the object is set or not.

func (Style) ShouldDrawDot

func (s Style) ShouldDrawDot() bool

ShouldDrawDot tells drawing functions if they should draw the dot.

func (Style) ShouldDrawFill

func (s Style) ShouldDrawFill() bool

ShouldDrawFill tells drawing functions if they should draw the stroke.

func (Style) ShouldDrawStroke

func (s Style) ShouldDrawStroke() bool

ShouldDrawStroke tells drawing functions if they should draw the stroke.

func (Style) String

func (s Style) String() string

String returns a text representation of the style.

func (Style) WriteDrawingOptionsToRenderer

func (s Style) WriteDrawingOptionsToRenderer(r Renderer)

WriteDrawingOptionsToRenderer passes just the drawing style options to a renderer.

func (Style) WriteTextOptionsToRenderer

func (s Style) WriteTextOptionsToRenderer(r Renderer)

WriteTextOptionsToRenderer passes just the text style options to a renderer.

func (Style) WriteToRenderer

func (s Style) WriteToRenderer(r Renderer)

WriteToRenderer passes the style's options to a renderer.

type StyleProvider

type StyleProvider interface {
	GetStyle() Style
}

StyleProvider is a type that returns a style.

type TextHorizontalAlign

type TextHorizontalAlign int

TextHorizontalAlign is an enum for the horizontal alignment options.

const (
	// TextHorizontalAlignUnset is the unset state for text horizontal alignment.
	TextHorizontalAlignUnset TextHorizontalAlign = 0
	// TextHorizontalAlignLeft aligns a string horizontally so that it's left ligature starts at horizontal pixel 0.
	TextHorizontalAlignLeft TextHorizontalAlign = 1
	// TextHorizontalAlignCenter left aligns a string horizontally so that there are equal pixels
	// to the left and to the right of a string within a box.
	TextHorizontalAlignCenter TextHorizontalAlign = 2
	// TextHorizontalAlignRight right aligns a string horizontally so that the right ligature ends at the right-most pixel
	// of a box.
	TextHorizontalAlignRight TextHorizontalAlign = 3
)

type TextStyle

type TextStyle struct {
	HorizontalAlign TextHorizontalAlign
	VerticalAlign   TextVerticalAlign
	Wrap            TextWrap
}

TextStyle encapsulates text style options.

type TextVerticalAlign

type TextVerticalAlign int

TextVerticalAlign is an enum for the vertical alignment options.

const (
	// TextVerticalAlignUnset is the unset state for vertical alignment options.
	TextVerticalAlignUnset TextVerticalAlign = 0
	// TextVerticalAlignBaseline aligns text according to the "baseline" of the string, or where a normal ascender begins.
	TextVerticalAlignBaseline TextVerticalAlign = 1
	// TextVerticalAlignBottom aligns the text according to the lowers pixel of any of the ligatures (ex. g or q both extend below the baseline).
	TextVerticalAlignBottom TextVerticalAlign = 2
	// TextVerticalAlignMiddle aligns the text so that there is an equal amount of space above and below the top and bottom of the ligatures.
	TextVerticalAlignMiddle TextVerticalAlign = 3
	// TextVerticalAlignMiddleBaseline aligns the text vertically so that there is an equal number of pixels above and below the baseline of the string.
	TextVerticalAlignMiddleBaseline TextVerticalAlign = 4
	// TextVerticalAlignTop alignts the text so that the top of the ligatures are at y-pixel 0 in the container.
	TextVerticalAlignTop TextVerticalAlign = 5
)

type TextWrap

type TextWrap int

TextWrap is an enum for the word wrap options.

const (
	// TextWrapUnset is the unset state for text wrap options.
	TextWrapUnset TextWrap = 0
	// TextWrapNone will spill text past horizontal boundaries.
	TextWrapNone TextWrap = 1
	// TextWrapWord will split a string on words (i.e. spaces) to fit within a horizontal boundary.
	TextWrapWord TextWrap = 2
	// TextWrapRune will split a string on a rune (i.e. utf-8 codepage) to fit within a horizontal boundary.
	TextWrapRune TextWrap = 3
)

type Tick

type Tick struct {
	Value float64
	Label string
}

Tick represents a label on an axis.

func GenerateContinuousTicks

func GenerateContinuousTicks(r Renderer, ra Range, isVertical bool, style Style, vf ValueFormatter) []Tick

GenerateContinuousTicks generates a set of ticks.

type TickPosition

type TickPosition int

TickPosition is an enumeration of possible tick drawing positions.

const (
	// TickPositionUnset means to use the default tick position.
	TickPositionUnset TickPosition = 0
	// TickPositionBetweenTicks draws the labels for a tick between the previous and current tick.
	TickPositionBetweenTicks TickPosition = 1
	// TickPositionUnderTick draws the tick below the tick.
	TickPositionUnderTick TickPosition = 2
)

type Ticks

type Ticks []Tick

Ticks is an array of ticks.

func (Ticks) Len

func (t Ticks) Len() int

Len returns the length of the ticks set.

func (Ticks) Less

func (t Ticks) Less(i, j int) bool

Less returns if i's value is less than j's value.

func (Ticks) String

func (t Ticks) String() string

String returns a string representation of the set of ticks.

func (Ticks) Swap

func (t Ticks) Swap(i, j int)

Swap swaps two elements.

type TicksProvider

type TicksProvider interface {
	GetTicks(r Renderer, defaults Style, vf ValueFormatter) []Tick
}

TicksProvider is a type that provides ticks.

type TimeAscending

type TimeAscending []time.Time

TimeAscending sorts a given list of times ascending, or min to max.

func (TimeAscending) Len

func (a TimeAscending) Len() int

Len implements sort.Sorter

func (TimeAscending) Less

func (a TimeAscending) Less(i, j int) bool

Less implements sort.Sorter

func (TimeAscending) Swap

func (a TimeAscending) Swap(i, j int)

Swap implements sort.Sorter

type TimeDescending

type TimeDescending []time.Time

TimeDescending sorts a given list of times ascending, or min to max.

func (TimeDescending) Len

func (d TimeDescending) Len() int

Len implements sort.Sorter

func (TimeDescending) Less

func (d TimeDescending) Less(i, j int) bool

Less implements sort.Sorter

func (TimeDescending) Swap

func (d TimeDescending) Swap(i, j int)

Swap implements sort.Sorter

type TimeSeries

type TimeSeries struct {
	Name  string
	Style Style

	YAxis YAxisType

	XValues []time.Time
	YValues []float64
}

TimeSeries is a line on a chart.

func (TimeSeries) GetFirstValues

func (ts TimeSeries) GetFirstValues() (x, y float64)

GetFirstValues gets the first values.

func (TimeSeries) GetLastValues

func (ts TimeSeries) GetLastValues() (x, y float64)

GetLastValues gets the last values.

func (TimeSeries) GetName

func (ts TimeSeries) GetName() string

GetName returns the name of the time series.

func (TimeSeries) GetStyle

func (ts TimeSeries) GetStyle() Style

GetStyle returns the line style.

func (TimeSeries) GetValueFormatters

func (TimeSeries) GetValueFormatters() (x, y ValueFormatter)

GetValueFormatters returns value formatter defaults for the series.

func (TimeSeries) GetValues

func (ts TimeSeries) GetValues(index int) (x, y float64)

GetValues gets x, y values at a given index.

func (TimeSeries) GetYAxis

func (ts TimeSeries) GetYAxis() YAxisType

GetYAxis returns which YAxis the series draws on.

func (TimeSeries) Len

func (ts TimeSeries) Len() int

Len returns the number of elements in the series.

func (TimeSeries) Render

func (ts TimeSeries) Render(r Renderer, canvasBox Box, xrange, yrange Range, defaults Style)

Render renders the series.

func (TimeSeries) Validate

func (ts TimeSeries) Validate() error

Validate validates the series.

type Times

type Times []time.Time

Times are an array of times. It wraps the array with methods that implement `seq.Provider`.

func (Times) Array

func (t Times) Array() []time.Time

Array returns the times to an array.

func (Times) GetValue

func (t Times) GetValue(index int) float64

GetValue returns a value at an index as a time.

func (Times) Len

func (t Times) Len() int

Len returns the length of the array.

func (Times) Less

func (t Times) Less(i, j int) bool

Less implements sort.Interface.

func (Times) Swap

func (t Times) Swap(i, j int)

Swap implements sort.Interface.

type Value

type Value struct {
	Style Style
	Label string
	Value float64
}

Value is a chart value.

type Value2

type Value2 struct {
	Style          Style
	Label          string
	XValue, YValue float64
}

Value2 is a two axis value.

type ValueBuffer

type ValueBuffer struct {
	// contains filtered or unexported fields
}

ValueBuffer is a fifo datastructure that is backed by a pre-allocated array. Instead of allocating a whole new node object for each element, array elements are re-used (which saves GC churn). Enqueue can be O(n), Dequeue is generally O(1). Buffer implements `seq.Provider`

func NewValueBuffer

func NewValueBuffer(values ...float64) *ValueBuffer

NewValueBuffer creates a new value buffer with an optional set of values.

func NewValueBufferWithCapacity

func NewValueBufferWithCapacity(capacity int) *ValueBuffer

NewValueBufferWithCapacity creates a new ValueBuffer pre-allocated with the given capacity.

func (*ValueBuffer) Array

func (b *ValueBuffer) Array() Array

Array returns the ring buffer, in order, as an array.

func (*ValueBuffer) Capacity

func (b *ValueBuffer) Capacity() int

Capacity returns the total size of the Buffer, including empty elements.

func (*ValueBuffer) Clear

func (b *ValueBuffer) Clear()

Clear removes all objects from the Buffer.

func (*ValueBuffer) Dequeue

func (b *ValueBuffer) Dequeue() float64

Dequeue removes the first element from the RingBuffer.

func (*ValueBuffer) Each

func (b *ValueBuffer) Each(mapfn func(int, float64))

Each calls the consumer for each element in the buffer.

func (*ValueBuffer) Enqueue

func (b *ValueBuffer) Enqueue(value float64)

Enqueue adds an element to the "back" of the Buffer.

func (*ValueBuffer) GetValue

func (b *ValueBuffer) GetValue(index int) float64

GetValue implements seq provider.

func (*ValueBuffer) Len

func (b *ValueBuffer) Len() int

Len returns the length of the Buffer (as it is currently populated). Actual memory footprint may be different.

func (*ValueBuffer) Peek

func (b *ValueBuffer) Peek() float64

Peek returns but does not remove the first element.

func (*ValueBuffer) PeekBack

func (b *ValueBuffer) PeekBack() float64

PeekBack returns but does not remove the last element.

func (*ValueBuffer) SetCapacity

func (b *ValueBuffer) SetCapacity(capacity int)

SetCapacity sets the capacity of the Buffer.

func (*ValueBuffer) String

func (b *ValueBuffer) String() string

String returns a string representation for value buffers.

func (*ValueBuffer) TrimExcess

func (b *ValueBuffer) TrimExcess()

TrimExcess resizes the capacity of the buffer to better fit the contents.

type ValueFormatter

type ValueFormatter func(v interface{}) string

ValueFormatter is a function that takes a value and produces a string.

func KValueFormatter

func KValueFormatter(k float64, vf ValueFormatter) ValueFormatter

KValueFormatter is a formatter for K values.

func TimeValueFormatterWithFormat

func TimeValueFormatterWithFormat(format string) ValueFormatter

TimeValueFormatterWithFormat returns a time formatter with a given format.

type ValueFormatterProvider

type ValueFormatterProvider interface {
	GetValueFormatters() (x, y ValueFormatter)
}

ValueFormatterProvider is a series that has custom formatters.

type Values

type Values []Value

Values is an array of Value.

func (Values) Normalize

func (vs Values) Normalize() []Value

Normalize returns the values normalized.

func (Values) Values

func (vs Values) Values() []float64

Values returns the values.

func (Values) ValuesNormalized

func (vs Values) ValuesNormalized() []float64

ValuesNormalized returns normalized values.

type ValuesProvider

type ValuesProvider interface {
	Len() int
	GetValues(index int) (x, y float64)
}

ValuesProvider is a type that produces values.

type XAxis

type XAxis struct {
	Name      string
	NameStyle Style

	Style          Style
	ValueFormatter ValueFormatter
	Range          Range

	TickStyle    Style
	Ticks        []Tick
	TickPosition TickPosition

	GridLines      []GridLine
	GridMajorStyle Style
	GridMinorStyle Style
}

XAxis represents the horizontal axis.

func HideXAxis

func HideXAxis() XAxis

HideXAxis hides the x-axis.

func (XAxis) GetGridLines

func (xa XAxis) GetGridLines(ticks []Tick) []GridLine

GetGridLines returns the gridlines for the axis.

func (XAxis) GetName

func (xa XAxis) GetName() string

GetName returns the name.

func (XAxis) GetStyle

func (xa XAxis) GetStyle() Style

GetStyle returns the style.

func (XAxis) GetTickPosition

func (xa XAxis) GetTickPosition(defaults ...TickPosition) TickPosition

GetTickPosition returns the tick position option for the axis.

func (XAxis) GetTicks

func (xa XAxis) GetTicks(r Renderer, ra Range, defaults Style, vf ValueFormatter) []Tick

GetTicks returns the ticks for a series. The coalesce priority is:

  • User Supplied Ticks (i.e. Ticks array on the axis itself).
  • Range ticks (i.e. if the range provides ticks).
  • Generating continuous ticks based on minimum spacing and canvas width.

func (XAxis) GetValueFormatter

func (xa XAxis) GetValueFormatter() ValueFormatter

GetValueFormatter returns the value formatter for the axis.

func (XAxis) Measure

func (xa XAxis) Measure(r Renderer, canvasBox Box, ra Range, defaults Style, ticks []Tick) Box

Measure returns the bounds of the axis.

func (XAxis) Render

func (xa XAxis) Render(r Renderer, canvasBox Box, ra Range, defaults Style, ticks []Tick)

Render renders the axis

type YAxis

type YAxis struct {
	Name      string
	NameStyle Style

	Style Style

	AxisType  YAxisType
	Ascending bool

	ValueFormatter ValueFormatter
	Range          Range

	TickStyle Style
	Ticks     []Tick

	GridLines      []GridLine
	GridMajorStyle Style
	GridMinorStyle Style
}

YAxis is a veritcal rule of the range. There can be (2) y-axes; a primary and secondary.

func HideYAxis

func HideYAxis() YAxis

HideYAxis hides a y-axis.

func (YAxis) GetGridLines

func (ya YAxis) GetGridLines(ticks []Tick) []GridLine

GetGridLines returns the gridlines for the axis.

func (YAxis) GetName

func (ya YAxis) GetName() string

GetName returns the name.

func (YAxis) GetNameStyle

func (ya YAxis) GetNameStyle() Style

GetNameStyle returns the name style.

func (YAxis) GetStyle

func (ya YAxis) GetStyle() Style

GetStyle returns the style.

func (YAxis) GetTickStyle

func (ya YAxis) GetTickStyle() Style

GetTickStyle returns the tick style.

func (YAxis) GetTicks

func (ya YAxis) GetTicks(r Renderer, ra Range, defaults Style, vf ValueFormatter) []Tick

GetTicks returns the ticks for a series. The coalesce priority is:

  • User Supplied Ticks (i.e. Ticks array on the axis itself).
  • Range ticks (i.e. if the range provides ticks).
  • Generating continuous ticks based on minimum spacing and canvas width.

func (YAxis) GetValueFormatter

func (ya YAxis) GetValueFormatter() ValueFormatter

GetValueFormatter returns the value formatter for the axis.

func (YAxis) Measure

func (ya YAxis) Measure(r Renderer, canvasBox Box, ra Range, defaults Style, ticks []Tick) Box

Measure returns the bounds of the axis.

func (YAxis) Render

func (ya YAxis) Render(r Renderer, canvasBox Box, ra Range, defaults Style, ticks []Tick)

Render renders the axis.

type YAxisType

type YAxisType int

YAxisType is a type of y-axis; it can either be primary or secondary.

const (
	// YAxisPrimary is the primary axis.
	YAxisPrimary YAxisType = 0
	// YAxisSecondary is the secondary axis.
	YAxisSecondary YAxisType = 1
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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