position

package
v0.0.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 14, 2026 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package position defines position adjustments that control how overlapping geometries are arranged. In ggplot2's grammar, position adjustments are applied after statistical transforms and before final rendering.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FillSetup added in v0.0.4

type FillSetup interface {
	Setup(allXs, allYs [][]float64)
}

FillSetup is optionally implemented by position adjustments that need a pre-pass over all groups before per-group Adjust calls.

type Name added in v0.0.4

type Name string

Name identifies a position adjustment type for factory lookup.

const (
	NameIdentity Name = "identity"
	NameDodge    Name = "dodge"
	NameStack    Name = "stack"
	NameFill     Name = "fill"
	NameJitter   Name = "jitter"
	NameNudge    Name = "nudge"
)

Position adjustment names.

type Pos

type Pos interface {
	// Adjust modifies (x, y) positions for a single group within a layer.
	// groupIdx is the 0-based index of this group, nGroups is the total count.
	// width is the available bin width for dodging/stacking calculations.
	Adjust(xs, ys []float64, width float64, groupIdx, nGroups int) ([]float64, []float64)

	// String returns a human-readable label.
	String() string
}

Pos adjusts the positions of geometric elements to handle overlap. Each adjustment receives the raw data coordinates and group metadata, and returns adjusted coordinates.

func Dodge

func Dodge() Pos

Dodge returns a position that shifts groups side by side within each bin. This is the standard adjustment for grouped bar charts.

func Fill added in v0.0.4

func Fill() Pos

Fill returns a position that stacks groups and normalizes each x-bin to a total of 1.0 (100% stacked bar chart).

Fill is a two-phase adjustment:

  1. Setup phase: call FillSetup with all groups' (xs, ys) to compute totals.
  2. Adjust phase: call Adjust for each group in order.

If Setup is not called, Fill behaves like Stack (no normalization).

func Identity

func Identity() Pos

Identity returns the identity position (no adjustment).

func Jitter

func Jitter(xAmount, yAmount float64) Pos

Jitter returns a position that adds random noise to (x, y) to reduce overplotting. The jitter is reproducible: same data length produces same offsets.

func New added in v0.0.4

func New(name Name) Pos

New creates a fresh Pos instance by name. This is used by the build pipeline to create per-panel-layer position instances (avoiding shared state across panels). Returns Identity for unknown names.

func Nudge

func Nudge(dx, dy float64) Pos

Nudge returns a position that shifts all points by a fixed offset.

func Stack

func Stack() Pos

Stack returns a position that stacks groups vertically. Each group's y-values are offset by the cumulative sum of prior groups at the same x-value.

Stack is stateful: it accumulates offsets across successive Adjust calls. The build pipeline must create a fresh Stack() instance per panel-layer to avoid cross-panel contamination.

type Stacker added in v0.0.4

type Stacker interface {
	AdjustStack(xs, ys []float64, width float64, groupIdx, nGroups int) (adjXs, yMin, yMax []float64)
}

Stacker is optionally implemented by positions that produce stacked output. When implemented, AdjustStack returns (adjustedXs, yMin, yMax) where yMin is the bottom of each bar and yMax is the top. The pipeline uses yMin to set the bar's base coordinate.

Jump to

Keyboard shortcuts

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