Documentation
¶
Overview ¶
Package scale provides scale transformations that map data values to visual aesthetic values. Scales control axis ranges, color mappings, size mappings, and produce the guides (axes and legends) that make plots interpretable.
Continuous scales map a numeric domain [min, max] to a visual range. Discrete scales map categorical values to a set of visual values.
Index ¶
- Variables
- func FormatNumber(v float64) string
- func NiceSequence(lo, hi float64, n int) []float64
- type BoundsSetter
- type DiscreteScale
- func (s *DiscreteScale) Bounds() (float64, float64)
- func (s *DiscreteScale) Categories() []string
- func (s *DiscreteScale) Format(v float64) string
- func (s *DiscreteScale) Inverse(v float64) float64
- func (s *DiscreteScale) Map(v float64) float64
- func (s *DiscreteScale) MapCategory(label string) float64
- func (s *DiscreteScale) SetBounds(mn, mx float64)
- func (s *DiscreteScale) String() string
- func (s *DiscreteScale) Ticks(n int) []float64
- func (s *DiscreteScale) Train(col dataset.AnyColumn) error
- func (s *DiscreteScale) TrainValues(labels []string)
- type LinearScale
- func (s *LinearScale) Bounds() (float64, float64)
- func (s *LinearScale) Format(v float64) string
- func (s *LinearScale) Inverse(v float64) float64
- func (s *LinearScale) Map(v float64) float64
- func (s *LinearScale) SetBounds(mn, mx float64)
- func (s *LinearScale) String() string
- func (s *LinearScale) Ticks(n int) []float64
- func (s *LinearScale) Train(col dataset.AnyColumn) error
- type Manager
- type Scale
- type Type
Constants ¶
This section is empty.
Variables ¶
var Q = []float64{1, 5, 2, 2.5, 4, 3}
Q is the preference-ordered set of "nice" step multipliers. Order encodes simplicity: earlier values are preferred.
Functions ¶
func FormatNumber ¶
FormatNumber formats a tick value for display. Integers are shown without decimals, floats use compact notation.
func NiceSequence ¶
NiceSequence produces approximately n optimally placed tick positions between lo and hi using the Talbot-Lin-Hanrahan (2010) extended Wilkinson algorithm. See ticks.go for the full implementation.
Types ¶
type BoundsSetter ¶
type BoundsSetter interface {
SetBounds(mn, mx float64)
}
BoundsSetter is an optional interface for scales that support manual bounds override. Both LinearScale and DiscreteScale implement this.
type DiscreteScale ¶
type DiscreteScale struct {
// contains filtered or unexported fields
}
DiscreteScale maps categorical string values to evenly-spaced [0, N-1] positions where N is the number of unique categories.
func Discrete ¶
func Discrete() *DiscreteScale
Discrete returns a discrete (categorical) scale that maps string labels to evenly-spaced numeric positions. Categories are extracted during Train and sorted alphabetically for deterministic ordering.
func (*DiscreteScale) Bounds ¶
func (s *DiscreteScale) Bounds() (float64, float64)
func (*DiscreteScale) Categories ¶
func (s *DiscreteScale) Categories() []string
Categories returns the ordered category labels.
func (*DiscreteScale) Format ¶
func (s *DiscreteScale) Format(v float64) string
func (*DiscreteScale) Inverse ¶
func (s *DiscreteScale) Inverse(v float64) float64
func (*DiscreteScale) Map ¶
func (s *DiscreteScale) Map(v float64) float64
func (*DiscreteScale) MapCategory ¶
func (s *DiscreteScale) MapCategory(label string) float64
MapCategory maps a category label to its numeric position.
func (*DiscreteScale) SetBounds ¶
func (s *DiscreteScale) SetBounds(mn, mx float64)
SetBounds overrides the domain bounds (used by pipeline padding logic).
func (*DiscreteScale) String ¶
func (s *DiscreteScale) String() string
func (*DiscreteScale) Ticks ¶
func (s *DiscreteScale) Ticks(n int) []float64
func (*DiscreteScale) Train ¶
func (s *DiscreteScale) Train(col dataset.AnyColumn) error
Train extracts unique string values from the column. If the column is already numeric (e.g. after stat transforms), this is a no-op.
func (*DiscreteScale) TrainValues ¶
func (s *DiscreteScale) TrainValues(labels []string)
TrainValues trains the scale from a pre-built slice of category labels.
type LinearScale ¶
type LinearScale struct {
// contains filtered or unexported fields
}
LinearScale is a standard linear continuous scale.
func (*LinearScale) Bounds ¶
func (s *LinearScale) Bounds() (float64, float64)
func (*LinearScale) Format ¶
func (s *LinearScale) Format(v float64) string
func (*LinearScale) Inverse ¶
func (s *LinearScale) Inverse(v float64) float64
func (*LinearScale) Map ¶
func (s *LinearScale) Map(v float64) float64
func (*LinearScale) SetBounds ¶
func (s *LinearScale) SetBounds(mn, mx float64)
SetBounds manually overrides the scale domain. Used by the rendering pipeline for padding and forcing Y=0.
func (*LinearScale) String ¶
func (s *LinearScale) String() string
func (*LinearScale) Ticks ¶
func (s *LinearScale) Ticks(n int) []float64
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager holds trained scales for all aesthetic channels.
type Scale ¶
type Scale interface {
// Train updates the scale's domain from the given column data.
Train(col dataset.AnyColumn) error
// Map transforms a raw value to the [0,1] normalized scale.
Map(v float64) float64
// Inverse maps a [0,1] normalized value back to data space.
Inverse(v float64) float64
// Ticks generates n nicely spaced tick positions in data space.
Ticks(n int) []float64
// Format converts a data value to a display string.
Format(v float64) string
// Bounds returns the trained domain [min, max].
Bounds() (float64, float64)
// String returns a description.
String() string
}
Scale defines the interface for all scale types.
func NewReverse ¶
func NewReverse() Scale
NewReverse returns a scale that inverts the axis direction.