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
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
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(),
style: None,
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
}
/// 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 user_style: Option<Style> = self.get_style();
let width: Length = user_style
.map(|s: Style| s.get_layout().get_width())
.filter(|w: &Length| *w != Length::Auto)
.unwrap_or(Length::Percent(100.0));
let height: Length = user_style
.map(|s: Style| s.get_layout().get_height())
.filter(|h: &Length| *h != Length::Auto)
.unwrap_or(Length::Px(ECHART_DEFAULT_HEIGHT));
let outer_overrides: Option<Style> = user_style.map(|mut s: Style| {
let _: &mut LayoutStyle = s.get_mut_layout().set_height(Length::Auto);
s
});
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 min_content_sz: Size = compute_chart_min_content_size(&initial_opt);
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 inline_scroll_cell: Rc<Cell<NodeId>> = Rc::new(Cell::new(NodeId::default()));
let inline_scroll_paint: Rc<Cell<NodeId>> = Rc::clone(&inline_scroll_cell);
let scene_inline_paint: SceneHandle = ctx.get_scene().clone();
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();
let sc_node: NodeId = inline_scroll_paint.get();
let scroll_info: Option<(Point, Size)> = if sc_node == NodeId::default() {
None
} else {
scene_inline_paint.with_read(
|tree: &SceneTree| {
tree.get_node(sc_node).map(|n: &SceneNode| {
let lb: LayoutBox = n.get_layout_box();
let cb: Rect = lb.get_content_bounds();
(
lb.get_scroll_offset(),
Size::new(cb.get_width(), cb.get_height()),
)
})
},
None,
)
};
let vis_vp: Rect = compute_visible_chart_viewport(bounds, scroll_info);
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.visible_viewport == vis_vp
&& 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_in_viewport(
&opt_snapshot,
&cur_state,
bounds,
vis_vp,
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,
visible_viewport: vis_vp,
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 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 (col_widths, total_w): (Vec<f32>, f32) = compute_data_view_col_widths(&table);
let mut dv_scroll_st: Style = Style::default();
dv_scroll_st
.get_mut_layout()
.set_flex_direction(FlexDirection::Column)
.set_align_items(AlignItems::Start);
let mut header_row: NodeId = NodeId::default();
let mut body_col: NodeId = NodeId::default();
let wrapper: NodeId = view! {
column {
style: {
width: Length::Percent(100.0)
padding: Edges::new(SPACE_SM, SPACE_MD, SPACE_MD, SPACE_MD)
}
column {
style: {
width: Length::Percent(100.0)
background: live_p.get_muted().multiply_alpha(0.32)
border: (1.0, live_p.get_border())
radius: live_g.get_radius_md()
overflow: Overflow::Hidden
}
row {
style: {
width: Length::Percent(100.0)
padding: Edges::symmetric(SPACE_XS + 2.0, SPACE_MD)
justify: JustifyContent::SpaceBetween
align: AlignItems::Center
background: live_p.get_card()
}
text {
style: {
flex_shrink: 1.0
min_width: Length::Px(0.0)
font_size: 11.5
font_weight: FontWeight::SemiBold
color: live_p.get_foreground()
}
{ ECHART_DATA_VIEW_TITLE }
}
}
view {
style: {
width: Length::Percent(100.0)
height: Length::Px(1.0)
background: live_p.get_border()
}
}
scroll {
style: {
dv_scroll_st
width: Length::Percent(100.0)
max_height: Length::Px(ECHART_DATA_VIEW_MAX_HEIGHT)
}
column {
style: {
min_width: Length::Px(total_w)
width: Length::Percent(100.0)
flex_shrink: 0.0
}
row {
node_ref: header_row
style: {
width: Length::Percent(100.0)
background: live_p.get_muted().multiply_alpha(0.55)
align: AlignItems::Stretch
}
}
column {
node_ref: body_col
style: {
width: Length::Percent(100.0)
}
}
}
}
}
}
};
let safe_total_w: f32 = total_w.max(1.0);
for (ci, h) in table.get_headers().iter().enumerate() {
let cw: f32 = col_widths
.get(ci)
.copied()
.unwrap_or(ECHART_DATA_VIEW_MIN_COL_W);
let pct: f32 = (cw / safe_total_w) * 100.0;
let h_txt: String = h.clone();
let cell: NodeId = view! {
row {
style: {
width: Length::Percent(pct)
min_width: Length::Px(cw)
flex_shrink: 0.0
padding: Edges::symmetric(6.0, SPACE_SM)
align: AlignItems::Center
overflow: Overflow::Hidden
}
text {
style: {
width: Length::Percent(100.0)
font_size: 11.0
font_weight: FontWeight::SemiBold
color: live_p.get_foreground()
text_overflow: TextOverflow::Wrap
}
{ h_txt }
}
}
};
local_ctx.append(header_row, cell);
}
for (ri, row) in table.get_rows().iter().take(40).enumerate() {
let row_bg: Color = if ri % 2 == 1 {
live_p.get_muted().multiply_alpha(0.30)
} else {
live_p.get_card()
};
let div_node: NodeId = view! {
view {
style: {
width: Length::Percent(100.0)
height: Length::Px(1.0)
background: live_p.get_border().multiply_alpha(0.5)
}
}
};
local_ctx.append(body_col, div_node);
let row_node: NodeId = view! {
row {
style: {
width: Length::Percent(100.0)
background: row_bg
align: AlignItems::Stretch
}
}
};
for (ci, c) in row.iter().enumerate() {
let cw: f32 = col_widths
.get(ci)
.copied()
.unwrap_or(ECHART_DATA_VIEW_MIN_COL_W);
let pct: f32 = (cw / safe_total_w) * 100.0;
let c_txt: String = c.clone();
let cell: NodeId = view! {
row {
style: {
width: Length::Percent(pct)
min_width: Length::Px(cw)
flex_shrink: 0.0
padding: Edges::symmetric(6.0, SPACE_SM)
align: AlignItems::Center
overflow: Overflow::Hidden
}
text {
style: {
width: Length::Percent(100.0)
font_size: 11.0
color: live_p.get_muted_foreground()
text_overflow: TextOverflow::Wrap
}
{ c_txt }
}
}
};
local_ctx.append(row_node, cell);
}
local_ctx.append(body_col, row_node);
}
vec![wrapper]
};
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_min_sz: Size = compute_chart_min_content_size(&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 body_scroll_cell: Rc<Cell<NodeId>> = Rc::new(Cell::new(NodeId::default()));
let body_scroll_paint: Rc<Cell<NodeId>> = Rc::clone(&body_scroll_cell);
let scene_modal_paint: SceneHandle = local_fs_ctx.get_scene().clone();
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();
let sc_node: NodeId = body_scroll_paint.get();
let scroll_info: Option<(Point, Size)> = if sc_node == NodeId::default() {
None
} else {
scene_modal_paint.with_read(
|tree: &SceneTree| {
tree.get_node(sc_node).map(|n: &SceneNode| {
let lb: LayoutBox = n.get_layout_box();
let cb: Rect = lb.get_content_bounds();
(
lb.get_scroll_offset(),
Size::new(cb.get_width(), cb.get_height()),
)
})
},
None,
)
};
let vis_vp: Rect = compute_visible_chart_viewport(bounds, scroll_info);
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.visible_viewport == vis_vp
&& 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_in_viewport(
&live_opt,
&cur_st,
bounds,
vis_vp,
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,
visible_viewport: vis_vp,
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_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 modal_base_min_w: f32 = ECHART_MODAL_MIN_WIDTH.max(modal_min_sz.get_width());
let modal_base_min_h: f32 = ECHART_MODAL_MIN_HEIGHT.max(modal_min_sz.get_height());
let init_canvas_w: f32 =
(init_vp.get_width() - init_safe.get_left() - init_safe.get_right())
.max(modal_base_min_w);
let init_canvas_h: f32 =
(init_vp.get_height() - 56.0 - init_safe.get_top() - init_safe.get_bottom())
.max(modal_base_min_h);
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 }
}
painter: paint_modal
}
}
}
};
body_scroll_cell.set(body_host_node);
let scene_modal_scroll: SceneHandle = local_fs_ctx.get_scene().clone();
local_fs_ctx.on_scroll(body_host_node, move |_: &UiEvent| {
scene_modal_scroll.mark_dirty(modal_canvas, DIRTY_PAINT);
});
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(modal_base_min_w)
* z;
let next_h: f32 = (vp.get_height() - 56.0 - safe.get_top() - safe.get_bottom())
.max(modal_base_min_h)
* 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 inline_scroll_st: Style = Style::default();
inline_scroll_st
.get_mut_layout()
.set_flex_direction(FlexDirection::Column)
.set_align_items(AlignItems::Start);
let mut toolbox_row: NodeId = NodeId::default();
let mut chart_scroll: NodeId = NodeId::default();
let mut chart_canvas: NodeId = NodeId::default();
let mut fs_portal: NodeId = NodeId::default();
let outer_style: Style = style! {
width: width
background: p.get_card()
border: (g.get_border_width(), p.get_border())
radius: g.get_radius_lg()
overflow: Overflow::Hidden
}
.with_overrides(outer_overrides);
let root: NodeId = view! {
column {
style: outer_style
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_SM, SPACE_SM, 0.0, SPACE_SM)
gap: SPACE_XS
}
}
scroll {
node_ref: chart_scroll
style: {
inline_scroll_st
width: Length::Percent(100.0)
}
canvas {
node_ref: chart_canvas
style: {
width: Length::Percent(100.0)
min_width: Length::Px(min_content_sz.get_width())
height: height
min_height: Length::Px(min_content_sz.get_height())
flex_shrink: 0.0
cursor: if interactive { CursorIcon::Pointer } else { CursorIcon::Default }
}
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
}
}
}
};
inline_scroll_cell.set(chart_scroll);
let scene_inline_scroll: SceneHandle = ctx.get_scene().clone();
ctx.on_scroll(chart_scroll, move |_: &UiEvent| {
scene_inline_scroll.mark_dirty(chart_canvas, DIRTY_PAINT);
});
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 cur_opt: EuvChartOption = sig.get();
let next_min: Size = compute_chart_min_content_size(&cur_opt);
rev_watch.set(rev_watch.get().wrapping_add(1));
scene_opt.with_write(
|tree: &mut SceneTree| {
if let Some(n) = tree.get_node_mut(chart_canvas) {
n.get_mut_style()
.get_mut_layout()
.set_min_width(Length::Px(next_min.get_width()))
.set_min_height(Length::Px(next_min.get_height()));
}
let dirty_l: u16 = DIRTY_LAYOUT | DIRTY_SUBTREE_LAYOUT;
tree.mark_dirty(chart_canvas, dirty_l | 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,
motion_duration(MOTION_STANDARD_SECS),
false,
)
.with_easing(MOTION_EASE_ENTER),
);
},
(),
);
} 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,
motion_duration(MOTION_STANDARD_SECS),
true,
)
.with_easing(MOTION_EASE_EXIT),
);
},
(),
);
}
})
});
ctx.get_scene().with_write(
|tree: &mut SceneTree| {
tree.attach_scope(root, scope);
},
(),
);
root
}
}