Documentation
¶
Overview ¶
Package scale holds the per-type scale implementations consumed by the encode stage. P06 ships the 8 canonical scale types: linear, log, pow, sqrt, time, band, point, ordinal. Each implementation satisfies the Scale interface declared here.
The package is leaf-y on purpose: it imports encode/scene (for the canonical ScaleType enum + Color) and errors, but nothing from encode/ itself. The dispatch lives in encode/scale.go so back-compat callers continue to use encode.ResolveScale.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type BandScale ¶
type BandScale struct {
Categories []string
RangeMin float64
RangeMax float64
Padding float64 // [0,1) inner padding (fraction of step)
}
BandScale is the categorical scale used by bar / rect marks. Each category gets a band of equal width; padding leaves an inner gap.
func (*BandScale) Apply ¶
Apply implements Scale. Returns the left edge of the band for the given category.
func (*BandScale) BandCenter ¶
BandCenter returns the center x of the band for category cat.
type BandSizer ¶
type BandSizer interface {
BandWidth() float64
}
BandSizer is the optional capability returning a band's pixel width. Implemented by BandScale; bar / rect mark encoders ask for it.
type LinearScale ¶
LinearScale is the canonical quantitative scale: linear interpolation from [DomainMin, DomainMax] to [RangeMin, RangeMax]. Range may be inverted (RangeMin > RangeMax) for y-axes where data 0 sits at the bottom of the SVG.
type LogScale ¶
type LogScale struct {
Base float64
DomainMin float64
DomainMax float64
RangeMin float64
RangeMax float64
}
LogScale interpolates log(value)/log(base) linearly into the pixel range. Domain must be strictly positive — non-positive values raise PRISM_SPEC_010 at resolve time.
type OrdinalScale ¶
OrdinalScale maps discrete categories to explicit pixel positions. Used when the caller already knows where each category sits (typical for fixed-position labels, color-scheme indexing).
func (*OrdinalScale) Apply ¶
func (s *OrdinalScale) Apply(value any) (float64, error)
Apply implements Scale.
func (*OrdinalScale) ApplyColor ¶
ApplyColor returns the palette entry indexed by the category's position in Categories (mod len(palette)). Returns nil when either category or palette is empty.
type PointScale ¶
type PointScale struct {
Categories []string
RangeMin float64
RangeMax float64
Padding float64 // [0,1) outer padding (fraction of step)
}
PointScale places each category at the center of an evenly-divided step. Unlike BandScale it has no bandwidth — Apply returns the point itself, not a band's left edge. Used for line/point fixtures where the x-axis is categorical but the marks need a single coordinate.
type PowScale ¶
type PowScale struct {
Exp float64
DomainMin float64
DomainMax float64
RangeMin float64
RangeMax float64
}
PowScale interpolates sign(v)*|v|^exp linearly into the pixel range. Default exp = 1 reduces to a linear scale. The signed-power shape handles negative inputs correctly (Vega-Lite parity).
type Scale ¶
type Scale interface {
// Apply resolves a data value to its pixel coordinate. Returns
// PRISM_ENCODE_001 on type / category mismatches.
Apply(value any) (float64, error)
// Domain returns the resolved input domain. Cast on read.
Domain() []any
// Range returns the [min,max] pixel range the scale maps into.
Range() [2]float64
// Type returns the canonical scene.ScaleType for this scale.
Type() scene.ScaleType
}
Scale resolves a single data value into a pixel coordinate. The concrete impls live one-per-file in this package.
type SqrtScale ¶
type SqrtScale struct {
Inner PowScale
}
SqrtScale is PowScale with exp=0.5 surfaced as its own type so scene.ScaleType reads correctly.
type TimeScale ¶
type TimeScale struct {
Linear *LinearScale
}
TimeScale wraps a LinearScale over epoch-ms. Apply accepts time.Time, ISO-8601 strings, and numeric epoch ms. Calendar-aware tick generation lives in encode/ticks_time.go.