render

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2023 License: MIT Imports: 7 Imported by: 34

Documentation

Index

Constants

View Source
const (
	// DefaultStrokeWidth is the default chart stroke width.
	DefaultStrokeWidth = 0.0

	// DefaultDotWidth is the default chart dot width.
	DefaultDotWidth = 0.0

	// DefaultFontSize is the default font size.
	DefaultFontSize = 10.0

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

Variables

View Source
var (
	// ColorTransparent is a transparent (alpha zero) color.
	ColorTransparent = color.RGBA{R: 255, G: 255, B: 255, A: 0}

	// ColorWhite is white.
	ColorWhite = color.RGBA{R: 255, G: 255, B: 255, A: 255}

	// ColorBlue is the basic theme blue color.
	ColorBlue = color.RGBA{R: 0, G: 116, B: 217, A: 255}

	// ColorCyan is the basic theme cyan color.
	ColorCyan = color.RGBA{R: 0, G: 217, B: 210, A: 255}

	// ColorGreen is the basic theme green color.
	ColorGreen = color.RGBA{R: 0, G: 217, B: 101, A: 255}

	// ColorRed is the basic theme red color.
	ColorRed = color.RGBA{R: 217, G: 0, B: 116, A: 255}

	// ColorOrange is the basic theme orange color.
	ColorOrange = color.RGBA{R: 217, G: 101, B: 0, A: 255}

	// ColorYellow is the basic theme yellow color.
	ColorYellow = color.RGBA{R: 217, G: 210, B: 0, A: 255}

	// ColorBlack is the basic theme black color.
	ColorBlack = color.RGBA{R: 51, G: 51, B: 51, A: 255}

	// ColorLightGray is the basic theme light gray color.
	ColorLightGray = color.RGBA{R: 239, G: 239, B: 239, A: 255}

	// ColorAlternateBlue is a alternate theme color.
	ColorAlternateBlue = color.RGBA{R: 106, G: 195, B: 203, A: 255}

	// ColorAlternateGreen is a alternate theme color.
	ColorAlternateGreen = color.RGBA{R: 42, G: 190, B: 137, A: 255}

	// ColorAlternateGray is a alternate theme color.
	ColorAlternateGray = color.RGBA{R: 110, G: 128, B: 139, A: 255}

	// ColorAlternateYellow is a alternate theme color.
	ColorAlternateYellow = color.RGBA{R: 240, G: 174, B: 90, A: 255}

	// ColorAlternateLightGray is a alternate theme color.
	ColorAlternateLightGray = color.RGBA{R: 187, G: 190, B: 191, A: 255}
)
View Source
var (
	// DefaultTextColor is the default text color.
	DefaultTextColor = ColorBlack

	// DefaultLineColor is the default line color.
	DefaultLineColor = ColorBlack
)
View Source
var AlternateColorPalette alternateColorPalette

AlternateColorPalette is an alternate color palatte.

View Source
var DefaultColorPalette defaultColorPalette

DefaultColorPalette is the default color palatte.

View Source
var (
	// Text contains utilities for text.
	Text = &text{}
)

Functions

func ColorIsZero

func ColorIsZero(c color.Color) bool

ColorIsZero returns true if the all the color components are zero.

func ColorToString

func ColorToString(c color.Color) string

ColorToString returns a string representation of the color.

func ColorWithAlpha

func ColorWithAlpha(c color.RGBA, a uint8) color.Color

ColorWithAlpha returns a copy of the color with a given alpha.

func GetAlternateColor

func GetAlternateColor(index int) color.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) color.Color

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

func Jet

func Jet(v, vmin, vmax float64) color.Color

Jet is a color map provider based on matlab's jet color map.

func Viridis

func Viridis(v, vmin, vmax float64) color.Color

Viridis creates a color map provider.

Types

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) AspectRatio

func (b Box) AspectRatio() float64

AspectRatio 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) Draw

func (b Box) Draw(r Renderer, s Style)

Draw draws the box using the specified style.

func (Box) DrawRotated

func (b Box) DrawRotated(r Renderer, thetaDegrees float64, s Style)

DrawRotated draws the box with the provided style, rotated by the specified degrees.

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 the 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 translates the 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) Draw

func (bc BoxCorners) Draw(r Renderer, s Style)

Draw draws the box corners using the specified style.

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 ChartRenderable

type ChartRenderable interface {
	Width() int
	SetWidth(width int)

	Height() int
	SetHeight(height int)

	Render(rp RendererProvider, w io.Writer) error
}

ChartRenderable represents a chart renderable component.

type ColorPalette

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

ColorPalette is a set of colors that.

type ColorProvider

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

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

type DotColorProvider

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

DotColorProvider is a provider for dot color.

type Font

type Font interface {
	String() string
}

Font represents a generic font type.

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

type Renderer

type Renderer interface {
	// ResetStyle resets all the style related settings of 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(color.Color)

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

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

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

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

	// LineTo draws a line to the specified point, starting from the previous one.
	LineTo(x, y int)

	// QuadCurveTo draws a quad curve. `cx` and `cy` are the Bézier control points.
	QuadCurveTo(cx, cy, x, y int)

	// ArcTo draws an arc with a given center (`cx`, `cy`), a given set of
	// radii (`rx`, `ry`), a `startAngle` and `deltaAngle` (in radians).
	ArcTo(cx, cy int, rx, ry, startAngle, delta float64)

	// Close finalizes a shape, closing the path.
	Close()

	// Stroke strokes the current path.
	Stroke()

	// Fill fills the current path.
	Fill()

	// FillStroke fills and strokes the current path.
	FillStroke()

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

	// SetFont sets the current font.
	SetFont(font Font)

	// SetFontColor sets the current font color.
	SetFontColor(color.Color)

	// SetFontSize sets the current font size.
	SetFontSize(size float64)

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

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

	// SetTextRotation sets the rotation of the text.
	SetTextRotation(radians float64)

	// ClearTextRotation clears rotation of the text.
	ClearTextRotation()

	// Save saves the rendered data to the given writer.
	Save(w io.Writer) error
}

Renderer represents a chart renderer.

type RendererProvider

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

RendererProvider is a function that returns a renderer.

type SizeProvider

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

SizeProvider is a provider for integer size.

type Style

type Style struct {
	Hidden  bool
	Padding Box

	ClassName string
	FillColor color.Color

	StrokeWidth     float64
	StrokeColor     color.Color
	StrokeDashArray []float64

	DotColor         color.Color
	DotWidth         float64
	DotWidthProvider SizeProvider
	DotColorProvider DotColorProvider

	Font      Font
	FontSize  float64
	FontColor color.Color

	TextHorizontalAlign TextHorizontalAlign
	TextVerticalAlign   TextVerticalAlign
	TextWrap            TextWrap
	TextLineSpacing     int
	TextRotationDegrees float64
}

Style is a simple style set.

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 ...color.Color) color.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 ...color.Color) color.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 ...Font) Font

GetFont returns the font face.

func (Style) GetFontColor

func (s Style) GetFontColor(defaults ...color.Color) color.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 ...color.Color) color.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 TextHorizontalAlign

type TextHorizontalAlign int

TextHorizontalAlign is an enum for the horizontal alignment options.

const (
	// TextHorizontalAlignUnset is an unset state for text horizontal alignment.
	TextHorizontalAlignUnset TextHorizontalAlign = iota

	// TextHorizontalAlignLeft aligns a string horizontally so that it's left
	// ligature starts at horizontal pixel 0.
	TextHorizontalAlignLeft

	// 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

	// TextHorizontalAlignRight right aligns a string horizontally so that
	// the right ligature ends at the right-most pixel of a box.
	TextHorizontalAlignRight
)

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 = iota

	// TextVerticalAlignBaseline aligns text according to the "baseline" of
	// the string, or where a normal ascender begins.
	TextVerticalAlignBaseline

	// TextVerticalAlignBottom aligns the text according to the lowers pixel
	// of any of the ligatures (ex. g or q both extend below the baseline).
	TextVerticalAlignBottom

	// TextVerticalAlignMiddle aligns the text so that there is an equal
	// amount of space above and below the top and bottom of the ligatures.
	TextVerticalAlignMiddle

	// TextVerticalAlignMiddleBaseline aligns the text vertically so that there
	// is an equal number of pixels above and below the baseline of the string.
	TextVerticalAlignMiddleBaseline

	// TextVerticalAlignTop alignts the text so that the top of the ligatures
	// are at y-pixel 0 in the container.
	TextVerticalAlignTop
)

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 = iota

	// TextWrapNone will spill text past horizontal boundaries.
	TextWrapNone

	// TextWrapWord will split a string on words (i.e. spaces) to fit within
	// a horizontal boundary.
	TextWrapWord

	// TextWrapRune will split a string on a rune (i.e. utf-8 codepage) to fit
	// within a horizontal boundary.
	TextWrapRune
)

Jump to

Keyboard shortcuts

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