Documentation
ΒΆ
Overview ΒΆ
Copyright (c) 2026, Anton Bespalov. Licensed under the MIT License.
Copyright (c) 2026, Anton Bespalov. Licensed under the MIT License.
Copyright (c) 2026, Anton Bespalov. Licensed under the MIT License.
Package csirender provides an engine for declarative rendering of visual dashboards.
Copyright (c) 2026, Anton Bespalov. Licensed under the MIT License.
Copyright (c) 2026, Anton Bespalov. Licensed under the MIT License.
Copyright (c) 2026, Anton Bespalov. Licensed under the MIT License.
Copyright (c) 2026, Anton Bespalov. Licensed under the MIT License.
Copyright (c) 2026, Anton Bespalov. Licensed under the MIT License.
Copyright (c) 2026, Anton Bespalov. Licensed under the MIT License.
Copyright (c) 2026, Anton Bespalov. Licensed under the MIT License.
Copyright (c) 2026, Anton Bespalov. Licensed under the MIT License.
Copyright (c) 2026, Anton Bespalov. Licensed under the MIT License.
Copyright (c) 2026, Anton Bespalov. Licensed under the MIT License.
Copyright (c) 2026, Anton Bespalov. Licensed under the MIT License.
Copyright (c) 2026, Anton Bespalov. Licensed under the MIT License.
Copyright (c) 2026, Anton Bespalov. Licensed under the MIT License.
Copyright (c) 2026, Anton Bespalov. Licensed under the MIT License.
Index ΒΆ
- func EncodeImage(img image.Image, format string, mapping map[string][]int, ...) ([]byte, error)
- func EncodePartialImage(oldImg, newImg image.Image, format string, mapping map[string][]int, ...) ([]byte, error)
- func PackEPDRaw(img image.Image, width, height int, mapping map[string][]int, ...) []byte
- func RenderErrorImage(width, height int, errMsg string, format string, mapping map[string][]int, ...) []byte
- func Version() string
- type Align
- type BaseElement
- type BorderConfig
- type ChartElement
- type ComponentConfig
- type CustomRenderer
- type DataProvider
- type Element
- type ElementWrapper
- type EmbeddedFont
- type Engine
- func (e *Engine) GetImage(path string) (image.Image, error)
- func (e *Engine) RegisterRenderer(typ string, renderer CustomRenderer)
- func (e *Engine) Render(cfg *LayoutConfig, data RenderData) (image.Image, error)
- func (e *Engine) RenderWithProvider(cfg *LayoutConfig, provider DataProvider) (image.Image, error)
- type ErrorConfig
- type FontConfig
- type FontStyle
- type GenericElement
- type ImageElement
- type LayoutConfig
- type LayoutDefaults
- type LineConfig
- type LineElement
- type LocalDataProvider
- func (l *LocalDataProvider) EnrichTelemetry(source string, value float64) map[string]interface{}
- func (l *LocalDataProvider) GetChart(source string) ([]float64, bool)
- func (l *LocalDataProvider) GetValue(key string) (interface{}, bool)
- func (l *LocalDataProvider) ResolveThreshold(condition string, chartSource string) (float64, bool)
- type MapDataProvider
- func (p *MapDataProvider) EnrichTelemetry(source string, value float64) map[string]interface{}
- func (p *MapDataProvider) GetChart(source string) ([]float64, bool)
- func (p *MapDataProvider) GetValue(key string) (interface{}, bool)
- func (p *MapDataProvider) ResolveThreshold(condition string, chartSource string) (float64, bool)
- type Margin
- type OutputConfig
- type Parser
- type Position
- type RenderContext
- type RenderData
- type ScreenConfig
- type ShapeElement
- type Size
- type TelemetryEnricher
- type TextElement
- type Threshold
- type ThresholdLine
- type ValueCardElement
- type ValueResolver
Constants ΒΆ
This section is empty.
Variables ΒΆ
This section is empty.
Functions ΒΆ
func EncodeImage ΒΆ
func EncodeImage(img image.Image, format string, mapping map[string][]int, palette map[string]string) ([]byte, error)
EncodeImage wraps final formatting for the target output stream.
func EncodePartialImage ΒΆ added in v0.2.7
func EncodePartialImage(oldImg, newImg image.Image, format string, mapping map[string][]int, palette map[string]string) ([]byte, error)
EncodePartialImage encodes an image using the epd_pr (partial refresh) format. It compares oldImg and newImg to find bounding boxes of differences on a 4x4 grid. If oldImg is nil, it encodes the entire newImg as a single tile.
func PackEPDRaw ΒΆ
func PackEPDRaw(img image.Image, width, height int, mapping map[string][]int, palette map[string]string) []byte
PackEPDRaw takes an image.Image and packs its pixels into a byte array corresponding to the physical color indices of the target E-Ink display.
Types ΒΆ
type Align ΒΆ
type Align struct {
H string `yaml:"h" json:"h"` // Horizontal alignment: left, center, right
V string `yaml:"v" json:"v"` // Vertical alignment: top, center, bottom, under_center, under
P string `yaml:"p" json:"p"` // Placement relative to other elements: right, left, bottom, none
S float64 `yaml:"s" json:"s"` // Spacing/gap size in pixels
}
Align defines vertical, horizontal, and relative alignments, along with spacers.
type BaseElement ΒΆ
type BaseElement struct {
Type string `yaml:"type" json:"type"` // Element type
Position Position `yaml:"position" json:"position"` // Offset position on canvas
Size Size `yaml:"size" json:"size"` // Layout box dimensions
Source string `yaml:"source,omitempty" json:"source,omitempty"` // Data mapping path (e.g. "pm25.value")
Parameters map[string]string `yaml:"parameters,omitempty" json:"parameters,omitempty"` // Arbitrary key-value parameters
}
BaseElement contains fields common to all visual elements.
func (*BaseElement) GetPosition ΒΆ
func (b *BaseElement) GetPosition() Position
func (*BaseElement) GetSize ΒΆ
func (b *BaseElement) GetSize() Size
func (*BaseElement) GetType ΒΆ
func (b *BaseElement) GetType() string
type BorderConfig ΒΆ
type BorderConfig struct {
Bg string `yaml:"bg,omitempty" json:"bg,omitempty"` // Background fill color
Padding float64 `yaml:"padding,omitempty" json:"padding,omitempty"` // Padding inside the border
Affects []string `yaml:"affects,omitempty" json:"affects,omitempty"` // Elements enclosed by the border
Thresholds []Threshold `yaml:"thresholds,omitempty" json:"thresholds,omitempty"` // Dynamic styling overrides
LineConfig `yaml:",inline" json:",inline"`
}
BorderConfig controls the border line and background of card components.
type ChartElement ΒΆ
type ChartElement struct {
BaseElement `yaml:",inline" json:",inline"`
Style string `yaml:"style,omitempty" json:"style,omitempty"`
Duration string `yaml:"duration,omitempty" json:"duration,omitempty"`
RefreshDelay string `yaml:"refresh_delay,omitempty" json:"refresh_delay,omitempty"`
Points int `yaml:"points,omitempty" json:"points,omitempty"`
Axis map[string]interface{} `yaml:"axis,omitempty" json:"axis,omitempty"`
ThresholdLines []ThresholdLine `yaml:"threshold_lines,omitempty" json:"threshold_lines,omitempty"`
Thresholds []Threshold `yaml:"thresholds,omitempty" json:"thresholds,omitempty"`
ChartType string `yaml:"chart_type,omitempty" json:"chart_type,omitempty"` // Obsolete
}
ChartElement represents a graph or chart.
type ComponentConfig ΒΆ
type ComponentConfig struct {
Font FontStyle `yaml:"font,omitempty" json:"font,omitempty"` // Font settings
Align Align `yaml:"align,omitempty" json:"align,omitempty"` // Alignment settings
Margin Margin `yaml:"margin,omitempty" json:"margin,omitempty"` // Outer spacing
Thresholds []Threshold `yaml:"thresholds,omitempty" json:"thresholds,omitempty"` // Conditional styling overrides
Border *BorderConfig `yaml:"border,omitempty" json:"border,omitempty"` // Optional border settings
Template string `yaml:"template,omitempty" json:"template,omitempty"` // Visual formatting template
Parameter string `yaml:"parameter,omitempty" json:"parameter,omitempty"` // Custom unit reference
}
ComponentConfig configures sub-components inside a complex widget like a value card.
type CustomRenderer ΒΆ
type CustomRenderer interface {
RenderElement(dc *gg.Context, rc *RenderContext, el Element) error
}
CustomRenderer allows the parent application to draw domain-specific elements.
type DataProvider ΒΆ
type DataProvider interface {
GetValue(key string) (interface{}, bool)
GetChart(source string) ([]float64, bool)
ResolveThreshold(condition string, chartSource string) (float64, bool)
EnrichTelemetry(source string, value float64) map[string]interface{}
}
DataProvider defines an interface for lazy evaluation of telemetry values, charts, and thresholds.
type ElementWrapper ΒΆ
type ElementWrapper struct {
Element Element
}
ElementWrapper is a helper type for unmarshaling elements into their concrete types.
func (*ElementWrapper) UnmarshalJSON ΒΆ
func (w *ElementWrapper) UnmarshalJSON(data []byte) error
UnmarshalJSON implements the json.Unmarshaler interface for ElementWrapper. It dynamically detects the "type" field and unmarshals the JSON into the appropriate concrete struct.
func (*ElementWrapper) UnmarshalYAML ΒΆ
func (w *ElementWrapper) UnmarshalYAML(node *yaml.Node) error
type EmbeddedFont ΒΆ
type Engine ΒΆ
type Engine struct {
Resolver ValueResolver // Deprecated: use DataProvider instead
Enricher TelemetryEnricher // Deprecated: use DataProvider instead
// contains filtered or unexported fields
}
Engine encapsulates the renderer and registered plugins.
func (*Engine) RegisterRenderer ΒΆ
func (e *Engine) RegisterRenderer(typ string, renderer CustomRenderer)
RegisterRenderer registers a plugin to handle a specific element type.
func (*Engine) Render ΒΆ
func (e *Engine) Render(cfg *LayoutConfig, data RenderData) (image.Image, error)
Render executes the full dashboard rendering pass and returns an image. Deprecated: use RenderWithProvider instead for lazy evaluation.
func (*Engine) RenderWithProvider ΒΆ
func (e *Engine) RenderWithProvider(cfg *LayoutConfig, provider DataProvider) (image.Image, error)
RenderWithProvider executes the full dashboard rendering pass using a lazy DataProvider.
type ErrorConfig ΒΆ
type ErrorConfig struct {
Margin struct {
X int `yaml:"x" json:"x"`
Y int `yaml:"y" json:"y"`
} `yaml:"margin" json:"margin"`
Size int `yaml:"size" json:"size"`
}
ErrorConfig defines how errors are rendered.
type FontConfig ΒΆ
type FontConfig struct {
File string `yaml:"file" json:"file"` // Path to TrueType font file
Size float64 `yaml:"size" json:"size"` // Default size of font
Hinting string `yaml:"hinting" json:"hinting"` // Hinting mode: none, vertical, full
}
FontConfig defines the TrueType font file and basic properties.
type FontStyle ΒΆ
type FontStyle struct {
Face string `yaml:"face" json:"face"`
Fg string `yaml:"fg" json:"fg"`
Bg string `yaml:"bg" json:"bg"`
}
FontStyle groups font family reference and foreground/background colors.
type GenericElement ΒΆ
type GenericElement struct {
BaseElement `yaml:",inline" json:",inline"`
Raw map[string]interface{} `yaml:",inline" json:",inline"`
}
GenericElement is a fallback for custom plugin elements.
type ImageElement ΒΆ
type ImageElement struct {
BaseElement `yaml:",inline" json:",inline"`
Path string `yaml:"path,omitempty" json:"path,omitempty"`
Mode string `yaml:"mode,omitempty" json:"mode,omitempty"`
Opacity *float64 `yaml:"opacity,omitempty" json:"opacity,omitempty"`
Align Align `yaml:"align,omitempty" json:"align,omitempty"`
Thresholds []Threshold `yaml:"thresholds,omitempty" json:"thresholds,omitempty"`
}
ImageElement represents a static or dynamic image.
type LayoutConfig ΒΆ
type LayoutConfig struct {
Screen ScreenConfig `yaml:"screen" json:"screen"`
Error ErrorConfig `yaml:"error" json:"error"`
Defaults LayoutDefaults `yaml:"defaults,omitempty" json:"defaults,omitempty"`
Output OutputConfig `yaml:"output" json:"output"`
Fonts map[string]FontConfig `yaml:"fonts" json:"fonts"`
Layout []ElementWrapper `yaml:"layout" json:"layout"` // Sequence of elements to draw
}
LayoutConfig represents the pure visual rendering configuration.
type LayoutDefaults ΒΆ
type LayoutDefaults struct {
FitText *bool `yaml:"fit_text,omitempty" json:"fit_text,omitempty"`
Align Align `yaml:"align,omitempty" json:"align,omitempty"`
Opacity *float64 `yaml:"opacity,omitempty" json:"opacity,omitempty"`
}
LayoutDefaults sets fallback values for visual properties.
type LineConfig ΒΆ
type LineConfig struct {
Color string `yaml:"color,omitempty" json:"color,omitempty"` // Stroke color
T *float64 `yaml:"t,omitempty" json:"t,omitempty"` // Line thickness
Style string `yaml:"style,omitempty" json:"style,omitempty"` // Line style: solid, dashed, dotted, dashdot, or custom
}
LineConfig defines shared visual properties for lines.
type LineElement ΒΆ
type LineElement struct {
BaseElement `yaml:",inline" json:",inline"`
LineConfig `yaml:",inline" json:",inline"`
L *float64 `yaml:"l,omitempty" json:"l,omitempty"`
Angle *float64 `yaml:"angle,omitempty" json:"angle,omitempty"`
}
LineElement renders a simple line or separator.
type LocalDataProvider ΒΆ
type LocalDataProvider struct {
Parent DataProvider
Overrides map[string]interface{}
}
LocalDataProvider wraps an existing DataProvider and overrides specific keys.
func (*LocalDataProvider) EnrichTelemetry ΒΆ
func (l *LocalDataProvider) EnrichTelemetry(source string, value float64) map[string]interface{}
func (*LocalDataProvider) GetChart ΒΆ
func (l *LocalDataProvider) GetChart(source string) ([]float64, bool)
func (*LocalDataProvider) GetValue ΒΆ
func (l *LocalDataProvider) GetValue(key string) (interface{}, bool)
func (*LocalDataProvider) ResolveThreshold ΒΆ
func (l *LocalDataProvider) ResolveThreshold(condition string, chartSource string) (float64, bool)
type MapDataProvider ΒΆ
type MapDataProvider struct {
Data RenderData
Resolver ValueResolver
Enricher TelemetryEnricher
}
MapDataProvider is a compatibility wrapper that implements DataProvider using a static RenderData map and engine callbacks.
func (*MapDataProvider) EnrichTelemetry ΒΆ
func (p *MapDataProvider) EnrichTelemetry(source string, value float64) map[string]interface{}
func (*MapDataProvider) GetChart ΒΆ
func (p *MapDataProvider) GetChart(source string) ([]float64, bool)
func (*MapDataProvider) GetValue ΒΆ
func (p *MapDataProvider) GetValue(key string) (interface{}, bool)
func (*MapDataProvider) ResolveThreshold ΒΆ
func (p *MapDataProvider) ResolveThreshold(condition string, chartSource string) (float64, bool)
type Margin ΒΆ
type Margin struct {
T float64 `yaml:"t" json:"t"` // Top margin
B float64 `yaml:"b" json:"b"` // Bottom margin
L float64 `yaml:"l" json:"l"` // Left margin
R float64 `yaml:"r" json:"r"` // Right margin
}
Margin defines external spacing around components.
type OutputConfig ΒΆ
type OutputConfig struct {
Format string `yaml:"format" json:"format"` // Serialization format: epd_raw, png, bmp
Background string `yaml:"background" json:"background"` // Base fill color
Mapping map[string][]int `yaml:"mapping" json:"mapping"` // Bit packing map for EPD outputs
}
OutputConfig configures serialization parameters.
type Parser ΒΆ
type Parser[T any] struct { // contains filtered or unexported fields }
Parser handles loading and caching of generic configuration structures. It allows business applications to define their own config struct that embeds LayoutConfig, parse it efficiently, and cache the parsed result to avoid expensive re-parsing.
type RenderContext ΒΆ
type RenderContext struct {
// contains filtered or unexported fields
}
RenderContext holds state for drawing elements on the GG context.
type RenderData ΒΆ
RenderData holds flattened telemetry and pre-sampled charts
type ScreenConfig ΒΆ
type ScreenConfig struct {
Width int `yaml:"width" json:"width"` // Canvas width in pixels
Height int `yaml:"height" json:"height"` // Canvas height in pixels
AntiAliasing bool `yaml:"anti_aliasing" json:"anti_aliasing"` // Enable/disable anti-aliasing
Palette map[string]string `yaml:"palette" json:"palette"` // Logical palette color mappings
}
ScreenConfig defines the canvas dimensions and palette.
type ShapeElement ΒΆ
type ShapeElement struct {
BaseElement `yaml:",inline" json:",inline"`
Kind string `yaml:"kind,omitempty" json:"kind,omitempty"` // "rect", "circle", "ellipse", "polygon"
Color string `yaml:"color,omitempty" json:"color,omitempty"` // Fill color
Border *BorderConfig `yaml:"border,omitempty" json:"border,omitempty"` // Stroke/border settings
CornerRadius float64 `yaml:"corner_radius,omitempty" json:"corner_radius,omitempty"` // For "rect"
Sides int `yaml:"sides,omitempty" json:"sides,omitempty"` // For "polygon"
Rotation float64 `yaml:"rotation,omitempty" json:"rotation,omitempty"` // Static rotation in degrees
RotationExpr string `yaml:"rotation_expr,omitempty" json:"rotation_expr,omitempty"` // Dynamic rotation expression/source
Thresholds []Threshold `yaml:"thresholds,omitempty" json:"thresholds,omitempty"`
}
ShapeElement represents a geometric primitive (rectangle, circle, polygon).
type TelemetryEnricher ΒΆ
TelemetryEnricher is an optional callback that injects derived key-value pairs into the local telemetry map when evaluating per-bar or per-label thresholds. It receives the chart source name and the current bar/label value, and returns any additional keys that should be visible in the condition expression.
type TextElement ΒΆ
type TextElement struct {
BaseElement `yaml:",inline" json:",inline"`
Font FontStyle `yaml:"font,omitempty" json:"font,omitempty"`
Align Align `yaml:"align,omitempty" json:"align,omitempty"`
Color string `yaml:"color,omitempty" json:"color,omitempty"`
Template string `yaml:"template,omitempty" json:"template,omitempty"`
FitText *bool `yaml:"fit_text,omitempty" json:"fit_text,omitempty"`
}
TextElement represents a text component.
type Threshold ΒΆ
type Threshold struct {
Condition string `yaml:"condition,omitempty" json:"condition,omitempty"` // Comparison expression (e.g. "aqi.us.zone.index >= 3")
Label string `yaml:"label,omitempty" json:"label,omitempty"` // Custom text label on match
Bg string `yaml:"bg,omitempty" json:"bg,omitempty"` // Custom background color on match
Fg string `yaml:"fg,omitempty" json:"fg,omitempty"` // Custom foreground/text color on match
Color string `yaml:"color,omitempty" json:"color,omitempty"` // Hex color code reference
Path string `yaml:"path,omitempty" json:"path,omitempty"` // Image path override
Opacity *float64 `yaml:"opacity,omitempty" json:"opacity,omitempty"` // Opacity override
}
Threshold defines a condition-based styling override.
type ThresholdLine ΒΆ
type ThresholdLine struct {
Condition string `yaml:"condition,omitempty" json:"condition,omitempty"` // Expression to trigger the line
Value float64 `yaml:"value,omitempty" json:"value,omitempty"` // Static threshold value
LineConfig `yaml:",inline" json:",inline"`
}
ThresholdLine configures a horizontal threshold line drawn on charts.
type ValueCardElement ΒΆ
type ValueCardElement struct {
BaseElement `yaml:",inline" json:",inline"`
Value ComponentConfig `yaml:"value,omitempty" json:"value,omitempty"`
Label ComponentConfig `yaml:"label,omitempty" json:"label,omitempty"`
Unit ComponentConfig `yaml:"unit,omitempty" json:"unit,omitempty"`
Border *BorderConfig `yaml:"border,omitempty" json:"border,omitempty"`
Format string `yaml:"format,omitempty" json:"format,omitempty"`
Padding float64 `yaml:"padding,omitempty" json:"padding,omitempty"`
Radius float64 `yaml:"radius,omitempty" json:"radius,omitempty"`
}
ValueCardElement represents a complex value displaying component.
(Image generated automatically from