egui_charts/services/marks.rs
1//! Bar annotations and time-axis events fetched for the visible range.
2
3use crate::data::{MaybeSend, Reply};
4use crate::model::{Marker, TimeScaleEvent, Timeframe};
5use chrono::{DateTime, Utc};
6
7/// Host source of marks. Attach with `Chart::set_mark_source`.
8///
9/// Called on the UI thread; return promptly and answer through the reply from any thread,
10/// runtime or browser task. Each answer replaces the previous source marks. Manually supplied
11/// markers and events remain independent. The chart ignores answers for an older view.
12pub trait Marks: MaybeSend + 'static {
13 /// All marks for the inclusive UTC range, including visible whitespace. Called again after
14 /// the symbol, interval or range changes, or `Chart::reload_marks` is requested.
15 fn marks(&self, request: MarksRequest, reply: Reply<MarksPage>);
16}
17
18/// The chart view for which a host supplies annotations and events.
19#[derive(Debug, Clone, PartialEq, Eq)]
20pub struct MarksRequest {
21 /// Current instrument key.
22 pub symbol: String,
23 /// Current chart interval.
24 pub timeframe: Timeframe,
25 /// Inclusive left edge of the view in UTC.
26 pub from: DateTime<Utc>,
27 /// Inclusive right edge of the view in UTC.
28 pub to: DateTime<Utc>,
29}
30
31/// One complete answer for a visible range. Empty vectors clear the source's marks.
32#[derive(Debug, Clone, Default)]
33pub struct MarksPage {
34 /// Bar annotations, including their optional hover text.
35 pub bar_marks: Vec<Marker>,
36 /// Generic time-axis badges, including their optional hover text and host IDs.
37 pub time_scale_marks: Vec<Marker>,
38 /// Typed corporate, economic and news events, filtered by chart event visibility.
39 pub events: Vec<TimeScaleEvent>,
40}