mirror of
https://github.com/apache/superset.git
synced 2026-04-19 08:04:53 +00:00
feat(chart): add toggle for percentage metric calculation mode in Table chart (#33656)
This commit is contained in:
@@ -37,6 +37,7 @@ def contribution(
|
||||
columns: list[str] | None = None,
|
||||
time_shifts: list[str] | None = None,
|
||||
rename_columns: list[str] | None = None,
|
||||
contribution_totals: dict[str, float] | None = None,
|
||||
) -> DataFrame:
|
||||
"""
|
||||
Calculate cell contribution to row/column total for numeric columns.
|
||||
@@ -82,10 +83,19 @@ def contribution(
|
||||
numeric_df_view = numeric_df[actual_columns]
|
||||
|
||||
if orientation == PostProcessingContributionOrientation.COLUMN:
|
||||
numeric_df_view = numeric_df_view / numeric_df_view.values.sum(
|
||||
axis=0, keepdims=True
|
||||
)
|
||||
contribution_df[rename_columns] = numeric_df_view
|
||||
if contribution_totals:
|
||||
for i, col in enumerate(numeric_df_view.columns):
|
||||
total = contribution_totals.get(col)
|
||||
rename_col = rename_columns[i]
|
||||
if total is None or total == 0:
|
||||
contribution_df[rename_col] = 0
|
||||
else:
|
||||
contribution_df[rename_col] = numeric_df_view[col] / total
|
||||
else:
|
||||
numeric_df_view = numeric_df_view / numeric_df_view.values.sum(
|
||||
axis=0, keepdims=True
|
||||
)
|
||||
contribution_df[rename_columns] = numeric_df_view
|
||||
return contribution_df
|
||||
|
||||
result = get_column_groups(numeric_df_view, time_shifts, rename_columns)
|
||||
|
||||
Reference in New Issue
Block a user