position

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 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 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 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 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.

NOTE: Real stacking requires the pipeline coordinator to accumulate offsets across groups. This is not yet implemented — calling Stack() with groupIdx > 0 will panic. Use Dodge or Identity instead.

Jump to

Keyboard shortcuts

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