Skip to content

OrdinalScale

Mojo struct 🡭

OrdinalScale

@memory_only
struct OrdinalScale

Fields

  • domain (List[String]): The fixed-order category list this scale’s bands index into – Plot’s own _categorical.x, index for index.
  • range_min (Float64): The pixel position the first category’s band starts from.
  • range_max (Float64): The pixel position the last category’s band ends at.
  • padding (Float64): The fraction of each category’s slot left as a gap, split evenly between a band and each of its neighbors; defaults to 0.2.

Implemented traits

AnyType, Deinitable, Movable

Methods

__init__

fn def __init__(out self, var domain: List[String], range_min: Float64, range_max: Float64, padding: Float64 = 0.20000000000000001)

Construct an OrdinalScale over domain, banded across [range_min, range_max].

Args:

  • domain (List[String]): The fixed-order category list, index for index.
  • range_min (Float64): The pixel position the first band starts from.
  • range_max (Float64): The pixel position the last band ends at.
  • padding (Float64): The fraction of each slot left as a gap; defaults to 0.2.
  • self (Self)

Returns:

Self

step

fn def step(self) -> Float64

The pixel width of one category’s full slot, band plus padding; 0.0 for an empty domain.

Args:

  • self (Self)

Returns:

Float64: The pixel width of one full slot.

bandwidth

fn def bandwidth(self) -> Float64

The pixel width of the band itself (a bar’s width): step() minus the padding on both sides.

Args:

  • self (Self)

Returns:

Float64: The pixel width of the band itself.

band_start

fn def band_start(self, index: Int) -> Float64

The left pixel edge of the band at index: half the slot’s padding in from the slot start.

Args:

  • self (Self)
  • index (Int): The category’s position in domain.

Returns:

Float64: The band’s left pixel edge.

band_end

fn def band_end(self, index: Int) -> Float64

The right pixel edge of the band at index: half the slot’s padding in from the next slot’s start.

Uses the same expression as the next band’s start so unpadded neighbors share a bitwise-identical boundary.

Args:

  • self (Self)
  • index (Int): The category’s position in domain.

Returns:

Float64: The band’s right pixel edge.

center

fn def center(self, index: Int) -> Float64

The horizontal pixel center of the band at index – band_start(index) plus half bandwidth().

Args:

  • self (Self)
  • index (Int): The category’s position in domain.

Returns:

Float64: The band’s horizontal pixel center.