Skip to main content

TimeFormatter

Trait TimeFormatter 

Source
pub trait TimeFormatter: Send + Sync {
    // Required methods
    fn format(&self, time: DateTime<Utc>, mark_type: TickMarkType) -> String;
    fn clone_box(&self) -> Box<dyn TimeFormatter>;

    // Provided methods
    fn format_tick(&self, context: TickMarkContext<'_>) -> Option<String> { ... }
    fn wall_time(&self, time: DateTime<Utc>) -> DateTime<Utc> { ... }
    fn utc_time(&self, wall_time: DateTime<Utc>) -> Option<DateTime<Utc>> { ... }
    fn time_visible(&self) -> bool { ... }
    fn format_crosshair(&self, time: DateTime<Utc>, bar_seconds: i64) -> String { ... }
}
Expand description

Trait for custom time formatting Allows users to customize how time labels are displayed on the axis

Required Methods§

Source

fn format(&self, time: DateTime<Utc>, mark_type: TickMarkType) -> String

Format a ts into a display string

§Arguments
  • time - The ts to format
  • mark_type - The type of tick mark (Year, Month, etc.)
§Returns

Formatted string to display on the time axis

Source

fn clone_box(&self) -> Box<dyn TimeFormatter>

Clone this formatter into a Box

Provided Methods§

Source

fn format_tick(&self, context: TickMarkContext<'_>) -> Option<String>

Formats one axis tick with the active chart locale and display-time fields.

Return None to use the chart’s normal locale and clock settings for this tick. Some(String::new()) keeps an empty label. The default calls format, preserving existing formatters. Builders and the chart call this after time-zone conversion; hidden intraday clocks still use date labels instead. This hook does not change format_crosshair.

Source

fn wall_time(&self, time: DateTime<Utc>) -> DateTime<Utc>

Clock-face time used to identify calendar boundaries. The returned UTC value holds local fields, not another instant.

Source

fn utc_time(&self, wall_time: DateTime<Utc>) -> Option<DateTime<Utc>>

Converts local calendar fields from wall_time back to an instant. Repeated times use the first instant; skipped times use the clock jump.

Source

fn time_visible(&self) -> bool

Whether intraday marks and hover labels include the clock.

Source

fn format_crosshair(&self, time: DateTime<Utc>, bar_seconds: i64) -> String

Formats the hovered bar, retaining this formatter’s date and clock conventions.

Trait Implementations§

Source§

impl HorizontalScale for Box<dyn TimeFormatter>

The time scale: calendar and clock boundaries in the formatter’s zone.

Source§

fn tick_marks( &self, points: &[(DateTime<Utc>, usize)], layout: &TickMarkLayout, ) -> Vec<TickMark>

The marks to label among points, the key and logical index of each bar in view in order, extended into whitespace on both sides using the chart’s full-history time mapping. When the keys reach before the first bar, every index is shifted by the same number of slots, so only the order of the indices and their differences carry meaning. The renderer places each mark at its key and skips labels that would overlap.
Source§

fn format_crosshair(&self, key: DateTime<Utc>, bar_seconds: i64) -> String

The crosshair label of key. bar_seconds is the duration of the bars in view, which the time scale uses for the precision of the clock.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§