annotations

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Anchor

type Anchor string

Anchor defines where text is anchored

const (
	AnchorStart  Anchor = "start"
	AnchorMiddle Anchor = "middle"
	AnchorEnd    Anchor = "end"
)

type Annotation

type Annotation interface {
	// Render renders the annotation to SVG
	Render(xScale, yScale scales.Scale) string
}

Annotation represents a visual annotation on a chart

type AnnotationLayer

type AnnotationLayer struct {
	Annotations []Annotation
}

AnnotationLayer groups multiple annotations

func NewAnnotationLayer

func NewAnnotationLayer() *AnnotationLayer

NewAnnotationLayer creates a new annotation layer

func (*AnnotationLayer) Add

func (al *AnnotationLayer) Add(annotation Annotation) *AnnotationLayer

Add adds an annotation to the layer

func (*AnnotationLayer) Render

func (al *AnnotationLayer) Render(xScale, yScale scales.Scale) string

Render renders all annotations in the layer

type AnnotationStyle

type AnnotationStyle struct {
	Stroke       string
	StrokeWidth  float64
	Fill         string
	Opacity      float64
	StrokeDash   string
	FontSize     units.Length
	FontFamily   string
	FontWeight   string
	TextAnchor   Anchor
	TextBaseline Baseline
	Color        string
}

AnnotationStyle contains common styling for annotations

func DefaultAnnotationStyle

func DefaultAnnotationStyle() AnnotationStyle

DefaultAnnotationStyle returns the default annotation style

type Arrow

type Arrow struct {
	// Start and end positions in data coordinates (if PositionData)
	X1, Y1, X2, Y2 interface{}

	// Pixel positions (if PositionPixel)
	PxX1, PxY1, PxX2, PxY2 float64

	// Positioning mode
	Mode Position

	// Arrow head style
	HeadSize   float64
	HeadStyle  ArrowHeadStyle
	ShowStart  bool // Show arrow head at start
	ShowEnd    bool // Show arrow head at end
	DoubleHead bool // Deprecated: use ShowStart and ShowEnd

	// Curvature for curved arrows (0 = straight)
	Curve float64

	Style AnnotationStyle
}

Arrow represents an arrow annotation

func NewArrow

func NewArrow(x1, y1, x2, y2 interface{}) *Arrow

NewArrow creates a new arrow annotation with data positioning

func NewArrowPixel

func NewArrowPixel(x1, y1, x2, y2 float64) *Arrow

NewArrowPixel creates a new arrow with pixel positioning

func (*Arrow) Render

func (a *Arrow) Render(xScale, yScale scales.Scale) string

Render renders the arrow

func (*Arrow) WithCurve

func (a *Arrow) WithCurve(curve float64) *Arrow

WithCurve sets the curvature

func (*Arrow) WithDoubleHead

func (a *Arrow) WithDoubleHead(double bool) *Arrow

WithDoubleHead makes the arrow double-headed

func (*Arrow) WithEndHead

func (a *Arrow) WithEndHead(show bool) *Arrow

WithEndHead controls the end arrow head

func (*Arrow) WithHeadSize

func (a *Arrow) WithHeadSize(size float64) *Arrow

WithHeadSize sets the arrow head size

func (*Arrow) WithHeadStyle

func (a *Arrow) WithHeadStyle(style ArrowHeadStyle) *Arrow

WithHeadStyle sets the arrow head style

func (*Arrow) WithStartHead

func (a *Arrow) WithStartHead(show bool) *Arrow

WithStartHead controls the start arrow head

func (*Arrow) WithStyle

func (a *Arrow) WithStyle(style AnnotationStyle) *Arrow

WithStyle sets the style

type ArrowHeadStyle

type ArrowHeadStyle string

ArrowHeadStyle defines the arrow head appearance

const (
	ArrowHeadTriangle ArrowHeadStyle = "triangle"
	ArrowHeadOpen     ArrowHeadStyle = "open"
	ArrowHeadDiamond  ArrowHeadStyle = "diamond"
	ArrowHeadCircle   ArrowHeadStyle = "circle"
)

type Baseline

type Baseline string

Baseline defines vertical text alignment

const (
	BaselineTop        Baseline = "hanging"
	BaselineMiddle     Baseline = "middle"
	BaselineBottom     Baseline = "baseline"
	BaselineAlphabetic Baseline = "alphabetic"
)

type CalloutLabel

type CalloutLabel struct {
	Text string
	X, Y interface{} // Data point position

	// Label position offset from point (in pixels)
	LabelOffsetX, LabelOffsetY float64

	// Whether to draw connecting line
	ShowLine bool

	Style AnnotationStyle
}

CalloutLabel is a text label with a line pointing to a data point

func NewCalloutLabel

func NewCalloutLabel(text string, x, y interface{}) *CalloutLabel

NewCalloutLabel creates a new callout label

func (*CalloutLabel) Render

func (cl *CalloutLabel) Render(xScale, yScale scales.Scale) string

Render renders the callout label

func (*CalloutLabel) WithLabelOffset

func (cl *CalloutLabel) WithLabelOffset(x, y float64) *CalloutLabel

WithLabelOffset sets the label offset

func (*CalloutLabel) WithShowLine

func (cl *CalloutLabel) WithShowLine(show bool) *CalloutLabel

WithShowLine sets whether to show the connecting line

func (*CalloutLabel) WithStyle

func (cl *CalloutLabel) WithStyle(style AnnotationStyle) *CalloutLabel

WithStyle sets the style

type Connector

type Connector struct {
	X1, Y1, X2, Y2 interface{}
	Mode           Position

	// Line style
	LineStyle ConnectorStyle
	Style     AnnotationStyle
}

Connector draws a line connecting two points (no arrow heads)

func NewConnector

func NewConnector(x1, y1, x2, y2 interface{}) *Connector

NewConnector creates a new connector

func (*Connector) Render

func (c *Connector) Render(xScale, yScale scales.Scale) string

Render renders the connector

func (*Connector) WithLineStyle

func (c *Connector) WithLineStyle(style ConnectorStyle) *Connector

WithLineStyle sets the connector line style

func (*Connector) WithStyle

func (c *Connector) WithStyle(style AnnotationStyle) *Connector

WithStyle sets the style

type ConnectorStyle

type ConnectorStyle string

ConnectorStyle defines connector line styles

const (
	ConnectorStraight   ConnectorStyle = "straight"
	ConnectorStep       ConnectorStyle = "step"
	ConnectorStepBefore ConnectorStyle = "step-before"
	ConnectorStepAfter  ConnectorStyle = "step-after"
	ConnectorElbow      ConnectorStyle = "elbow"
)

type Grid

type Grid struct {
	// Show horizontal and vertical grid lines
	ShowHorizontal bool
	ShowVertical   bool

	// Number of grid lines (0 = auto based on scale ticks)
	HorizontalCount int
	VerticalCount   int

	Style AnnotationStyle
}

Grid represents a reference grid

func NewGrid

func NewGrid() *Grid

NewGrid creates a new grid

func (*Grid) Render

func (g *Grid) Render(xScale, yScale scales.Scale) string

Render renders the grid

func (*Grid) WithCounts

func (g *Grid) WithCounts(horizontal, vertical int) *Grid

WithCounts sets the grid line counts

func (*Grid) WithStyle

func (g *Grid) WithStyle(style AnnotationStyle) *Grid

WithStyle sets the style

type MultilineText

type MultilineText struct {
	Lines []string
	X, Y  interface{}
	Mode  Position

	// Line spacing (multiplier of font size)
	LineSpacing float64

	OffsetX, OffsetY float64
	Style            AnnotationStyle
}

MultilineText represents a text annotation with multiple lines

func NewMultilineText

func NewMultilineText(lines []string, x, y interface{}) *MultilineText

NewMultilineText creates a new multiline text annotation

func (*MultilineText) Render

func (mt *MultilineText) Render(xScale, yScale scales.Scale) string

Render renders the multiline text

func (*MultilineText) WithLineSpacing

func (mt *MultilineText) WithLineSpacing(spacing float64) *MultilineText

WithLineSpacing sets the line spacing

func (*MultilineText) WithStyle

func (mt *MultilineText) WithStyle(style AnnotationStyle) *MultilineText

WithStyle sets the style

type Orientation

type Orientation string

Orientation defines line orientation

const (
	OrientationHorizontal Orientation = "horizontal"
	OrientationVertical   Orientation = "vertical"
)

type Position

type Position string

Position represents how to position an annotation

const (
	// PositionData positions relative to data coordinates (uses scales)
	PositionData Position = "data"

	// PositionPixel positions using absolute pixel coordinates
	PositionPixel Position = "pixel"

	// PositionRelative positions as percentage (0-1) of plot area
	PositionRelative Position = "relative"
)

type ReferenceLine

type ReferenceLine struct {
	// Value in data coordinates
	Value interface{}

	// Orientation
	Orientation Orientation

	// Label (optional)
	Label string

	// Label position (0-1 along the line)
	LabelPosition float64

	// Label alignment
	LabelAnchor Anchor

	Style AnnotationStyle
}

ReferenceLine represents a horizontal or vertical reference line

func NewHLine

func NewHLine(yValue interface{}) *ReferenceLine

NewHLine creates a new horizontal reference line

func NewVLine

func NewVLine(xValue interface{}) *ReferenceLine

NewVLine creates a new vertical reference line

func (*ReferenceLine) Render

func (rl *ReferenceLine) Render(xScale, yScale scales.Scale) string

Render renders the reference line

func (*ReferenceLine) WithDashed

func (rl *ReferenceLine) WithDashed() *ReferenceLine

WithDashed makes the line dashed

func (*ReferenceLine) WithLabel

func (rl *ReferenceLine) WithLabel(label string) *ReferenceLine

WithLabel sets the label

func (*ReferenceLine) WithLabelAnchor

func (rl *ReferenceLine) WithLabelAnchor(anchor Anchor) *ReferenceLine

WithLabelAnchor sets the label anchor

func (*ReferenceLine) WithLabelPosition

func (rl *ReferenceLine) WithLabelPosition(pos float64) *ReferenceLine

WithLabelPosition sets the label position (0-1)

func (*ReferenceLine) WithStyle

func (rl *ReferenceLine) WithStyle(style AnnotationStyle) *ReferenceLine

WithStyle sets the style

type ReferenceRegion

type ReferenceRegion struct {
	// Data coordinates for region bounds
	X1, Y1, X2, Y2 interface{}

	// Use nil for unbounded dimensions (spans full range)
	Mode Position

	// Label (optional)
	Label string

	// Label position within region (0-1, 0-1)
	LabelX, LabelY float64

	Style AnnotationStyle
}

ReferenceRegion represents a shaded rectangular region

func NewHRegion

func NewHRegion(y1, y2 interface{}) *ReferenceRegion

NewHRegion creates a horizontal band (full width, bounded Y)

func NewReferenceRegion

func NewReferenceRegion(x1, y1, x2, y2 interface{}) *ReferenceRegion

NewReferenceRegion creates a new reference region

func NewVRegion

func NewVRegion(x1, x2 interface{}) *ReferenceRegion

NewVRegion creates a vertical band (full height, bounded X)

func (*ReferenceRegion) Render

func (rr *ReferenceRegion) Render(xScale, yScale scales.Scale) string

Render renders the reference region

func (*ReferenceRegion) WithLabel

func (rr *ReferenceRegion) WithLabel(label string) *ReferenceRegion

WithLabel sets the label

func (*ReferenceRegion) WithLabelPosition

func (rr *ReferenceRegion) WithLabelPosition(x, y float64) *ReferenceRegion

WithLabelPosition sets the label position (0-1, 0-1)

func (*ReferenceRegion) WithStyle

func (rr *ReferenceRegion) WithStyle(style AnnotationStyle) *ReferenceRegion

WithStyle sets the style

type TextLabel

type TextLabel struct {
	// Text content
	Text string

	// Position in data coordinates (if PositionData)
	X, Y interface{}

	// Position in pixels (if PositionPixel)
	PxX, PxY float64

	// Position as relative (0-1) (if PositionRelative)
	RelX, RelY float64

	// Positioning mode
	Mode Position

	// Offset from position (in pixels)
	OffsetX, OffsetY float64

	// Rotation angle in degrees
	Rotation float64

	// Style
	Style AnnotationStyle
}

TextLabel represents a text annotation

func NewTextLabel

func NewTextLabel(text string, x, y interface{}) *TextLabel

NewTextLabel creates a new text label with data positioning

func NewTextLabelPixel

func NewTextLabelPixel(text string, x, y float64) *TextLabel

NewTextLabelPixel creates a new text label with pixel positioning

func NewTextLabelRelative

func NewTextLabelRelative(text string, x, y float64) *TextLabel

NewTextLabelRelative creates a new text label with relative positioning

func (*TextLabel) Render

func (tl *TextLabel) Render(xScale, yScale scales.Scale) string

Render renders the text label

func (*TextLabel) WithAnchor

func (tl *TextLabel) WithAnchor(anchor Anchor) *TextLabel

WithAnchor sets the text anchor

func (*TextLabel) WithBaseline

func (tl *TextLabel) WithBaseline(baseline Baseline) *TextLabel

WithBaseline sets the text baseline

func (*TextLabel) WithOffset

func (tl *TextLabel) WithOffset(x, y float64) *TextLabel

WithOffset sets the offset

func (*TextLabel) WithRotation

func (tl *TextLabel) WithRotation(degrees float64) *TextLabel

WithRotation sets the rotation angle

func (*TextLabel) WithStyle

func (tl *TextLabel) WithStyle(style AnnotationStyle) *TextLabel

WithStyle sets the style

Jump to

Keyboard shortcuts

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