Skip to content

Commit 1044461

Browse files
authored
Merge pull request #26 from cognizant-ai-labs/fix-timeline
Fix timeline and slider reset
2 parents 22ceb1c + 5a2d1a6 commit 1044461

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

app/components/context.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -234,11 +234,18 @@ def enable_button(_):
234234
def select_ssp_dropdown(value):
235235
"""
236236
When we select a dropdown value, update the sliders.
237+
If we clear the dropdown, reset the sliders to the default values.
237238
"""
238-
scenario = f"{value}-Baseline"
239-
row = self.context_df[self.context_df["scenario"] == scenario].iloc[0]
240239
input_specs = load_input_specs()
241-
return [row[id_to_varid(self.context[i], input_specs)] for i in range(4)]
240+
241+
# If the value is a scenario, find the corresponding row in context_df.
242+
scenario = f"{value}-Baseline"
243+
if scenario in self.context_df["scenario"].unique():
244+
row = self.context_df[self.context_df["scenario"] == scenario].iloc[0]
245+
return [row[id_to_varid(self.context[i], input_specs)] for i in range(4)]
246+
247+
# Default case: if the scenario is not found just get the default values
248+
return [input_specs[input_specs["id"] == self.context[i]]["defaultValue"].iloc[0] for i in range(4)]
242249

243250
@app.callback(
244251
Output("ssp-dropdown", "value", allow_duplicate=True),

app/components/timeline.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ def _create_timeline_events(self,
4444
Returns a dict with the year as the key and the event as the value.
4545
"""
4646
# Parse details into ids instead of varids
47+
details = dict(details.items())
4748
if "start" in details:
4849
details["start"] = varid_to_id(details["start"], self.input_specs)
4950
if "stop" in details:

0 commit comments

Comments
 (0)