Skip to content

Commit 148dc90

Browse files
authored
Merge pull request #8 from openmc-data-storage/moving-buttons
Moving buttons
2 parents 0ad9419 + de4aa20 commit 148dc90

File tree

1 file changed

+49
-41
lines changed

1 file changed

+49
-41
lines changed

src/sauce/home.rs

Lines changed: 49 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,16 @@ pub struct XsCache {
3333
#[derive(Properties, PartialEq)]
3434
pub struct PlotProps {
3535
pub selected_indexes: HashSet<usize>,
36+
pub is_y_log: UseStateHandle<bool>,
37+
pub is_x_log: UseStateHandle<bool>,
3638
pub clear_plot_callback: Callback<MouseEvent>,
3739
}
3840

39-
#[function_component(App)]
41+
#[function_component(PlotComponent)]
4042
pub fn plot_component(props: &PlotProps) -> Html {
4143
let selected_indexes = &props.selected_indexes;
42-
let is_y_log = use_state(|| true);
43-
let is_x_log = use_state(|| true);
44+
let is_y_log = props.is_y_log.clone();
45+
let is_x_log = props.is_x_log.clone();
4446

4547
let p = use_async::<_, _, ()>({
4648
let selected_indexes = selected_indexes.clone();
@@ -110,45 +112,10 @@ pub fn plot_component(props: &PlotProps) -> Html {
110112
p.run();
111113
});
112114

113-
let onclick_toggle_y_log = {
114-
let is_y_log = is_y_log.clone();
115-
Callback::from(move |_| {
116-
is_y_log.set(!*is_y_log);
117-
})
118-
};
119-
120-
let onclick_toggle_x_log = {
121-
let is_x_log = is_x_log.clone();
122-
Callback::from(move |_| {
123-
is_x_log.set(!*is_x_log);
124-
})
125-
};
126-
127115
html! {
128116
<div style="text-align: center;">
129117
<div class="d-flex mb-2">
130118

131-
<button
132-
onclick={onclick_toggle_y_log}
133-
class="btn btn-primary me-2"
134-
>
135-
{if *is_y_log { "Switch Y to Linear Scale" } else { "Switch Y to Log Scale" }}
136-
</button>
137-
138-
<button
139-
onclick={onclick_toggle_x_log}
140-
class="btn btn-primary me-2"
141-
>
142-
{if *is_x_log { "Switch X to Linear Scale" } else { "Switch X to Log Scale" }}
143-
</button>
144-
145-
<button
146-
onclick={props.clear_plot_callback.clone()} // <-- Add this button
147-
class="btn btn-primary me-2"
148-
>
149-
{ "Clear Plot" }
150-
</button>
151-
152119
</div>
153120
<div id="plot-div"></div>
154121
</div>
@@ -242,6 +209,23 @@ pub fn home() -> Html {
242209
let selected_indexes = use_set(HashSet::<usize>::new());
243210
let sum = selected_indexes.current().len();
244211

212+
let is_y_log = use_state(|| true);
213+
let is_x_log = use_state(|| true);
214+
215+
let onclick_toggle_y_log = {
216+
let is_y_log = is_y_log.clone();
217+
Callback::from(move |_| {
218+
is_y_log.set(!*is_y_log);
219+
})
220+
};
221+
222+
let onclick_toggle_x_log = {
223+
let is_x_log = is_x_log.clone();
224+
Callback::from(move |_| {
225+
is_x_log.set(!*is_x_log);
226+
})
227+
};
228+
245229
let columns = vec![
246230
ColumnBuilder::new("select").orderable(true).short_name("Select").data_property("select").header_class("user-select-none").build(),
247231
// ColumnBuilder::new("id").orderable(true).short_name("ID").data_property("id").header_class("user-select-none").build(),
@@ -491,7 +475,29 @@ pub fn home() -> Html {
491475
</div>
492476
</div>
493477

494-
478+
<div class="d-flex mb-2 justify-content-center">
479+
<button
480+
onclick={clear_plot_callback.clone()}
481+
class="btn btn-primary me-2"
482+
>
483+
{ "Clear Plot" }
484+
</button>
485+
486+
<button
487+
onclick={onclick_toggle_x_log}
488+
class="btn btn-primary me-2"
489+
>
490+
{if *is_x_log { "Switch X to Linear Scale" } else { "Switch X to Log Scale" }}
491+
</button>
492+
493+
<button
494+
onclick={onclick_toggle_y_log}
495+
class="btn btn-primary me-2"
496+
>
497+
{if *is_y_log { "Switch Y to Linear Scale" } else { "Switch Y to Log Scale" }}
498+
</button>
499+
</div>
500+
495501
<div class="d-flex mb-2">
496502
<div class="flex-grow-1 p-2 input-group me-2">
497503
<Table<TableLine>
@@ -516,9 +522,11 @@ pub fn home() -> Html {
516522
// on_page={Some(handle_page)}
517523
// />
518524
<div class="flex-grow-1" style="width: 100%;">
519-
<App
525+
<PlotComponent
520526
selected_indexes={(*selected_indexes.current()).clone()}
521-
clear_plot_callback={clear_plot_callback}
527+
is_y_log={is_y_log.clone()}
528+
is_x_log={is_x_log.clone()}
529+
clear_plot_callback={clear_plot_callback.clone()}
522530
/>
523531
</div>
524532
// <h5>{"Created by Jon Shimwell, source code available "}</h5>

0 commit comments

Comments
 (0)