Skip to content

Commit

Permalink
allow custom period naming
Browse files Browse the repository at this point in the history
  • Loading branch information
wbaccinelli committed Apr 9, 2024
1 parent 8c10b3b commit 10656e1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions eit_dash/callbacks/preprocessing_callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,13 +391,13 @@ def select_period(
period_index = data_object.get_stable_periods_list_length()

cut_data = data.select_by_time(
start_time=start_sample, end_time=stop_sample, label=str(period_index)
start_time=start_sample, end_time=stop_sample, label=f"Period {period_index}"
)

data_object.add_stable_period(cut_data, int(dataset))

# TODO: explore Patch https://dash.plotly.com/partial-properties
current_figure = mark_selected_periods(current_figure, [cut_data])
current_figure = mark_selected_periods(current_figure, [cut_data], period_index)

# TODO: refactor to avoid duplications
ok = [options[s]["label"] for s in signals]
Expand Down Expand Up @@ -471,7 +471,7 @@ def remove_period(n_clicks, container, figure):
Removes the card from the results and the period from the saved selections.
"""

# at the element creation time, the update should avoided
# at the element creation time, the update should be avoided
if all(element is None for element in n_clicks):
raise PreventUpdate

Expand All @@ -484,7 +484,7 @@ def remove_period(n_clicks, container, figure):
figure["data"] = [
trace
for trace in figure["data"]
if "meta" not in trace or trace["meta"]["uid"] != input_id
if "meta" not in trace or trace["meta"]["uid"] != int(input_id)
]

results = [card for card in container if f"'index': '{input_id}'" not in str(card)]
Expand Down
8 changes: 4 additions & 4 deletions eit_dash/utils/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,7 @@ def create_slider_figure(


def mark_selected_periods(
original_figure: go.Figure | dict,
periods: List[Sequence],
original_figure: go.Figure | dict, periods: List[Sequence], period_index: int
) -> go.Figure:
"""
Create the figure for the selection of range.
Expand All @@ -113,14 +112,15 @@ def mark_selected_periods(
original_figure: figure to update
periods: list of Sequence object containing the selected dataset.
These ranges, the signal is plotted in black
period_index: index of the selected period
"""
for period in periods:
for eit_variant in period.eit_data:
selected_impedance = go.Scatter(
x=period.eit_data[eit_variant].time,
y=period.eit_data[eit_variant].global_impedance,
name=eit_variant,
meta={"uid": period.label},
meta={"uid": period_index},
line={"color": "black"},
showlegend=False,
).to_plotly_json()
Expand All @@ -135,7 +135,7 @@ def mark_selected_periods(
x=period.continuous_data[cont_signal].time,
y=period.continuous_data[cont_signal].values,
name=cont_signal,
meta={"uid": period.label},
meta={"uid": period_index},
opacity=0.5,
yaxis=f"y{n + 2}",
line={"color": "black"},
Expand Down

0 comments on commit 10656e1

Please sign in to comment.