Documentation
¶
Overview ¶
Package chartir provides a non-polymorphic intermediate representation for Apache ECharts configurations. The IR is designed to be AI-friendly, easily validated via JSON Schema, and compiled to ECharts option objects.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Axis ¶
type Axis struct {
// ID uniquely identifies this axis.
ID string `json:"id"`
// Type specifies the axis scale type.
Type AxisType `json:"type"`
// Position specifies where the axis is placed.
Position AxisPosition `json:"position"`
// Name is the axis label/title.
Name string `json:"name,omitempty"`
// Min is the minimum axis value. If nil, auto-calculated.
Min *float64 `json:"min,omitempty"`
// Max is the maximum axis value. If nil, auto-calculated.
Max *float64 `json:"max,omitempty"`
}
Axis defines a chart axis.
func (Axis) IsHorizontal ¶
IsHorizontal returns true if the axis position is horizontal (top/bottom).
func (Axis) IsVertical ¶
IsVertical returns true if the axis position is vertical (left/right).
type AxisPosition ¶
type AxisPosition string
AxisPosition defines axis placement.
const ( AxisPositionBottom AxisPosition = "bottom" AxisPositionTop AxisPosition = "top" AxisPositionLeft AxisPosition = "left" AxisPositionRight AxisPosition = "right" )
func AxisPositions ¶
func AxisPositions() []AxisPosition
AxisPositions returns all valid axis position values.
func (AxisPosition) JSONSchema ¶
func (AxisPosition) JSONSchema() *jsonschema.Schema
JSONSchema implements jsonschema.Schema interface for enum generation.
type AxisType ¶
type AxisType string
AxisType defines the axis scale type.
func (AxisType) JSONSchema ¶
func (AxisType) JSONSchema() *jsonschema.Schema
JSONSchema implements jsonschema.Schema interface for enum generation.
type ChartIR ¶
type ChartIR struct {
// Title is the chart title text.
Title string `json:"title,omitempty"`
// Datasets contains the data sources for the chart.
// Each dataset is referenced by marks via DatasetID.
Datasets []Dataset `json:"datasets"`
// Marks define the visual representations (equivalent to ECharts series).
// All marks have the same structure regardless of geometry type.
Marks []Mark `json:"marks"`
// Axes define the chart axes. Optional for non-Cartesian charts (e.g., pie).
Axes []Axis `json:"axes,omitempty"`
// Legend configures the chart legend.
Legend *Legend `json:"legend,omitempty"`
// Tooltip configures hover tooltips.
Tooltip *Tooltip `json:"tooltip,omitempty"`
// Grid configures the chart container/grid positioning.
Grid *Grid `json:"grid,omitempty"`
}
ChartIR is the top-level chart intermediate representation. It provides a normalized, non-polymorphic structure that can be compiled to Apache ECharts option objects.
type Column ¶
type Column struct {
// Name is the column name/header.
Name string `json:"name"`
// Type is the data type for values in this column.
Type ColumnType `json:"type"`
}
Column defines a typed column in a dataset.
type ColumnType ¶
type ColumnType string
ColumnType defines the data type for a column.
const ( ColumnTypeString ColumnType = "string" ColumnTypeNumber ColumnType = "number" )
type CoordinateSystem ¶
type CoordinateSystem string
CoordinateSystem defines the coordinate system type.
const ( CoordinateCartesian2D CoordinateSystem = "cartesian2d" CoordinatePolar CoordinateSystem = "polar" CoordinateRadial CoordinateSystem = "radial" )
func CoordinateSystems ¶
func CoordinateSystems() []CoordinateSystem
CoordinateSystems returns all valid coordinate system values.
func (CoordinateSystem) JSONSchema ¶
func (CoordinateSystem) JSONSchema() *jsonschema.Schema
JSONSchema implements jsonschema.Schema interface for enum generation.
type Dataset ¶
type Dataset struct {
// ID uniquely identifies this dataset for reference by marks.
ID string `json:"id"`
// Columns defines the typed column definitions for the data.
Columns []Column `json:"columns"`
// Rows contains the data values as strings. Each row is an array
// of string values corresponding to the columns. The compiler
// parses values to numbers based on the column type.
Rows [][]string `json:"rows"`
}
Dataset represents tabular data for chart consumption. The structure is intentionally simple and uniform - always typed column definitions plus rows of string values.
type Encode ¶
type Encode struct {
// X maps to the x-axis (for Cartesian geometries).
X string `json:"x,omitempty"`
// Y maps to the y-axis (for Cartesian geometries).
Y string `json:"y,omitempty"`
// Value maps to the primary value (for pie, funnel, gauge, treemap).
Value string `json:"value,omitempty"`
// Name maps to the name/label (for pie chart segments, etc.).
Name string `json:"name,omitempty"`
// Size maps to mark size (for scatter plots).
Size string `json:"size,omitempty"`
// Color maps to mark color (for color encoding by data).
Color string `json:"color,omitempty"`
// Category maps to categorical grouping (for pie, funnel, treemap).
Category string `json:"category,omitempty"`
// Indicator maps to radar indicator (for radar charts).
Indicator string `json:"indicator,omitempty"`
// Source maps to source node (for sankey diagrams).
Source string `json:"source,omitempty"`
// Target maps to target node (for sankey diagrams).
Target string `json:"target,omitempty"`
// Heat maps to heat intensity (for heatmaps).
Heat string `json:"heat,omitempty"`
}
Encode maps data columns to visual channels. Not all fields are used by all geometry types.
type Geometry ¶
type Geometry string
Geometry defines the visual representation type. This replaces ECharts' polymorphic series.type with a simple enum.
const ( GeometryLine Geometry = "line" GeometryBar Geometry = "bar" GeometryPie Geometry = "pie" GeometryScatter Geometry = "scatter" GeometryArea Geometry = "area" GeometryRadar Geometry = "radar" GeometryFunnel Geometry = "funnel" GeometryGauge Geometry = "gauge" GeometryHeatmap Geometry = "heatmap" GeometryTreemap Geometry = "treemap" GeometrySankey Geometry = "sankey" )
func (Geometry) JSONSchema ¶
func (Geometry) JSONSchema() *jsonschema.Schema
JSONSchema implements jsonschema.Schema interface for enum generation.
type Grid ¶
type Grid struct {
// Left is the distance from the left edge.
Left string `json:"left,omitempty"`
// Right is the distance from the right edge.
Right string `json:"right,omitempty"`
// Top is the distance from the top edge.
Top string `json:"top,omitempty"`
// Bottom is the distance from the bottom edge.
Bottom string `json:"bottom,omitempty"`
// Width is the grid width.
Width string `json:"width,omitempty"`
// Height is the grid height.
Height string `json:"height,omitempty"`
// ContainLabel adjusts grid to contain axis labels.
ContainLabel bool `json:"containLabel,omitempty"`
}
Grid defines the chart container/grid positioning. Values can be percentages (e.g., "10%") or pixel values (e.g., "50").
type Legend ¶
type Legend struct {
// Show controls legend visibility.
Show bool `json:"show,omitempty"`
// Position specifies legend placement.
Position LegendPosition `json:"position,omitempty"`
// Items lists specific items to show. If empty, auto-generated from marks.
Items []string `json:"items,omitempty"`
}
Legend defines legend configuration.
type LegendPosition ¶
type LegendPosition string
LegendPosition defines legend placement.
const ( LegendPositionTop LegendPosition = "top" LegendPositionBottom LegendPosition = "bottom" LegendPositionLeft LegendPosition = "left" LegendPositionRight LegendPosition = "right" )
func LegendPositions ¶
func LegendPositions() []LegendPosition
LegendPositions returns all valid legend position values.
func (LegendPosition) JSONSchema ¶
func (LegendPosition) JSONSchema() *jsonschema.Schema
JSONSchema implements jsonschema.Schema interface for enum generation.
type Mark ¶
type Mark struct {
// ID uniquely identifies this mark.
ID string `json:"id"`
// DatasetID references the dataset to use for this mark.
DatasetID string `json:"datasetId"`
// Geometry specifies the visual representation type.
Geometry Geometry `json:"geometry"`
// CoordinateSystem specifies the coordinate system.
// Defaults to cartesian2d if not specified.
CoordinateSystem CoordinateSystem `json:"coordinateSystem,omitempty"`
// Encode maps data columns to visual channels.
Encode Encode `json:"encode"`
// Style defines visual styling properties.
Style *Style `json:"style,omitempty"`
// Stack groups marks for stacking. Marks with the same stack
// value are stacked together.
Stack string `json:"stack,omitempty"`
// Smooth enables smooth curves for line/area geometries.
Smooth bool `json:"smooth,omitempty"`
// Name is the display name for this mark in legends/tooltips.
Name string `json:"name,omitempty"`
}
Mark defines a visual mark (equivalent to ECharts series). All marks have the same structure regardless of geometry type. The compiler handles geometry-specific transformations.
type Style ¶
type Style struct {
// Color is the primary color (hex, rgb, or named color).
Color string `json:"color,omitempty"`
// Opacity is the transparency level (0.0 to 1.0).
Opacity *float64 `json:"opacity,omitempty"`
// BorderColor is the border/stroke color.
BorderColor string `json:"borderColor,omitempty"`
// BorderWidth is the border/stroke width in pixels.
BorderWidth *float64 `json:"borderWidth,omitempty"`
// Smooth enables smooth curves for line/area geometries.
Smooth bool `json:"smooth,omitempty"`
// AreaOpacity sets opacity for area fill (0.0 to 1.0).
AreaOpacity *float64 `json:"areaOpacity,omitempty"`
// LineWidth sets line stroke width in pixels.
LineWidth *float64 `json:"lineWidth,omitempty"`
// BarWidth sets bar width (number or percentage string).
BarWidth any `json:"barWidth,omitempty"`
// BarGap sets gap between bars (percentage string).
BarGap string `json:"barGap,omitempty"`
// BorderRadius sets bar corner radius.
BorderRadius any `json:"borderRadius,omitempty"`
// Symbol sets the marker symbol type.
Symbol string `json:"symbol,omitempty"`
// SymbolSize sets the marker symbol size.
SymbolSize *float64 `json:"symbolSize,omitempty"`
// Shape sets radar chart shape (polygon or circle).
Shape string `json:"shape,omitempty"`
// FunnelAlign sets funnel alignment (left, center, right).
FunnelAlign string `json:"funnelAlign,omitempty"`
// FunnelSort sets funnel sort direction (ascending, descending, none).
FunnelSort string `json:"funnelSort,omitempty"`
// FunnelGap sets gap between funnel segments.
FunnelGap *float64 `json:"funnelGap,omitempty"`
// StartAngle sets gauge start angle in degrees.
StartAngle *float64 `json:"startAngle,omitempty"`
// EndAngle sets gauge end angle in degrees.
EndAngle *float64 `json:"endAngle,omitempty"`
// GaugeMin sets gauge minimum value.
GaugeMin *float64 `json:"gaugeMin,omitempty"`
// GaugeMax sets gauge maximum value.
GaugeMax *float64 `json:"gaugeMax,omitempty"`
}
Style defines visual styling properties. The structure is intentionally flat and simple to avoid deep nesting that would require polymorphic handling.
type Tooltip ¶
type Tooltip struct {
// Show controls tooltip visibility.
Show bool `json:"show,omitempty"`
// Trigger specifies what triggers the tooltip.
Trigger TooltipTrigger `json:"trigger,omitempty"`
}
Tooltip defines tooltip configuration.
type TooltipTrigger ¶
type TooltipTrigger string
TooltipTrigger defines what triggers the tooltip.
const ( TooltipTriggerItem TooltipTrigger = "item" TooltipTriggerAxis TooltipTrigger = "axis" TooltipTriggerNone TooltipTrigger = "none" )
func TooltipTriggers ¶
func TooltipTriggers() []TooltipTrigger
TooltipTriggers returns all valid tooltip trigger values.
func (TooltipTrigger) JSONSchema ¶
func (TooltipTrigger) JSONSchema() *jsonschema.Schema
JSONSchema implements jsonschema.Schema interface for enum generation.