euv_ui/component/chart/widget/struct.rs
1use super::*;
2
3/// Full-featured native vector Apache ECharts component supporting all 20 series types, multi-axis grids, interactive legends, tooltips, DataZoom, VisualMap, and compact icon-only Toolbox.
4#[derive(Clone, CustomDebug, Data, Props)]
5pub struct EuvEChart {
6 /// Static declarative chart option document.
7 #[prop(custom)]
8 pub(crate) option: EuvChartOption,
9 /// Optional reactive chart option signal overriding `option` when provided.
10 #[debug(skip)]
11 #[get(skip)]
12 #[prop(custom)]
13 pub(crate) option_signal: Option<Signal<EuvChartOption>>,
14 /// Optional lazy chart option factory invoked once on first visible paint or interactive query.
15 #[debug(skip)]
16 #[get(skip)]
17 #[prop(custom)]
18 pub(crate) option_loader: Option<EuvChartOptionLoader>,
19 /// Active UI theme tokens.
20 #[get(type(copy))]
21 #[prop(custom)]
22 pub(crate) tokens: ThemeTokens,
23 /// Optional style overrides controlling chart width/height and container appearance (defaults to `width: Length::Percent(100.0)` and `height: Length::Px(340.0)`).
24 #[get(type(copy))]
25 pub(crate) style: Option<Style>,
26 /// Whether hover tooltip, legend toggle, data-zoom, and click interaction are active (defaults to `true`).
27 #[get(type(copy))]
28 #[prop(custom, default = true)]
29 pub(crate) interactive: bool,
30 /// Optional callback invoked when a plotted datum or slice is clicked.
31 #[debug(skip)]
32 #[get(skip)]
33 #[prop(custom)]
34 pub(crate) on_point_click: Option<EuvChartHitCallback>,
35 /// Optional callback invoked when a legend item toggles `(series_name, now_visible)`.
36 #[debug(skip)]
37 #[get(skip)]
38 #[prop(custom)]
39 pub(crate) on_legend_change: Option<EuvChartLegendCallback>,
40 /// Optional callback invoked when DataZoom adjusts `(start_pct, end_pct)`.
41 #[debug(skip)]
42 #[get(skip)]
43 #[prop(custom)]
44 pub(crate) on_zoom_change: Option<Rc<dyn Fn(f32, f32)>>,
45}
46
47/// Bundled shared handles used to attach pointer, click, drag, and wheel listeners to `EuvEChart`.
48#[derive(Clone, CustomDebug, Data, New)]
49pub(crate) struct ChartPointerWiring {
50 /// Mounted chart canvas node handle.
51 #[get(type(copy))]
52 pub(crate) canvas_node: NodeId,
53 /// Reactive structural interactive chart state signal (excludes pointer hover).
54 #[get(type(copy))]
55 pub(crate) state_sig: Signal<EuvChartState>,
56 /// Reactive pointer hover position signal isolated from structural chart state.
57 #[get(type(copy))]
58 pub(crate) hover_pos_sig: Signal<Option<Point>>,
59 /// Latest painted chart hit-testing snapshot.
60 pub(crate) last_render: Rc<RefCell<EuvChartRenderResult>>,
61 /// Latest painted logical canvas rect.
62 pub(crate) last_bounds: Rc<RefCell<Rect>>,
63 /// Active drag gesture cell `(target, start_x, orig_start_pct, orig_end_pct)`.
64 pub(crate) drag_state: Rc<Cell<(ChartDragTarget, f32, f32, f32)>>,
65 /// Static or lazy declarative chart option holder.
66 pub(crate) static_opt: Rc<LazyChartOption>,
67 /// Optional reactive option signal.
68 #[debug(skip)]
69 #[new(skip)]
70 pub(crate) opt_sig: Option<Signal<EuvChartOption>>,
71 /// Optional datum click callback.
72 #[debug(skip)]
73 #[new(skip)]
74 pub(crate) on_point_click: Option<EuvChartHitCallback>,
75 /// Optional legend change callback.
76 #[debug(skip)]
77 #[new(skip)]
78 pub(crate) on_legend_change: Option<EuvChartLegendCallback>,
79 /// Optional data-zoom change callback.
80 #[debug(skip)]
81 #[new(skip)]
82 pub(crate) on_zoom_change: Option<Rc<dyn Fn(f32, f32)>>,
83 /// Whether `PointerDown` drag handlers should be attached (enabled only when DataZoom is active).
84 #[get(type(copy))]
85 #[new(skip)]
86 pub(crate) enable_drag: bool,
87}
88
89/// Cached static base-layer `DrawCommand` snapshot reused across chart hover frames.
90#[derive(Clone, Data, Debug)]
91pub(crate) struct ChartPaintCache {
92 /// Logical bounds associated with this cached display list.
93 #[get(type(copy))]
94 pub(crate) bounds: Rect,
95 /// Visible scroll viewport associated with this cached display list.
96 #[get(type(copy))]
97 pub(crate) visible_viewport: Rect,
98 /// Theme tokens active when cached.
99 #[get(type(copy))]
100 pub(crate) tokens: ThemeTokens,
101 /// Hover-independent chart state active when cached.
102 pub(crate) base_state: EuvChartState,
103 /// Monotonic reactive option revision when cached.
104 #[get(type(copy))]
105 pub(crate) rev: u64,
106 /// IEEE-754 bit pattern of the physical DPI `scale_factor` active when cached.
107 #[get(type(copy))]
108 pub(crate) scale_bits: u32,
109 /// Cached static base-layer vector drawing commands.
110 pub(crate) base_commands: Vec<DrawCommand>,
111 /// Cached static base-layer render result holding datum and legend hit boxes.
112 pub(crate) base_result: EuvChartRenderResult,
113}
114
115/// Shared declarative chart option holder supporting deferred on-demand materialization for off-screen cards.
116#[derive(Clone, CustomDebug)]
117pub(crate) struct LazyChartOption {
118 /// Static shell or fallback option available immediately on mount without allocating series data.
119 pub(crate) fallback: EuvChartOption,
120 /// Optional deferred builder invoked at most once when the chart enters the viewport or is inspected.
121 #[debug(skip)]
122 pub(crate) loader: Option<EuvChartOptionLoader>,
123 /// Lazily materialized full option cache populated on first demand.
124 pub(crate) materialized: Rc<RefCell<Option<EuvChartOption>>>,
125}