From 69fc6f38125e91b18e10f1f4c200e72e4b0271db Mon Sep 17 00:00:00 2001 From: Walter Baccinelli Date: Fri, 5 Apr 2024 09:05:40 +0200 Subject: [PATCH] improving the graph --- eit_dash/callbacks/load_callbacks.py | 6 ++++-- eit_dash/callbacks/preprocessing_callbacks.py | 5 +++-- eit_dash/utils/common.py | 18 +++++++++++++++++- 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/eit_dash/callbacks/load_callbacks.py b/eit_dash/callbacks/load_callbacks.py index 015dbcc..5c34037 100644 --- a/eit_dash/callbacks/load_callbacks.py +++ b/eit_dash/callbacks/load_callbacks.py @@ -161,6 +161,7 @@ def open_data_selector(data, cancel_load, sig, file_type, fig): file_data, ["raw"], [continuous_datum for continuous_datum in file_data.continuous_data], + True, ) ok = ["raw"] @@ -198,12 +199,13 @@ def show_info( ): """Creates the preview for preselecting part of the dataset.""" if file_data: + # get the first and last sample selected in the slidebar if slidebar_stat is not None: - # TODO: the following is used also in preprocessing. Refactor to avoid duplications start_sample, stop_sample = get_selections_slidebar(slidebar_stat) - if not start_sample or not stop_sample: + if not start_sample: start_sample = file_data.eit_data["raw"].time[0] + if not stop_sample: stop_sample = file_data.eit_data["raw"].time[-1] else: start_sample = file_data.eit_data["raw"].time[0] diff --git a/eit_dash/callbacks/preprocessing_callbacks.py b/eit_dash/callbacks/preprocessing_callbacks.py index 448e1f3..729cabb 100644 --- a/eit_dash/callbacks/preprocessing_callbacks.py +++ b/eit_dash/callbacks/preprocessing_callbacks.py @@ -358,12 +358,13 @@ def select_period( ): """Mark the selected period in the graph and save it.""" data = data_object.get_sequence_at(int(dataset)) - + # get the first and last sample selected in the slidebar if slidebar_stat is not None: start_sample, stop_sample = get_selections_slidebar(slidebar_stat) - if not start_sample or not stop_sample: + if not start_sample: start_sample = data.time[0] + if not stop_sample: stop_sample = data.time[-1] else: start_sample = data.time[0] diff --git a/eit_dash/utils/common.py b/eit_dash/utils/common.py index 67768b0..069428c 100644 --- a/eit_dash/utils/common.py +++ b/eit_dash/utils/common.py @@ -21,6 +21,7 @@ def create_slider_figure( dataset: Sequence, eit_variants: list[str] | None = None, continuous_data: list[str] | None = None, + clickable_legend: bool = False, ) -> go.Figure: """Create the figure for the selection of range. @@ -28,6 +29,7 @@ def create_slider_figure( dataset: Sequence object containing the selected dataset eit_variants: list of the eit variants to be plotted continuous_data: list of the continuous data signals to be plotted + clickable_legend: if True, the user can hide a signal by clicking on the legend """ figure = go.Figure() params = dict() @@ -89,10 +91,14 @@ def create_slider_figure( figure.update_layout( xaxis={"rangeslider": {"visible": True}}, margin={"t": 0, "l": 0, "b": 0, "r": 0}, - legend={"itemclick": False, "itemdoubleclick": False}, **params, ) + # itemclick is a toggable element, so it can only be deactivated, and it is not possible + # to set it to True + if not clickable_legend: + figure.update_layout(legend={"itemclick": False, "itemdoubleclick": False}) + return figure @@ -168,6 +174,16 @@ def get_signal_options( def get_selections_slidebar(slidebar_stat: dict) -> tuple: + """Given the layout data of a graph slidebar, it returns the first + and the last sample selected. + + Args: + slidebar_stat: Layout data of a graph slidebar. + Returns: + A tuple where the first value is the starting sample and the second value is the + end sample. If a sample cannot be determined, None is returned. + """ + if "xaxis.range" in slidebar_stat: start_sample = slidebar_stat["xaxis.range"][0] stop_sample = slidebar_stat["xaxis.range"][1]