Skip to content

Commit

Permalink
Added an additional attribute to prevent showing the texed latex expr…
Browse files Browse the repository at this point in the history
…ession for the fit function

This closes #39
  • Loading branch information
ckoerber committed Nov 11, 2021
1 parent c470f31 commit 9777b96
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
9 changes: 7 additions & 2 deletions lsqfitgui/frontend/content.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand All @@ -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}$$"))
Expand Down Expand Up @@ -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.
Expand All @@ -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"),
Expand Down
8 changes: 7 additions & 1 deletion lsqfitgui/frontend/dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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(
Expand Down
6 changes: 6 additions & 0 deletions lsqfitgui/lsqfitgui.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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",
Expand All @@ -304,6 +308,7 @@ def run_server(
These must match `dcc.Input <https://dash.plotly.com/dash-core-components/input#input-properties>`_ 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`.
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 9777b96

Please sign in to comment.