Taille de donut flexible #65
This commit is contained in:
@@ -609,6 +609,7 @@ def make_donut(
|
|||||||
names_col,
|
names_col,
|
||||||
per_uid: bool,
|
per_uid: bool,
|
||||||
nulls="?",
|
nulls="?",
|
||||||
|
potentially_many_names: bool = False,
|
||||||
):
|
):
|
||||||
title = data_schema[names_col]["title"]
|
title = data_schema[names_col]["title"]
|
||||||
lff = lff.rename({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.group_by(title).len("Nombre")
|
||||||
lff = lff.with_columns(pl.col(title).replace(None, pl.lit(nulls)))
|
lff = lff.with_columns(pl.col(title).replace(None, pl.lit(nulls)))
|
||||||
dff = lff.collect(engine="streaming")
|
dff = lff.collect(engine="streaming")
|
||||||
|
nb_names = dff[title].n_unique()
|
||||||
dff = dff.with_columns(
|
dff = dff.with_columns(
|
||||||
pl.col("Nombre")
|
pl.col("Nombre")
|
||||||
.map_elements(format_number, return_dtype=pl.String)
|
.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))
|
fig = fig.update_layout(showlegend=False, font=dict(size=14))
|
||||||
graph = dcc.Graph(figure=fig)
|
graph = dcc.Graph(figure=fig)
|
||||||
|
if potentially_many_names:
|
||||||
|
return graph, nb_names
|
||||||
return graph
|
return graph
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -539,16 +539,20 @@ def udpate_dashboard_cards(
|
|||||||
|
|
||||||
cards.append(make_card(title="Résumé", paragraphs=card_basic_counts))
|
cards.append(make_card(title="Résumé", paragraphs=card_basic_counts))
|
||||||
|
|
||||||
donut_acheteur_categorie = make_donut(
|
donut_acheteur_categorie, nb_acheteur_categories = make_donut(
|
||||||
lff, "acheteur_categorie", nulls="Autres", per_uid=True
|
lff,
|
||||||
|
"acheteur_categorie",
|
||||||
|
nulls="Autres",
|
||||||
|
per_uid=True,
|
||||||
|
potentially_many_names=True,
|
||||||
)
|
)
|
||||||
cards.append(
|
cards.append(
|
||||||
make_card(
|
make_card(
|
||||||
title="Catégorie d'acheteur",
|
title="Catégorie d'acheteur",
|
||||||
subtitle="en nombre de marchés attribués",
|
subtitle="en nombre de marchés attribués",
|
||||||
fig=donut_acheteur_categorie,
|
fig=donut_acheteur_categorie,
|
||||||
lg=12,
|
lg=12 if nb_acheteur_categories > 4 else 6,
|
||||||
xl=8,
|
xl=8 if nb_acheteur_categories > 4 else 4,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user