use super::*;
impl LazyChartOption {
#[must_use]
pub(crate) fn new(fallback: EuvChartOption, loader: Option<EuvChartOptionLoader>) -> Self {
Self {
fallback,
loader,
materialized: Rc::new(RefCell::new(None)),
}
}
fn ensure_materialized(&self) {
let Self {
loader,
materialized,
..
} = self;
let Some(factory) = loader.as_ref() else {
return;
};
let already_loaded: bool = materialized
.try_borrow()
.is_ok_and(|slot: Ref<'_, Option<EuvChartOption>>| slot.is_some());
if already_loaded {
return;
}
let built: EuvChartOption = factory();
record_chart_lazy_materialize();
if let Ok(mut slot) = materialized.try_borrow_mut() {
*slot = Some(built);
}
}
pub(crate) fn with_resolved<ConsumerFn, ReturnType>(&self, consumer: ConsumerFn) -> ReturnType
where
ConsumerFn: FnOnce(&EuvChartOption) -> ReturnType,
{
self.ensure_materialized();
let Self {
fallback,
materialized,
..
} = self;
if let Ok(slot) = materialized.try_borrow()
&& let Some(loaded) = slot.as_ref()
{
return consumer(loaded);
}
consumer(fallback)
}
#[must_use]
pub(crate) fn resolve_clone(&self) -> EuvChartOption {
self.with_resolved(EuvChartOption::clone)
}
}
impl Default for EuvEChart {
fn default() -> Self {
Self {
option: EuvChartOption::default(),
option_signal: None,
option_loader: None,
tokens: ThemeTokens::default(),
style: None,
interactive: true,
on_point_click: None,
on_legend_change: None,
on_zoom_change: None,
}
}
}
impl EuvEChart {
#[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
}
#[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
}
#[must_use]
pub fn option(mut self, option: EuvChartOption) -> Self {
self.set_option(option);
self
}
#[must_use]
pub fn option_signal(mut self, option_signal: Signal<EuvChartOption>) -> Self {
self.set_option_signal(Some(option_signal));
self
}
#[must_use]
pub fn option_loader(mut self, loader: EuvChartOptionLoader) -> Self {
self.set_option_loader(Some(loader));
self
}
#[must_use]
pub fn tokens(mut self, tokens: ThemeTokens) -> Self {
self.set_tokens(tokens);
self
}
#[must_use]
pub fn interactive(mut self, interactive: bool) -> Self {
self.set_interactive(interactive);
self
}
#[must_use]
pub fn on_point_click(mut self, handler: EuvChartHitCallback) -> Self {
self.set_on_point_click(Some(handler));
self
}
#[must_use]
pub fn on_legend_change(mut self, handler: EuvChartLegendCallback) -> Self {
self.set_on_legend_change(Some(handler));
self
}
#[must_use]
pub fn on_zoom_change(mut self, handler: Rc<dyn Fn(f32, f32)>) -> Self {
self.set_on_zoom_change(Some(handler));
self
}
#[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(),
}
}
}
#[component]
impl EuvEChart {
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 palette: ThemePalette = tokens.get_palette();
let geometry: ThemeGeometry = tokens.get_geometry();
let user_style: Option<Style> = self.get_style();
let width: Length = user_style
.map(|computed_style: Style| computed_style.get_layout().get_width())
.filter(|width_val: &Length| *width_val != Length::Auto)
.unwrap_or(Length::Percent(100.0));
let height: Length = user_style
.map(|element_style: Style| element_style.get_layout().get_height())
.filter(|height_val: &Length| *height_val != Length::Auto)
.unwrap_or(Length::Px(ECHART_DEFAULT_HEIGHT));
let outer_overrides: Option<Style> = user_style.map(|mut resolved_style: Style| {
let _: &mut LayoutStyle = resolved_style.get_mut_layout().set_height(Length::Auto);
resolved_style
});
let interactive: bool = self.get_interactive();
let Self {
option: static_opt,
option_signal,
option_loader,
on_point_click,
on_legend_change,
on_zoom_change,
..
} = self;
let opt_sig_opt: Option<Signal<EuvChartOption>> = *option_signal;
let static_opt_rc: Rc<LazyChartOption> = Rc::new(LazyChartOption::new(
static_opt.clone(),
option_loader.clone(),
));
let initial_opt: EuvChartOption = self.current_option_untracked();
let state_sig: Signal<EuvChartState> =
Signal::new(EuvChartState::from_option(&initial_opt));
let hover_pos_sig: Signal<Option<Point>> = Signal::new(None);
let data_view_open_memo: Memo<bool> =
Memo::new(move || state_sig.get().get_data_view_open());
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 (init_title_text, init_subtext, init_title_align, init_has_title): (
String,
String,
TextAlign,
bool,
) = resolve_chart_header_meta(&initial_opt);
let has_header: bool = init_has_title || show_toolbox;
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<LazyChartOption> = 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, display_list: &mut DisplayList| {
if !is_chart_rect_in_viewport(bounds, display_list.get_viewport()) {
return;
}
let live_tok: ThemeTokens = live_tokens_untracked(base_tokens);
let cur_state: EuvChartState = state_sig.get_untracked();
let hover_pos: Option<Point> = hover_pos_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(|scene_node: &SceneNode| {
let lb: LayoutBox = scene_node.get_layout_box();
let rect_bounds: Rect = lb.get_content_bounds();
(
lb.get_scroll_offset(),
Size::new(rect_bounds.get_width(), rect_bounds.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;
}
let scale_factor: f32 = display_list.get_scale_factor().max(0.5);
let scale_bits: u32 = scale_factor.to_bits();
let base_state: EuvChartState = if cur_state.hover_pos_opt().is_some() {
cur_state.without_hover()
} else {
cur_state
};
if let Ok(guard) = inline_cache.try_borrow()
&& let Some(cached) = guard.as_ref()
&& cached.get_bounds() == bounds
&& cached.get_visible_viewport() == vis_vp
&& cached.get_tokens() == live_tok
&& cached.get_base_state() == &base_state
&& cached.get_rev() == cur_rev
&& cached.get_scale_bits() == scale_bits
{
display_list.extend_commands(cached.get_base_commands().as_slice());
let matched: Vec<EuvChartDatumHit> = if hover_pos.is_some() {
let mut hover_state: EuvChartState = base_state;
hover_state.set_hover_pos(hover_pos);
match opt_sig_opt {
Some(sig) => {
let live_opt: EuvChartOption = sig.get_untracked();
render_echart_hover_overlay(
&live_opt,
&hover_state,
cached.get_base_result(),
vis_vp,
live_tok,
display_list,
)
}
None => paint_opt_rc.with_resolved(|live_opt: &EuvChartOption| {
render_echart_hover_overlay(
live_opt,
&hover_state,
cached.get_base_result(),
vis_vp,
live_tok,
display_list,
)
}),
}
} else {
Vec::new()
};
if let Ok(mut r_guard) = paint_res.try_borrow_mut() {
r_guard.set_active_tooltip_hits(matched);
}
return;
}
record_chart_paint_build();
let opt_snapshot: EuvChartOption = match opt_sig_opt {
Some(sig) => sig.get_untracked(),
None => paint_opt_rc.resolve_clone(),
};
let canvas_opt: EuvChartOption = opt_snapshot.without_title();
let mut scratch: DisplayList = DisplayList::default();
scratch.reset(display_list.get_viewport(), scale_factor);
let base_res: EuvChartRenderResult = render_echart_in_viewport(
&canvas_opt,
&base_state,
bounds,
vis_vp,
live_tok,
&mut scratch,
);
let base_cmds: Vec<DrawCommand> = take(scratch.get_mut_commands());
display_list.extend_commands(base_cmds.as_slice());
let matched: Vec<EuvChartDatumHit> = if hover_pos.is_some() {
let mut hover_state: EuvChartState = base_state.clone();
hover_state.set_hover_pos(hover_pos);
render_echart_hover_overlay(
&canvas_opt,
&hover_state,
&base_res,
vis_vp,
live_tok,
display_list,
)
} else {
Vec::new()
};
let mut full_res: EuvChartRenderResult = base_res.clone();
if !matched.is_empty() {
full_res.set_active_tooltip_hits(matched);
}
if let Ok(mut r_guard) = paint_res.try_borrow_mut() {
*r_guard = full_res;
}
if let Ok(mut guard) = inline_cache.try_borrow_mut() {
*guard = Some(ChartPaintCache {
bounds,
visible_viewport: vis_vp,
tokens: live_tok,
base_state,
rev: cur_rev,
scale_bits,
base_commands: base_cmds,
base_result: base_res,
});
}
};
let dv_opt_rc: Rc<LazyChartOption> = Rc::clone(&static_opt_rc);
let dv_ctx: Context = ctx.clone();
let build_data_view = move || -> Vec<NodeId> {
record_chart_data_view_build();
let mut local_ctx: Context = dv_ctx.clone();
if !data_view_open_memo.get() {
return Vec::new();
}
let node_style: EuvChartState = state_sig.get();
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.resolve_clone(),
};
let table: EuvChartDataViewTable = extract_data_view_table(&opt_snapshot, &node_style);
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 column_quaternary_style: Style = style! {
Width(Length::Percent(100.0))
Padding(Edges::new(SPACE_SM, SPACE_MD, SPACE_MD, SPACE_MD))
};
let column_fifth_style: Style = style! {
Width(Length::Percent(100.0))
Background(live_p.get_muted().multiply_alpha(0.32))
Border::new(1.0, live_p.get_border())
Radius(live_g.get_radius_md())
Overflow::Hidden
};
let row_eleventh_style: Style = style! {
Width(Length::Percent(100.0))
Padding(Edges::symmetric(SPACE_XS + 2.0, SPACE_MD))
JustifyContent::SpaceBetween
AlignItems::Center
Background(live_p.get_card())
};
let text_eighth_style: Style = style! {
FlexShrink(1.0)
MinWidth(Length::Px(0.0))
FontSize(11.5)
FontWeight::SemiBold
TextColor(live_p.get_foreground())
};
let view_tertiary_style: Style = style! {
Width(Length::Percent(100.0))
Height(Length::Px(1.0))
Background(live_p.get_border())
};
let scroll_tertiary_style: Style = style! {
dv_scroll_st
Width(Length::Percent(100.0))
MaxHeight(Length::Px(ECHART_DATA_VIEW_MAX_HEIGHT))
};
let column_sixth_style: Style = style! {
MinWidth(Length::Px(total_w))
Width(Length::Percent(100.0))
FlexShrink(0.0)
};
let row_twelfth_style: Style = style! {
Width(Length::Percent(100.0))
Background(live_p.get_muted().multiply_alpha(0.55))
AlignItems::Stretch
};
let column_seventh_style: Style = style! {
Width(Length::Percent(100.0))
};
let wrapper: NodeId = view! {
column {
style: column_quaternary_style
column {
style: column_fifth_style
row {
style: row_eleventh_style
text {
style: text_eighth_style
{ ECHART_DATA_VIEW_TITLE }
}
}
view {
style: view_tertiary_style
}
scroll {
style: scroll_tertiary_style
column {
style: column_sixth_style
row {
node_ref: header_row
style: row_twelfth_style
}
column {
node_ref: body_col
style: column_seventh_style
}
}
}
}
}
};
let safe_total_w: f32 = total_w.max(1.0);
for (ci, span_height) 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 = span_height.clone();
let row_tenth_style: Style = style! {
Width(Length::Percent(pct))
MinWidth(Length::Px(cw))
FlexShrink(0.0)
Padding(Edges::symmetric(6.0, SPACE_SM))
AlignItems::Center
Overflow::Hidden
};
let text_seventh_style: Style = style! {
Width(Length::Percent(100.0))
FontSize(11.0)
FontWeight::SemiBold
TextColor(live_p.get_foreground())
TextOverflow::Wrap
};
let cell: NodeId = view! {
row {
style: row_tenth_style
text {
style: text_seventh_style
{ 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 view_secondary_style: Style = style! {
Width(Length::Percent(100.0))
Height(Length::Px(1.0))
Background(live_p.get_border().multiply_alpha(0.5))
};
let div_node: NodeId = view! {
view {
style: view_secondary_style
}
};
local_ctx.append(body_col, div_node);
let row_ninth_style: Style = style! {
Width(Length::Percent(100.0))
Background(row_bg)
AlignItems::Stretch
};
let row_node: NodeId = view! {
row {
style: row_ninth_style
}
};
for (ci, char_item) 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 = char_item.clone();
let row_eighth_style: Style = style! {
Width(Length::Percent(pct))
MinWidth(Length::Px(cw))
FlexShrink(0.0)
Padding(Edges::symmetric(6.0, SPACE_SM))
AlignItems::Center
Overflow::Hidden
};
let text_sixth_style: Style = style! {
Width(Length::Percent(100.0))
FontSize(11.0)
TextColor(live_p.get_muted_foreground())
TextOverflow::Wrap
};
let cell: NodeId = view! {
row {
style: row_eighth_style
text {
style: text_sixth_style
{ 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<LazyChartOption> = 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.resolve_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 = hover_pos_sig.set_if_changed(None);
let _: bool = state_sig.set(restored);
if let Some(callback_fn) = z_cb.as_ref() {
callback_fn(s_pct, e_pct);
}
};
toolbox_nodes.push(build_toolbox_icon_button(
base_tokens,
ChartToolboxIcon::Restore,
ECHART_BUTTON_RESTORE,
on_restore,
));
}
if tb.get_magic_type() {
let on_magic = move |_: &UiEvent| {
let _: bool = {
if let Some(mut updated_value) = state_sig.try_get_untracked() {
{
let active_style: &mut EuvChartState = &mut updated_value;
let _: EuvChartMagicType = active_style.cycle_magic_type();
}
state_sig.set(updated_value)
} else {
false
}
};
};
toolbox_nodes.push(build_toolbox_icon_button(
base_tokens,
ChartToolboxIcon::MagicType,
ECHART_BUTTON_MAGIC_TYPE,
on_magic,
));
}
if tb.get_data_view() {
let on_dv = move |_: &UiEvent| {
let _: bool = {
if let Some(mut updated_value) = state_sig.try_get_untracked() {
{
let state_val: &mut EuvChartState = &mut updated_value;
let _: bool = state_val.toggle_data_view();
}
state_sig.set(updated_value)
} else {
false
}
};
};
toolbox_nodes.push(build_toolbox_icon_button(
base_tokens,
ChartToolboxIcon::DataView,
ECHART_BUTTON_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_button(
base_tokens,
ChartToolboxIcon::Fullscreen,
ECHART_BUTTON_FULLSCREEN,
on_fs,
));
}
}
let fs_opt_rc: Rc<LazyChartOption> = 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.resolve_clone(),
};
let modal_title: String = cur_opt
.title_opt()
.map(|blend_factor: &EuvChartTitle| blend_factor.get_text().clone())
.filter(|text_value: &String| !text_value.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<LazyChartOption> = Rc::clone(&fs_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_hover_pos_sig: Signal<Option<Point>> = Signal::new(None);
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, draw_commands: &mut DisplayList| {
let cur_tok: ThemeTokens = live_tokens_untracked(base_tokens);
let cur_st: EuvChartState = state_sig.get_untracked();
let hover_pos: Option<Point> = modal_hover_pos_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(|target_node: &SceneNode| {
let lb: LayoutBox = target_node.get_layout_box();
let clip_bounds: Rect = lb.get_content_bounds();
(
lb.get_scroll_offset(),
Size::new(clip_bounds.get_width(), clip_bounds.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;
}
let scale_factor: f32 = draw_commands.get_scale_factor().max(0.5);
let scale_bits: u32 = scale_factor.to_bits();
let base_state: EuvChartState = if cur_st.hover_pos_opt().is_some() {
cur_st.without_hover()
} else {
cur_st
};
if let Ok(guard) = modal_cache.try_borrow()
&& let Some(cached) = guard.as_ref()
&& cached.get_bounds() == bounds
&& cached.get_visible_viewport() == vis_vp
&& cached.get_tokens() == cur_tok
&& cached.get_base_state() == &base_state
&& cached.get_rev() == cur_rev
&& cached.get_scale_bits() == scale_bits
{
draw_commands.extend_commands(cached.get_base_commands().as_slice());
let matched: Vec<EuvChartDatumHit> = if hover_pos.is_some() {
let mut hover_state: EuvChartState = base_state;
hover_state.set_hover_pos(hover_pos);
match opt_sig_opt {
Some(sig) => {
let live_opt: EuvChartOption = sig.get_untracked();
render_echart_hover_overlay(
&live_opt,
&hover_state,
cached.get_base_result(),
vis_vp,
cur_tok,
draw_commands,
)
}
None => render_echart_hover_overlay(
modal_opt_rc.as_ref(),
&hover_state,
cached.get_base_result(),
vis_vp,
cur_tok,
draw_commands,
),
}
} else {
Vec::new()
};
if let Ok(mut r_guard) = modal_render_paint.try_borrow_mut() {
r_guard.set_active_tooltip_hits(matched);
}
return;
}
let live_opt: EuvChartOption = match opt_sig_opt {
Some(sig) => sig.get_untracked(),
None => (*modal_opt_rc).clone(),
};
let modal_canvas_opt: EuvChartOption = live_opt.without_title();
let mut scratch: DisplayList = DisplayList::default();
scratch.reset(draw_commands.get_viewport(), scale_factor);
let base_res: EuvChartRenderResult = render_echart_in_viewport(
&modal_canvas_opt,
&base_state,
bounds,
vis_vp,
cur_tok,
&mut scratch,
);
let base_cmds: Vec<DrawCommand> = take(scratch.get_mut_commands());
draw_commands.extend_commands(base_cmds.as_slice());
let matched: Vec<EuvChartDatumHit> = if hover_pos.is_some() {
let mut hover_state: EuvChartState = base_state.clone();
hover_state.set_hover_pos(hover_pos);
render_echart_hover_overlay(
&modal_canvas_opt,
&hover_state,
&base_res,
vis_vp,
cur_tok,
draw_commands,
)
} else {
Vec::new()
};
let mut full_res: EuvChartRenderResult = base_res.clone();
if !matched.is_empty() {
full_res.set_active_tooltip_hits(matched);
}
if let Ok(mut r_guard) = modal_render_paint.try_borrow_mut() {
*r_guard = full_res;
}
if let Ok(mut guard) = modal_cache.try_borrow_mut() {
*guard = Some(ChartPaintCache {
bounds,
visible_viewport: vis_vp,
tokens: cur_tok,
base_state,
rev: cur_rev,
scale_bits,
base_commands: base_cmds,
base_result: base_res,
});
}
};
let paint_close_icon = move |bounds: Rect, command_list: &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_chart_toolbox_icon(
ChartToolboxIcon::ExitFullscreen,
bounds,
command_list,
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 = {
if let Some(mut updated_value) = zoom_sig.try_get_untracked() {
{
let pos_z: &mut f32 = &mut updated_value;
*pos_z =
(*pos_z - ECHART_ZOOM_STEP).clamp(ECHART_ZOOM_MIN, ECHART_ZOOM_MAX);
}
zoom_sig.set(updated_value)
} else {
false
}
};
};
let on_zoom_in = move |_: &UiEvent| {
let _: bool = {
if let Some(mut updated_value) = zoom_sig.try_get_untracked() {
{
let coord_z: &mut f32 = &mut updated_value;
*coord_z = (*coord_z + ECHART_ZOOM_STEP)
.clamp(ECHART_ZOOM_MIN, ECHART_ZOOM_MAX);
}
zoom_sig.set(updated_value)
} else {
false
}
};
};
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 node_id: NodeId = body_scroll_reset.get();
scene_reset.with_write(
|tree: &mut SceneTree| {
tree.set_scroll_offset(node_id, 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_fs: FullscreenSafeLayout = resolve_fullscreen_safe_layout(init_vp, init_safe);
let init_body: Edges = init_fs.get_body_padding();
let init_head: Edges = init_fs.get_header_padding();
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_body.get_left() - init_body.get_right())
.max(modal_base_min_w);
let init_canvas_h: f32 =
(init_vp.get_height() - 56.0 - init_head.get_top() - init_body.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 column_tertiary_style: Style = style! {
Width(Length::Percent(100.0))
Height(Length::Percent(100.0))
FlexGrow(1.0)
Padding(Edges::all(0.0))
Margin(Edges::all(0.0))
Background(live_p.get_card())
Border::new(0.0, COLOR_TRANSPARENT)
Radius(0.0)
Overflow::Hidden
StopEventPropagation(true)
};
let row_tertiary_style: Style = style! {
Width(Length::Percent(100.0))
FlexShrink(0.0)
Padding(init_head)
JustifyContent::SpaceBetween
AlignItems::Center
Gap(SPACE_SM)
Overflow::Hidden
Background(live_p.get_muted().multiply_alpha(0.4))
};
let text_tertiary_style: Style = style! {
FlexShrink(1.0)
MinWidth(Length::Px(0.0))
Overflow::Hidden
TextOverflow::Ellipsis
FontSize(13.5)
FontWeight::SemiBold
TextColor(live_p.get_foreground())
};
let row_quaternary_style: Style = style! {
FlexShrink(0.0)
AlignItems::Center
Gap(SPACE_XS)
};
let row_fifth_style: Style = style! {
Width(Length::Px(modal_ctrl_h))
Height(Length::Px(modal_ctrl_h))
JustifyContent::Center
AlignItems::Center
Radius(live_g.get_radius_sm())
Overflow::Hidden
CursorIcon::Pointer
Background(live_p.get_card())
Border::new(1.0, live_p.get_border())
};
let text_quaternary_style: Style = style! {
FontSize(14.0)
FontWeight::Bold
TextColor(live_p.get_foreground())
TextOverflow::Clip
};
let row_sixth_style: Style = style! {
Height(Length::Px(modal_ctrl_h))
Padding(Edges::symmetric(0.0, SPACE_SM))
JustifyContent::Center
AlignItems::Center
Radius(live_g.get_radius_sm())
Overflow::Hidden
CursorIcon::Pointer
Background(live_p.get_card())
Border::new(1.0, live_p.get_border())
};
let text_fifth_style: Style = style! {
FontSize(11.0)
FontFamily::Monospace
FontWeight::SemiBold
TextColor(live_p.get_foreground())
TextOverflow::Clip
};
let row_seventh_style: Style = style! {
Width(Length::Px(modal_ctrl_h))
Height(Length::Px(modal_ctrl_h))
JustifyContent::Center
AlignItems::Center
Radius(live_g.get_radius_sm())
Overflow::Hidden
CursorIcon::Pointer
Background(close_surface.get_bg())
};
let canvas_secondary_style: Style = style! {
Width(Length::Px(16.0))
Height(Length::Px(16.0))
FlexShrink(0.0)
};
let view_style: Style = style! {
Width(Length::Percent(100.0))
Height(Length::Px(1.0))
Background(live_p.get_border())
};
let scroll_secondary_style: Style = style! {
modal_scroll_st
FlexGrow(1.0)
FlexShrink(1.0)
MinHeight(Length::Px(0.0))
Width(Length::Percent(100.0))
Padding(Edges::new(
SPACE_XS,
init_body.get_right(),
init_body.get_bottom(),
init_body.get_left()
))
StopScrollPropagation(true)
};
let canvas_tertiary_style: Style = style! {
Width(Length::Px(init_canvas_w))
Height(Length::Px(init_canvas_h))
FlexShrink(0.0)
if has_data_zoom { CursorIcon::Pointer } else { CursorIcon::Grab }
};
let panel: NodeId = view! {
column {
style: column_tertiary_style
row {
node_ref: top_bar_node
style: row_tertiary_style
text {
style: text_tertiary_style
{ modal_title }
}
row {
style: row_quaternary_style
row {
style: row_fifth_style
role: A11yRole::Button
a11y_label: ECHART_BUTTON_ZOOM_OUT.to_string()
on_click: on_zoom_out
text {
style: text_quaternary_style
{ ECHART_ZOOM_MINUS }
}
}
row {
style: row_sixth_style
role: A11yRole::Button
a11y_label: ECHART_BUTTON_ZOOM_RESET.to_string()
on_click: on_zoom_reset
text {
node_ref: zoom_reset_txt
style: text_fifth_style
{ ECHART_ZOOM_INIT_LABEL }
}
}
row {
style: row_fifth_style
role: A11yRole::Button
a11y_label: ECHART_BUTTON_ZOOM_IN.to_string()
on_click: on_zoom_in
text {
style: text_quaternary_style
{ ECHART_ZOOM_PLUS }
}
}
row {
style: row_seventh_style
role: A11yRole::Button
a11y_label: ECHART_BUTTON_CLOSE.to_string()
on_click: on_close_fs
canvas {
caching: CanvasCaching::RetainedStatic
style: canvas_secondary_style
painter: paint_close_icon
}
}
}
}
view {
style: view_style
}
scroll {
node_ref: body_host_node
style: scroll_secondary_style
canvas {
node_ref: modal_canvas
caching: CanvasCaching::RetainedStatic
style: canvas_tertiary_style
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 {
let mut modal_wiring: ChartPointerWiring = ChartPointerWiring::new(
modal_canvas,
state_sig,
modal_hover_pos_sig,
modal_render,
modal_bounds,
Rc::clone(&modal_drag),
modal_opt_wire,
);
let _: &mut ChartPointerWiring = modal_wiring
.set_opt_sig(opt_sig_opt)
.set_on_point_click(fs_click_cb.clone())
.set_on_legend_change(fs_legend_cb.clone())
.set_on_zoom_change(fs_zoom_cb.clone())
.set_enable_drag(has_data_zoom);
wire_chart_pointer_events(&mut local_fs_ctx, modal_wiring);
}
let handle_safe: SceneHandle = local_fs_ctx.get_scene().clone();
let handle_modal_st: SceneHandle = handle_safe.clone();
let handle_modal_theme: 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 mounted_modal_st: Cell<bool> = Cell::new(false);
let _: Effect = Effect::new(move || {
let _: EuvChartState = state_sig.get();
if !mounted_modal_st.replace(true) {
return;
}
handle_modal_st.mark_dirty(modal_canvas, DIRTY_PAINT);
});
let prev_modal_theme: Cell<ThemeKey> = Cell::new(live_tok.key());
let _: Effect = Effect::new(move || {
let next_theme_key: ThemeKey = use_live_tokens(base_tokens).key();
if prev_modal_theme.replace(next_theme_key) == next_theme_key {
return;
}
handle_modal_theme.mark_dirty(modal_canvas, DIRTY_PAINT);
});
if let Some(sig) = opt_sig_opt {
let handle_modal_opt: SceneHandle = handle_safe.clone();
let mounted_modal_opt: Cell<bool> = Cell::new(false);
let _: Effect = Effect::new(move || {
let _: EuvChartOption = sig.get();
if !mounted_modal_opt.replace(true) {
return;
}
handle_modal_opt.mark_dirty(modal_canvas, DIRTY_PAINT);
});
}
Effect::new(move || {
let safe: SafeAreaInsets = safe_sig.get();
let box_size: Size = vp_sig.get();
let depth_z: f32 = zoom_sig.get();
if !fs_open.get_untracked() {
return;
}
let fs_lay: FullscreenSafeLayout =
resolve_fullscreen_safe_layout(box_size, safe);
let fs_head: Edges = fs_lay.get_header_padding();
let fs_body: Edges = fs_lay.get_body_padding();
let next_w: f32 =
(box_size.get_width() - fs_body.get_left() - fs_body.get_right())
.max(modal_base_min_w)
* depth_z;
let next_h: f32 =
(box_size.get_height() - 56.0 - fs_head.get_top() - fs_body.get_bottom())
.max(modal_base_min_h)
* depth_z;
let pct_label: String = format!("{}%", (depth_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(item_count) = tree.get_node_mut(top_bar_node) {
item_count
.get_mut_style()
.get_mut_layout()
.set_padding(fs_head);
tree.mark_dirty(top_bar_node, dirty_l | DIRTY_PAINT);
}
if let Some(node_entry) = tree.get_node_mut(body_host_node) {
node_entry.get_mut_style().get_mut_layout().set_padding(
Edges::new(
SPACE_XS,
fs_body.get_right(),
fs_body.get_bottom(),
fs_body.get_left(),
),
);
tree.mark_dirty(body_host_node, dirty_l | DIRTY_PAINT);
}
if let Some(normal_vec) = tree.get_node_mut(modal_canvas) {
let lay: &mut LayoutStyle =
normal_vec.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 header_row: NodeId = NodeId::default();
let mut title_col: NodeId = NodeId::default();
let mut title_txt_node: NodeId = NodeId::default();
let mut subtext_txt_node: NodeId = NodeId::default();
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 init_title_vis: Display = if init_title_text.is_empty() {
Display::None
} else {
Display::Flex
};
let init_subtext_vis: Display = if init_subtext.is_empty() {
Display::None
} else {
Display::Flex
};
let init_header_justify: JustifyContent = if init_has_title {
JustifyContent::SpaceBetween
} else {
JustifyContent::End
};
let outer_style: Style = style! {
Width(width)
Background(palette.get_card())
Border::new(geometry.get_border_width(), palette.get_border())
Radius(geometry.get_radius_lg())
Overflow::Hidden
}
.with_overrides(outer_overrides);
let row_style: Style = style! {
Width(Length::Percent(100.0))
if has_header { Display::Flex } else { Display::None }
init_header_justify
AlignItems::Center
Padding(Edges::new(SPACE_SM, SPACE_MD, SPACE_XS, SPACE_MD))
Gap(SPACE_SM)
Overflow::Hidden
};
let column_style: Style = style! {
if init_has_title { Display::Flex } else { Display::None }
FlexGrow(1.0)
FlexShrink(1.0)
MinWidth(Length::Px(0.0))
JustifyContent::Center
Gap(2.0)
Overflow::Hidden
};
let text_style: Style = style! {
Width(Length::Percent(100.0))
init_title_vis
FontSize(13.5)
FontWeight::SemiBold
TextColor(palette.get_foreground())
init_title_align
Overflow::Hidden
TextOverflow::Ellipsis
};
let text_secondary_style: Style = style! {
Width(Length::Percent(100.0))
init_subtext_vis
FontSize(11.0)
TextColor(palette.get_muted_foreground())
init_title_align
Overflow::Hidden
TextOverflow::Ellipsis
};
let row_secondary_style: Style = style! {
if show_toolbox { Display::Flex } else { Display::None }
FlexShrink(0.0)
AlignItems::Center
Gap(SPACE_XS)
};
let scroll_style: Style = style! {
inline_scroll_st
Width(Length::Percent(100.0))
};
let canvas_style: Style = style! {
Width(Length::Percent(100.0))
MinWidth(Length::Px(min_content_sz.get_width()))
Height(height)
MinHeight(Length::Px(min_content_sz.get_height()))
FlexShrink(0.0)
if interactive { CursorIcon::Pointer } else { CursorIcon::Default }
};
let column_secondary_style: Style = style! {
Width(Length::Percent(100.0))
};
let portal_style: Style = style! {
FlexDirection::Column
Display::None
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))
JustifyContent::Start
AlignItems::Stretch
Background(palette.get_card())
Border::new(0.0, COLOR_TRANSPARENT)
Radius(0.0)
Overflow::Hidden
PointerEvents::None
StopScrollPropagation(true)
StopEventPropagation(true)
ZIndex(Z_INDEX_FULLSCREEN)
};
let root: NodeId = view! {
column {
style: outer_style
row {
node_ref: header_row
style: row_style
column {
node_ref: title_col
style: column_style
text {
node_ref: title_txt_node
style: text_style
{ init_title_text }
}
text {
node_ref: subtext_txt_node
style: text_secondary_style
{ init_subtext }
}
}
row {
node_ref: toolbox_row
style: row_secondary_style
}
}
scroll {
node_ref: chart_scroll
style: scroll_style
canvas {
node_ref: chart_canvas
caching: CanvasCaching::RetainedStatic
style: canvas_style
painter: paint_inline
}
}
column {
style: column_secondary_style
bind_children: build_data_view
}
portal {
node_ref: fs_portal
style: portal_style
}
}
};
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);
});
if has_data_zoom {
let portal_zoom_cb: Option<Rc<dyn Fn(f32, f32)>> = on_zoom_change.clone();
let portal_scene: SceneHandle = ctx.get_scene().clone();
ctx.on_scroll(fs_portal, move |ui_event: &UiEvent| {
if !fs_open.get_untracked() {
return;
}
let UiEventKind::Scroll(delta) = ui_event.get_kind() else {
return;
};
if delta.get_x().abs() <= delta.get_y().abs() || delta.get_x().abs() < 1e-4 {
return;
}
let vp_w: f32 = portal_scene.with_read(
|tree: &SceneTree| {
tree.node_screen_bounds(fs_portal)
.map(|region_bounds: Rect| region_bounds.get_width())
.filter(|span_width: &f32| *span_width > 32.0)
.unwrap_or(480.0)
},
480.0,
);
let mut out_range: Option<(f32, f32)> = None;
let _: bool = {
if let Some(mut updated_value) = state_sig.try_get_untracked() {
{
let node_style_primary: &mut EuvChartState = &mut updated_value;
let span: f32 = node_style_primary.get_zoom_end_pct()
- node_style_primary.get_zoom_start_pct();
if span < 99.9 {
let delta_pct: f32 = (delta.get_x() / vp_w) * span;
if node_style_primary.pan_by_pct(delta_pct) {
out_range = Some((
node_style_primary.get_zoom_start_pct(),
node_style_primary.get_zoom_end_pct(),
));
}
}
}
state_sig.set(updated_value)
} else {
false
}
};
if let Some((lo, hi)) = out_range
&& let Some(handler_cb) = portal_zoom_cb.as_ref()
{
handler_cb(lo, hi);
}
});
}
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 {
let mut inline_wiring: ChartPointerWiring = ChartPointerWiring::new(
chart_canvas,
state_sig,
hover_pos_sig,
last_render,
last_bounds,
drag_state,
static_opt_rc,
);
let _: &mut ChartPointerWiring = inline_wiring
.set_opt_sig(opt_sig_opt)
.set_on_point_click(on_point_click.clone())
.set_on_legend_change(on_legend_change.clone())
.set_on_zoom_change(on_zoom_change.clone())
.set_enable_drag(has_data_zoom);
wire_chart_pointer_events(&mut ctx, inline_wiring);
}
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 prev_dv_open: Cell<bool> = Cell::new(false);
let mounted_st_effect: Cell<bool> = Cell::new(false);
let _: Effect = Effect::new(move || {
let st_now: EuvChartState = state_sig.get();
let dv_open: bool = st_now.get_data_view_open();
if !mounted_st_effect.replace(true) {
prev_dv_open.set(dv_open);
return;
}
if prev_dv_open.replace(dv_open) != dv_open {
let next_disp: Display = if dv_open {
Display::None
} else {
Display::Flex
};
scene_st.with_write(
|tree: &mut SceneTree| {
if let Some(total_len) = tree.get_node_mut(chart_scroll) {
total_len
.get_mut_style()
.get_mut_layout()
.set_display(next_disp);
}
let mut dirty_root: u16 = DIRTY_LAYOUT | DIRTY_SUBTREE_LAYOUT;
dirty_root |= DIRTY_PAINT;
tree.mark_dirty(root, dirty_root);
},
(),
);
}
scene_st.mark_dirty(chart_canvas, DIRTY_PAINT);
});
let scene_theme: SceneHandle = scene_dirty.clone();
let prev_theme_key: Cell<ThemeKey> = Cell::new(tokens.key());
let _: Effect = Effect::new(move || {
let live_tok: ThemeTokens = use_live_tokens(base_tokens);
let next_key: ThemeKey = live_tok.key();
if prev_theme_key.replace(next_key) == next_key {
return;
}
let live_p: ThemePalette = live_tok.get_palette();
scene_theme.with_write(
|tree: &mut SceneTree| {
if let Some(item_count_primary) = tree.get_node_mut(title_txt_node) {
item_count_primary
.get_mut_style()
.get_mut_text()
.set_color(live_p.get_foreground());
tree.mark_dirty(title_txt_node, DIRTY_PAINT);
}
if let Some(item_count_secondary) = tree.get_node_mut(subtext_txt_node) {
item_count_secondary
.get_mut_style()
.get_mut_text()
.set_color(live_p.get_muted_foreground());
tree.mark_dirty(subtext_txt_node, DIRTY_PAINT);
}
tree.mark_dirty(chart_canvas, DIRTY_PAINT);
},
(),
);
});
if let Some(sig) = opt_sig_opt {
let scene_opt: SceneHandle = scene_dirty.clone();
let mounted_opt_effect: Cell<bool> = Cell::new(false);
let _: Effect = Effect::new(move || {
let cur_opt: EuvChartOption = sig.get();
if !mounted_opt_effect.replace(true) {
return;
}
let next_min: Size = compute_chart_min_content_size(&cur_opt);
let next_show_tb: bool =
cur_opt.toolbox_opt().is_some_and(EuvChartToolbox::get_show);
let (next_title, next_sub, next_align, next_has_title): (
String,
String,
TextAlign,
bool,
) = resolve_chart_header_meta(&cur_opt);
let next_has_header: bool = next_has_title || next_show_tb;
rev_watch.set(rev_watch.get().wrapping_add(1));
scene_opt.with_write(
|tree: &mut SceneTree| {
let dirty_l: u16 = DIRTY_LAYOUT | DIRTY_SUBTREE_LAYOUT;
if let Some(item_count_next) = tree.get_node_mut(header_row) {
let lay: &mut LayoutStyle =
item_count_next.get_mut_style().get_mut_layout();
lay.set_display(if next_has_header {
Display::Flex
} else {
Display::None
})
.set_justify_content(
if next_has_title {
JustifyContent::SpaceBetween
} else {
JustifyContent::End
},
);
tree.mark_dirty(header_row, dirty_l | DIRTY_PAINT);
}
if let Some(item_count_alt) = tree.get_node_mut(title_col) {
item_count_alt.get_mut_style().get_mut_layout().set_display(
if next_has_title {
Display::Flex
} else {
Display::None
},
);
tree.mark_dirty(title_col, dirty_l | DIRTY_PAINT);
}
if let Some(item_count_inner) = tree.get_node_mut(title_txt_node) {
let computed_style_primary: &mut Style =
item_count_inner.get_mut_style();
computed_style_primary.get_mut_layout().set_display(
if next_title.is_empty() {
Display::None
} else {
Display::Flex
},
);
computed_style_primary.get_mut_text().set_align(next_align);
}
tree.set_text(title_txt_node, next_title);
if let Some(item_count_local) = tree.get_node_mut(subtext_txt_node) {
let computed_style_secondary: &mut Style =
item_count_local.get_mut_style();
computed_style_secondary.get_mut_layout().set_display(
if next_sub.is_empty() {
Display::None
} else {
Display::Flex
},
);
computed_style_secondary
.get_mut_text()
.set_align(next_align);
}
tree.set_text(subtext_txt_node, next_sub);
if let Some(item_count_cur) = tree.get_node_mut(chart_canvas) {
item_count_cur
.get_mut_style()
.get_mut_layout()
.set_min_width(Length::Px(next_min.get_width()))
.set_min_height(Length::Px(next_min.get_height()));
}
tree.mark_dirty(chart_canvas, dirty_l | DIRTY_PAINT);
},
(),
);
});
}
let vp_sig: Signal<Size> = ctx_build.get_viewport_size();
let scene_vp: SceneHandle = scene_fs.clone();
let _: Effect = Effect::new(move || {
let viewport_size: Size = vp_sig.get();
if !fs_open.get() {
return;
}
let vw: f32 = viewport_size.get_width().max(1.0);
let vh: f32 = viewport_size.get_height().max(1.0);
scene_vp.with_write(
|scene_tree: &mut SceneTree| {
if let Some(item_count_slot) = scene_tree.get_node_mut(fs_portal) {
item_count_slot
.get_mut_style()
.get_mut_layout()
.set_width(Length::Px(vw))
.set_height(Length::Px(vh));
let dirty_l: u16 = DIRTY_LAYOUT | DIRTY_SUBTREE_LAYOUT;
scene_tree.mark_dirty(fs_portal, dirty_l | DIRTY_PAINT);
notify_frame_needed();
}
},
(),
);
});
let in_enter_guard: Rc<Cell<bool>> = Rc::new(Cell::new(false));
let global_fs_sig: Signal<bool> = use_fullscreen_active();
let ctx_fs_sig: Signal<bool> = ctx_build.immersive_fullscreen_signal();
let saw_global_fs: Rc<Cell<bool>> = Rc::new(Cell::new(false));
let saw_ctx_fs: Rc<Cell<bool>> = Rc::new(Cell::new(false));
let saw_global_reset: Rc<Cell<bool>> = Rc::clone(&saw_global_fs);
let saw_ctx_reset: Rc<Cell<bool>> = Rc::clone(&saw_ctx_fs);
let fs_acquired_sync: Rc<Cell<bool>> = Rc::clone(&fs_acquired);
let enter_guard_sync: Rc<Cell<bool>> = Rc::clone(&in_enter_guard);
let _: Effect = Effect::new(move || {
let g_active: bool = global_fs_sig.get();
let c_active: bool = ctx_fs_sig.get();
if enter_guard_sync.get() {
if g_active {
saw_global_fs.set(true);
}
if c_active {
saw_ctx_fs.set(true);
}
return;
}
if !fs_acquired_sync.get() {
saw_global_fs.set(false);
saw_ctx_fs.set(false);
return;
}
if g_active {
saw_global_fs.set(true);
}
if c_active {
saw_ctx_fs.set(true);
}
let external_exit: bool =
(saw_global_fs.get() && !g_active) || (saw_ctx_fs.get() && !c_active);
if external_exit {
let _: bool = fs_open.set_if_changed(false);
}
});
Effect::new(move || {
let is_open: bool = fs_open.get();
if is_open == prev_open.replace(is_open) {
return;
}
if is_open {
in_enter_guard.set(true);
saw_global_reset.set(false);
saw_ctx_reset.set(false);
let live_bg: Color =
live_tokens_untracked(base_tokens).get_palette().get_card();
let vp_now: Size = vp_sig.get_untracked();
let vw: f32 = vp_now.get_width().max(1.0);
let vh: f32 = vp_now.get_height().max(1.0);
let panel: NodeId = with_context(ctx_build.clone(), &build_fs_panel);
let portal_shown: bool = panel != NodeId::default()
&& scene_fs.with_write(
|tree: &mut SceneTree| {
if tree.get_node(fs_portal).is_none()
|| tree.get_node(panel).is_none()
{
return false;
}
tree.cancel_subtree_transitions(fs_portal);
tree.replace_children(fs_portal, vec![panel]);
if let Some(item_count_2) = tree.get_node_mut(fs_portal) {
let computed_style_next: &mut Style =
item_count_2.get_mut_style();
computed_style_next
.get_mut_layout()
.set_display(Display::Flex)
.set_width(Length::Px(vw))
.set_height(Length::Px(vh));
computed_style_next
.get_mut_paint()
.set_background(Some(live_bg))
.set_pointer_events(PointerEvents::Auto)
.set_opacity(1.0)
.set_transform(Transform2D::default());
}
let dirty_l: u16 = DIRTY_LAYOUT | DIRTY_SUBTREE_LAYOUT;
tree.mark_dirty(fs_portal, dirty_l | DIRTY_PAINT);
notify_frame_needed();
true
},
false,
);
let entered: bool = portal_shown
&& (fs_acquired.get()
|| enter_fullscreen_for_portal(&ctx_build, fs_portal));
if entered {
fs_acquired.set(true);
} else {
scene_fs.dismiss_portal_immediate(fs_portal);
if fs_acquired.replace(false) {
exit_fullscreen();
}
prev_open.set(false);
let _: bool = fs_open.set_if_changed(false);
}
in_enter_guard.set(false);
notify_frame_needed();
} else {
in_enter_guard.set(false);
if fs_acquired.replace(false) {
exit_fullscreen();
}
scene_fs.dismiss_portal_immediate(fs_portal);
}
})
});
ctx.get_scene().with_write(
|tree: &mut SceneTree| {
tree.attach_scope(root, scope);
},
(),
);
root
}
}