Taille de donut flexible #65

This commit is contained in:
Colin Maudry
2026-03-18 20:57:30 +01:00
parent f2046d6ba7
commit c77511d4e8
2 changed files with 12 additions and 4 deletions
+4
View File
@@ -609,6 +609,7 @@ def make_donut(
names_col,
per_uid: bool,
nulls="?",
potentially_many_names: bool = False,
):
title = data_schema[names_col]["title"]
lff = lff.rename({names_col: title})
@@ -620,6 +621,7 @@ def make_donut(
lff = lff.group_by(title).len("Nombre")
lff = lff.with_columns(pl.col(title).replace(None, pl.lit(nulls)))
dff = lff.collect(engine="streaming")
nb_names = dff[title].n_unique()
dff = dff.with_columns(
pl.col("Nombre")
.map_elements(format_number, return_dtype=pl.String)
@@ -639,6 +641,8 @@ def make_donut(
)
fig = fig.update_layout(showlegend=False, font=dict(size=14))
graph = dcc.Graph(figure=fig)
if potentially_many_names:
return graph, nb_names
return graph
+8 -4
View File
@@ -539,16 +539,20 @@ def udpate_dashboard_cards(
cards.append(make_card(title="Résumé", paragraphs=card_basic_counts))
donut_acheteur_categorie = make_donut(
lff, "acheteur_categorie", nulls="Autres", per_uid=True
donut_acheteur_categorie, nb_acheteur_categories = make_donut(
lff,
"acheteur_categorie",
nulls="Autres",
per_uid=True,
potentially_many_names=True,
)
cards.append(
make_card(
title="Catégorie d'acheteur",
subtitle="en nombre de marchés attribués",
fig=donut_acheteur_categorie,
lg=12,
xl=8,
lg=12 if nb_acheteur_categories > 4 else 6,
xl=8 if nb_acheteur_categories > 4 else 4,
)
)