layout

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: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ChartCell

func ChartCell(row, col, rowSpan, colSpan int) *layout.Node

ChartCell creates a chart cell with specific grid positioning

func ChartGrid

func ChartGrid(rows, cols int) *layout.Node

ChartGrid creates a CSS Grid layout for charts Uses fr units to create equally-sized cells

func ChartGridCustom

func ChartGridCustom(rowTracks, colTracks []layout.GridTrack) *layout.Node

ChartGridCustom creates a grid with custom track sizes

func ChartGridWithGap

func ChartGridWithGap(rows, cols int, gap float64) *layout.Node

ChartGridWithGap creates a grid with gap between cells

func ChartHStack

func ChartHStack() *layout.Node

ChartHStack creates a horizontal flexbox stack of charts

func ChartVStack

func ChartVStack() *layout.Node

ChartVStack creates a vertical flexbox stack of charts

func ComputeMarginForAxes

func ComputeMarginForAxes(hasLeft, hasRight, hasTop, hasBottom, hasTitle bool) (top, right, bottom, left float64)

ComputeMarginForAxes automatically computes margins based on axis requirements

func ComputeSharedDomain

func ComputeSharedDomain(facets []FacetData, field string) (min, max float64)

ComputeSharedDomain calculates shared domain across all facets

func DefaultChartMargin

func DefaultChartMargin() (top, right, bottom, left float64)

DefaultChartMargin returns typical margins for a chart with axes

func GetScaleDomain

func GetScaleDomain(facets []FacetData, facetIndex int, field string, sharing ScaleSharing) (min, max float64)

GetScaleDomain returns the domain for a scale based on sharing strategy

func QuadLayout

func QuadLayout(width, height float64) *layout.Node

QuadLayout creates a 2x2 grid layout

func RenderChartTree

func RenderChartTree(root *layout.Node, width, height float64, renderFunc func(*layout.Node) string) string

Helper to render chart nodes to SVG

func SideBySideLayout

func SideBySideLayout(width, height float64) *layout.Node

SideBySideLayout creates a 1x2 grid layout

func TopBottomLayout

func TopBottomLayout(width, height float64) *layout.Node

TopBottomLayout creates a 2x1 grid layout

func TraverseAndRender

func TraverseAndRender(node *layout.Node) string

TraverseAndRender walks the tree and renders each chart node

func WithCustomMargin

func WithCustomMargin(node *layout.Node, top, right, bottom, left float64) *layout.Node

WithCustomMargin adds custom margin to each side

func WithCustomPadding

func WithCustomPadding(node *layout.Node, top, right, bottom, left float64) *layout.Node

WithCustomPadding adds custom padding to each side

func WithFlexGrow

func WithFlexGrow(node *layout.Node, grow float64) *layout.Node

WithFlexGrow sets the flex grow factor

func WithMargin

func WithMargin(node *layout.Node, margin float64) *layout.Node

WithMargin adds margin to a chart node

func WithPadding

func WithPadding(node *layout.Node, padding float64) *layout.Node

WithPadding adds padding to a chart node

func WithSize

func WithSize(node *layout.Node, width, height float64) *layout.Node

WithSize sets explicit width and height

Types

type ChartNode

type ChartNode struct {
	*layout.Node

	// Chart-specific metadata
	ChartType string        // Type of chart (bar, line, scatter, etc.)
	Data      interface{}   // Chart data
	Renderer  ChartRenderer // Function to render this chart
}

ChartNode wraps a layout.Node with chart-specific functionality This provides the bridge between dataviz concepts and the layout engine

func NewChartNode

func NewChartNode() *ChartNode

NewChartNode creates a new chart node

func (*ChartNode) Render

func (cn *ChartNode) Render() string

Render renders this chart node

func (*ChartNode) WithData

func (cn *ChartNode) WithData(data interface{}) *ChartNode

WithData sets the chart data

func (*ChartNode) WithRenderer

func (cn *ChartNode) WithRenderer(renderer ChartRenderer) *ChartNode

WithRenderer sets the chart renderer

func (*ChartNode) WithType

func (cn *ChartNode) WithType(chartType string) *ChartNode

WithType sets the chart type

type ChartRenderer

type ChartRenderer func(node *layout.Node) string

ChartRenderer renders a chart within its layout bounds

type Dashboard

type Dashboard struct {
	Width  float64
	Height float64
	Gap    float64
	Charts []*ChartNode
}

Dashboard creates a flexible dashboard layout Allows charts to specify their grid position and span

func NewDashboard

func NewDashboard(width, height float64) *Dashboard

NewDashboard creates a new dashboard

func (*Dashboard) AddChart

func (d *Dashboard) AddChart(chart *ChartNode) *Dashboard

AddChart adds a chart to the dashboard

func (*Dashboard) Layout

func (d *Dashboard) Layout() *layout.Node

Layout computes the layout and returns the root node

func (*Dashboard) Render

func (d *Dashboard) Render() string

Render renders the dashboard to SVG

func (*Dashboard) WithGap

func (d *Dashboard) WithGap(gap float64) *Dashboard

WithGap sets the gap between charts

type FacetData

type FacetData struct {
	Value string                 // Facet category value
	Data  []transforms.DataPoint // Data points for this facet
	Index int                    // Position in facet order
	Node  *layout.Node           // Layout node for this facet
}

FacetData holds data split by facet values

type FacetLayout

type FacetLayout struct {
	Rows   int
	Cols   int
	Gap    float64
	Width  float64
	Height float64
}

FacetLayout creates a grid layout for faceted plots

func NewFacetLayout

func NewFacetLayout(rows, cols int, width, height float64) *FacetLayout

NewFacetLayout creates a new facet layout

func (*FacetLayout) Build

func (fl *FacetLayout) Build() *layout.Node

Build creates the layout node

type FacetPlot

type FacetPlot struct {
	Spec   *FacetSpec
	Width  float64
	Height float64
	Data   []transforms.DataPoint

	// Renderer for each facet cell
	CellRenderer func(data []transforms.DataPoint, bounds layout.Rect) string

	// Optional title renderer
	TitleRenderer func(value string, bounds layout.Rect) string
}

FacetPlot creates a faceted visualization

func NewFacetPlot

func NewFacetPlot(spec *FacetSpec, width, height float64) *FacetPlot

NewFacetPlot creates a new faceted plot

func (*FacetPlot) Render

func (fp *FacetPlot) Render() string

Render renders the faceted plot

func (*FacetPlot) WithCellRenderer

func (fp *FacetPlot) WithCellRenderer(renderer func(data []transforms.DataPoint, bounds layout.Rect) string) *FacetPlot

WithCellRenderer sets the cell renderer

func (*FacetPlot) WithData

func (fp *FacetPlot) WithData(data []transforms.DataPoint) *FacetPlot

WithData sets the data

func (*FacetPlot) WithTitleRenderer

func (fp *FacetPlot) WithTitleRenderer(renderer func(value string, bounds layout.Rect) string) *FacetPlot

WithTitleRenderer sets the title renderer

type FacetSpec

type FacetSpec struct {
	// Field to facet by (DataPoint.Group or other field)
	Field string

	// Number of columns
	NCols int

	// Number of rows (0 = auto)
	NRows int

	// Scale sharing strategy
	ScaleSharing ScaleSharing

	// Whether to show titles for each facet
	ShowTitles bool

	// Custom ordering for facet values
	Order []string

	// Gap between facets
	Gap float64

	// Margin around each facet plot area
	FacetMargin float64
}

Facet represents a specification for creating small multiples

func NewFacetSpec

func NewFacetSpec(field string) *FacetSpec

NewFacetSpec creates a new facet specification

func (*FacetSpec) BuildLayout

func (f *FacetSpec) BuildLayout(numFacets int, width, height float64) *layout.Node

BuildLayout creates a CSS Grid layout for facets

func (*FacetSpec) CalculateDimensions

func (f *FacetSpec) CalculateDimensions(numFacets int) (rows, cols int)

CalculateDimensions calculates grid dimensions based on number of facets

func (*FacetSpec) Split

func (f *FacetSpec) Split(data []transforms.DataPoint) []FacetData

Split splits data into facets based on the field

func (*FacetSpec) WithCols

func (f *FacetSpec) WithCols(cols int) *FacetSpec

WithCols sets the number of columns

func (*FacetSpec) WithFacetMargin

func (f *FacetSpec) WithFacetMargin(margin float64) *FacetSpec

WithFacetMargin sets the margin around each facet

func (*FacetSpec) WithGap

func (f *FacetSpec) WithGap(gap float64) *FacetSpec

WithGap sets the gap between facets

func (*FacetSpec) WithOrder

func (f *FacetSpec) WithOrder(order []string) *FacetSpec

WithOrder sets custom ordering for facet values

func (*FacetSpec) WithRows

func (f *FacetSpec) WithRows(rows int) *FacetSpec

WithRows sets the number of rows

func (*FacetSpec) WithScaleSharing

func (f *FacetSpec) WithScaleSharing(sharing ScaleSharing) *FacetSpec

WithScaleSharing sets the scale sharing strategy

func (*FacetSpec) WithTitles

func (f *FacetSpec) WithTitles(show bool) *FacetSpec

WithTitles sets whether to show titles

type MarginConvention

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

MarginConvention implements the D3 margin convention for charts This pattern reserves space for axes, titles, and labels around a plot area

Example:

mc := NewMarginConvention(800, 600)
mc.SetMargin(60, 20, 50, 60) // top, right, bottom, left
plotArea := mc.PlotArea() // Get inner drawing area

func NewMarginConvention

func NewMarginConvention(width, height float64) *MarginConvention

NewMarginConvention creates a new margin convention

func (*MarginConvention) AsNode

func (mc *MarginConvention) AsNode() *layout.Node

AsNode creates a layout.Node with the margin convention applied

func (*MarginConvention) BottomMarginArea

func (mc *MarginConvention) BottomMarginArea() layout.Rect

BottomMarginArea returns the bounds of the bottom margin (for X axis)

func (*MarginConvention) LeftMarginArea

func (mc *MarginConvention) LeftMarginArea() layout.Rect

LeftMarginArea returns the bounds of the left margin (for Y axis)

func (*MarginConvention) PlotArea

func (mc *MarginConvention) PlotArea() layout.Rect

PlotArea returns a Rect representing the plot area

func (*MarginConvention) PlotHeight

func (mc *MarginConvention) PlotHeight() float64

PlotHeight returns the height of the plot area

func (*MarginConvention) PlotWidth

func (mc *MarginConvention) PlotWidth() float64

PlotWidth returns the width of the plot area

func (*MarginConvention) RightMarginArea

func (mc *MarginConvention) RightMarginArea() layout.Rect

RightMarginArea returns the bounds of the right margin

func (*MarginConvention) SetMargin

func (mc *MarginConvention) SetMargin(top, right, bottom, left float64) *MarginConvention

SetMargin sets all margins at once

func (*MarginConvention) SetUniformMargin

func (mc *MarginConvention) SetUniformMargin(margin float64) *MarginConvention

SetUniformMargin sets the same margin on all sides

func (*MarginConvention) TopMarginArea

func (mc *MarginConvention) TopMarginArea() layout.Rect

TopMarginArea returns the bounds of the top margin (for title)

func (*MarginConvention) TotalBounds

func (mc *MarginConvention) TotalBounds() layout.Rect

TotalBounds returns the full canvas bounds

type ScaleSharing

type ScaleSharing string

ScaleSharing defines how scales are shared across facets

const (
	ScaleShareNone ScaleSharing = "none" // Independent scales per facet
	ScaleShareX    ScaleSharing = "x"    // Share X scale only
	ScaleShareY    ScaleSharing = "y"    // Share Y scale only
	ScaleShareXY   ScaleSharing = "xy"   // Share both X and Y scales
)

Jump to

Keyboard shortcuts

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