Skip to content

Commit d9330a9

Browse files
fix(altair): address review feedback for waterfall-basic
Attempt 1/3 - fixes based on AI review: - Include connectors layer in alt.layer() for connecting lines - Fix image dimensions from 1500x800 to 1600x900 - Use explicit Scale domain for category ordering
1 parent b593cbd commit d9330a9

1 file changed

Lines changed: 10 additions & 10 deletions

File tree

  • plots/waterfall-basic/implementations

plots/waterfall-basic/implementations/altair.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@
7979
range=["#306998", "#2E8B57", "#DC3545"], # Blue for totals, green for positive, red for negative
8080
)
8181

82+
# Explicit x-axis scale with category sort order
83+
x_scale = alt.Scale(domain=categories)
84+
8285
# Create bars
8386
bars = (
8487
alt.Chart(data)
@@ -89,7 +92,7 @@
8992
x=alt.X(
9093
"category:N",
9194
title="Category",
92-
sort=alt.EncodingSortField(field="order", order="ascending"),
95+
scale=x_scale,
9396
axis=alt.Axis(labelAngle=-30, labelFontSize=16, titleFontSize=20),
9497
),
9598
y=alt.Y("start:Q", title="Amount ($)", axis=alt.Axis(labelFontSize=16, titleFontSize=20)),
@@ -111,10 +114,7 @@
111114
alt.Chart(data)
112115
.mark_text(fontSize=14, fontWeight="bold")
113116
.encode(
114-
x=alt.X("category:N", sort=alt.EncodingSortField(field="order", order="ascending")),
115-
y=alt.Y("label_y:Q"),
116-
text=alt.Text("label:N"),
117-
color=alt.value("#333333"),
117+
x=alt.X("category:N", scale=x_scale), y=alt.Y("label_y:Q"), text=alt.Text("label:N"), color=alt.value("#333333")
118118
)
119119
)
120120

@@ -135,15 +135,15 @@
135135
connectors = (
136136
alt.Chart(connector_df)
137137
.mark_rule(color="#666666", strokeWidth=1.5, strokeDash=[4, 4])
138-
.encode(x=alt.X("cat_start:N", sort=categories), x2=alt.X2("cat_end:N"), y=alt.Y("y:Q"))
138+
.encode(x=alt.X("cat_start:N", scale=x_scale), x2=alt.X2("cat_end:N"), y=alt.Y("y:Q"))
139139
)
140140

141-
# Combine chart layers
141+
# Combine chart layers (bars, connectors for cumulative flow, and labels)
142142
chart = (
143-
alt.layer(bars, labels)
143+
alt.layer(bars, connectors, labels)
144144
.properties(
145-
width=1500,
146-
height=800,
145+
width=1600,
146+
height=900,
147147
title=alt.Title(text="Quarterly P&L Breakdown · waterfall-basic · altair · pyplots.ai", fontSize=28),
148148
)
149149
.configure_view(strokeWidth=0)

0 commit comments

Comments
 (0)