Skip to main content

euv_ui/component/chart/widget/
impl.rs

1use super::*;
2
3/// Lazy option materialization helpers for `LazyChartOption`.
4impl LazyChartOption {
5    /// Creates a lazy option holder wrapping `fallback` and an optional deferred `loader`.
6    ///
7    /// # Arguments
8    ///
9    /// - `EuvChartOption` - Static fallback or lightweight metadata shell option.
10    /// - `Option<EuvChartOptionLoader>` - Optional deferred full option factory.
11    ///
12    /// # Returns
13    ///
14    /// - `Self` - Constructed lazy chart option holder.
15    #[must_use]
16    pub(crate) fn new(fallback: EuvChartOption, loader: Option<EuvChartOptionLoader>) -> Self {
17        Self {
18            fallback,
19            loader,
20            materialized: Rc::new(RefCell::new(None)),
21        }
22    }
23
24    /// Ensures the deferred option has been materialized if a `loader` is configured.
25    ///
26    /// # Arguments
27    ///
28    /// - `&Self` - Lazy option holder reference.
29    fn ensure_materialized(&self) {
30        let Self {
31            loader,
32            materialized,
33            ..
34        } = self;
35        let Some(factory) = loader.as_ref() else {
36            return;
37        };
38        let already_loaded: bool = materialized
39            .try_borrow()
40            .is_ok_and(|slot: Ref<'_, Option<EuvChartOption>>| slot.is_some());
41        if already_loaded {
42            return;
43        }
44        let built: EuvChartOption = factory();
45        record_chart_lazy_materialize();
46        if let Ok(mut slot) = materialized.try_borrow_mut() {
47            *slot = Some(built);
48        }
49    }
50
51    /// Invokes `consumer` with a borrowed reference to the resolved chart option without cloning.
52    ///
53    /// # Arguments
54    ///
55    /// - `&Self` - Lazy option holder reference.
56    /// - `ConsumerFn` - Consumer receiving the resolved option reference.
57    ///
58    /// # Returns
59    ///
60    /// - `ReturnType` - Value returned by `consumer`.
61    pub(crate) fn with_resolved<ConsumerFn, ReturnType>(&self, consumer: ConsumerFn) -> ReturnType
62    where
63        ConsumerFn: FnOnce(&EuvChartOption) -> ReturnType,
64    {
65        self.ensure_materialized();
66        let Self {
67            fallback,
68            materialized,
69            ..
70        } = self;
71        if let Ok(slot) = materialized.try_borrow()
72            && let Some(loaded) = slot.as_ref()
73        {
74            return consumer(loaded);
75        }
76        consumer(fallback)
77    }
78
79    /// Returns a cloned copy of the resolved chart option, materializing the deferred factory on first demand.
80    ///
81    /// # Arguments
82    ///
83    /// - `&Self` - Lazy option holder reference.
84    ///
85    /// # Returns
86    ///
87    /// - `EuvChartOption` - Cloned resolved chart option.
88    #[must_use]
89    pub(crate) fn resolve_clone(&self) -> EuvChartOption {
90        self.with_resolved(EuvChartOption::clone)
91    }
92}
93
94/// Default props for `EuvEChart` (100% width, 320px height, interactive enabled).
95impl Default for EuvEChart {
96    /// Creates an empty interactive `EuvEChart` ready for `view!` named-prop setters.
97    ///
98    /// # Returns
99    ///
100    /// - `Self` - Default chart component.
101    fn default() -> Self {
102        Self {
103            option: EuvChartOption::default(),
104            option_signal: None,
105            option_loader: None,
106            tokens: ThemeTokens::default(),
107            style: None,
108            interactive: true,
109            on_point_click: None,
110            on_legend_change: None,
111            on_zoom_change: None,
112        }
113    }
114}
115
116/// Constructors and fluent prop builders for `EuvEChart`.
117impl EuvEChart {
118    /// Constructs an interactive `EuvEChart` from a static `EuvChartOption` and `ThemeTokens`.
119    ///
120    /// # Arguments
121    ///
122    /// - `EuvChartOption` - Declarative chart option document.
123    /// - `ThemeTokens` - Active UI theme tokens.
124    ///
125    /// # Returns
126    ///
127    /// - `Self` - Constructed chart component.
128    #[must_use]
129    pub fn new(option: EuvChartOption, tokens: ThemeTokens) -> Self {
130        let mut chart: Self = Self::default();
131        chart.set_option(option);
132        chart.set_tokens(tokens);
133        chart
134    }
135
136    /// Constructs a reactive `EuvEChart` driven by a live `Signal<EuvChartOption>`.
137    ///
138    /// # Arguments
139    ///
140    /// - `Signal<EuvChartOption>` - Reactive chart option signal.
141    /// - `ThemeTokens` - Active UI theme tokens.
142    ///
143    /// # Returns
144    ///
145    /// - `Self` - Constructed reactive chart component.
146    #[must_use]
147    pub fn from_signal(option_signal: Signal<EuvChartOption>, tokens: ThemeTokens) -> Self {
148        let mut chart: Self = Self::default();
149        chart.set_option_signal(Some(option_signal));
150        chart.set_tokens(tokens);
151        chart
152    }
153
154    /// Sets the declarative chart option fluently (used by `view! { EuvEChart { option: ... } }`).
155    ///
156    /// # Arguments
157    ///
158    /// - `Self` - Source chart component.
159    /// - `EuvChartOption` - Declarative chart option.
160    ///
161    /// # Returns
162    ///
163    /// - `Self` - Updated chart component.
164    #[must_use]
165    pub fn option(mut self, option: EuvChartOption) -> Self {
166        self.set_option(option);
167        self
168    }
169
170    /// Binds a reactive `Signal<EuvChartOption>` fluently.
171    ///
172    /// # Arguments
173    ///
174    /// - `Self` - Source chart component.
175    /// - `Signal<EuvChartOption>` - Reactive option signal.
176    ///
177    /// # Returns
178    ///
179    /// - `Self` - Updated chart component.
180    #[must_use]
181    pub fn option_signal(mut self, option_signal: Signal<EuvChartOption>) -> Self {
182        self.set_option_signal(Some(option_signal));
183        self
184    }
185
186    /// Registers a deferred chart option factory evaluated lazily on first visible paint or interactive inspection.
187    ///
188    /// # Arguments
189    ///
190    /// - `Self` - Source chart component.
191    /// - `EuvChartOptionLoader` - Deferred full chart option builder.
192    ///
193    /// # Returns
194    ///
195    /// - `Self` - Updated chart component.
196    #[must_use]
197    pub fn option_loader(mut self, loader: EuvChartOptionLoader) -> Self {
198        self.set_option_loader(Some(loader));
199        self
200    }
201
202    /// Sets the active UI theme tokens fluently.
203    ///
204    /// # Arguments
205    ///
206    /// - `Self` - Source chart component.
207    /// - `ThemeTokens` - Theme token bundle.
208    ///
209    /// # Returns
210    ///
211    /// - `Self` - Updated chart component.
212    #[must_use]
213    pub fn tokens(mut self, tokens: ThemeTokens) -> Self {
214        self.set_tokens(tokens);
215        self
216    }
217
218    /// Enables or disables pointer interaction fluently.
219    ///
220    /// # Arguments
221    ///
222    /// - `Self` - Source chart component.
223    /// - `bool` - Interaction enabled flag.
224    ///
225    /// # Returns
226    ///
227    /// - `Self` - Updated chart component.
228    #[must_use]
229    pub fn interactive(mut self, interactive: bool) -> Self {
230        self.set_interactive(interactive);
231        self
232    }
233
234    /// Registers a datum click callback fluently.
235    ///
236    /// # Arguments
237    ///
238    /// - `Self` - Source chart component.
239    /// - `EuvChartHitCallback` - Click callback invoked with clicked datum hit.
240    ///
241    /// # Returns
242    ///
243    /// - `Self` - Updated chart component.
244    #[must_use]
245    pub fn on_point_click(mut self, handler: EuvChartHitCallback) -> Self {
246        self.set_on_point_click(Some(handler));
247        self
248    }
249
250    /// Registers a legend toggle callback fluently.
251    ///
252    /// # Arguments
253    ///
254    /// - `Self` - Source chart component.
255    /// - `EuvChartLegendCallback` - Legend toggle callback `(series_name, visible)`.
256    ///
257    /// # Returns
258    ///
259    /// - `Self` - Updated chart component.
260    #[must_use]
261    pub fn on_legend_change(mut self, handler: EuvChartLegendCallback) -> Self {
262        self.set_on_legend_change(Some(handler));
263        self
264    }
265
266    /// Registers a data-zoom change callback fluently.
267    ///
268    /// # Arguments
269    ///
270    /// - `Self` - Source chart component.
271    /// - `Rc<dyn Fn(f32, f32)>` - Zoom callback `(start_pct, end_pct)`.
272    ///
273    /// # Returns
274    ///
275    /// - `Self` - Updated chart component.
276    #[must_use]
277    pub fn on_zoom_change(mut self, handler: Rc<dyn Fn(f32, f32)>) -> Self {
278        self.set_on_zoom_change(Some(handler));
279        self
280    }
281
282    /// Resolves the initial `EuvChartOption` snapshot from `option_signal` or static `option`.
283    ///
284    /// # Arguments
285    ///
286    /// - `&Self` - Component descriptor.
287    ///
288    /// # Returns
289    ///
290    /// - `EuvChartOption` - Snapshot option.
291    #[must_use]
292    fn current_option_untracked(&self) -> EuvChartOption {
293        let Self {
294            option,
295            option_signal,
296            ..
297        } = self;
298        match option_signal {
299            Some(sig) => sig.get_untracked(),
300            None => option.clone(),
301        }
302    }
303}
304
305/// Declarative `#[component]` implementation for `EuvEChart`.
306#[component]
307/// Inherent implementation of [`EuvEChart`].
308impl EuvEChart {
309    /// Mounts `EuvEChart` with cached vector canvas rendering, pointer tooltip/legend/DataZoom handling, compact icon-only Toolbox, DataView table, and Fullscreen portal modal.
310    ///
311    /// # Arguments
312    ///
313    /// - `&Self` - Chart component descriptor.
314    ///
315    /// # Returns
316    ///
317    /// - `NodeId` - Mounted root scene node handle.
318    fn render(&self) -> NodeId {
319        let mut ctx: Context = current_context();
320        bind_fullscreen_context(&ctx);
321        let base_tokens: ThemeTokens = self.get_tokens();
322        let tokens: ThemeTokens = live_tokens_untracked(base_tokens);
323        let palette: ThemePalette = tokens.get_palette();
324        let geometry: ThemeGeometry = tokens.get_geometry();
325        let user_style: Option<Style> = self.get_style();
326        let width: Length = user_style
327            .map(|computed_style: Style| computed_style.get_layout().get_width())
328            .filter(|width_val: &Length| *width_val != Length::Auto)
329            .unwrap_or(Length::Percent(100.0));
330        let height: Length = user_style
331            .map(|element_style: Style| element_style.get_layout().get_height())
332            .filter(|height_val: &Length| *height_val != Length::Auto)
333            .unwrap_or(Length::Px(ECHART_DEFAULT_HEIGHT));
334        let outer_overrides: Option<Style> = user_style.map(|mut resolved_style: Style| {
335            let _: &mut LayoutStyle = resolved_style.get_mut_layout().set_height(Length::Auto);
336            resolved_style
337        });
338        let interactive: bool = self.get_interactive();
339        let Self {
340            option: static_opt,
341            option_signal,
342            option_loader,
343            on_point_click,
344            on_legend_change,
345            on_zoom_change,
346            ..
347        } = self;
348        let opt_sig_opt: Option<Signal<EuvChartOption>> = *option_signal;
349        let static_opt_rc: Rc<LazyChartOption> = Rc::new(LazyChartOption::new(
350            static_opt.clone(),
351            option_loader.clone(),
352        ));
353        let initial_opt: EuvChartOption = self.current_option_untracked();
354        let state_sig: Signal<EuvChartState> =
355            Signal::new(EuvChartState::from_option(&initial_opt));
356        let hover_pos_sig: Signal<Option<Point>> = Signal::new(None);
357        let data_view_open_memo: Memo<bool> =
358            Memo::new(move || state_sig.get().get_data_view_open());
359        let fs_open: Signal<bool> = Signal::new(false);
360        let opt_rev: Rc<Cell<u64>> = Rc::new(Cell::new(0));
361        let last_render: Rc<RefCell<EuvChartRenderResult>> =
362            Rc::new(RefCell::new(EuvChartRenderResult::default()));
363        let last_bounds: Rc<RefCell<Rect>> = Rc::new(RefCell::new(Rect::default()));
364        let drag_state: Rc<Cell<(ChartDragTarget, f32, f32, f32)>> =
365            Rc::new(Cell::new((ChartDragTarget::None, 0.0, 0.0, 100.0)));
366        let has_data_zoom: bool = !initial_opt.get_data_zoom().is_empty();
367        let min_content_sz: Size = compute_chart_min_content_size(&initial_opt);
368        let toolbox_cfg: Option<EuvChartToolbox> = initial_opt.toolbox_opt().cloned();
369        let show_toolbox: bool = toolbox_cfg.as_ref().is_some_and(EuvChartToolbox::get_show);
370        let (init_title_text, init_subtext, init_title_align, init_has_title): (
371            String,
372            String,
373            TextAlign,
374            bool,
375        ) = resolve_chart_header_meta(&initial_opt);
376        let has_header: bool = init_has_title || show_toolbox;
377        let inline_scroll_cell: Rc<Cell<NodeId>> = Rc::new(Cell::new(NodeId::default()));
378        let inline_scroll_paint: Rc<Cell<NodeId>> = Rc::clone(&inline_scroll_cell);
379        let scene_inline_paint: SceneHandle = ctx.get_scene().clone();
380        let paint_opt_rc: Rc<LazyChartOption> = Rc::clone(&static_opt_rc);
381        let paint_res: Rc<RefCell<EuvChartRenderResult>> = Rc::clone(&last_render);
382        let paint_bounds: Rc<RefCell<Rect>> = Rc::clone(&last_bounds);
383        let paint_opt_rev: Rc<Cell<u64>> = Rc::clone(&opt_rev);
384        let inline_cache: RefCell<Option<ChartPaintCache>> = RefCell::new(None);
385        let paint_inline = move |bounds: Rect, display_list: &mut DisplayList| {
386            if !is_chart_rect_in_viewport(bounds, display_list.get_viewport()) {
387                return;
388            }
389            let live_tok: ThemeTokens = live_tokens_untracked(base_tokens);
390            let cur_state: EuvChartState = state_sig.get_untracked();
391            let hover_pos: Option<Point> = hover_pos_sig.get_untracked();
392            let cur_rev: u64 = paint_opt_rev.get();
393            let sc_node: NodeId = inline_scroll_paint.get();
394            let scroll_info: Option<(Point, Size)> = if sc_node == NodeId::default() {
395                None
396            } else {
397                scene_inline_paint.with_read(
398                    |tree: &SceneTree| {
399                        tree.get_node(sc_node).map(|scene_node: &SceneNode| {
400                            let lb: LayoutBox = scene_node.get_layout_box();
401                            let rect_bounds: Rect = lb.get_content_bounds();
402                            (
403                                lb.get_scroll_offset(),
404                                Size::new(rect_bounds.get_width(), rect_bounds.get_height()),
405                            )
406                        })
407                    },
408                    None,
409                )
410            };
411            let vis_vp: Rect = compute_visible_chart_viewport(bounds, scroll_info);
412            if let Ok(mut b_guard) = paint_bounds.try_borrow_mut() {
413                *b_guard = bounds;
414            }
415            let scale_factor: f32 = display_list.get_scale_factor().max(0.5);
416            let scale_bits: u32 = scale_factor.to_bits();
417            let base_state: EuvChartState = if cur_state.hover_pos_opt().is_some() {
418                cur_state.without_hover()
419            } else {
420                cur_state
421            };
422            if let Ok(guard) = inline_cache.try_borrow()
423                && let Some(cached) = guard.as_ref()
424                && cached.get_bounds() == bounds
425                && cached.get_visible_viewport() == vis_vp
426                && cached.get_tokens() == live_tok
427                && cached.get_base_state() == &base_state
428                && cached.get_rev() == cur_rev
429                && cached.get_scale_bits() == scale_bits
430            {
431                display_list.extend_commands(cached.get_base_commands().as_slice());
432                let matched: Vec<EuvChartDatumHit> = if hover_pos.is_some() {
433                    let mut hover_state: EuvChartState = base_state;
434                    hover_state.set_hover_pos(hover_pos);
435                    match opt_sig_opt {
436                        Some(sig) => {
437                            let live_opt: EuvChartOption = sig.get_untracked();
438                            render_echart_hover_overlay(
439                                &live_opt,
440                                &hover_state,
441                                cached.get_base_result(),
442                                vis_vp,
443                                live_tok,
444                                display_list,
445                            )
446                        }
447                        None => paint_opt_rc.with_resolved(|live_opt: &EuvChartOption| {
448                            render_echart_hover_overlay(
449                                live_opt,
450                                &hover_state,
451                                cached.get_base_result(),
452                                vis_vp,
453                                live_tok,
454                                display_list,
455                            )
456                        }),
457                    }
458                } else {
459                    Vec::new()
460                };
461                if let Ok(mut r_guard) = paint_res.try_borrow_mut() {
462                    r_guard.set_active_tooltip_hits(matched);
463                }
464                return;
465            }
466            record_chart_paint_build();
467            let opt_snapshot: EuvChartOption = match opt_sig_opt {
468                Some(sig) => sig.get_untracked(),
469                None => paint_opt_rc.resolve_clone(),
470            };
471            let canvas_opt: EuvChartOption = opt_snapshot.without_title();
472            let mut scratch: DisplayList = DisplayList::default();
473            scratch.reset(display_list.get_viewport(), scale_factor);
474            let base_res: EuvChartRenderResult = render_echart_in_viewport(
475                &canvas_opt,
476                &base_state,
477                bounds,
478                vis_vp,
479                live_tok,
480                &mut scratch,
481            );
482            let base_cmds: Vec<DrawCommand> = take(scratch.get_mut_commands());
483            display_list.extend_commands(base_cmds.as_slice());
484            let matched: Vec<EuvChartDatumHit> = if hover_pos.is_some() {
485                let mut hover_state: EuvChartState = base_state.clone();
486                hover_state.set_hover_pos(hover_pos);
487                render_echart_hover_overlay(
488                    &canvas_opt,
489                    &hover_state,
490                    &base_res,
491                    vis_vp,
492                    live_tok,
493                    display_list,
494                )
495            } else {
496                Vec::new()
497            };
498            let mut full_res: EuvChartRenderResult = base_res.clone();
499            if !matched.is_empty() {
500                full_res.set_active_tooltip_hits(matched);
501            }
502            if let Ok(mut r_guard) = paint_res.try_borrow_mut() {
503                *r_guard = full_res;
504            }
505            if let Ok(mut guard) = inline_cache.try_borrow_mut() {
506                *guard = Some(ChartPaintCache {
507                    bounds,
508                    visible_viewport: vis_vp,
509                    tokens: live_tok,
510                    base_state,
511                    rev: cur_rev,
512                    scale_bits,
513                    base_commands: base_cmds,
514                    base_result: base_res,
515                });
516            }
517        };
518        let dv_opt_rc: Rc<LazyChartOption> = Rc::clone(&static_opt_rc);
519        let dv_ctx: Context = ctx.clone();
520        let build_data_view = move || -> Vec<NodeId> {
521            record_chart_data_view_build();
522            let mut local_ctx: Context = dv_ctx.clone();
523            if !data_view_open_memo.get() {
524                return Vec::new();
525            }
526            let node_style: EuvChartState = state_sig.get();
527            let live_tok: ThemeTokens = use_live_tokens(base_tokens);
528            let live_p: ThemePalette = live_tok.get_palette();
529            let live_g: ThemeGeometry = live_tok.get_geometry();
530            let opt_snapshot: EuvChartOption = match opt_sig_opt {
531                Some(sig) => sig.get(),
532                None => dv_opt_rc.resolve_clone(),
533            };
534            let table: EuvChartDataViewTable = extract_data_view_table(&opt_snapshot, &node_style);
535            let (col_widths, total_w): (Vec<f32>, f32) = compute_data_view_col_widths(&table);
536            let mut dv_scroll_st: Style = Style::default();
537            dv_scroll_st
538                .get_mut_layout()
539                .set_flex_direction(FlexDirection::Column)
540                .set_align_items(AlignItems::Start);
541            let mut header_row: NodeId = NodeId::default();
542            let mut body_col: NodeId = NodeId::default();
543            let column_quaternary_style: Style = style! {
544                Width(Length::Percent(100.0))
545                Padding(Edges::new(SPACE_SM, SPACE_MD, SPACE_MD, SPACE_MD))
546            };
547            let column_fifth_style: Style = style! {
548                Width(Length::Percent(100.0))
549                Background(live_p.get_muted().multiply_alpha(0.32))
550                Border::new(1.0, live_p.get_border())
551                Radius(live_g.get_radius_md())
552                Overflow::Hidden
553            };
554            let row_eleventh_style: Style = style! {
555                Width(Length::Percent(100.0))
556                Padding(Edges::symmetric(SPACE_XS + 2.0, SPACE_MD))
557                JustifyContent::SpaceBetween
558                AlignItems::Center
559                Background(live_p.get_card())
560            };
561            let text_eighth_style: Style = style! {
562                FlexShrink(1.0)
563                MinWidth(Length::Px(0.0))
564                FontSize(11.5)
565                FontWeight::SemiBold
566                TextColor(live_p.get_foreground())
567            };
568            let view_tertiary_style: Style = style! {
569                Width(Length::Percent(100.0))
570                Height(Length::Px(1.0))
571                Background(live_p.get_border())
572            };
573            let scroll_tertiary_style: Style = style! {
574                dv_scroll_st
575                Width(Length::Percent(100.0))
576                MaxHeight(Length::Px(ECHART_DATA_VIEW_MAX_HEIGHT))
577            };
578            let column_sixth_style: Style = style! {
579                MinWidth(Length::Px(total_w))
580                Width(Length::Percent(100.0))
581                FlexShrink(0.0)
582            };
583            let row_twelfth_style: Style = style! {
584                Width(Length::Percent(100.0))
585                Background(live_p.get_muted().multiply_alpha(0.55))
586                AlignItems::Stretch
587            };
588            let column_seventh_style: Style = style! {
589                Width(Length::Percent(100.0))
590            };
591            let wrapper: NodeId = view! {
592                column {
593                    style: column_quaternary_style
594                    column {
595                        style: column_fifth_style
596                        row {
597                            style: row_eleventh_style
598                            text {
599                                style: text_eighth_style
600                                { ECHART_DATA_VIEW_TITLE }
601                            }
602                        }
603                        view {
604                            style: view_tertiary_style
605                        }
606                        scroll {
607                            style: scroll_tertiary_style
608                            column {
609                                style: column_sixth_style
610                                row {
611                                    node_ref: header_row
612                                    style: row_twelfth_style
613                                }
614                                column {
615                                    node_ref: body_col
616                                    style: column_seventh_style
617                                }
618                            }
619                        }
620                    }
621                }
622            };
623            let safe_total_w: f32 = total_w.max(1.0);
624            for (ci, span_height) in table.get_headers().iter().enumerate() {
625                let cw: f32 = col_widths
626                    .get(ci)
627                    .copied()
628                    .unwrap_or(ECHART_DATA_VIEW_MIN_COL_W);
629                let pct: f32 = (cw / safe_total_w) * 100.0;
630                let h_txt: String = span_height.clone();
631                let row_tenth_style: Style = style! {
632                    Width(Length::Percent(pct))
633                    MinWidth(Length::Px(cw))
634                    FlexShrink(0.0)
635                    Padding(Edges::symmetric(6.0, SPACE_SM))
636                    AlignItems::Center
637                    Overflow::Hidden
638                };
639                let text_seventh_style: Style = style! {
640                    Width(Length::Percent(100.0))
641                    FontSize(11.0)
642                    FontWeight::SemiBold
643                    TextColor(live_p.get_foreground())
644                    TextOverflow::Wrap
645                };
646                let cell: NodeId = view! {
647                    row {
648                        style: row_tenth_style
649                        text {
650                            style: text_seventh_style
651                            { h_txt }
652                        }
653                    }
654                };
655                local_ctx.append(header_row, cell);
656            }
657            for (ri, row) in table.get_rows().iter().take(40).enumerate() {
658                let row_bg: Color = if ri % 2 == 1 {
659                    live_p.get_muted().multiply_alpha(0.30)
660                } else {
661                    live_p.get_card()
662                };
663                let view_secondary_style: Style = style! {
664                    Width(Length::Percent(100.0))
665                    Height(Length::Px(1.0))
666                    Background(live_p.get_border().multiply_alpha(0.5))
667                };
668                let div_node: NodeId = view! {
669                    view {
670                        style: view_secondary_style
671                    }
672                };
673                local_ctx.append(body_col, div_node);
674                let row_ninth_style: Style = style! {
675                    Width(Length::Percent(100.0))
676                    Background(row_bg)
677                    AlignItems::Stretch
678                };
679                let row_node: NodeId = view! {
680                    row {
681                        style: row_ninth_style
682                    }
683                };
684                for (ci, char_item) in row.iter().enumerate() {
685                    let cw: f32 = col_widths
686                        .get(ci)
687                        .copied()
688                        .unwrap_or(ECHART_DATA_VIEW_MIN_COL_W);
689                    let pct: f32 = (cw / safe_total_w) * 100.0;
690                    let c_txt: String = char_item.clone();
691                    let row_eighth_style: Style = style! {
692                        Width(Length::Percent(pct))
693                        MinWidth(Length::Px(cw))
694                        FlexShrink(0.0)
695                        Padding(Edges::symmetric(6.0, SPACE_SM))
696                        AlignItems::Center
697                        Overflow::Hidden
698                    };
699                    let text_sixth_style: Style = style! {
700                        Width(Length::Percent(100.0))
701                        FontSize(11.0)
702                        TextColor(live_p.get_muted_foreground())
703                        TextOverflow::Wrap
704                    };
705                    let cell: NodeId = view! {
706                        row {
707                            style: row_eighth_style
708                            text {
709                                style: text_sixth_style
710                                { c_txt }
711                            }
712                        }
713                    };
714                    local_ctx.append(row_node, cell);
715                }
716                local_ctx.append(body_col, row_node);
717            }
718            vec![wrapper]
719        };
720        let mut toolbox_nodes: Vec<NodeId> = Vec::new();
721        if show_toolbox && let Some(tb) = toolbox_cfg.as_ref() {
722            if tb.get_restore() {
723                let r_opt: Rc<LazyChartOption> = Rc::clone(&static_opt_rc);
724                let z_cb: Option<Rc<dyn Fn(f32, f32)>> = on_zoom_change.clone();
725                let on_restore = move |_: &UiEvent| {
726                    let cur_opt: EuvChartOption = match opt_sig_opt {
727                        Some(sig) => sig.get_untracked(),
728                        None => r_opt.resolve_clone(),
729                    };
730                    let restored: EuvChartState = EuvChartState::from_option(&cur_opt);
731                    let s_pct: f32 = restored.get_zoom_start_pct();
732                    let e_pct: f32 = restored.get_zoom_end_pct();
733                    let _: bool = hover_pos_sig.set_if_changed(None);
734                    let _: bool = state_sig.set(restored);
735                    if let Some(callback_fn) = z_cb.as_ref() {
736                        callback_fn(s_pct, e_pct);
737                    }
738                };
739                toolbox_nodes.push(build_toolbox_icon_button(
740                    base_tokens,
741                    ChartToolboxIcon::Restore,
742                    ECHART_BUTTON_RESTORE,
743                    on_restore,
744                ));
745            }
746            if tb.get_magic_type() {
747                let on_magic = move |_: &UiEvent| {
748                    let _: bool = {
749                        if let Some(mut updated_value) = state_sig.try_get_untracked() {
750                            {
751                                let active_style: &mut EuvChartState = &mut updated_value;
752                                let _: EuvChartMagicType = active_style.cycle_magic_type();
753                            }
754                            state_sig.set(updated_value)
755                        } else {
756                            false
757                        }
758                    };
759                };
760                toolbox_nodes.push(build_toolbox_icon_button(
761                    base_tokens,
762                    ChartToolboxIcon::MagicType,
763                    ECHART_BUTTON_MAGIC_TYPE,
764                    on_magic,
765                ));
766            }
767            if tb.get_data_view() {
768                let on_dv = move |_: &UiEvent| {
769                    let _: bool = {
770                        if let Some(mut updated_value) = state_sig.try_get_untracked() {
771                            {
772                                let state_val: &mut EuvChartState = &mut updated_value;
773                                let _: bool = state_val.toggle_data_view();
774                            }
775                            state_sig.set(updated_value)
776                        } else {
777                            false
778                        }
779                    };
780                };
781                toolbox_nodes.push(build_toolbox_icon_button(
782                    base_tokens,
783                    ChartToolboxIcon::DataView,
784                    ECHART_BUTTON_DATA_VIEW,
785                    on_dv,
786                ));
787            }
788            if tb.get_fullscreen() {
789                let on_fs = move |_: &UiEvent| {
790                    let _: bool = fs_open.set_if_changed(true);
791                };
792                toolbox_nodes.push(build_toolbox_icon_button(
793                    base_tokens,
794                    ChartToolboxIcon::Fullscreen,
795                    ECHART_BUTTON_FULLSCREEN,
796                    on_fs,
797                ));
798            }
799        }
800        let fs_opt_rc: Rc<LazyChartOption> = Rc::clone(&static_opt_rc);
801        let ctx_fs: Context = ctx.clone();
802        let fs_opt_rev: Rc<Cell<u64>> = Rc::clone(&opt_rev);
803        let fs_click_cb: Option<EuvChartHitCallback> = on_point_click.clone();
804        let fs_legend_cb: Option<EuvChartLegendCallback> = on_legend_change.clone();
805        let fs_zoom_cb: Option<Rc<dyn Fn(f32, f32)>> = on_zoom_change.clone();
806        let build_fs_panel = move || -> NodeId {
807            let mut local_fs_ctx: Context = ctx_fs.clone();
808            let live_tok: ThemeTokens = live_tokens_untracked(base_tokens);
809            let live_p: ThemePalette = live_tok.get_palette();
810            let live_g: ThemeGeometry = live_tok.get_geometry();
811            let modal_ctrl_h: f32 = live_g.get_control_sm();
812            let close_surface: SurfaceColors = live_p.surface(SurfaceRole::Primary);
813            let cur_opt: EuvChartOption = match opt_sig_opt {
814                Some(sig) => sig.get_untracked(),
815                None => fs_opt_rc.resolve_clone(),
816            };
817            let modal_title: String = cur_opt
818                .title_opt()
819                .map(|blend_factor: &EuvChartTitle| blend_factor.get_text().clone())
820                .filter(|text_value: &String| !text_value.is_empty())
821                .unwrap_or_else(|| ECHART_DEFAULT_MODAL_TITLE.to_string());
822            let modal_opt_rc: Rc<EuvChartOption> = Rc::new(cur_opt);
823            let modal_opt_wire: Rc<LazyChartOption> = Rc::clone(&fs_opt_rc);
824            let modal_min_sz: Size = compute_chart_min_content_size(&modal_opt_rc);
825            let modal_render: Rc<RefCell<EuvChartRenderResult>> =
826                Rc::new(RefCell::new(EuvChartRenderResult::default()));
827            let modal_bounds: Rc<RefCell<Rect>> = Rc::new(RefCell::new(Rect::default()));
828            let modal_drag: Rc<Cell<(ChartDragTarget, f32, f32, f32)>> =
829                Rc::new(Cell::new((ChartDragTarget::None, 0.0, 0.0, 100.0)));
830            let modal_hover_pos_sig: Signal<Option<Point>> = Signal::new(None);
831            let modal_render_paint: Rc<RefCell<EuvChartRenderResult>> = Rc::clone(&modal_render);
832            let modal_bounds_paint: Rc<RefCell<Rect>> = Rc::clone(&modal_bounds);
833            let modal_rev_paint: Rc<Cell<u64>> = Rc::clone(&fs_opt_rev);
834            let body_scroll_cell: Rc<Cell<NodeId>> = Rc::new(Cell::new(NodeId::default()));
835            let body_scroll_paint: Rc<Cell<NodeId>> = Rc::clone(&body_scroll_cell);
836            let scene_modal_paint: SceneHandle = local_fs_ctx.get_scene().clone();
837            let modal_cache: RefCell<Option<ChartPaintCache>> = RefCell::new(None);
838            let paint_modal = move |bounds: Rect, draw_commands: &mut DisplayList| {
839                let cur_tok: ThemeTokens = live_tokens_untracked(base_tokens);
840                let cur_st: EuvChartState = state_sig.get_untracked();
841                let hover_pos: Option<Point> = modal_hover_pos_sig.get_untracked();
842                let cur_rev: u64 = modal_rev_paint.get();
843                let sc_node: NodeId = body_scroll_paint.get();
844                let scroll_info: Option<(Point, Size)> = if sc_node == NodeId::default() {
845                    None
846                } else {
847                    scene_modal_paint.with_read(
848                        |tree: &SceneTree| {
849                            tree.get_node(sc_node).map(|target_node: &SceneNode| {
850                                let lb: LayoutBox = target_node.get_layout_box();
851                                let clip_bounds: Rect = lb.get_content_bounds();
852                                (
853                                    lb.get_scroll_offset(),
854                                    Size::new(clip_bounds.get_width(), clip_bounds.get_height()),
855                                )
856                            })
857                        },
858                        None,
859                    )
860                };
861                let vis_vp: Rect = compute_visible_chart_viewport(bounds, scroll_info);
862                if let Ok(mut b_guard) = modal_bounds_paint.try_borrow_mut() {
863                    *b_guard = bounds;
864                }
865                let scale_factor: f32 = draw_commands.get_scale_factor().max(0.5);
866                let scale_bits: u32 = scale_factor.to_bits();
867                let base_state: EuvChartState = if cur_st.hover_pos_opt().is_some() {
868                    cur_st.without_hover()
869                } else {
870                    cur_st
871                };
872                if let Ok(guard) = modal_cache.try_borrow()
873                    && let Some(cached) = guard.as_ref()
874                    && cached.get_bounds() == bounds
875                    && cached.get_visible_viewport() == vis_vp
876                    && cached.get_tokens() == cur_tok
877                    && cached.get_base_state() == &base_state
878                    && cached.get_rev() == cur_rev
879                    && cached.get_scale_bits() == scale_bits
880                {
881                    draw_commands.extend_commands(cached.get_base_commands().as_slice());
882                    let matched: Vec<EuvChartDatumHit> = if hover_pos.is_some() {
883                        let mut hover_state: EuvChartState = base_state;
884                        hover_state.set_hover_pos(hover_pos);
885                        match opt_sig_opt {
886                            Some(sig) => {
887                                let live_opt: EuvChartOption = sig.get_untracked();
888                                render_echart_hover_overlay(
889                                    &live_opt,
890                                    &hover_state,
891                                    cached.get_base_result(),
892                                    vis_vp,
893                                    cur_tok,
894                                    draw_commands,
895                                )
896                            }
897                            None => render_echart_hover_overlay(
898                                modal_opt_rc.as_ref(),
899                                &hover_state,
900                                cached.get_base_result(),
901                                vis_vp,
902                                cur_tok,
903                                draw_commands,
904                            ),
905                        }
906                    } else {
907                        Vec::new()
908                    };
909                    if let Ok(mut r_guard) = modal_render_paint.try_borrow_mut() {
910                        r_guard.set_active_tooltip_hits(matched);
911                    }
912                    return;
913                }
914                let live_opt: EuvChartOption = match opt_sig_opt {
915                    Some(sig) => sig.get_untracked(),
916                    None => (*modal_opt_rc).clone(),
917                };
918                let modal_canvas_opt: EuvChartOption = live_opt.without_title();
919                let mut scratch: DisplayList = DisplayList::default();
920                scratch.reset(draw_commands.get_viewport(), scale_factor);
921                let base_res: EuvChartRenderResult = render_echart_in_viewport(
922                    &modal_canvas_opt,
923                    &base_state,
924                    bounds,
925                    vis_vp,
926                    cur_tok,
927                    &mut scratch,
928                );
929                let base_cmds: Vec<DrawCommand> = take(scratch.get_mut_commands());
930                draw_commands.extend_commands(base_cmds.as_slice());
931                let matched: Vec<EuvChartDatumHit> = if hover_pos.is_some() {
932                    let mut hover_state: EuvChartState = base_state.clone();
933                    hover_state.set_hover_pos(hover_pos);
934                    render_echart_hover_overlay(
935                        &modal_canvas_opt,
936                        &hover_state,
937                        &base_res,
938                        vis_vp,
939                        cur_tok,
940                        draw_commands,
941                    )
942                } else {
943                    Vec::new()
944                };
945                let mut full_res: EuvChartRenderResult = base_res.clone();
946                if !matched.is_empty() {
947                    full_res.set_active_tooltip_hits(matched);
948                }
949                if let Ok(mut r_guard) = modal_render_paint.try_borrow_mut() {
950                    *r_guard = full_res;
951                }
952                if let Ok(mut guard) = modal_cache.try_borrow_mut() {
953                    *guard = Some(ChartPaintCache {
954                        bounds,
955                        visible_viewport: vis_vp,
956                        tokens: cur_tok,
957                        base_state,
958                        rev: cur_rev,
959                        scale_bits,
960                        base_commands: base_cmds,
961                        base_result: base_res,
962                    });
963                }
964            };
965            let paint_close_icon = move |bounds: Rect, command_list: &mut DisplayList| {
966                let cur_p: ThemePalette = live_tokens_untracked(base_tokens).get_palette();
967                let close_fg: Color = cur_p.surface(SurfaceRole::Primary).get_fg();
968                draw_chart_toolbox_icon(
969                    ChartToolboxIcon::ExitFullscreen,
970                    bounds,
971                    command_list,
972                    close_fg,
973                );
974            };
975            let on_close_fs = move |_: &UiEvent| {
976                let _: bool = fs_open.set_if_changed(false);
977            };
978            let zoom_sig: Signal<f32> = Signal::new(1.0);
979            let on_zoom_out = move |_: &UiEvent| {
980                let _: bool = {
981                    if let Some(mut updated_value) = zoom_sig.try_get_untracked() {
982                        {
983                            let pos_z: &mut f32 = &mut updated_value;
984                            *pos_z =
985                                (*pos_z - ECHART_ZOOM_STEP).clamp(ECHART_ZOOM_MIN, ECHART_ZOOM_MAX);
986                        }
987                        zoom_sig.set(updated_value)
988                    } else {
989                        false
990                    }
991                };
992            };
993            let on_zoom_in = move |_: &UiEvent| {
994                let _: bool = {
995                    if let Some(mut updated_value) = zoom_sig.try_get_untracked() {
996                        {
997                            let coord_z: &mut f32 = &mut updated_value;
998                            *coord_z = (*coord_z + ECHART_ZOOM_STEP)
999                                .clamp(ECHART_ZOOM_MIN, ECHART_ZOOM_MAX);
1000                        }
1001                        zoom_sig.set(updated_value)
1002                    } else {
1003                        false
1004                    }
1005                };
1006            };
1007            let body_scroll_reset: Rc<Cell<NodeId>> = Rc::clone(&body_scroll_cell);
1008            let scene_reset: SceneHandle = local_fs_ctx.get_scene().clone();
1009            let on_zoom_reset = move |_: &UiEvent| {
1010                let _: bool = zoom_sig.set_if_changed(1.0);
1011                let node_id: NodeId = body_scroll_reset.get();
1012                scene_reset.with_write(
1013                    |tree: &mut SceneTree| {
1014                        tree.set_scroll_offset(node_id, Point::default());
1015                    },
1016                    (),
1017                );
1018            };
1019            let safe_sig: Signal<SafeAreaInsets> = local_fs_ctx.get_safe_area();
1020            let vp_sig: Signal<Size> = local_fs_ctx.get_viewport_size();
1021            let init_safe: SafeAreaInsets = safe_sig.get_untracked();
1022            let init_vp: Size = vp_sig.get_untracked();
1023            let init_fs: FullscreenSafeLayout = resolve_fullscreen_safe_layout(init_vp, init_safe);
1024            let init_body: Edges = init_fs.get_body_padding();
1025            let init_head: Edges = init_fs.get_header_padding();
1026            let modal_base_min_w: f32 = ECHART_MODAL_MIN_WIDTH.max(modal_min_sz.get_width());
1027            let modal_base_min_h: f32 = ECHART_MODAL_MIN_HEIGHT.max(modal_min_sz.get_height());
1028            let init_canvas_w: f32 =
1029                (init_vp.get_width() - init_body.get_left() - init_body.get_right())
1030                    .max(modal_base_min_w);
1031            let init_canvas_h: f32 =
1032                (init_vp.get_height() - 56.0 - init_head.get_top() - init_body.get_bottom())
1033                    .max(modal_base_min_h);
1034            let mut modal_scroll_st: Style = Style::default();
1035            modal_scroll_st
1036                .get_mut_layout()
1037                .set_flex_direction(FlexDirection::Column)
1038                .set_align_items(AlignItems::Start);
1039            let mut top_bar_node: NodeId = NodeId::default();
1040            let mut body_host_node: NodeId = NodeId::default();
1041            let mut modal_canvas: NodeId = NodeId::default();
1042            let mut zoom_reset_txt: NodeId = NodeId::default();
1043            let column_tertiary_style: Style = style! {
1044                Width(Length::Percent(100.0))
1045                Height(Length::Percent(100.0))
1046                FlexGrow(1.0)
1047                Padding(Edges::all(0.0))
1048                Margin(Edges::all(0.0))
1049                Background(live_p.get_card())
1050                Border::new(0.0, COLOR_TRANSPARENT)
1051                Radius(0.0)
1052                Overflow::Hidden
1053                StopEventPropagation(true)
1054            };
1055            let row_tertiary_style: Style = style! {
1056                Width(Length::Percent(100.0))
1057                FlexShrink(0.0)
1058                Padding(init_head)
1059                JustifyContent::SpaceBetween
1060                AlignItems::Center
1061                Gap(SPACE_SM)
1062                Overflow::Hidden
1063                Background(live_p.get_muted().multiply_alpha(0.4))
1064            };
1065            let text_tertiary_style: Style = style! {
1066                FlexShrink(1.0)
1067                MinWidth(Length::Px(0.0))
1068                Overflow::Hidden
1069                TextOverflow::Ellipsis
1070                FontSize(13.5)
1071                FontWeight::SemiBold
1072                TextColor(live_p.get_foreground())
1073            };
1074            let row_quaternary_style: Style = style! {
1075                FlexShrink(0.0)
1076                AlignItems::Center
1077                Gap(SPACE_XS)
1078            };
1079            let row_fifth_style: Style = style! {
1080                Width(Length::Px(modal_ctrl_h))
1081                Height(Length::Px(modal_ctrl_h))
1082                JustifyContent::Center
1083                AlignItems::Center
1084                Radius(live_g.get_radius_sm())
1085                Overflow::Hidden
1086                CursorIcon::Pointer
1087                Background(live_p.get_card())
1088                Border::new(1.0, live_p.get_border())
1089            };
1090            let text_quaternary_style: Style = style! {
1091                FontSize(14.0)
1092                FontWeight::Bold
1093                TextColor(live_p.get_foreground())
1094                TextOverflow::Clip
1095            };
1096            let row_sixth_style: Style = style! {
1097                Height(Length::Px(modal_ctrl_h))
1098                Padding(Edges::symmetric(0.0, SPACE_SM))
1099                JustifyContent::Center
1100                AlignItems::Center
1101                Radius(live_g.get_radius_sm())
1102                Overflow::Hidden
1103                CursorIcon::Pointer
1104                Background(live_p.get_card())
1105                Border::new(1.0, live_p.get_border())
1106            };
1107            let text_fifth_style: Style = style! {
1108                FontSize(11.0)
1109                FontFamily::Monospace
1110                FontWeight::SemiBold
1111                TextColor(live_p.get_foreground())
1112                TextOverflow::Clip
1113            };
1114            let row_seventh_style: Style = style! {
1115                Width(Length::Px(modal_ctrl_h))
1116                Height(Length::Px(modal_ctrl_h))
1117                JustifyContent::Center
1118                AlignItems::Center
1119                Radius(live_g.get_radius_sm())
1120                Overflow::Hidden
1121                CursorIcon::Pointer
1122                Background(close_surface.get_bg())
1123            };
1124            let canvas_secondary_style: Style = style! {
1125                Width(Length::Px(16.0))
1126                Height(Length::Px(16.0))
1127                FlexShrink(0.0)
1128            };
1129            let view_style: Style = style! {
1130                Width(Length::Percent(100.0))
1131                Height(Length::Px(1.0))
1132                Background(live_p.get_border())
1133            };
1134            let scroll_secondary_style: Style = style! {
1135                modal_scroll_st
1136                FlexGrow(1.0)
1137                FlexShrink(1.0)
1138                MinHeight(Length::Px(0.0))
1139                Width(Length::Percent(100.0))
1140                Padding(Edges::new(
1141                    SPACE_XS,
1142                    init_body.get_right(),
1143                    init_body.get_bottom(),
1144                    init_body.get_left()
1145                ))
1146                StopScrollPropagation(true)
1147            };
1148            let canvas_tertiary_style: Style = style! {
1149                Width(Length::Px(init_canvas_w))
1150                Height(Length::Px(init_canvas_h))
1151                FlexShrink(0.0)
1152                if has_data_zoom { CursorIcon::Pointer } else { CursorIcon::Grab }
1153            };
1154            let panel: NodeId = view! {
1155                column {
1156                    style: column_tertiary_style
1157                    row {
1158                        node_ref: top_bar_node
1159                        style: row_tertiary_style
1160                        text {
1161                            style: text_tertiary_style
1162                            { modal_title }
1163                        }
1164                        row {
1165                            style: row_quaternary_style
1166                            row {
1167                                style: row_fifth_style
1168                                role: A11yRole::Button
1169                                a11y_label: ECHART_BUTTON_ZOOM_OUT.to_string()
1170                                on_click: on_zoom_out
1171                                text {
1172                                    style: text_quaternary_style
1173                                    { ECHART_ZOOM_MINUS }
1174                                }
1175                            }
1176                            row {
1177                                style: row_sixth_style
1178                                role: A11yRole::Button
1179                                a11y_label: ECHART_BUTTON_ZOOM_RESET.to_string()
1180                                on_click: on_zoom_reset
1181                                text {
1182                                    node_ref: zoom_reset_txt
1183                                    style: text_fifth_style
1184                                    { ECHART_ZOOM_INIT_LABEL }
1185                                }
1186                            }
1187                            row {
1188                                style: row_fifth_style
1189                                role: A11yRole::Button
1190                                a11y_label: ECHART_BUTTON_ZOOM_IN.to_string()
1191                                on_click: on_zoom_in
1192                                text {
1193                                    style: text_quaternary_style
1194                                    { ECHART_ZOOM_PLUS }
1195                                }
1196                            }
1197                            row {
1198                                style: row_seventh_style
1199                                role: A11yRole::Button
1200                                a11y_label: ECHART_BUTTON_CLOSE.to_string()
1201                                on_click: on_close_fs
1202                                canvas {
1203                                    caching: CanvasCaching::RetainedStatic
1204                                    style: canvas_secondary_style
1205                                    painter: paint_close_icon
1206                                }
1207                            }
1208                        }
1209                    }
1210                    view {
1211                        style: view_style
1212                    }
1213                    scroll {
1214                        node_ref: body_host_node
1215                        style: scroll_secondary_style
1216                        canvas {
1217                            node_ref: modal_canvas
1218                            caching: CanvasCaching::RetainedStatic
1219                            style: canvas_tertiary_style
1220                            painter: paint_modal
1221                        }
1222                    }
1223                }
1224            };
1225            body_scroll_cell.set(body_host_node);
1226            let scene_modal_scroll: SceneHandle = local_fs_ctx.get_scene().clone();
1227            local_fs_ctx.on_scroll(body_host_node, move |_: &UiEvent| {
1228                scene_modal_scroll.mark_dirty(modal_canvas, DIRTY_PAINT);
1229            });
1230            if interactive {
1231                let mut modal_wiring: ChartPointerWiring = ChartPointerWiring::new(
1232                    modal_canvas,
1233                    state_sig,
1234                    modal_hover_pos_sig,
1235                    modal_render,
1236                    modal_bounds,
1237                    Rc::clone(&modal_drag),
1238                    modal_opt_wire,
1239                );
1240                let _: &mut ChartPointerWiring = modal_wiring
1241                    .set_opt_sig(opt_sig_opt)
1242                    .set_on_point_click(fs_click_cb.clone())
1243                    .set_on_legend_change(fs_legend_cb.clone())
1244                    .set_on_zoom_change(fs_zoom_cb.clone())
1245                    .set_enable_drag(has_data_zoom);
1246                wire_chart_pointer_events(&mut local_fs_ctx, modal_wiring);
1247            }
1248            let handle_safe: SceneHandle = local_fs_ctx.get_scene().clone();
1249            let handle_modal_st: SceneHandle = handle_safe.clone();
1250            let handle_modal_theme: SceneHandle = handle_safe.clone();
1251            let app_state_fs: Signal<AppState> = local_fs_ctx.get_app_state();
1252            let (safe_scope, _): (Scope, Effect) = Scope::run(|_: Scope| {
1253                let _: Effect = Effect::new(move || {
1254                    if app_state_fs.get() != AppState::Active {
1255                        modal_drag.set((ChartDragTarget::None, 0.0, 0.0, 100.0));
1256                    }
1257                });
1258                let mounted_modal_st: Cell<bool> = Cell::new(false);
1259                let _: Effect = Effect::new(move || {
1260                    let _: EuvChartState = state_sig.get();
1261                    if !mounted_modal_st.replace(true) {
1262                        return;
1263                    }
1264                    handle_modal_st.mark_dirty(modal_canvas, DIRTY_PAINT);
1265                });
1266                let prev_modal_theme: Cell<ThemeKey> = Cell::new(live_tok.key());
1267                let _: Effect = Effect::new(move || {
1268                    let next_theme_key: ThemeKey = use_live_tokens(base_tokens).key();
1269                    if prev_modal_theme.replace(next_theme_key) == next_theme_key {
1270                        return;
1271                    }
1272                    handle_modal_theme.mark_dirty(modal_canvas, DIRTY_PAINT);
1273                });
1274                if let Some(sig) = opt_sig_opt {
1275                    let handle_modal_opt: SceneHandle = handle_safe.clone();
1276                    let mounted_modal_opt: Cell<bool> = Cell::new(false);
1277                    let _: Effect = Effect::new(move || {
1278                        let _: EuvChartOption = sig.get();
1279                        if !mounted_modal_opt.replace(true) {
1280                            return;
1281                        }
1282                        handle_modal_opt.mark_dirty(modal_canvas, DIRTY_PAINT);
1283                    });
1284                }
1285                Effect::new(move || {
1286                    let safe: SafeAreaInsets = safe_sig.get();
1287                    let box_size: Size = vp_sig.get();
1288                    let depth_z: f32 = zoom_sig.get();
1289                    if !fs_open.get_untracked() {
1290                        return;
1291                    }
1292                    let fs_lay: FullscreenSafeLayout =
1293                        resolve_fullscreen_safe_layout(box_size, safe);
1294                    let fs_head: Edges = fs_lay.get_header_padding();
1295                    let fs_body: Edges = fs_lay.get_body_padding();
1296                    let next_w: f32 =
1297                        (box_size.get_width() - fs_body.get_left() - fs_body.get_right())
1298                            .max(modal_base_min_w)
1299                            * depth_z;
1300                    let next_h: f32 =
1301                        (box_size.get_height() - 56.0 - fs_head.get_top() - fs_body.get_bottom())
1302                            .max(modal_base_min_h)
1303                            * depth_z;
1304                    let pct_label: String = format!("{}%", (depth_z * 100.0).round() as u32);
1305                    handle_safe.with_write(
1306                        |tree: &mut SceneTree| {
1307                            let dirty_l: u16 = DIRTY_LAYOUT | DIRTY_SUBTREE_LAYOUT;
1308                            if let Some(item_count) = tree.get_node_mut(top_bar_node) {
1309                                item_count
1310                                    .get_mut_style()
1311                                    .get_mut_layout()
1312                                    .set_padding(fs_head);
1313                                tree.mark_dirty(top_bar_node, dirty_l | DIRTY_PAINT);
1314                            }
1315                            if let Some(node_entry) = tree.get_node_mut(body_host_node) {
1316                                node_entry.get_mut_style().get_mut_layout().set_padding(
1317                                    Edges::new(
1318                                        SPACE_XS,
1319                                        fs_body.get_right(),
1320                                        fs_body.get_bottom(),
1321                                        fs_body.get_left(),
1322                                    ),
1323                                );
1324                                tree.mark_dirty(body_host_node, dirty_l | DIRTY_PAINT);
1325                            }
1326                            if let Some(normal_vec) = tree.get_node_mut(modal_canvas) {
1327                                let lay: &mut LayoutStyle =
1328                                    normal_vec.get_mut_style().get_mut_layout();
1329                                lay.set_width(Length::Px(next_w))
1330                                    .set_height(Length::Px(next_h));
1331                                tree.mark_dirty(modal_canvas, dirty_l | DIRTY_PAINT);
1332                            }
1333                            tree.set_text(zoom_reset_txt, pct_label);
1334                        },
1335                        (),
1336                    );
1337                })
1338            });
1339            local_fs_ctx.get_scene().with_write(
1340                |tree: &mut SceneTree| {
1341                    tree.attach_scope(panel, safe_scope);
1342                },
1343                (),
1344            );
1345            panel
1346        };
1347        let mut inline_scroll_st: Style = Style::default();
1348        inline_scroll_st
1349            .get_mut_layout()
1350            .set_flex_direction(FlexDirection::Column)
1351            .set_align_items(AlignItems::Start);
1352        let mut header_row: NodeId = NodeId::default();
1353        let mut title_col: NodeId = NodeId::default();
1354        let mut title_txt_node: NodeId = NodeId::default();
1355        let mut subtext_txt_node: NodeId = NodeId::default();
1356        let mut toolbox_row: NodeId = NodeId::default();
1357        let mut chart_scroll: NodeId = NodeId::default();
1358        let mut chart_canvas: NodeId = NodeId::default();
1359        let mut fs_portal: NodeId = NodeId::default();
1360        let init_title_vis: Display = if init_title_text.is_empty() {
1361            Display::None
1362        } else {
1363            Display::Flex
1364        };
1365        let init_subtext_vis: Display = if init_subtext.is_empty() {
1366            Display::None
1367        } else {
1368            Display::Flex
1369        };
1370        let init_header_justify: JustifyContent = if init_has_title {
1371            JustifyContent::SpaceBetween
1372        } else {
1373            JustifyContent::End
1374        };
1375        let outer_style: Style = style! {
1376            Width(width)
1377            Background(palette.get_card())
1378            Border::new(geometry.get_border_width(), palette.get_border())
1379            Radius(geometry.get_radius_lg())
1380            Overflow::Hidden
1381        }
1382        .with_overrides(outer_overrides);
1383        let row_style: Style = style! {
1384            Width(Length::Percent(100.0))
1385            if has_header { Display::Flex } else { Display::None }
1386            init_header_justify
1387            AlignItems::Center
1388            Padding(Edges::new(SPACE_SM, SPACE_MD, SPACE_XS, SPACE_MD))
1389            Gap(SPACE_SM)
1390            Overflow::Hidden
1391        };
1392        let column_style: Style = style! {
1393            if init_has_title { Display::Flex } else { Display::None }
1394            FlexGrow(1.0)
1395            FlexShrink(1.0)
1396            MinWidth(Length::Px(0.0))
1397            JustifyContent::Center
1398            Gap(2.0)
1399            Overflow::Hidden
1400        };
1401        let text_style: Style = style! {
1402            Width(Length::Percent(100.0))
1403            init_title_vis
1404            FontSize(13.5)
1405            FontWeight::SemiBold
1406            TextColor(palette.get_foreground())
1407            init_title_align
1408            Overflow::Hidden
1409            TextOverflow::Ellipsis
1410        };
1411        let text_secondary_style: Style = style! {
1412            Width(Length::Percent(100.0))
1413            init_subtext_vis
1414            FontSize(11.0)
1415            TextColor(palette.get_muted_foreground())
1416            init_title_align
1417            Overflow::Hidden
1418            TextOverflow::Ellipsis
1419        };
1420        let row_secondary_style: Style = style! {
1421            if show_toolbox { Display::Flex } else { Display::None }
1422            FlexShrink(0.0)
1423            AlignItems::Center
1424            Gap(SPACE_XS)
1425        };
1426        let scroll_style: Style = style! {
1427            inline_scroll_st
1428            Width(Length::Percent(100.0))
1429        };
1430        let canvas_style: Style = style! {
1431            Width(Length::Percent(100.0))
1432            MinWidth(Length::Px(min_content_sz.get_width()))
1433            Height(height)
1434            MinHeight(Length::Px(min_content_sz.get_height()))
1435            FlexShrink(0.0)
1436            if interactive { CursorIcon::Pointer } else { CursorIcon::Default }
1437        };
1438        let column_secondary_style: Style = style! {
1439            Width(Length::Percent(100.0))
1440        };
1441        let portal_style: Style = style! {
1442            FlexDirection::Column
1443            Display::None
1444            Position::Fixed
1445            Inset(Some(0.0), Some(0.0), Some(0.0), Some(0.0))
1446            Width(Length::Percent(100.0))
1447            Height(Length::Percent(100.0))
1448            Padding(Edges::all(0.0))
1449            Margin(Edges::all(0.0))
1450            JustifyContent::Start
1451            AlignItems::Stretch
1452            Background(palette.get_card())
1453            Border::new(0.0, COLOR_TRANSPARENT)
1454            Radius(0.0)
1455            Overflow::Hidden
1456            PointerEvents::None
1457            StopScrollPropagation(true)
1458            StopEventPropagation(true)
1459            ZIndex(Z_INDEX_FULLSCREEN)
1460        };
1461        let root: NodeId = view! {
1462            column {
1463                style: outer_style
1464                row {
1465                    node_ref: header_row
1466                    style: row_style
1467                    column {
1468                        node_ref: title_col
1469                        style: column_style
1470                        text {
1471                            node_ref: title_txt_node
1472                            style: text_style
1473                            { init_title_text }
1474                        }
1475                        text {
1476                            node_ref: subtext_txt_node
1477                            style: text_secondary_style
1478                            { init_subtext }
1479                        }
1480                    }
1481                    row {
1482                        node_ref: toolbox_row
1483                        style: row_secondary_style
1484                    }
1485                }
1486                scroll {
1487                    node_ref: chart_scroll
1488                    style: scroll_style
1489                    canvas {
1490                        node_ref: chart_canvas
1491                        caching: CanvasCaching::RetainedStatic
1492                        style: canvas_style
1493                        painter: paint_inline
1494                    }
1495                }
1496                column {
1497                    style: column_secondary_style
1498                    bind_children: build_data_view
1499                }
1500                portal {
1501                    node_ref: fs_portal
1502                    style: portal_style
1503                }
1504            }
1505        };
1506        inline_scroll_cell.set(chart_scroll);
1507        let scene_inline_scroll: SceneHandle = ctx.get_scene().clone();
1508        ctx.on_scroll(chart_scroll, move |_: &UiEvent| {
1509            scene_inline_scroll.mark_dirty(chart_canvas, DIRTY_PAINT);
1510        });
1511        if has_data_zoom {
1512            let portal_zoom_cb: Option<Rc<dyn Fn(f32, f32)>> = on_zoom_change.clone();
1513            let portal_scene: SceneHandle = ctx.get_scene().clone();
1514            ctx.on_scroll(fs_portal, move |ui_event: &UiEvent| {
1515                if !fs_open.get_untracked() {
1516                    return;
1517                }
1518                let UiEventKind::Scroll(delta) = ui_event.get_kind() else {
1519                    return;
1520                };
1521                if delta.get_x().abs() <= delta.get_y().abs() || delta.get_x().abs() < 1e-4 {
1522                    return;
1523                }
1524                let vp_w: f32 = portal_scene.with_read(
1525                    |tree: &SceneTree| {
1526                        tree.node_screen_bounds(fs_portal)
1527                            .map(|region_bounds: Rect| region_bounds.get_width())
1528                            .filter(|span_width: &f32| *span_width > 32.0)
1529                            .unwrap_or(480.0)
1530                    },
1531                    480.0,
1532                );
1533                let mut out_range: Option<(f32, f32)> = None;
1534                let _: bool = {
1535                    if let Some(mut updated_value) = state_sig.try_get_untracked() {
1536                        {
1537                            let node_style_primary: &mut EuvChartState = &mut updated_value;
1538                            let span: f32 = node_style_primary.get_zoom_end_pct()
1539                                - node_style_primary.get_zoom_start_pct();
1540                            if span < 99.9 {
1541                                let delta_pct: f32 = (delta.get_x() / vp_w) * span;
1542                                if node_style_primary.pan_by_pct(delta_pct) {
1543                                    out_range = Some((
1544                                        node_style_primary.get_zoom_start_pct(),
1545                                        node_style_primary.get_zoom_end_pct(),
1546                                    ));
1547                                }
1548                            }
1549                        }
1550                        state_sig.set(updated_value)
1551                    } else {
1552                        false
1553                    }
1554                };
1555                if let Some((lo, hi)) = out_range
1556                    && let Some(handler_cb) = portal_zoom_cb.as_ref()
1557                {
1558                    handler_cb(lo, hi);
1559                }
1560            });
1561        }
1562        for tb_node in toolbox_nodes.into_iter() {
1563            ctx.append(toolbox_row, tb_node);
1564        }
1565        let drag_bg_reset: Rc<Cell<(ChartDragTarget, f32, f32, f32)>> = Rc::clone(&drag_state);
1566        if interactive {
1567            let mut inline_wiring: ChartPointerWiring = ChartPointerWiring::new(
1568                chart_canvas,
1569                state_sig,
1570                hover_pos_sig,
1571                last_render,
1572                last_bounds,
1573                drag_state,
1574                static_opt_rc,
1575            );
1576            let _: &mut ChartPointerWiring = inline_wiring
1577                .set_opt_sig(opt_sig_opt)
1578                .set_on_point_click(on_point_click.clone())
1579                .set_on_legend_change(on_legend_change.clone())
1580                .set_on_zoom_change(on_zoom_change.clone())
1581                .set_enable_drag(has_data_zoom);
1582            wire_chart_pointer_events(&mut ctx, inline_wiring);
1583        }
1584        let scene_dirty: SceneHandle = ctx.get_scene().clone();
1585        let scene_fs: SceneHandle = ctx.get_scene().clone();
1586        let ctx_build: Context = ctx.clone();
1587        let app_state_sig: Signal<AppState> = ctx.get_app_state();
1588        let prev_open: Rc<Cell<bool>> = Rc::new(Cell::new(false));
1589        let fs_acquired: Rc<Cell<bool>> = Rc::new(Cell::new(false));
1590        let fs_cleanup: Rc<Cell<bool>> = Rc::clone(&fs_acquired);
1591        let rev_watch: Rc<Cell<u64>> = Rc::clone(&opt_rev);
1592        let (scope, _): (Scope, Effect) = Scope::run(|_: Scope| {
1593            on_cleanup(move || {
1594                if fs_cleanup.replace(false) {
1595                    exit_fullscreen();
1596                }
1597            });
1598            let _: Effect = Effect::new(move || {
1599                if app_state_sig.get() != AppState::Active {
1600                    drag_bg_reset.set((ChartDragTarget::None, 0.0, 0.0, 100.0));
1601                }
1602            });
1603            let _: Effect = EuvOverlayStack::bind_signal(
1604                fs_open,
1605                ECHART_FULLSCREEN_OVERLAY_NAME,
1606                Z_INDEX_FULLSCREEN,
1607            );
1608            let scene_st: SceneHandle = scene_dirty.clone();
1609            let prev_dv_open: Cell<bool> = Cell::new(false);
1610            let mounted_st_effect: Cell<bool> = Cell::new(false);
1611            let _: Effect = Effect::new(move || {
1612                let st_now: EuvChartState = state_sig.get();
1613                let dv_open: bool = st_now.get_data_view_open();
1614                if !mounted_st_effect.replace(true) {
1615                    prev_dv_open.set(dv_open);
1616                    return;
1617                }
1618                if prev_dv_open.replace(dv_open) != dv_open {
1619                    let next_disp: Display = if dv_open {
1620                        Display::None
1621                    } else {
1622                        Display::Flex
1623                    };
1624                    scene_st.with_write(
1625                        |tree: &mut SceneTree| {
1626                            if let Some(total_len) = tree.get_node_mut(chart_scroll) {
1627                                total_len
1628                                    .get_mut_style()
1629                                    .get_mut_layout()
1630                                    .set_display(next_disp);
1631                            }
1632                            let mut dirty_root: u16 = DIRTY_LAYOUT | DIRTY_SUBTREE_LAYOUT;
1633                            dirty_root |= DIRTY_PAINT;
1634                            tree.mark_dirty(root, dirty_root);
1635                        },
1636                        (),
1637                    );
1638                }
1639                scene_st.mark_dirty(chart_canvas, DIRTY_PAINT);
1640            });
1641            let scene_theme: SceneHandle = scene_dirty.clone();
1642            let prev_theme_key: Cell<ThemeKey> = Cell::new(tokens.key());
1643            let _: Effect = Effect::new(move || {
1644                let live_tok: ThemeTokens = use_live_tokens(base_tokens);
1645                let next_key: ThemeKey = live_tok.key();
1646                if prev_theme_key.replace(next_key) == next_key {
1647                    return;
1648                }
1649                let live_p: ThemePalette = live_tok.get_palette();
1650                scene_theme.with_write(
1651                    |tree: &mut SceneTree| {
1652                        if let Some(item_count_primary) = tree.get_node_mut(title_txt_node) {
1653                            item_count_primary
1654                                .get_mut_style()
1655                                .get_mut_text()
1656                                .set_color(live_p.get_foreground());
1657                            tree.mark_dirty(title_txt_node, DIRTY_PAINT);
1658                        }
1659                        if let Some(item_count_secondary) = tree.get_node_mut(subtext_txt_node) {
1660                            item_count_secondary
1661                                .get_mut_style()
1662                                .get_mut_text()
1663                                .set_color(live_p.get_muted_foreground());
1664                            tree.mark_dirty(subtext_txt_node, DIRTY_PAINT);
1665                        }
1666                        tree.mark_dirty(chart_canvas, DIRTY_PAINT);
1667                    },
1668                    (),
1669                );
1670            });
1671            if let Some(sig) = opt_sig_opt {
1672                let scene_opt: SceneHandle = scene_dirty.clone();
1673                let mounted_opt_effect: Cell<bool> = Cell::new(false);
1674                let _: Effect = Effect::new(move || {
1675                    let cur_opt: EuvChartOption = sig.get();
1676                    if !mounted_opt_effect.replace(true) {
1677                        return;
1678                    }
1679                    let next_min: Size = compute_chart_min_content_size(&cur_opt);
1680                    let next_show_tb: bool =
1681                        cur_opt.toolbox_opt().is_some_and(EuvChartToolbox::get_show);
1682                    let (next_title, next_sub, next_align, next_has_title): (
1683                        String,
1684                        String,
1685                        TextAlign,
1686                        bool,
1687                    ) = resolve_chart_header_meta(&cur_opt);
1688                    let next_has_header: bool = next_has_title || next_show_tb;
1689                    rev_watch.set(rev_watch.get().wrapping_add(1));
1690                    scene_opt.with_write(
1691                        |tree: &mut SceneTree| {
1692                            let dirty_l: u16 = DIRTY_LAYOUT | DIRTY_SUBTREE_LAYOUT;
1693                            if let Some(item_count_next) = tree.get_node_mut(header_row) {
1694                                let lay: &mut LayoutStyle =
1695                                    item_count_next.get_mut_style().get_mut_layout();
1696                                lay.set_display(if next_has_header {
1697                                    Display::Flex
1698                                } else {
1699                                    Display::None
1700                                })
1701                                .set_justify_content(
1702                                    if next_has_title {
1703                                        JustifyContent::SpaceBetween
1704                                    } else {
1705                                        JustifyContent::End
1706                                    },
1707                                );
1708                                tree.mark_dirty(header_row, dirty_l | DIRTY_PAINT);
1709                            }
1710                            if let Some(item_count_alt) = tree.get_node_mut(title_col) {
1711                                item_count_alt.get_mut_style().get_mut_layout().set_display(
1712                                    if next_has_title {
1713                                        Display::Flex
1714                                    } else {
1715                                        Display::None
1716                                    },
1717                                );
1718                                tree.mark_dirty(title_col, dirty_l | DIRTY_PAINT);
1719                            }
1720                            if let Some(item_count_inner) = tree.get_node_mut(title_txt_node) {
1721                                let computed_style_primary: &mut Style =
1722                                    item_count_inner.get_mut_style();
1723                                computed_style_primary.get_mut_layout().set_display(
1724                                    if next_title.is_empty() {
1725                                        Display::None
1726                                    } else {
1727                                        Display::Flex
1728                                    },
1729                                );
1730                                computed_style_primary.get_mut_text().set_align(next_align);
1731                            }
1732                            tree.set_text(title_txt_node, next_title);
1733                            if let Some(item_count_local) = tree.get_node_mut(subtext_txt_node) {
1734                                let computed_style_secondary: &mut Style =
1735                                    item_count_local.get_mut_style();
1736                                computed_style_secondary.get_mut_layout().set_display(
1737                                    if next_sub.is_empty() {
1738                                        Display::None
1739                                    } else {
1740                                        Display::Flex
1741                                    },
1742                                );
1743                                computed_style_secondary
1744                                    .get_mut_text()
1745                                    .set_align(next_align);
1746                            }
1747                            tree.set_text(subtext_txt_node, next_sub);
1748                            if let Some(item_count_cur) = tree.get_node_mut(chart_canvas) {
1749                                item_count_cur
1750                                    .get_mut_style()
1751                                    .get_mut_layout()
1752                                    .set_min_width(Length::Px(next_min.get_width()))
1753                                    .set_min_height(Length::Px(next_min.get_height()));
1754                            }
1755                            tree.mark_dirty(chart_canvas, dirty_l | DIRTY_PAINT);
1756                        },
1757                        (),
1758                    );
1759                });
1760            }
1761            let vp_sig: Signal<Size> = ctx_build.get_viewport_size();
1762            let scene_vp: SceneHandle = scene_fs.clone();
1763            let _: Effect = Effect::new(move || {
1764                let viewport_size: Size = vp_sig.get();
1765                if !fs_open.get() {
1766                    return;
1767                }
1768                let vw: f32 = viewport_size.get_width().max(1.0);
1769                let vh: f32 = viewport_size.get_height().max(1.0);
1770                scene_vp.with_write(
1771                    |scene_tree: &mut SceneTree| {
1772                        if let Some(item_count_slot) = scene_tree.get_node_mut(fs_portal) {
1773                            item_count_slot
1774                                .get_mut_style()
1775                                .get_mut_layout()
1776                                .set_width(Length::Px(vw))
1777                                .set_height(Length::Px(vh));
1778                            let dirty_l: u16 = DIRTY_LAYOUT | DIRTY_SUBTREE_LAYOUT;
1779                            scene_tree.mark_dirty(fs_portal, dirty_l | DIRTY_PAINT);
1780                            notify_frame_needed();
1781                        }
1782                    },
1783                    (),
1784                );
1785            });
1786            let in_enter_guard: Rc<Cell<bool>> = Rc::new(Cell::new(false));
1787            let global_fs_sig: Signal<bool> = use_fullscreen_active();
1788            let ctx_fs_sig: Signal<bool> = ctx_build.immersive_fullscreen_signal();
1789            let saw_global_fs: Rc<Cell<bool>> = Rc::new(Cell::new(false));
1790            let saw_ctx_fs: Rc<Cell<bool>> = Rc::new(Cell::new(false));
1791            let saw_global_reset: Rc<Cell<bool>> = Rc::clone(&saw_global_fs);
1792            let saw_ctx_reset: Rc<Cell<bool>> = Rc::clone(&saw_ctx_fs);
1793            let fs_acquired_sync: Rc<Cell<bool>> = Rc::clone(&fs_acquired);
1794            let enter_guard_sync: Rc<Cell<bool>> = Rc::clone(&in_enter_guard);
1795            let _: Effect = Effect::new(move || {
1796                let g_active: bool = global_fs_sig.get();
1797                let c_active: bool = ctx_fs_sig.get();
1798                if enter_guard_sync.get() {
1799                    if g_active {
1800                        saw_global_fs.set(true);
1801                    }
1802                    if c_active {
1803                        saw_ctx_fs.set(true);
1804                    }
1805                    return;
1806                }
1807                if !fs_acquired_sync.get() {
1808                    saw_global_fs.set(false);
1809                    saw_ctx_fs.set(false);
1810                    return;
1811                }
1812                if g_active {
1813                    saw_global_fs.set(true);
1814                }
1815                if c_active {
1816                    saw_ctx_fs.set(true);
1817                }
1818                let external_exit: bool =
1819                    (saw_global_fs.get() && !g_active) || (saw_ctx_fs.get() && !c_active);
1820                if external_exit {
1821                    let _: bool = fs_open.set_if_changed(false);
1822                }
1823            });
1824            Effect::new(move || {
1825                let is_open: bool = fs_open.get();
1826                if is_open == prev_open.replace(is_open) {
1827                    return;
1828                }
1829                if is_open {
1830                    in_enter_guard.set(true);
1831                    saw_global_reset.set(false);
1832                    saw_ctx_reset.set(false);
1833                    let live_bg: Color =
1834                        live_tokens_untracked(base_tokens).get_palette().get_card();
1835                    let vp_now: Size = vp_sig.get_untracked();
1836                    let vw: f32 = vp_now.get_width().max(1.0);
1837                    let vh: f32 = vp_now.get_height().max(1.0);
1838                    let panel: NodeId = with_context(ctx_build.clone(), &build_fs_panel);
1839                    let portal_shown: bool = panel != NodeId::default()
1840                        && scene_fs.with_write(
1841                            |tree: &mut SceneTree| {
1842                                if tree.get_node(fs_portal).is_none()
1843                                    || tree.get_node(panel).is_none()
1844                                {
1845                                    return false;
1846                                }
1847                                tree.cancel_subtree_transitions(fs_portal);
1848                                tree.replace_children(fs_portal, vec![panel]);
1849                                if let Some(item_count_2) = tree.get_node_mut(fs_portal) {
1850                                    let computed_style_next: &mut Style =
1851                                        item_count_2.get_mut_style();
1852                                    computed_style_next
1853                                        .get_mut_layout()
1854                                        .set_display(Display::Flex)
1855                                        .set_width(Length::Px(vw))
1856                                        .set_height(Length::Px(vh));
1857                                    computed_style_next
1858                                        .get_mut_paint()
1859                                        .set_background(Some(live_bg))
1860                                        .set_pointer_events(PointerEvents::Auto)
1861                                        .set_opacity(1.0)
1862                                        .set_transform(Transform2D::default());
1863                                }
1864                                let dirty_l: u16 = DIRTY_LAYOUT | DIRTY_SUBTREE_LAYOUT;
1865                                tree.mark_dirty(fs_portal, dirty_l | DIRTY_PAINT);
1866                                notify_frame_needed();
1867                                true
1868                            },
1869                            false,
1870                        );
1871                    let entered: bool = portal_shown
1872                        && (fs_acquired.get()
1873                            || enter_fullscreen_for_portal(&ctx_build, fs_portal));
1874                    if entered {
1875                        fs_acquired.set(true);
1876                    } else {
1877                        scene_fs.dismiss_portal_immediate(fs_portal);
1878                        if fs_acquired.replace(false) {
1879                            exit_fullscreen();
1880                        }
1881                        prev_open.set(false);
1882                        let _: bool = fs_open.set_if_changed(false);
1883                    }
1884                    in_enter_guard.set(false);
1885                    notify_frame_needed();
1886                } else {
1887                    in_enter_guard.set(false);
1888                    if fs_acquired.replace(false) {
1889                        exit_fullscreen();
1890                    }
1891                    scene_fs.dismiss_portal_immediate(fs_portal);
1892                }
1893            })
1894        });
1895        ctx.get_scene().with_write(
1896            |tree: &mut SceneTree| {
1897                tree.attach_scope(root, scope);
1898            },
1899            (),
1900        );
1901        root
1902    }
1903}