Skip to content

Commit 79ad11f

Browse files
authored
Merge pull request #468 from mangalap123/develop
Moved the legend to the bottom of the chart #465.
2 parents 029bd80 + dde6995 commit 79ad11f

File tree

3 files changed

+43
-25
lines changed

3 files changed

+43
-25
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,4 @@ devel.ipynb
2626

2727
# build artifacts
2828
results/
29+
runtime.txt

runtime.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
python-3.7.2
1+
python-3.7.7
22

src/penn_chime/charts.py

Lines changed: 41 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
from datetime import datetime
32
from math import ceil
43
from typing import Dict, Optional
@@ -12,10 +11,7 @@
1211

1312

1413
def build_admits_chart(
15-
*,
16-
alt,
17-
admits_floor_df: pd.DataFrame,
18-
max_y_axis: Optional[int] = None,
14+
*, alt, admits_floor_df: pd.DataFrame, max_y_axis: Optional[int] = None
1915
) -> Chart:
2016
"""Build admits chart."""
2117
y_scale = alt.Scale()
@@ -25,14 +21,26 @@ def build_admits_chart(
2521
x = dict(shorthand="date:T", title="Date", axis=alt.Axis(format=(DATE_FORMAT)))
2622
y = dict(shorthand="value:Q", title="Daily admissions", scale=y_scale)
2723
color = "key:N"
28-
tooltip=["date:T", alt.Tooltip("value:Q", format=".0f", title="Admit"), "key:N"]
24+
tooltip = ["date:T", alt.Tooltip("value:Q", format=".0f", title="Admit"), "key:N"]
2925

3026
# TODO fix the fold to allow any number of dispositions
3127
points = (
3228
alt.Chart()
3329
.transform_fold(fold=["hospitalized", "icu", "ventilated"])
3430
.encode(x=alt.X(**x), y=alt.Y(**y), color=color, tooltip=tooltip)
3531
.mark_line(point=True)
32+
.encode(
33+
x=alt.X(**x_kwargs),
34+
y=alt.Y("value:Q", title="Daily admissions", scale=y_scale),
35+
color="key:N",
36+
tooltip=[
37+
tooltip_dict[as_date],
38+
alt.Tooltip("value:Q", format=".0f", title="Admissions"),
39+
"key:N",
40+
],
41+
)
42+
.configure_legend(orient="bottom")
43+
.interactive()
3644
)
3745
bar = (
3846
alt.Chart()
@@ -43,12 +51,8 @@ def build_admits_chart(
4351
return alt.layer(points, bar, data=admits_floor_df)
4452

4553

46-
4754
def build_census_chart(
48-
*,
49-
alt,
50-
census_floor_df: pd.DataFrame,
51-
max_y_axis: Optional[int] = None,
55+
*, alt, census_floor_df: pd.DataFrame, max_y_axis: Optional[int] = None
5256
) -> Chart:
5357
"""Build census chart."""
5458
y_scale = alt.Scale()
@@ -66,6 +70,18 @@ def build_census_chart(
6670
.transform_fold(fold=["hospitalized", "icu", "ventilated"])
6771
.encode(x=alt.X(**x), y=alt.Y(**y), color=color, tooltip=tooltip)
6872
.mark_line(point=True)
73+
.encode(
74+
x=alt.X(**x_kwargs),
75+
y=alt.Y("value:Q", title="Census", scale=y_scale),
76+
color="key:N",
77+
tooltip=[
78+
idx,
79+
alt.Tooltip("value:Q", format=".0f", title="Census"),
80+
"key:N",
81+
],
82+
)
83+
.configure_legend(orient="bottom")
84+
.interactive()
6985
)
7086
bar = (
7187
alt.Chart()
@@ -77,10 +93,7 @@ def build_census_chart(
7793

7894

7995
def build_sim_sir_w_date_chart(
80-
*,
81-
alt,
82-
sim_sir_w_date_floor_df: pd.DataFrame,
83-
max_y_axis: Optional[int] = None,
96+
*, alt, sim_sir_w_date_floor_df: pd.DataFrame, max_y_axis: Optional[int] = None
8497
) -> Chart:
8598
"""Build sim sir w date chart."""
8699
y_scale = alt.Scale()
@@ -98,6 +111,14 @@ def build_sim_sir_w_date_chart(
98111
.transform_fold(fold=["susceptible", "infected", "recovered"])
99112
.encode(x=alt.X(**x), y=alt.Y(**y), color=color, tooltip=tooltip)
100113
.mark_line()
114+
.encode(
115+
x=alt.X(**x_kwargs),
116+
y=alt.Y("value:Q", title="Case Volume", scale=y_scale),
117+
tooltip=["key:N", "value:Q"],
118+
color="key:N",
119+
)
120+
.configure_legend(orient="bottom")
121+
.interactive()
101122
)
102123
bar = (
103124
alt.Chart()
@@ -109,10 +130,7 @@ def build_sim_sir_w_date_chart(
109130

110131

111132
def build_descriptions(
112-
*,
113-
chart: Chart,
114-
labels: Dict[str, str],
115-
suffix: str = ""
133+
*, chart: Chart, labels: Dict[str, str], suffix: str = ""
116134
) -> str:
117135
"""
118136
@@ -146,15 +164,14 @@ def build_descriptions(
146164
)
147165

148166
if asterisk:
149-
messages.append("_* The max is at the upper bound of the data, and therefore may not be the actual max_")
167+
messages.append(
168+
"_* The max is at the upper bound of the data, and therefore may not be the actual max_"
169+
)
150170
return "\n\n".join(messages)
151171

152172

153173
def build_table(
154-
*,
155-
df: pd.DataFrame,
156-
labels: Dict[str, str],
157-
modulo: int = 1,
174+
*, df: pd.DataFrame, labels: Dict[str, str], modulo: int = 1
158175
) -> pd.DataFrame:
159176
table_df = df[np.mod(df.day, modulo) == 0].copy()
160177
table_df.date = table_df.date.dt.strftime(DATE_FORMAT)

0 commit comments

Comments
 (0)