pub struct NumericFormat { /* private fields */ }Expand description
Immutable scientific numeric presentation with explicitly selected locale.
Rounding defaults to nearest with ties to even, after exact decimal scaling. Affixes are literal: a percent suffix alone does not scale the scientific value. Adaptive precision is selected uniformly for each complete semantic set, independently of geometric fit. The default is Decimal/Fractional(2), scale zero, absent affixes, preserved negative zero and retained trailing zeros.
use lichtung_plot::{NumericFormat, NumericValues, Plot, formatting::{NumericNotation, NumericPrecision}};
let percent = NumericFormat::new(NumericNotation::Decimal, NumericPrecision::Fractional(1))?
.decimal_scale(2)?
.suffix("%")?;
assert_eq!(percent.get_decimal_scale(), 2);
let plot = Plot::scatter(NumericValues::new("x", [1.0, 2.0]),
NumericValues::new("rate", [0.125, 0.875]))
.y_tick_format(percent);Fields and the implementation module stay private:
use lichtung_plot::NumericFormat;
let _ = NumericFormat::default().decimal_scale;use lichtung_plot::numeric::format::NumericFormat;Precision edits take an explicit precision policy:
use lichtung_plot::NumericFormat;
let _ = NumericFormat::default().precision(2);Implementations§
Source§impl NumericFormat
impl NumericFormat
Sourcepub fn new(
notation: NumericNotation,
precision: NumericPrecision,
) -> Result<Self>
pub fn new( notation: NumericNotation, precision: NumericPrecision, ) -> Result<Self>
Construct a validated format with scale zero, no affixes, Preserve, Keep and NearestEven rounding.
Sourcepub const fn get_notation(&self) -> NumericNotation
pub const fn get_notation(&self) -> NumericNotation
The selected decimal/exponent notation.
Sourcepub const fn get_precision(&self) -> NumericPrecision
pub const fn get_precision(&self) -> NumericPrecision
The exact precision or complete adaptive bounds.
Sourcepub const fn get_decimal_scale(&self) -> i16
pub const fn get_decimal_scale(&self) -> i16
The exact signed decimal display shift, from -324 through 324.
Sourcepub fn get_prefix(&self) -> Option<&str>
pub fn get_prefix(&self) -> Option<&str>
Literal text before the sign and number, or absence.
Sourcepub fn get_suffix(&self) -> Option<&str>
pub fn get_suffix(&self) -> Option<&str>
Literal text immediately after the number, or absence.
Sourcepub const fn get_negative_zero(&self) -> NegativeZero
pub const fn get_negative_zero(&self) -> NegativeZero
Actual and rounded negative-zero handling.
Sourcepub const fn get_trailing_zeros(&self) -> TrailingZeros
pub const fn get_trailing_zeros(&self) -> TrailingZeros
Fractional trailing-zero handling.
Sourcepub fn notation(self, value: NumericNotation) -> Result<Self>
pub fn notation(self, value: NumericNotation) -> Result<Self>
Replace notation while retaining and validating every other field.
Sourcepub fn precision(self, value: NumericPrecision) -> Result<Self>
pub fn precision(self, value: NumericPrecision) -> Result<Self>
Replace precision; fractional bounds are 0..=20 and significant bounds 1..=21.
Adaptive min must not exceed max.
Sourcepub fn decimal_scale(self, value: i16) -> Result<Self>
pub fn decimal_scale(self, value: i16) -> Result<Self>
Replace the exact decimal display shift within -324..=324. This never changes scientific coordinates or color mapping.
Sourcepub fn prefix(self, value: impl Into<String>) -> Result<Self>
pub fn prefix(self, value: impl Into<String>) -> Result<Self>
Replace the literal prefix with nonempty, control-free text. Spaces and combining marks are preserved exactly.
Sourcepub fn suffix(self, value: impl Into<String>) -> Result<Self>
pub fn suffix(self, value: impl Into<String>) -> Result<Self>
Replace the literal suffix with nonempty, control-free text. No scaling or spacing is inferred from its contents.
Sourcepub fn negative_zero(self, value: NegativeZero) -> Result<Self>
pub fn negative_zero(self, value: NegativeZero) -> Result<Self>
Replace handling of actual or rounded negative zero.
Sourcepub fn trailing_zeros(self, value: TrailingZeros) -> Result<Self>
pub fn trailing_zeros(self, value: TrailingZeros) -> Result<Self>
Replace fractional zero trimming; integral place-value zeros are retained.
Sourcepub fn rounding(self, value: NumericRounding) -> Result<Self>
pub fn rounding(self, value: NumericRounding) -> Result<Self>
Replace exact rounding at the selected decimal quantum. Signed floor/ceiling and tie handling apply before negative-zero normalization.
Sourcepub fn multiplier(self, value: f64) -> Result<Self>
pub fn multiplier(self, value: f64) -> Result<Self>
Multiply by the exact represented finite factor before the one rounding. Negative factors reverse display signs; either signed zero selects zero.
Sourcepub fn locale(self, value: NumericLocale) -> Result<Self>
pub fn locale(self, value: NumericLocale) -> Result<Self>
Select complete explicit locale tokens, without host inference.
Sourcepub fn grouping(self, value: bool) -> Result<Self>
pub fn grouping(self, value: bool) -> Result<Self>
Enable integer grouping using the selected locale’s optional pattern.
Sourcepub fn sign(self, value: NumericSign) -> Result<Self>
pub fn sign(self, value: NumericSign) -> Result<Self>
Select sign presentation, after numeric rounding and zero normalization.
Sourcepub fn symbol(self, value: NumericSymbol) -> Result<Self>
pub fn symbol(self, value: NumericSymbol) -> Result<Self>
Select currency or an applicable nondecimal integer-radix prefix.
Sourcepub fn field(self, value: Option<NumericField>) -> Result<Self>
pub fn field(self, value: Option<NumericField>) -> Result<Self>
Set or clear minimum Unicode-scalar field width.
Sourcepub fn rate(self, value: NumericRate) -> Result<Self>
pub fn rate(self, value: NumericRate) -> Result<Self>
Select an exact rate factor and the locale’s automatic suffix.
Sourcepub fn prefixes(self, value: NumericPrefixes) -> Result<Self>
pub fn prefixes(self, value: NumericPrefixes) -> Result<Self>
Replace the sole SI, compact or common exact-divisor policy.
Source§impl NumericFormat
impl NumericFormat
Sourcepub fn value_function<F>(self, function: F) -> Self
pub fn value_function<F>(self, function: F) -> Self
Select final per-occurrence text, retaining built-in options for helpers.
Sourcepub fn set_function<F>(self, function: F) -> Self
pub fn set_function<F>(self, function: F) -> Self
Select final complete-set text and optional common explanatory Text.
Source§impl NumericFormat
impl NumericFormat
Sourcepub fn from_specifier(specifier: &str) -> Result<Self>
pub fn from_specifier(specifier: &str) -> Result<Self>
Compile [[fill]align][sign][symbol][0][width][,][.precision][~][type].
Numeric types are f/e/g/r/s/%/p/d/b/o/x/X/n or omitted; unknown types and
text coercion reject. Exact renderer rounding is not JavaScript arithmetic.
Source§impl NumericFormat
impl NumericFormat
Sourcepub fn unit(self, value: Option<NumericUnit>) -> Result<Self>
pub fn unit(self, value: Option<NumericUnit>) -> Result<Self>
Set or clear literal unit text, validating its single-line tokens.
Sourcepub fn explanation(self, value: NumericExplanation) -> Self
pub fn explanation(self, value: NumericExplanation) -> Self
Replace instructions/content for the one common explanation slot.
Trait Implementations§
Source§impl Clone for NumericFormat
impl Clone for NumericFormat
Source§impl Debug for NumericFormat
impl Debug for NumericFormat
Source§impl Default for NumericFormat
impl Default for NumericFormat
impl Eq for NumericFormat
Source§impl PartialEq for NumericFormat
impl PartialEq for NumericFormat
impl StructuralPartialEq for NumericFormat
Auto Trait Implementations§
impl !RefUnwindSafe for NumericFormat
impl !UnwindSafe for NumericFormat
impl Forget for NumericFormat
impl Freeze for NumericFormatwhere
*const u8 is !null: Freeze,
PhantomData<u8>: Freeze,
*const ArcInner<LocaleData> is !null: Freeze,
PhantomData<ArcInner<LocaleData>>: Freeze,
*const ArcInner<PrefixMode> is !null: Freeze,
PhantomData<ArcInner<PrefixMode>>: Freeze,
*const ArcInner<UnitPolicy> is !null: Freeze,
PhantomData<ArcInner<UnitPolicy>>: Freeze,
*const ArcInner<Function> is !null: Freeze,
PhantomData<ArcInner<Function>>: Freeze,
impl Move for NumericFormat
impl Send for NumericFormat
impl Sync for NumericFormat
impl Unpin for NumericFormat
impl UnsafeUnpin for NumericFormatwhere
*const u8 is !null: UnsafeUnpin,
PhantomData<u8>: UnsafeUnpin,
*const ArcInner<LocaleData> is !null: UnsafeUnpin,
PhantomData<ArcInner<LocaleData>>: UnsafeUnpin,
*const ArcInner<PrefixMode> is !null: UnsafeUnpin,
PhantomData<ArcInner<PrefixMode>>: UnsafeUnpin,
*const ArcInner<UnitPolicy> is !null: UnsafeUnpin,
PhantomData<ArcInner<UnitPolicy>>: UnsafeUnpin,
*const ArcInner<Function> is !null: UnsafeUnpin,
PhantomData<ArcInner<Function>>: UnsafeUnpin,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
impl<T> Scalar for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.