Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed axis names for parallel coordinates #19

Merged
merged 1 commit into from
Nov 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions app/components/filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ def __init__(self, metrics: list[str]):
with open("app/units.json", "r", encoding="utf-8") as f:
self.units = json.load(f)

self.names_map = dict(zip(self.metrics, ["Temperature change from 1850",
"Highest cost of energy",
"Government spending",
"Reduction in energy demand"]))

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move names_map into the constructor so we can use it in other functions

def create_metric_sliders(self):
"""
Creates initial metric sliders and lines them up with their labels.
Expand All @@ -48,17 +53,16 @@ def create_metric_sliders(self):
)
sliders.append(slider)

names_map = dict(zip(self.metrics, ["Temperature change from 1850",
"Highest cost of energy",
"Government spending",
"Reduction in energy demand"]))
# w-25 and flex-grow-1 ensures they line up
div = html.Div(
children=[
html.Div(
className="d-flex flex-row mb-2",
children=[
html.Label(f"{names_map[self.metrics[i]]} ({self.units[self.metrics[i]]})", className="w-25"),
html.Label(
f"{self.names_map[self.metrics[i]]} ({self.units[self.metrics[i]]})",
className="w-25"
),
html.Div(sliders[i], className="flex-grow-1")
]
)
Expand All @@ -79,6 +83,7 @@ def plot_parallel_coordinates_line(self,
fig = go.Figure()

normalized_df = filter_metrics_json(metrics_json, metric_ranges, normalize=True)
normalized_df.rename(self.names_map, axis=1, inplace=True)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Simply rename the df before we plot it to fix the axis names


cand_idxs = list(normalized_df.index)[:-1] # Leave out the baseline
n_special_cands = min(10, len(cand_idxs))
Expand Down
Loading