euv-ui 0.47.0

Cross-platform UI component library and 17-scheme design system for the euv framework with pixel-consistent rendering across Web, Android, iOS, iPadOS, macOS, Windows, and Linux.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
use super::*;

/// Default props for `EuvEChart` (100% width, 320px height, interactive enabled).
impl Default for EuvEChart {
    /// Creates an empty interactive `EuvEChart` ready for `view!` named-prop setters.
    ///
    /// # Returns
    ///
    /// - `Self` - Default chart component.
    fn default() -> Self {
        Self {
            option: EuvChartOption::default(),
            option_signal: None,
            tokens: ThemeTokens::default(),
            width: Length::Percent(100.0),
            height: Length::Px(ECHART_DEFAULT_HEIGHT),
            interactive: true,
            on_point_click: None,
            on_legend_change: None,
            on_zoom_change: None,
        }
    }
}

/// Constructors and fluent prop builders for `EuvEChart`.
impl EuvEChart {
    /// Constructs an interactive `EuvEChart` from a static `EuvChartOption` and `ThemeTokens`.
    ///
    /// # Arguments
    ///
    /// - `EuvChartOption` - Declarative chart option document.
    /// - `ThemeTokens` - Active UI theme tokens.
    ///
    /// # Returns
    ///
    /// - `Self` - Constructed chart component.
    #[must_use]
    pub fn new(option: EuvChartOption, tokens: ThemeTokens) -> Self {
        let mut chart: Self = Self::default();
        chart.set_option(option);
        chart.set_tokens(tokens);
        chart
    }

    /// Constructs a reactive `EuvEChart` driven by a live `Signal<EuvChartOption>`.
    ///
    /// # Arguments
    ///
    /// - `Signal<EuvChartOption>` - Reactive chart option signal.
    /// - `ThemeTokens` - Active UI theme tokens.
    ///
    /// # Returns
    ///
    /// - `Self` - Constructed reactive chart component.
    #[must_use]
    pub fn from_signal(option_signal: Signal<EuvChartOption>, tokens: ThemeTokens) -> Self {
        let mut chart: Self = Self::default();
        chart.set_option_signal(Some(option_signal));
        chart.set_tokens(tokens);
        chart
    }

    /// Sets the declarative chart option fluently (used by `view! { EuvEChart { option: ... } }`).
    ///
    /// # Arguments
    ///
    /// - `Self` - Source chart component.
    /// - `EuvChartOption` - Declarative chart option.
    ///
    /// # Returns
    ///
    /// - `Self` - Updated chart component.
    #[must_use]
    pub fn option(mut self, option: EuvChartOption) -> Self {
        self.set_option(option);
        self
    }

    /// Binds a reactive `Signal<EuvChartOption>` fluently.
    ///
    /// # Arguments
    ///
    /// - `Self` - Source chart component.
    /// - `Signal<EuvChartOption>` - Reactive option signal.
    ///
    /// # Returns
    ///
    /// - `Self` - Updated chart component.
    #[must_use]
    pub fn option_signal(mut self, option_signal: Signal<EuvChartOption>) -> Self {
        self.set_option_signal(Some(option_signal));
        self
    }

    /// Sets the active UI theme tokens fluently.
    ///
    /// # Arguments
    ///
    /// - `Self` - Source chart component.
    /// - `ThemeTokens` - Theme token bundle.
    ///
    /// # Returns
    ///
    /// - `Self` - Updated chart component.
    #[must_use]
    pub fn tokens(mut self, tokens: ThemeTokens) -> Self {
        self.set_tokens(tokens);
        self
    }

    /// Sets the outer component width fluently.
    ///
    /// # Arguments
    ///
    /// - `Self` - Source chart component.
    /// - `Length` - Target width.
    ///
    /// # Returns
    ///
    /// - `Self` - Updated chart component.
    #[must_use]
    pub fn width(mut self, width: Length) -> Self {
        self.set_width(width);
        self
    }

    /// Sets the chart canvas height fluently.
    ///
    /// # Arguments
    ///
    /// - `Self` - Source chart component.
    /// - `Length` - Target height.
    ///
    /// # Returns
    ///
    /// - `Self` - Updated chart component.
    #[must_use]
    pub fn height(mut self, height: Length) -> Self {
        self.set_height(height);
        self
    }

    /// Enables or disables pointer interaction fluently.
    ///
    /// # Arguments
    ///
    /// - `Self` - Source chart component.
    /// - `bool` - Interaction enabled flag.
    ///
    /// # Returns
    ///
    /// - `Self` - Updated chart component.
    #[must_use]
    pub fn interactive(mut self, interactive: bool) -> Self {
        self.set_interactive(interactive);
        self
    }

    /// Registers a datum click callback fluently.
    ///
    /// # Arguments
    ///
    /// - `Self` - Source chart component.
    /// - `EuvChartHitCallback` - Click callback invoked with clicked datum hit.
    ///
    /// # Returns
    ///
    /// - `Self` - Updated chart component.
    #[must_use]
    pub fn on_point_click(mut self, handler: EuvChartHitCallback) -> Self {
        self.set_on_point_click(Some(handler));
        self
    }

    /// Registers a legend toggle callback fluently.
    ///
    /// # Arguments
    ///
    /// - `Self` - Source chart component.
    /// - `EuvChartLegendCallback` - Legend toggle callback `(series_name, visible)`.
    ///
    /// # Returns
    ///
    /// - `Self` - Updated chart component.
    #[must_use]
    pub fn on_legend_change(mut self, handler: EuvChartLegendCallback) -> Self {
        self.set_on_legend_change(Some(handler));
        self
    }

    /// Registers a data-zoom change callback fluently.
    ///
    /// # Arguments
    ///
    /// - `Self` - Source chart component.
    /// - `Rc<dyn Fn(f32, f32)>` - Zoom callback `(start_pct, end_pct)`.
    ///
    /// # Returns
    ///
    /// - `Self` - Updated chart component.
    #[must_use]
    pub fn on_zoom_change(mut self, handler: Rc<dyn Fn(f32, f32)>) -> Self {
        self.set_on_zoom_change(Some(handler));
        self
    }

    /// Resolves the initial `EuvChartOption` snapshot from `option_signal` or static `option`.
    ///
    /// # Arguments
    ///
    /// - `&Self` - Component descriptor.
    ///
    /// # Returns
    ///
    /// - `EuvChartOption` - Snapshot option.
    #[must_use]
    fn current_option_untracked(&self) -> EuvChartOption {
        let Self {
            option,
            option_signal,
            ..
        } = self;
        match option_signal {
            Some(sig) => sig.get_untracked(),
            None => option.clone(),
        }
    }
}

/// Declarative `#[component]` implementation for `EuvEChart`.
#[component]
/// Inherent implementation of [`EuvEChart`].
impl EuvEChart {
    /// Mounts `EuvEChart` with cached vector canvas rendering, pointer tooltip/legend/DataZoom handling, compact icon-only Toolbox, DataView table, and Fullscreen portal modal.
    ///
    /// # Arguments
    ///
    /// - `&Self` - Chart component descriptor.
    ///
    /// # Returns
    ///
    /// - `NodeId` - Mounted root scene node handle.
    fn render(&self) -> NodeId {
        let mut ctx: Context = current_context();
        bind_fullscreen_context(&ctx);
        let base_tokens: ThemeTokens = self.get_tokens();
        let tokens: ThemeTokens = live_tokens_untracked(base_tokens);
        let p: ThemePalette = tokens.get_palette();
        let g: ThemeGeometry = tokens.get_geometry();
        let width: Length = self.get_width();
        let height: Length = self.get_height();
        let interactive: bool = self.get_interactive();
        let Self {
            option: static_opt,
            option_signal,
            on_point_click,
            on_legend_change,
            on_zoom_change,
            ..
        } = self;
        let opt_sig_opt: Option<Signal<EuvChartOption>> = *option_signal;
        let static_opt_rc: Rc<EuvChartOption> = Rc::new(static_opt.clone());
        let initial_opt: EuvChartOption = self.current_option_untracked();
        let state_sig: Signal<EuvChartState> =
            Signal::new(EuvChartState::from_option(&initial_opt));
        let fs_open: Signal<bool> = Signal::new(false);
        let opt_rev: Rc<Cell<u64>> = Rc::new(Cell::new(0));
        let last_render: Rc<RefCell<EuvChartRenderResult>> =
            Rc::new(RefCell::new(EuvChartRenderResult::default()));
        let last_bounds: Rc<RefCell<Rect>> = Rc::new(RefCell::new(Rect::default()));
        let drag_state: Rc<Cell<(ChartDragTarget, f32, f32, f32)>> =
            Rc::new(Cell::new((ChartDragTarget::None, 0.0, 0.0, 100.0)));
        let has_data_zoom: bool = !initial_opt.get_data_zoom().is_empty();
        let toolbox_cfg: Option<EuvChartToolbox> = initial_opt.toolbox_opt().cloned();
        let show_toolbox: bool = toolbox_cfg.as_ref().is_some_and(EuvChartToolbox::get_show);
        let paint_opt_rc: Rc<EuvChartOption> = Rc::clone(&static_opt_rc);
        let paint_res: Rc<RefCell<EuvChartRenderResult>> = Rc::clone(&last_render);
        let paint_bounds: Rc<RefCell<Rect>> = Rc::clone(&last_bounds);
        let paint_opt_rev: Rc<Cell<u64>> = Rc::clone(&opt_rev);
        let inline_cache: RefCell<Option<ChartPaintCache>> = RefCell::new(None);
        let paint_inline = move |bounds: Rect, dl: &mut DisplayList| {
            let live_tok: ThemeTokens = live_tokens_untracked(base_tokens);
            let cur_state: EuvChartState = state_sig.get_untracked();
            let cur_rev: u64 = paint_opt_rev.get();
            if let Ok(mut b_guard) = paint_bounds.try_borrow_mut() {
                *b_guard = bounds;
            }
            if let Ok(guard) = inline_cache.try_borrow()
                && let Some(cached) = guard.as_ref()
                && cached.bounds == bounds
                && cached.tokens == live_tok
                && cached.state == cur_state
                && cached.rev == cur_rev
            {
                dl.get_mut_commands()
                    .extend_from_slice(cached.commands.as_slice());
                return;
            }
            let opt_snapshot: EuvChartOption = match opt_sig_opt {
                Some(sig) => sig.get_untracked(),
                None => (*paint_opt_rc).clone(),
            };
            let mut scratch: DisplayList = DisplayList::default();
            let res: EuvChartRenderResult = render_echart_to_display_list(
                &opt_snapshot,
                &cur_state,
                bounds,
                live_tok,
                &mut scratch,
            );
            if let Ok(mut r_guard) = paint_res.try_borrow_mut() {
                *r_guard = res;
            }
            let cmds: Vec<DrawCommand> = take(scratch.get_mut_commands());
            dl.get_mut_commands().extend_from_slice(cmds.as_slice());
            if let Ok(mut guard) = inline_cache.try_borrow_mut() {
                *guard = Some(ChartPaintCache {
                    bounds,
                    tokens: live_tok,
                    state: cur_state,
                    rev: cur_rev,
                    commands: cmds,
                });
            }
        };
        let dv_opt_rc: Rc<EuvChartOption> = Rc::clone(&static_opt_rc);
        let dv_ctx: Context = ctx.clone();
        let build_data_view = move || -> Vec<NodeId> {
            let mut local_ctx: Context = dv_ctx.clone();
            let st: EuvChartState = state_sig.get();
            if !st.get_data_view_open() {
                return Vec::new();
            }
            let live_tok: ThemeTokens = use_live_tokens(base_tokens);
            let live_p: ThemePalette = live_tok.get_palette();
            let live_g: ThemeGeometry = live_tok.get_geometry();
            let dv_inner_r: f32 = concentric_radius(live_g.get_radius_md(), CONTROL_INSET);
            let opt_snapshot: EuvChartOption = match opt_sig_opt {
                Some(sig) => sig.get(),
                None => (*dv_opt_rc).clone(),
            };
            let table: EuvChartDataViewTable = extract_data_view_table(&opt_snapshot, &st);
            let mut header_row: NodeId = NodeId::default();
            let mut body_col: NodeId = NodeId::default();
            let panel: NodeId = view! {
                column {
                    style: {
                        width: Length::Percent(100.0)
                        padding: Edges::all(CONTROL_INSET)
                        gap: CONTROL_INSET
                        background: live_p.get_muted().multiply_alpha(0.35)
                        border: (1.0, live_p.get_border())
                        radius: live_g.get_radius_md()
                        overflow: Overflow::Hidden
                    }
                    text {
                        style: {
                            width: Length::Percent(100.0)
                            font_size: 11.5
                            font_weight: FontWeight::SemiBold
                            color: live_p.get_foreground()
                        }
                        { ECHART_DATA_VIEW_TITLE }
                    }
                    row {
                        node_ref: header_row
                        style: {
                            width: Length::Percent(100.0)
                            padding: Edges::symmetric(4.0, SPACE_SM)
                            gap: SPACE_SM
                            background: live_p.get_card()
                            radius: dv_inner_r
                            overflow: Overflow::Hidden
                        }
                    }
                    column {
                        node_ref: body_col
                        style: {
                            width: Length::Percent(100.0)
                            gap: 2.0
                        }
                    }
                }
            };
            for h in table.get_headers().iter() {
                let h_txt: String = h.clone();
                let cell: NodeId = view! {
                    text {
                        style: {
                            flex_grow: 1.0
                            flex_shrink: 1.0
                            min_width: Length::Px(0.0)
                            font_size: 11.0
                            font_weight: FontWeight::SemiBold
                            color: live_p.get_foreground()
                            text_overflow: TextOverflow::Ellipsis
                        }
                        { h_txt }
                    }
                };
                local_ctx.append(header_row, cell);
            }
            for row in table.get_rows().iter().take(40) {
                let row_node: NodeId = view! {
                    row {
                        style: {
                            width: Length::Percent(100.0)
                            padding: Edges::symmetric(4.0, SPACE_SM)
                            gap: SPACE_SM
                            border: (1.0, live_p.get_border().multiply_alpha(0.35))
                        }
                    }
                };
                for c in row.iter() {
                    let c_txt: String = c.clone();
                    let cell: NodeId = view! {
                        text {
                            style: {
                                flex_grow: 1.0
                                flex_shrink: 1.0
                                min_width: Length::Px(0.0)
                                font_size: 11.0
                                color: live_p.get_muted_foreground()
                                text_overflow: TextOverflow::Ellipsis
                            }
                            { c_txt }
                        }
                    };
                    local_ctx.append(row_node, cell);
                }
                local_ctx.append(body_col, row_node);
            }
            vec![panel]
        };
        let mut toolbox_nodes: Vec<NodeId> = Vec::new();
        if show_toolbox && let Some(tb) = toolbox_cfg.as_ref() {
            if tb.get_restore() {
                let r_opt: Rc<EuvChartOption> = Rc::clone(&static_opt_rc);
                let z_cb: Option<Rc<dyn Fn(f32, f32)>> = on_zoom_change.clone();
                let on_restore = move |_: &UiEvent| {
                    let cur_opt: EuvChartOption = match opt_sig_opt {
                        Some(sig) => sig.get_untracked(),
                        None => (*r_opt).clone(),
                    };
                    let restored: EuvChartState = EuvChartState::from_option(&cur_opt);
                    let s_pct: f32 = restored.get_zoom_start_pct();
                    let e_pct: f32 = restored.get_zoom_end_pct();
                    let _: bool = state_sig.set(restored);
                    if let Some(cb) = z_cb.as_ref() {
                        cb(s_pct, e_pct);
                    }
                };
                toolbox_nodes.push(build_toolbox_icon_btn(
                    base_tokens,
                    EuvIconName::Refresh,
                    ECHART_BTN_RESTORE,
                    on_restore,
                ));
            }
            if tb.get_magic_type() {
                let on_magic = move |_: &UiEvent| {
                    let _: bool = state_sig.update(|st: &mut EuvChartState| {
                        let _: EuvChartMagicType = st.cycle_magic_type();
                    });
                };
                toolbox_nodes.push(build_toolbox_icon_btn(
                    base_tokens,
                    EuvIconName::Palette,
                    ECHART_BTN_MAGIC_TYPE,
                    on_magic,
                ));
            }
            if tb.get_data_view() {
                let on_dv = move |_: &UiEvent| {
                    let _: bool = state_sig.update(|st: &mut EuvChartState| {
                        let _: bool = st.toggle_data_view();
                    });
                };
                toolbox_nodes.push(build_toolbox_icon_btn(
                    base_tokens,
                    EuvIconName::Menu,
                    ECHART_BTN_DATA_VIEW,
                    on_dv,
                ));
            }
            if tb.get_fullscreen() {
                let on_fs = move |_: &UiEvent| {
                    let _: bool = fs_open.set_if_changed(true);
                };
                toolbox_nodes.push(build_toolbox_icon_btn(
                    base_tokens,
                    EuvIconName::Maximize,
                    ECHART_BTN_FULLSCREEN,
                    on_fs,
                ));
            }
        }
        let fs_opt_rc: Rc<EuvChartOption> = Rc::clone(&static_opt_rc);
        let ctx_fs: Context = ctx.clone();
        let fs_opt_rev: Rc<Cell<u64>> = Rc::clone(&opt_rev);
        let fs_click_cb: Option<EuvChartHitCallback> = on_point_click.clone();
        let fs_legend_cb: Option<EuvChartLegendCallback> = on_legend_change.clone();
        let fs_zoom_cb: Option<Rc<dyn Fn(f32, f32)>> = on_zoom_change.clone();
        let build_fs_panel = move || -> NodeId {
            let mut local_fs_ctx: Context = ctx_fs.clone();
            let live_tok: ThemeTokens = live_tokens_untracked(base_tokens);
            let live_p: ThemePalette = live_tok.get_palette();
            let live_g: ThemeGeometry = live_tok.get_geometry();
            let modal_ctrl_h: f32 = live_g.get_control_sm();
            let close_surface: SurfaceColors = live_p.surface(SurfaceRole::Primary);
            let cur_opt: EuvChartOption = match opt_sig_opt {
                Some(sig) => sig.get_untracked(),
                None => (*fs_opt_rc).clone(),
            };
            let modal_title: String = cur_opt
                .title_opt()
                .map(|t: &EuvChartTitle| t.get_text().clone())
                .filter(|t: &String| !t.is_empty())
                .unwrap_or_else(|| ECHART_DEFAULT_MODAL_TITLE.to_string());
            let modal_opt_rc: Rc<EuvChartOption> = Rc::new(cur_opt);
            let modal_opt_wire: Rc<EuvChartOption> = Rc::clone(&modal_opt_rc);
            let modal_render: Rc<RefCell<EuvChartRenderResult>> =
                Rc::new(RefCell::new(EuvChartRenderResult::default()));
            let modal_bounds: Rc<RefCell<Rect>> = Rc::new(RefCell::new(Rect::default()));
            let modal_drag: Rc<Cell<(ChartDragTarget, f32, f32, f32)>> =
                Rc::new(Cell::new((ChartDragTarget::None, 0.0, 0.0, 100.0)));
            let modal_render_paint: Rc<RefCell<EuvChartRenderResult>> = Rc::clone(&modal_render);
            let modal_bounds_paint: Rc<RefCell<Rect>> = Rc::clone(&modal_bounds);
            let modal_rev_paint: Rc<Cell<u64>> = Rc::clone(&fs_opt_rev);
            let modal_cache: RefCell<Option<ChartPaintCache>> = RefCell::new(None);
            let paint_modal = move |bounds: Rect, dl: &mut DisplayList| {
                let cur_tok: ThemeTokens = live_tokens_untracked(base_tokens);
                let cur_st: EuvChartState = state_sig.get_untracked();
                let cur_rev: u64 = modal_rev_paint.get();
                if let Ok(mut b_guard) = modal_bounds_paint.try_borrow_mut() {
                    *b_guard = bounds;
                }
                if let Ok(guard) = modal_cache.try_borrow()
                    && let Some(cached) = guard.as_ref()
                    && cached.bounds == bounds
                    && cached.tokens == cur_tok
                    && cached.state == cur_st
                    && cached.rev == cur_rev
                {
                    dl.get_mut_commands()
                        .extend_from_slice(cached.commands.as_slice());
                    return;
                }
                let live_opt: EuvChartOption = match opt_sig_opt {
                    Some(sig) => sig.get_untracked(),
                    None => (*modal_opt_rc).clone(),
                };
                let mut scratch: DisplayList = DisplayList::default();
                let res: EuvChartRenderResult = render_echart_to_display_list(
                    &live_opt,
                    &cur_st,
                    bounds,
                    cur_tok,
                    &mut scratch,
                );
                if let Ok(mut r_guard) = modal_render_paint.try_borrow_mut() {
                    *r_guard = res;
                }
                let cmds: Vec<DrawCommand> = take(scratch.get_mut_commands());
                dl.get_mut_commands().extend_from_slice(cmds.as_slice());
                if let Ok(mut guard) = modal_cache.try_borrow_mut() {
                    *guard = Some(ChartPaintCache {
                        bounds,
                        tokens: cur_tok,
                        state: cur_st,
                        rev: cur_rev,
                        commands: cmds,
                    });
                }
            };
            let paint_close_icon = move |bounds: Rect, dl: &mut DisplayList| {
                let cur_p: ThemePalette = live_tokens_untracked(base_tokens).get_palette();
                let close_fg: Color = cur_p.surface(SurfaceRole::Primary).get_fg();
                draw_euv_icon(EuvIconName::Minimize, bounds, dl, close_fg);
            };
            let on_close_fs = move |_: &UiEvent| {
                let _: bool = fs_open.set_if_changed(false);
            };
            let zoom_sig: Signal<f32> = Signal::new(1.0);
            let on_zoom_out = move |_: &UiEvent| {
                let _: bool = zoom_sig.update(|z: &mut f32| {
                    *z = (*z - ECHART_ZOOM_STEP).clamp(ECHART_ZOOM_MIN, ECHART_ZOOM_MAX);
                });
            };
            let on_zoom_in = move |_: &UiEvent| {
                let _: bool = zoom_sig.update(|z: &mut f32| {
                    *z = (*z + ECHART_ZOOM_STEP).clamp(ECHART_ZOOM_MIN, ECHART_ZOOM_MAX);
                });
            };
            let body_scroll_cell: Rc<Cell<NodeId>> = Rc::new(Cell::new(NodeId::default()));
            let body_scroll_reset: Rc<Cell<NodeId>> = Rc::clone(&body_scroll_cell);
            let scene_reset: SceneHandle = local_fs_ctx.get_scene().clone();
            let on_zoom_reset = move |_: &UiEvent| {
                let _: bool = zoom_sig.set_if_changed(1.0);
                let sc: NodeId = body_scroll_reset.get();
                scene_reset.with_write(
                    |tree: &mut SceneTree| {
                        tree.set_scroll_offset(sc, Point::default());
                    },
                    (),
                );
            };
            let safe_sig: Signal<SafeAreaInsets> = local_fs_ctx.get_safe_area();
            let vp_sig: Signal<Size> = local_fs_ctx.get_viewport_size();
            let init_safe: SafeAreaInsets = safe_sig.get_untracked();
            let init_vp: Size = vp_sig.get_untracked();
            let init_canvas_w: f32 =
                (init_vp.get_width() - init_safe.get_left() - init_safe.get_right())
                    .max(ECHART_MODAL_MIN_WIDTH);
            let init_canvas_h: f32 =
                (init_vp.get_height() - 56.0 - init_safe.get_top() - init_safe.get_bottom())
                    .max(ECHART_MODAL_MIN_HEIGHT);
            let mut modal_scroll_st: Style = Style::default();
            modal_scroll_st
                .get_mut_layout()
                .set_flex_direction(FlexDirection::Column)
                .set_align_items(AlignItems::Start);
            let mut top_bar_node: NodeId = NodeId::default();
            let mut body_host_node: NodeId = NodeId::default();
            let mut modal_canvas: NodeId = NodeId::default();
            let mut zoom_reset_txt: NodeId = NodeId::default();
            let panel: NodeId = view! {
                column {
                    style: {
                        width: Length::Percent(100.0)
                        height: Length::Percent(100.0)
                        flex_grow: 1.0
                        padding: Edges::all(0.0)
                        margin: Edges::all(0.0)
                        background: live_p.get_card()
                        border: (0.0, COLOR_TRANSPARENT)
                        radius: 0.0
                        overflow: Overflow::Hidden
                        stop_event_propagation: true
                    }
                    row {
                        node_ref: top_bar_node
                        style: {
                            width: Length::Percent(100.0)
                            flex_shrink: 0.0
                            padding: Edges::new(
                                SPACE_SM + init_safe.get_top(),
                                SPACE_MD + init_safe.get_right(),
                                SPACE_SM,
                                SPACE_MD + init_safe.get_left()
                            )
                            justify: JustifyContent::SpaceBetween
                            align: AlignItems::Center
                            gap: SPACE_SM
                            overflow: Overflow::Hidden
                            background: live_p.get_muted().multiply_alpha(0.4)
                        }
                        text {
                            style: {
                                flex_shrink: 1.0
                                min_width: Length::Px(0.0)
                                overflow: Overflow::Hidden
                                text_overflow: TextOverflow::Ellipsis
                                font_size: 13.5
                                font_weight: FontWeight::SemiBold
                                color: live_p.get_foreground()
                            }
                            { modal_title }
                        }
                        row {
                            style: {
                                flex_shrink: 0.0
                                align: AlignItems::Center
                                gap: SPACE_XS
                            }
                            row {
                                style: {
                                    width: Length::Px(modal_ctrl_h)
                                    height: Length::Px(modal_ctrl_h)
                                    justify: JustifyContent::Center
                                    align: AlignItems::Center
                                    radius: live_g.get_radius_sm()
                                    overflow: Overflow::Hidden
                                    cursor: CursorIcon::Pointer
                                    background: live_p.get_card()
                                    border: (1.0, live_p.get_border())
                                }
                                role: A11yRole::Button
                                a11y_label: ECHART_BTN_ZOOM_OUT.to_string()
                                on_click: on_zoom_out
                                text {
                                    style: {
                                        font_size: 14.0
                                        font_weight: FontWeight::Bold
                                        color: live_p.get_foreground()
                                        text_overflow: TextOverflow::Clip
                                    }
                                    { ECHART_ZOOM_MINUS }
                                }
                            }
                            row {
                                style: {
                                    height: Length::Px(modal_ctrl_h)
                                    padding: Edges::symmetric(0.0, SPACE_SM)
                                    justify: JustifyContent::Center
                                    align: AlignItems::Center
                                    radius: live_g.get_radius_sm()
                                    overflow: Overflow::Hidden
                                    cursor: CursorIcon::Pointer
                                    background: live_p.get_card()
                                    border: (1.0, live_p.get_border())
                                }
                                role: A11yRole::Button
                                a11y_label: ECHART_BTN_ZOOM_RESET.to_string()
                                on_click: on_zoom_reset
                                text {
                                    node_ref: zoom_reset_txt
                                    style: {
                                        font_size: 11.0
                                        font_family: FontFamily::Monospace
                                        font_weight: FontWeight::SemiBold
                                        color: live_p.get_foreground()
                                        text_overflow: TextOverflow::Clip
                                    }
                                    { ECHART_ZOOM_INIT_LABEL }
                                }
                            }
                            row {
                                style: {
                                    width: Length::Px(modal_ctrl_h)
                                    height: Length::Px(modal_ctrl_h)
                                    justify: JustifyContent::Center
                                    align: AlignItems::Center
                                    radius: live_g.get_radius_sm()
                                    overflow: Overflow::Hidden
                                    cursor: CursorIcon::Pointer
                                    background: live_p.get_card()
                                    border: (1.0, live_p.get_border())
                                }
                                role: A11yRole::Button
                                a11y_label: ECHART_BTN_ZOOM_IN.to_string()
                                on_click: on_zoom_in
                                text {
                                    style: {
                                        font_size: 14.0
                                        font_weight: FontWeight::Bold
                                        color: live_p.get_foreground()
                                        text_overflow: TextOverflow::Clip
                                    }
                                    { ECHART_ZOOM_PLUS }
                                }
                            }
                            row {
                                style: {
                                    width: Length::Px(modal_ctrl_h)
                                    height: Length::Px(modal_ctrl_h)
                                    justify: JustifyContent::Center
                                    align: AlignItems::Center
                                    radius: live_g.get_radius_sm()
                                    overflow: Overflow::Hidden
                                    cursor: CursorIcon::Pointer
                                    background: close_surface.get_bg()
                                }
                                role: A11yRole::Button
                                a11y_label: ECHART_BTN_CLOSE.to_string()
                                on_click: on_close_fs
                                canvas {
                                    style: {
                                        width: Length::Px(14.0)
                                        height: Length::Px(14.0)
                                    }
                                    painter: paint_close_icon
                                }
                            }
                        }
                    }
                    view {
                        style: {
                            width: Length::Percent(100.0)
                            height: Length::Px(1.0)
                            background: live_p.get_border()
                        }
                    }
                    scroll {
                        node_ref: body_host_node
                        style: {
                            modal_scroll_st
                            flex_grow: 1.0
                            flex_shrink: 1.0
                            min_height: Length::Px(0.0)
                            width: Length::Percent(100.0)
                            padding: Edges::new(
                                SPACE_XS,
                                init_safe.get_right(),
                                init_safe.get_bottom(),
                                init_safe.get_left()
                            )
                            stop_scroll_propagation: true
                        }
                        canvas {
                            node_ref: modal_canvas
                            style: {
                                width: Length::Px(init_canvas_w)
                                height: Length::Px(init_canvas_h)
                                flex_shrink: 0.0
                                cursor: if has_data_zoom { CursorIcon::Pointer } else { CursorIcon::Grab }
                                stop_scroll_propagation: has_data_zoom
                                stop_event_propagation: has_data_zoom
                            }
                            painter: paint_modal
                        }
                    }
                }
            };
            body_scroll_cell.set(body_host_node);
            if interactive {
                wire_chart_pointer_events(
                    &mut local_fs_ctx,
                    ChartPointerWiring {
                        canvas_node: modal_canvas,
                        state_sig,
                        last_render: modal_render,
                        last_bounds: modal_bounds,
                        drag_state: Rc::clone(&modal_drag),
                        static_opt: modal_opt_wire,
                        opt_sig: opt_sig_opt,
                        on_point_click: fs_click_cb.clone(),
                        on_legend_change: fs_legend_cb.clone(),
                        on_zoom_change: fs_zoom_cb.clone(),
                        enable_drag: has_data_zoom,
                    },
                );
            }
            let handle_safe: SceneHandle = local_fs_ctx.get_scene().clone();
            let handle_modal_st: SceneHandle = handle_safe.clone();
            let app_state_fs: Signal<AppState> = local_fs_ctx.get_app_state();
            let (safe_scope, _): (Scope, Effect) = Scope::run(|_: Scope| {
                let _: Effect = Effect::new(move || {
                    if app_state_fs.get() != AppState::Active {
                        modal_drag.set((ChartDragTarget::None, 0.0, 0.0, 100.0));
                    }
                });
                let _: Effect = Effect::new(move || {
                    let _: EuvChartState = state_sig.get();
                    handle_modal_st.mark_dirty(modal_canvas, DIRTY_PAINT);
                });
                if let Some(sig) = opt_sig_opt {
                    let handle_modal_opt: SceneHandle = handle_safe.clone();
                    let _: Effect = Effect::new(move || {
                        let _: EuvChartOption = sig.get();
                        handle_modal_opt.mark_dirty(modal_canvas, DIRTY_PAINT);
                    });
                }
                Effect::new(move || {
                    let safe: SafeAreaInsets = safe_sig.get();
                    let vp: Size = vp_sig.get();
                    let z: f32 = zoom_sig.get();
                    let next_w: f32 = (vp.get_width() - safe.get_left() - safe.get_right())
                        .max(ECHART_MODAL_MIN_WIDTH)
                        * z;
                    let next_h: f32 = (vp.get_height() - 56.0 - safe.get_top() - safe.get_bottom())
                        .max(ECHART_MODAL_MIN_HEIGHT)
                        * z;
                    let pct_label: String = format!("{}%", (z * 100.0).round() as u32);
                    handle_safe.with_write(
                        |tree: &mut SceneTree| {
                            let dirty_l: u16 = DIRTY_LAYOUT | DIRTY_SUBTREE_LAYOUT;
                            if let Some(n) = tree.get_node_mut(top_bar_node) {
                                n.get_mut_style().get_mut_layout().set_padding(Edges::new(
                                    SPACE_SM + safe.get_top(),
                                    SPACE_MD + safe.get_right(),
                                    SPACE_SM,
                                    SPACE_MD + safe.get_left(),
                                ));
                                tree.mark_dirty(top_bar_node, dirty_l | DIRTY_PAINT);
                            }
                            if let Some(n) = tree.get_node_mut(body_host_node) {
                                n.get_mut_style().get_mut_layout().set_padding(Edges::new(
                                    SPACE_XS,
                                    safe.get_right(),
                                    safe.get_bottom(),
                                    safe.get_left(),
                                ));
                                tree.mark_dirty(body_host_node, dirty_l | DIRTY_PAINT);
                            }
                            if let Some(n) = tree.get_node_mut(modal_canvas) {
                                let lay: &mut LayoutStyle = n.get_mut_style().get_mut_layout();
                                lay.set_width(Length::Px(next_w))
                                    .set_height(Length::Px(next_h));
                                tree.mark_dirty(modal_canvas, dirty_l | DIRTY_PAINT);
                            }
                            tree.set_text(zoom_reset_txt, pct_label);
                        },
                        (),
                    );
                })
            });
            local_fs_ctx.get_scene().with_write(
                |tree: &mut SceneTree| {
                    tree.attach_scope(panel, safe_scope);
                },
                (),
            );
            panel
        };
        let mut toolbox_row: NodeId = NodeId::default();
        let mut chart_canvas: NodeId = NodeId::default();
        let mut fs_portal: NodeId = NodeId::default();
        let root: NodeId = view! {
            column {
                style: {
                    width: width
                    background: p.get_card()
                    border: (g.get_border_width(), p.get_border())
                    radius: g.get_radius_lg()
                    overflow: Overflow::Hidden
                }
                row {
                    node_ref: toolbox_row
                    style: {
                        width: Length::Percent(100.0)
                        display: if show_toolbox { Display::Flex } else { Display::None }
                        justify: JustifyContent::End
                        align: AlignItems::Center
                        padding: Edges::new(SPACE_XS, SPACE_SM, 0.0, SPACE_SM)
                        gap: SPACE_XS
                    }
                }
                canvas {
                    node_ref: chart_canvas
                    style: {
                        width: Length::Percent(100.0)
                        height: height
                        cursor: if interactive { CursorIcon::Pointer } else { CursorIcon::Default }
                        stop_scroll_propagation: has_data_zoom
                        stop_event_propagation: has_data_zoom
                    }
                    painter: paint_inline
                }
                column {
                    style: {
                        width: Length::Percent(100.0)
                    }
                    bind_children: build_data_view
                }
                portal {
                    node_ref: fs_portal
                    style: {
                        Style::default().column()
                        display: Display::None
                        position: Position::Fixed
                        inset: (Some(0.0), Some(0.0), Some(0.0), Some(0.0))
                        width: Length::Percent(100.0)
                        height: Length::Percent(100.0)
                        padding: Edges::all(0.0)
                        margin: Edges::all(0.0)
                        justify: JustifyContent::Start
                        align: AlignItems::Stretch
                        background: p.get_card()
                        border: (0.0, COLOR_TRANSPARENT)
                        radius: 0.0
                        overflow: Overflow::Hidden
                        pointer_events: PointerEvents::None
                        stop_scroll_propagation: true
                        stop_event_propagation: true
                        z_index: Z_INDEX_FULLSCREEN
                    }
                }
            }
        };
        for tb_node in toolbox_nodes.into_iter() {
            ctx.append(toolbox_row, tb_node);
        }
        let drag_bg_reset: Rc<Cell<(ChartDragTarget, f32, f32, f32)>> = Rc::clone(&drag_state);
        if interactive {
            wire_chart_pointer_events(
                &mut ctx,
                ChartPointerWiring {
                    canvas_node: chart_canvas,
                    state_sig,
                    last_render,
                    last_bounds,
                    drag_state,
                    static_opt: static_opt_rc,
                    opt_sig: opt_sig_opt,
                    on_point_click: on_point_click.clone(),
                    on_legend_change: on_legend_change.clone(),
                    on_zoom_change: on_zoom_change.clone(),
                    enable_drag: has_data_zoom,
                },
            );
        }
        let scene_dirty: SceneHandle = ctx.get_scene().clone();
        let scene_fs: SceneHandle = ctx.get_scene().clone();
        let ctx_build: Context = ctx.clone();
        let app_state_sig: Signal<AppState> = ctx.get_app_state();
        let prev_open: Rc<Cell<bool>> = Rc::new(Cell::new(false));
        let fs_acquired: Rc<Cell<bool>> = Rc::new(Cell::new(false));
        let fs_cleanup: Rc<Cell<bool>> = Rc::clone(&fs_acquired);
        let rev_watch: Rc<Cell<u64>> = Rc::clone(&opt_rev);
        let (scope, _): (Scope, Effect) = Scope::run(|_: Scope| {
            on_cleanup(move || {
                if fs_cleanup.replace(false) {
                    exit_fullscreen();
                }
            });
            let _: Effect = Effect::new(move || {
                if app_state_sig.get() != AppState::Active {
                    drag_bg_reset.set((ChartDragTarget::None, 0.0, 0.0, 100.0));
                }
            });
            let _: Effect = EuvOverlayStack::bind_signal(
                fs_open,
                ECHART_FULLSCREEN_OVERLAY_NAME,
                Z_INDEX_FULLSCREEN,
            );
            let scene_st: SceneHandle = scene_dirty.clone();
            let _: Effect = Effect::new(move || {
                let _: EuvChartState = state_sig.get();
                scene_st.mark_dirty(chart_canvas, DIRTY_PAINT);
            });
            if let Some(sig) = opt_sig_opt {
                let scene_opt: SceneHandle = scene_dirty.clone();
                let _: Effect = Effect::new(move || {
                    let _: EuvChartOption = sig.get();
                    rev_watch.set(rev_watch.get().wrapping_add(1));
                    scene_opt.mark_dirty(chart_canvas, DIRTY_PAINT);
                });
            }
            Effect::new(move || {
                let is_open: bool = fs_open.get();
                if is_open == prev_open.replace(is_open) {
                    return;
                }
                if is_open {
                    if !fs_acquired.replace(true) {
                        enter_fullscreen();
                    }
                    let live_bg: Color =
                        live_tokens_untracked(base_tokens).get_palette().get_card();
                    let panel: NodeId = with_context(ctx_build.clone(), &build_fs_panel);
                    scene_fs.with_write(
                        |tree: &mut SceneTree| {
                            let from_op: f32 = tree
                                .get_node(fs_portal)
                                .filter(|n: &&SceneNode| {
                                    n.style_ref().get_layout().get_display() != Display::None
                                })
                                .map(|n: &SceneNode| n.style_ref().get_paint().get_opacity())
                                .unwrap_or(0.0);
                            tree.cancel_subtree_transitions(fs_portal);
                            tree.replace_children(fs_portal, vec![panel]);
                            if let Some(n) = tree.get_node_mut(fs_portal) {
                                let st: &mut Style = n.get_mut_style();
                                st.get_mut_layout().set_display(Display::Flex);
                                st.get_mut_paint()
                                    .set_background(Some(live_bg))
                                    .set_pointer_events(PointerEvents::Auto)
                                    .set_opacity(from_op)
                                    .set_transform(Transform2D::default());
                            }
                            let dirty_l: u16 = DIRTY_LAYOUT | DIRTY_SUBTREE_LAYOUT;
                            tree.mark_dirty(fs_portal, dirty_l | DIRTY_PAINT);
                            tree.start_transition(NodeTransition::fade(
                                fs_portal, from_op, 1.0, 0.18, false,
                            ));
                        },
                        (),
                    );
                } else {
                    if fs_acquired.replace(false) {
                        exit_fullscreen();
                    }
                    scene_fs.with_write(
                        |tree: &mut SceneTree| {
                            let cur_op: f32 = tree
                                .get_node(fs_portal)
                                .map(|n: &SceneNode| n.style_ref().get_paint().get_opacity())
                                .unwrap_or(1.0);
                            tree.cancel_subtree_transitions(fs_portal);
                            if let Some(n) = tree.get_node_mut(fs_portal) {
                                n.get_mut_style()
                                    .get_mut_paint()
                                    .set_pointer_events(PointerEvents::None);
                            }
                            tree.mark_dirty(fs_portal, DIRTY_PAINT);
                            tree.start_transition(NodeTransition::fade(
                                fs_portal, cur_op, 0.0, 0.18, true,
                            ));
                        },
                        (),
                    );
                }
            })
        });
        ctx.get_scene().with_write(
            |tree: &mut SceneTree| {
                tree.attach_scope(root, scope);
            },
            (),
        );
        root
    }
}