@@ -33,14 +33,16 @@ pub struct XsCache {
3333#[ derive( Properties , PartialEq ) ]
3434pub 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 ) ]
4042pub 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,38 +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-
145119 <button
146120 onclick={ props. clear_plot_callback. clone( ) } // <-- Add this button
147121 class="btn btn-primary me-2"
@@ -242,6 +216,23 @@ pub fn home() -> Html {
242216 let selected_indexes = use_set ( HashSet :: < usize > :: new ( ) ) ;
243217 let sum = selected_indexes. current ( ) . len ( ) ;
244218
219+ let is_y_log = use_state ( || true ) ;
220+ let is_x_log = use_state ( || true ) ;
221+
222+ let onclick_toggle_y_log = {
223+ let is_y_log = is_y_log. clone ( ) ;
224+ Callback :: from ( move |_| {
225+ is_y_log. set ( !* is_y_log) ;
226+ } )
227+ } ;
228+
229+ let onclick_toggle_x_log = {
230+ let is_x_log = is_x_log. clone ( ) ;
231+ Callback :: from ( move |_| {
232+ is_x_log. set ( !* is_x_log) ;
233+ } )
234+ } ;
235+
245236 let columns = vec ! [
246237 ColumnBuilder :: new( "select" ) . orderable( true ) . short_name( "Select" ) . data_property( "select" ) . header_class( "user-select-none" ) . build( ) ,
247238 // ColumnBuilder::new("id").orderable(true).short_name("ID").data_property("id").header_class("user-select-none").build(),
@@ -491,7 +482,20 @@ pub fn home() -> Html {
491482 </div>
492483 </div>
493484
494-
485+ <button
486+ onclick={ onclick_toggle_x_log}
487+ class="btn btn-primary me-2"
488+ >
489+ { if * is_x_log { "Switch X to Linear Scale" } else { "Switch X to Log Scale" } }
490+ </button>
491+
492+ <button
493+ onclick={ onclick_toggle_y_log}
494+ class="btn btn-primary me-2"
495+ >
496+ { if * is_y_log { "Switch Y to Linear Scale" } else { "Switch Y to Log Scale" } }
497+ </button>
498+
495499 <div class="d-flex mb-2" >
496500 <div class="flex-grow-1 p-2 input-group me-2" >
497501 <Table <TableLine >
@@ -516,8 +520,10 @@ pub fn home() -> Html {
516520 // on_page={Some(handle_page)}
517521 // />
518522 <div class="flex-grow-1" style="width: 100%;" >
519- <App
523+ <PlotComponent
520524 selected_indexes={ ( * selected_indexes. current( ) ) . clone( ) }
525+ is_y_log={ is_y_log. clone( ) }
526+ is_x_log={ is_x_log. clone( ) }
521527 clear_plot_callback={ clear_plot_callback}
522528 />
523529 </div>
0 commit comments