Skip to content

Commit

Permalink
improving the graph
Browse files Browse the repository at this point in the history
  • Loading branch information
wbaccinelli committed Apr 5, 2024
1 parent 2c33cad commit 69fc6f3
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
6 changes: 4 additions & 2 deletions eit_dash/callbacks/load_callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down Expand Up @@ -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]
Expand Down
5 changes: 3 additions & 2 deletions eit_dash/callbacks/preprocessing_callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
18 changes: 17 additions & 1 deletion eit_dash/utils/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@ 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.
Args:
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()
Expand Down Expand Up @@ -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


Expand Down Expand Up @@ -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]
Expand Down

0 comments on commit 69fc6f3

Please sign in to comment.