Skip to content

Commit

Permalink
fix bug in plots
Browse files Browse the repository at this point in the history
  • Loading branch information
slavistan committed Dec 5, 2024
1 parent ab0fd39 commit a4bebf4
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions src/plotly_plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,13 @@ def num_identities_per_client(df: pd.DataFrame) -> go.Figure:
return no_data()

df = df.filter(["ClientId", "ClientType", "NumIdentities"])
# TODO: We have to set the category orders explicitly by sorting our values
# manually, instead of using plotly's xaxis_categoryorder layout
# option. plotly.js seems to cache data between updates, leading to
# ghost categories being displayed. See
# https://github.com/streamlit/streamlit/issues/5902 for a similar
# issue.
df = df.sort_values(by=["NumIdentities"], ascending=False)

p = px.bar(
df,
Expand All @@ -119,11 +126,9 @@ def num_identities_per_client(df: pd.DataFrame) -> go.Figure:
"ClientType": False,
},
color_discrete_map=client_type_colmap,
category_orders={"ClientId": df["ClientId"]},
)

p.update_layout(
xaxis_categoryorder="total descending",
)
return p


Expand All @@ -139,6 +144,7 @@ def num_sent_messages_per_client(df: pd.DataFrame) -> go.Figure:
return no_data()

df = df.filter(["NumMessages", "SenderClientId", "SenderClientType"])
df = df.sort_values(by=["NumMessages"], ascending=False)

p = px.bar(
df,
Expand All @@ -158,11 +164,9 @@ def num_sent_messages_per_client(df: pd.DataFrame) -> go.Figure:
"SenderClientType": False,
},
color_discrete_map=client_type_colmap,
category_orders={"SenderClientId": df["SenderClientId"]},
)

p.update_layout(
xaxis_categoryorder="total descending",
)
return p


Expand All @@ -178,6 +182,7 @@ def num_received_messages_per_client(df: pd.DataFrame) -> go.Figure:
return no_data()

df = df.filter(["NumMessages", "RecipientClientId", "RecipientClientType"])
df = df.sort_values(by=["NumMessages"], ascending=False)

p = px.bar(
df,
Expand All @@ -197,11 +202,9 @@ def num_received_messages_per_client(df: pd.DataFrame) -> go.Figure:
"RecipientClientType": False,
},
color_discrete_map=client_type_colmap,
category_orders={"RecipientClientId": df["RecipientClientId"]},
)

p.update_layout(
xaxis_categoryorder="total descending",
)
return p


Expand Down Expand Up @@ -474,8 +477,7 @@ def sync_errors(df: pd.DataFrame) -> go.Figure:
"ErrorCode": df["ErrorCode"].cat.categories,
},
)
p.update_layout(
)
p.update_layout()
return p


Expand Down

0 comments on commit a4bebf4

Please sign in to comment.