Skip to main content

Position

Trait Position 

Source
pub trait Position: Send + Sync {
    // Required methods
    fn compute(&self, data: &mut DataFrame, params: &PositionParams);
    fn name(&self) -> &str;

    // Provided methods
    fn per_panel(&self) -> bool { ... }
    fn group_order(&self, _data: &DataFrame) -> Option<Vec<String>> { ... }
    fn validate(&self, _warnings: &mut Vec<String>) { ... }
}
Expand description

Trait for position adjustments.

Required Methods§

Source

fn compute(&self, data: &mut DataFrame, params: &PositionParams)

Adjust positions for data.

Source

fn name(&self) -> &str

Provided Methods§

Source

fn per_panel(&self) -> bool

Whether this position must run separately per facet panel rather than once on the pooled rows before facets are split (B3-3, D8). Default false. PositionStack/PositionFill override this to true — a shared x category’s stack height must not mix rows from different panels. PositionDodge/PositionDodge2/PositionJitter also override this to true (sipemu/ggplot-rs#153): ggplot2 computes a dodge’s group count/offset via compute_panel (per panel), and position_jitter’s default width/height — 40% of resolution() — is likewise measured from each panel’s own x/y, not the rows pooled across panels (verified against ggplot2 4.0.3 with layer_data() on faceted plots; see tests/position_panels_r.rs).

Source

fn group_order(&self, _data: &DataFrame) -> Option<Vec<String>>

The whole layer’s group rank order (first-appearance, pre-panel- split), for a per_panel position whose group ranking must come from the whole layer even though its per-x counting stays per-panel (review #167 finding 2; sipemu/ggplot-rs#153). build::compute_position_per_panel calls this on the pooled data before splitting and threads the result through PositionParams::group_order to every panel’s compute call. Default None — positions that don’t need this (stack/fill/ jitter) are unaffected.

Source

fn validate(&self, _warnings: &mut Vec<String>)

Validate this position’s own parameters once per layer (D2); default no-op. Implementations push a warning and fall back to a sane default rather than panicking or silently miscomputing.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§