Spaces:
Running
Running
Commit
·
3517474
1
Parent(s):
d414ddf
removed duplicate container width argument. does this fix the wiggling charts?
Browse files- app/utils.py +10 -7
app/utils.py
CHANGED
|
@@ -270,7 +270,8 @@ def area_chart(df, column):
|
|
| 270 |
]
|
| 271 |
)
|
| 272 |
)
|
| 273 |
-
return pie.properties(width="container", height=290)
|
|
|
|
| 274 |
|
| 275 |
|
| 276 |
def bar_chart(df, x, y, title, metric = "percent"):
|
|
@@ -306,8 +307,8 @@ def get_chart_settings(x, y, stacked, metric):
|
|
| 306 |
elif metric == "acres":
|
| 307 |
y_titles = "Acres"
|
| 308 |
|
| 309 |
-
angle = 270 if x in ["manager_type", "ecoregion", "status", "habitat_type", "resilient_connected_network"] else 0
|
| 310 |
-
height = 470 if y == "percent_rarityweighted_endemic_plant_richness" else 250 if stacked else
|
| 311 |
|
| 312 |
return sort_options.get(x, "x"), angle, height, y_titles
|
| 313 |
|
|
@@ -358,7 +359,7 @@ def create_bar_chart(df, x, y, title, metric, color=None, stacked=False, colors=
|
|
| 358 |
sort, angle, height, y_title = get_chart_settings(x, y, stacked, metric)
|
| 359 |
label_transform = get_label_transform(x)
|
| 360 |
y_format = "~s" if metric == "acres" else ",.1%"
|
| 361 |
-
|
| 362 |
# create base chart
|
| 363 |
chart = (
|
| 364 |
alt.Chart(df)
|
|
@@ -371,7 +372,8 @@ def create_bar_chart(df, x, y, title, metric, color=None, stacked=False, colors=
|
|
| 371 |
|
| 372 |
tooltip=[alt.Tooltip(x, type="nominal"), alt.Tooltip(y, type="quantitative")]
|
| 373 |
)
|
| 374 |
-
.properties(width="container", height=height)
|
|
|
|
| 375 |
|
| 376 |
)
|
| 377 |
|
|
@@ -389,7 +391,6 @@ def create_bar_chart(df, x, y, title, metric, color=None, stacked=False, colors=
|
|
| 389 |
# build chart
|
| 390 |
chart = chart.encode(
|
| 391 |
x=alt.X("xlabel:N", sort=sort, title=None, axis=alt.Axis(labels=False)),
|
| 392 |
-
# y=alt.Y(y, axis=alt.Axis(title=y_title, offset = -5),scale = alt.Scale(domain = [0,1])),
|
| 393 |
y=y_axis_scale,
|
| 394 |
color=alt.Color(color, sort=sort_order, scale=alt.Scale(domain=sort_order, range=color_hex)) ,
|
| 395 |
order=alt.Order("stack_order:Q", sort="ascending"),
|
|
@@ -414,7 +415,9 @@ def create_bar_chart(df, x, y, title, metric, color=None, stacked=False, colors=
|
|
| 414 |
axis=alt.Axis(labelAngle=angle, title=None, labelLimit=200)),
|
| 415 |
color=alt.Color("color:N", scale=None),
|
| 416 |
)
|
| 417 |
-
.properties(height=1, width="container")
|
|
|
|
|
|
|
| 418 |
)
|
| 419 |
# append symbols below base chart
|
| 420 |
final_chart = alt.vconcat(chart, symbol_layer, spacing=8).resolve_scale(x="shared")
|
|
|
|
| 270 |
]
|
| 271 |
)
|
| 272 |
)
|
| 273 |
+
# return pie.properties(width="container", height=290)
|
| 274 |
+
return pie.properties(height=290)
|
| 275 |
|
| 276 |
|
| 277 |
def bar_chart(df, x, y, title, metric = "percent"):
|
|
|
|
| 307 |
elif metric == "acres":
|
| 308 |
y_titles = "Acres"
|
| 309 |
|
| 310 |
+
angle = 270 if x in ["manager_type", "ecoregion", "status", "habitat_type", "resilient_connected_network","access_type"] else 0
|
| 311 |
+
height = 470 if y == "percent_rarityweighted_endemic_plant_richness" else 250 if stacked else 450 if x in ["ecoregion",'habitat_type'] else 350 if x == "manager_type" else 450 if x == "access_type" else 330
|
| 312 |
|
| 313 |
return sort_options.get(x, "x"), angle, height, y_titles
|
| 314 |
|
|
|
|
| 359 |
sort, angle, height, y_title = get_chart_settings(x, y, stacked, metric)
|
| 360 |
label_transform = get_label_transform(x)
|
| 361 |
y_format = "~s" if metric == "acres" else ",.1%"
|
| 362 |
+
|
| 363 |
# create base chart
|
| 364 |
chart = (
|
| 365 |
alt.Chart(df)
|
|
|
|
| 372 |
|
| 373 |
tooltip=[alt.Tooltip(x, type="nominal"), alt.Tooltip(y, type="quantitative")]
|
| 374 |
)
|
| 375 |
+
# .properties(width="container", height=height)
|
| 376 |
+
.properties(height=height)
|
| 377 |
|
| 378 |
)
|
| 379 |
|
|
|
|
| 391 |
# build chart
|
| 392 |
chart = chart.encode(
|
| 393 |
x=alt.X("xlabel:N", sort=sort, title=None, axis=alt.Axis(labels=False)),
|
|
|
|
| 394 |
y=y_axis_scale,
|
| 395 |
color=alt.Color(color, sort=sort_order, scale=alt.Scale(domain=sort_order, range=color_hex)) ,
|
| 396 |
order=alt.Order("stack_order:Q", sort="ascending"),
|
|
|
|
| 415 |
axis=alt.Axis(labelAngle=angle, title=None, labelLimit=200)),
|
| 416 |
color=alt.Color("color:N", scale=None),
|
| 417 |
)
|
| 418 |
+
# .properties(height=1, width="container")
|
| 419 |
+
.properties(height=1)
|
| 420 |
+
|
| 421 |
)
|
| 422 |
# append symbols below base chart
|
| 423 |
final_chart = alt.vconcat(chart, symbol_layer, spacing=8).resolve_scale(x="shared")
|