Skip to main content

euv_ui/component/chart/engine/
struct.rs

1use super::*;
2
3/// Shared frame-level rendering context passed to coordinate and series renderers.
4#[derive(Clone, Copy, Data, Debug, New)]
5pub(crate) struct ChartDrawFrame<'a> {
6    /// Active UI theme tokens.
7    #[get(type(copy))]
8    pub(crate) tokens: ThemeTokens,
9    /// Resolved categorical color palette.
10    #[get(type(copy))]
11    pub(crate) palette: &'a [Color],
12    /// Optional visual-map color evaluator.
13    pub(crate) visual_eval: Option<&'a EuvChartVisualEvaluator>,
14    /// Optional shared tabular dataset.
15    pub(crate) dataset: Option<&'a EuvChartDataset>,
16    /// Optional active pointer position in logical canvas coordinates.
17    pub(crate) hover_pos: Option<Point>,
18    /// Optional interactively popped-out pie slice index.
19    pub(crate) selected_pie_slice: Option<usize>,
20}
21
22/// Lightweight per-series metadata passed into individual series painters.
23#[derive(Clone, Copy, Data, Debug, New)]
24pub(crate) struct SeriesMeta<'a> {
25    /// Zero-based index inside `EuvChartOption::series`.
26    #[get(type(copy))]
27    pub(crate) index: usize,
28    /// Series legend and tooltip name.
29    #[get(type(copy))]
30    pub(crate) name: &'a str,
31    /// Resolved base series color.
32    #[get(type(copy))]
33    pub(crate) color: Color,
34}
35
36/// Hit-testable plotted datum emitted by every chart series for hover tooltips and click callbacks.
37#[derive(Clone, Data, Debug, PartialEq)]
38pub struct EuvChartDatumHit {
39    /// Zero-based index of the owning series.
40    #[get(type(copy))]
41    pub(crate) series_index: usize,
42    /// Display name of the owning series.
43    pub(crate) series_name: String,
44    /// Zero-based index of the datum inside the series.
45    #[get(type(copy))]
46    pub(crate) data_index: usize,
47    /// Category label or datum caption.
48    pub(crate) category_label: String,
49    /// Primary numeric scalar value.
50    #[get(type(copy))]
51    pub(crate) value: f32,
52    /// Formatted detail string shown in tooltips.
53    pub(crate) detail: String,
54    /// Rendered series or datum swatch color.
55    #[get(type(copy))]
56    pub(crate) color: Color,
57    /// Logical canvas anchor point for tooltip placement and distance testing.
58    #[get(type(copy))]
59    pub(crate) anchor: Point,
60    /// Circular hit radius in logical pixels when `hit_rect` is absent.
61    #[get(type(copy))]
62    pub(crate) hit_radius: f32,
63    /// Optional bounding box for rectangular datums (bars, cells, treemap tiles, candles).
64    #[get(skip)]
65    pub(crate) hit_rect: Option<Rect>,
66}
67
68/// Interactive hit box for a single rendered legend chip.
69#[derive(Clone, Data, Debug, PartialEq)]
70pub struct EuvChartLegendHit {
71    /// Owning series index (`usize::MAX` for multi-item slices/categories).
72    #[get(type(copy))]
73    pub(crate) series_index: usize,
74    /// Legend entry name matching `EuvChartSeries::name`.
75    pub(crate) name: String,
76    /// Swatch indicator color.
77    #[get(type(copy))]
78    pub(crate) color: Color,
79    /// Current visibility state.
80    #[get(type(copy))]
81    pub(crate) visible: bool,
82    /// Clickable chip bounds in logical canvas coordinates.
83    #[get(type(copy))]
84    pub(crate) rect: Rect,
85}
86
87/// Logical geometry of the bottom interactive `DataZoom::Slider` scrubber.
88#[derive(Clone, Copy, Data, Debug, PartialEq)]
89pub struct EuvChartSliderRects {
90    /// Full scrubber track rectangle.
91    #[get(type(copy))]
92    pub(crate) track_rect: Rect,
93    /// Active selected percentage range rectangle.
94    #[get(type(copy))]
95    pub(crate) window_rect: Rect,
96    /// Left draggable start handle rectangle.
97    #[get(type(copy))]
98    pub(crate) left_handle: Rect,
99    /// Right draggable end handle rectangle.
100    #[get(type(copy))]
101    pub(crate) right_handle: Rect,
102}
103
104/// Tabular snapshot generated for the interactive `DataView` toolbox mode.
105#[derive(Clone, Data, Debug, Default, PartialEq)]
106pub struct EuvChartDataViewTable {
107    /// Column header titles.
108    pub(crate) headers: Vec<String>,
109    /// Ordered tabular string rows.
110    pub(crate) rows: Vec<Vec<String>>,
111}
112
113/// Mutable interactive runtime state governing legend toggles, zoom window, magic-type, data-view, pie pop-out, and hover pointer.
114#[derive(Clone, Data, Debug, PartialEq)]
115pub struct EuvChartState {
116    /// Series names currently hidden via interactive legend toggles.
117    pub(crate) hidden_series: Vec<String>,
118    /// Active data-zoom lower window percentage in `[0.0, 100.0]`.
119    #[get(type(copy))]
120    pub(crate) zoom_start_pct: f32,
121    /// Active data-zoom upper window percentage in `[0.0, 100.0]`.
122    #[get(type(copy))]
123    pub(crate) zoom_end_pct: f32,
124    /// Active toolbox MagicType override (`Default`, `Line`, `Bar`, `Stack`).
125    #[get(type(copy))]
126    pub(crate) magic_type: EuvChartMagicType,
127    /// Whether the tabular `DataView` overlay panel is currently open.
128    #[get(type(copy))]
129    pub(crate) data_view_open: bool,
130    /// Optional interactively clicked pie slice index popped outward.
131    #[get(skip)]
132    pub(crate) selected_pie_slice: Option<usize>,
133    /// Optional active pointer coordinate in logical canvas space.
134    #[get(skip)]
135    pub(crate) hover_pos: Option<Point>,
136}
137
138/// Complete deterministic layout and hit-testing output returned by `render_echart_to_display_list`.
139#[derive(Clone, Data, Debug, Default, PartialEq)]
140pub struct EuvChartRenderResult {
141    /// Primary plot area rectangle inside canvas bounds.
142    #[get(type(copy))]
143    pub(crate) plot_rect: Rect,
144    /// All hit-testable plotted datums emitted during this frame.
145    pub(crate) hits: Vec<EuvChartDatumHit>,
146    /// All clickable legend chip boxes emitted during this frame.
147    pub(crate) legend_hits: Vec<EuvChartLegendHit>,
148    /// Optional bottom `DataZoom::Slider` interactive geometry.
149    #[get(skip)]
150    pub(crate) slider_rects: Option<EuvChartSliderRects>,
151    /// Active datums snapped by the current hover pointer for tooltip rendering.
152    pub(crate) active_tooltip_hits: Vec<EuvChartDatumHit>,
153    /// Computed X axis scales for Cartesian subplots.
154    pub(crate) x_scales: Vec<EuvChartAxisScale>,
155    /// Computed Y axis scales for Cartesian subplots.
156    pub(crate) y_scales: Vec<EuvChartAxisScale>,
157    /// Whether any 2D Cartesian subplot was rendered into the base display list.
158    #[get(type(copy))]
159    pub(crate) cartesian_rendered: bool,
160}
161
162/// Bundled Cartesian subplot inputs passed into `render_cartesian_subplots`.
163#[derive(Clone, Copy, Debug)]
164pub(crate) struct SubplotRenderInput<'a> {
165    /// Declarative chart option.
166    pub(crate) option: &'a EuvChartOption,
167    /// Active interactive chart state.
168    pub(crate) state: &'a EuvChartState,
169    /// Effective transformed chart series slice.
170    pub(crate) series: &'a [EuvChartSeries],
171    /// Series visibility flags aligned with `series`.
172    pub(crate) visible: &'a [bool],
173    /// Visible scroll viewport in logical canvas coordinates.
174    pub(crate) visible_viewport: Rect,
175    /// Resolved opaque chart background color for pinned Y-axis backing plates.
176    pub(crate) backing_bg: Color,
177}
178
179/// Deferred per-subplot foreground axes state painted strictly after all Cartesian series.
180#[derive(Clone, Debug)]
181pub(crate) struct DeferredSubplotAxes {
182    /// Plot rectangle for this subplot.
183    pub(crate) plot_rect: Rect,
184    /// Configured X axes assigned to this subplot.
185    pub(crate) x_axes: Vec<EuvChartAxis>,
186    /// Computed X axis scales for this subplot.
187    pub(crate) x_scales: Vec<EuvChartAxisScale>,
188    /// Configured Y axes assigned to this subplot.
189    pub(crate) y_axes: Vec<EuvChartAxis>,
190    /// Computed Y axis scales for this subplot.
191    pub(crate) y_scales: Vec<EuvChartAxisScale>,
192    /// Whether to draw an outer border box around the plot rect.
193    pub(crate) show_border: bool,
194}