Skip to content

Commit

Permalink
Merge pull request #19 from danyoungday/fix-parcoord-axes
Browse files Browse the repository at this point in the history
Fixed axis names for parallel coordinates
  • Loading branch information
danyoungday authored Nov 5, 2024
2 parents 41df439 + ea6ea4c commit 81ba9c8
Showing 1 changed file with 10 additions and 5 deletions.
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"]))

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)

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

0 comments on commit 81ba9c8

Please sign in to comment.