From 9777b9608cbb8e960d6e9e72c8598e892407c8e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christopher=20K=C3=B6rber?= Date: Thu, 11 Nov 2021 11:28:14 +0100 Subject: [PATCH] Added an additional attribute to prevent showing the texed latex expression for the fit function This closes #39 --- lsqfitgui/frontend/content.py | 9 +++++++-- lsqfitgui/frontend/dashboard.py | 8 +++++++- lsqfitgui/lsqfitgui.py | 6 ++++++ 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/lsqfitgui/frontend/content.py b/lsqfitgui/frontend/content.py index 6a8bf03..b507007 100644 --- a/lsqfitgui/frontend/content.py +++ b/lsqfitgui/frontend/content.py @@ -17,6 +17,7 @@ def document_function( fcn: Callable, parameters: Optional[Dict] = None, x_dict_keys: Optional[List[str]] = None, + tex_function: bool = True, ) -> List[html.Base]: """Documents the function.""" documentation = [] @@ -42,7 +43,7 @@ def document_function( html.Pre(get_entrypoint_string() + "\n" + get_version_string()) ) - if parameters: + if parameters and tex_function: tex = parse_function_expression(fcn, parameters, x_dict_keys=x_dict_keys) if tex: documentation.append(html.P(fr"$${tex}$$")) @@ -135,7 +136,10 @@ def get_figures(fit, plots: Optional[List[Dict[str, Any]]] = None): def get_content( - fit, name: str = "Lsqfit GUI", plots: Optional[List[Dict[str, Any]]] = None, + fit, + name: str = "Lsqfit GUI", + plots: Optional[List[Dict[str, Any]]] = None, + tex_function: bool = True, ): """Create default content block for fit object. @@ -156,6 +160,7 @@ def get_content( x_dict_keys=list(fit.x.keys()) if isinstance(fit.x, dict) else None, + tex_function=tex_function, ) ), html.H4("Fit parameters"), diff --git a/lsqfitgui/frontend/dashboard.py b/lsqfitgui/frontend/dashboard.py index d6182c4..840f8eb 100644 --- a/lsqfitgui/frontend/dashboard.py +++ b/lsqfitgui/frontend/dashboard.py @@ -34,6 +34,7 @@ def get_layout( use_default_content: Optional[bool] = True, get_additional_content: Optional[Callable[[nonlinear_fit], html.Base]] = None, plots: Optional[List[Dict[str, Any]]] = None, + tex_function: bool = True, ) -> html.Div: """Create sidebar and content given fit and config values. @@ -44,11 +45,16 @@ def get_layout( use_default_content: Render default GUI elements or not. get_additional_content: Function to return additional html content given a fit. This should be used for customizations. + tex_function: Try to display latex expression for fit function. """ sidebar = get_sidebar(fit.prior, meta_config=meta_config, meta_values=meta_values) sidebar.className = "sticky-top bg-light p-4" - content = get_content(fit, name=name, plots=plots) if use_default_content else None + content = ( + get_content(fit, name=name, plots=plots, tex_function=tex_function) + if use_default_content + else None + ) additional_content = get_additional_content(fit) if get_additional_content else None layout = html.Div( diff --git a/lsqfitgui/lsqfitgui.py b/lsqfitgui/lsqfitgui.py index 039a643..a7b0470 100644 --- a/lsqfitgui/lsqfitgui.py +++ b/lsqfitgui/lsqfitgui.py @@ -90,6 +90,8 @@ def generate_fit(n_exp=3): self._meta_config = meta_config self._use_default_content = use_default_content self._layout = None + self.tex_function: bool = True + """Try to render the fit function as a latex expression.""" self.get_additional_content: Callable[[nonlinear_fit], html.Base] = None """Function used to determine dynamic content depending on fit results.""" @@ -180,6 +182,7 @@ def layout(self) -> html.Base: use_default_content=self._use_default_content, get_additional_content=self.get_additional_content, plots=self.plots, + tex_function=self.tex_function, ) return self._layout @@ -285,6 +288,7 @@ def run_server( use_default_content: Optional[bool] = True, get_additional_content: Optional[Callable[[nonlinear_fit], html.Base]] = None, additional_plots: Optional[Dict[str, Callable]] = None, + tex_function: bool = True, run_app: bool = True, debug: bool = True, host: str = "localhost", @@ -304,6 +308,7 @@ def run_server( These must match `dcc.Input `_ arguments. use_default_content: Add default elements like the function documentation and plot tabs to the GUI. get_additional_content: Function used to determine dynamic content depending on fit results. + tex_function: Try to render the fit function as latex. additional_plots: List of dictionaries specifying plots rendered in the tab element. Must contain at least the `name: str` and `fcn:Callable[[nonlinear_fit], Figure]` items. This populates :attr:`FitGUI.plots`. @@ -342,6 +347,7 @@ def generate_fit(n_exp=3): use_default_content=use_default_content, ) fit_gui.name = name + fit_gui.tex_function = tex_function fit_gui.get_additional_content = get_additional_content fit_gui.plots += additional_plots or [] fit_gui.setup_app()