Skip to content
TickFormat

TickFormat

Mojo struct 🡭

TickFormat

@memory_only
struct TickFormat

How Theme.x_tick_format/y_tick_format render a tick label, Theme.show_data_labels’s value label, or a continuous legend’s endpoint labels – everywhere Ticks.labels()/ _format_tick() are the formatter. Same small-struct-with-comptime- constants-and-__eq__ pattern as Mark/OutputFormat, except FIXED() is a @staticmethod rather than a fixed comptime instance, since it carries a caller-chosen decimal count.

  • AUTO (default): SI prefixes at magnitudes >= 1e6 or below 1e-3 (except zero); otherwise _format_fixed at the domain’s own nice-step decimal count.
  • PERCENT: value * 100, suffixed % – 0.25 -> "25%".
  • THOUSANDS: comma-grouped – 1500000 -> "1,500,000".
  • SI: SI-prefixed at the nearest 1000-power tier – 1500000 -> "1.5M", 0.0025 -> "2.5m".
  • SCIENTIFIC: "1.5e+6" – a decimal mantissa plus a signed exponent, unlike _format_fixed_overflow’s bare String(Float64) fallback. Also the principled version of that same fallback: past _FORMAT_FIXED_MAX_EXACT_MAGNITUDE, _format_tick defers to this shape regardless of the requested format, so an overflow never produces raw digit garbage.
  • FIXED(n): always n decimal places, ignoring the domain’s own nice-step count – for currency (FIXED(2)) or a whole-number axis (FIXED(0)) regardless of what step size the data picks.

prefix/suffix wrap the formatted number for every kind (FIXED(2).with_affixes(prefix="$") -> "$19.99"); set via with_affixes() since comptime constants can’t take a per-call string.

Aliases

  • AUTO = TickFormat(Int(0), Int(0), String(""), String(""))
  • PERCENT = TickFormat(Int(1), Int(0), String(""), String(""))
  • THOUSANDS = TickFormat(Int(2), Int(0), String(""), String(""))
  • SI = TickFormat(Int(3), Int(0), String(""), String(""))
  • SCIENTIFIC = TickFormat(Int(4), Int(0), String(""), String(""))

Fields

  • prefix (String)
  • suffix (String)

Implemented traits

AnyType, Copyable, Deinitable, ImplicitlyCopyable, Movable

Methods

__init__

fn def __init__(out self, kind: Int, n: Int, prefix: String, suffix: String)

Args:

  • kind (Int)
  • n (Int)
  • prefix (String)
  • suffix (String)
  • self (Self)

Returns:

Self

__eq__

fn def __eq__(self, other: Self) -> Bool

Args:

  • self (Self)
  • other (Self)

Returns:

Bool

FIXED

@staticmethod
fn def FIXED(decimals: Int) -> Self

Always decimals places, regardless of the axis’s own nice-step decimal count.

Args:

  • decimals (Int): How many decimal places to always show.

Returns:

Self

with_affixes

fn def with_affixes(self, prefix: String = "", suffix: String = "") -> Self

This format with prefix/suffix wrapped around every formatted number ("$"/"/mo", …).

Args:

  • self (Self)
  • prefix (String): Text prepended to every formatted number.
  • suffix (String): Text appended to every formatted number.

Returns:

Self: A copy of this format with the given affixes.