Documentation
¶
Overview ¶
Package facet splits a dataset into subsets for "small multiple" panel layouts. Faceting is a core component of the Grammar of Graphics, allowing the same plot specification to be repeated across levels of a categorical variable.
Index ¶
Constants ¶
const MarginLabel = "All"
MarginLabel is the display value used for aggregate margin panels.
Variables ¶
var ErrFacetConfig = errors.New("facet: invalid configuration")
ErrFacetConfig is returned for invalid facet configuration.
Functions ¶
This section is empty.
Types ¶
type Facet ¶
type Facet interface {
// Split partitions the dataset into panels. Each panel has a label
// and a filtered subset of the data.
Split(ctx context.Context, ds dataset.Dataset) ([]Panel, error)
// GridDims returns the (rows, cols) grid dimensions for layout.
// For Wrap, this is computed from the number of panels and nCols.
GridDims(nPanels int) (rows, cols int)
// FreeScales returns whether X and Y scales are independent per panel.
// When false (default), all panels share unified scale bounds.
FreeScales() (freeX, freeY bool)
// SpaceMode returns the space allocation mode for panels:
// "fixed" — all panels have equal size (default)
// "free" — panel sizes proportional to data range (both axes)
// "free_x" — column widths proportional to X range
// "free_y" — row heights proportional to Y range
SpaceMode() string
// StripPositions returns the strip label placement for column and row strips.
// col: "top" (default) or "bottom"
// row: "right" (default) or "left"
StripPositions() (col, row string)
// String returns a human-readable description.
String() string
}
Facet defines how a dataset is split into panels for small-multiple layouts.
type GridOpt ¶ added in v0.0.9
type GridOpt func(*gridFacet)
GridOpt configures a Grid facet.
func GridFreeX ¶ added in v0.0.9
func GridFreeX() GridOpt
GridFreeX makes each column's X scale independent.
func GridFreeY ¶ added in v0.0.9
func GridFreeY() GridOpt
GridFreeY makes each row's Y scale independent.
func GridLabeller ¶ added in v0.0.9
GridLabeller sets the label formatter for Grid facets.
func GridMargins ¶ added in v0.0.9
GridMargins enables aggregate margin panels (default: false). When true, extra panels are added that aggregate across row/column values.
func GridSpace ¶ added in v0.0.9
GridSpace sets the space allocation mode for grid panels. Valid modes: "fixed" (default), "free", "free_x", "free_y". "free" modes make panel sizes proportional to their data range. Requires the corresponding free scale to be meaningful.
func GridStripBottom ¶ added in v0.0.9
func GridStripBottom() GridOpt
GridStripBottom places column strip labels at the bottom of the grid.
func GridStripLeft ¶ added in v0.0.9
func GridStripLeft() GridOpt
GridStripLeft places row strip labels at the left of the grid.
type Labeller ¶ added in v0.0.9
Labeller formats facet panel strip labels. It receives the faceting variable name and the panel's raw value, returning the display string.
func LabelBoth ¶ added in v0.0.9
func LabelBoth() Labeller
LabelBoth returns a labeller that shows "variable: value".
"species: setosa", "species: versicolor"
func LabelContext ¶ added in v0.0.9
func LabelContext() Labeller
LabelContext returns a labeller that shows "variable: value" for Grid facets (where context is ambiguous) and just "value" for Wrap facets. The choice is made internally by the facet type at Split time.
func LabelValue ¶ added in v0.0.9
func LabelValue() Labeller
LabelValue returns a labeller that shows only the value. This is the default labeller.
"setosa", "versicolor", "virginica"
type Panel ¶
type Panel struct {
Label string // formatted display label
RowVal string // raw row facet value (Grid only, "" for Wrap)
ColVal string // raw column facet value (Grid only, "" for Wrap)
Dataset dataset.Dataset
NumRows int // number of rows matching this panel's filter
IsMargin bool // true for aggregate margin panels
}
Panel represents a single facet panel containing a data subset.
type WrapOpt ¶
type WrapOpt func(*wrapFacet)
WrapOpt configures a Wrap facet.
func FreeXY ¶ added in v0.0.9
func FreeXY() WrapOpt
FreeXY makes both X and Y scales independent per panel.
func StripBottom ¶ added in v0.0.9
func StripBottom() WrapOpt
StripBottom places wrap strip labels at the bottom of each panel.
func WithDrop ¶ added in v0.0.9
WithDrop controls whether empty panels are omitted (default: true). When false, panels with zero rows are emitted for all distinct values.
func WithLabeller ¶ added in v0.0.9
WithLabeller sets the label formatter for Wrap facets.