Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: nvd3 bar chart sortby metric #15318

Merged
merged 3 commits into from
Jun 30, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions superset/viz.py
Original file line number Diff line number Diff line change
Expand Up @@ -1760,8 +1760,12 @@ def get_data(self, df: pd.DataFrame) -> VizData:
df = df.copy()
df[filled_cols] = df[filled_cols].fillna(value=NULL_STRING)

row = df.groupby(self.groupby).sum()[metrics[0]].copy()
row.sort_values(ascending=False, inplace=True)
sortby = utils.get_metric_name(
self.form_data.get("timeseries_limit_metric") or metrics[0]
)
row = df.groupby(self.groupby).sum()[sortby].copy()
is_asc = not self.form_data.get("order_desc")
row.sort_values(ascending=is_asc, inplace=True)
pt = df.pivot_table(index=self.groupby, columns=columns, values=metrics)
if fd.get("contribution"):
pt = pt.T
Expand Down
4 changes: 3 additions & 1 deletion tests/core_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -976,6 +976,7 @@ def test_explore_json_dist_bar_order(self):
"optionName": "metric_80g1qb9b6o7_ci5vquydcbe",
},
],
"order_desc": True,
"adhoc_filters": [],
"groupby": ["name"],
"columns": [],
Expand All @@ -999,7 +1000,8 @@ def test_explore_json_dist_bar_order(self):
SELECT count(name) AS count_name, count(ds) AS count_ds
FROM birth_names
WHERE ds >= '1921-01-22 00:00:00.000000' AND ds < '2021-01-22 00:00:00.000000'
GROUP BY name ORDER BY count_name DESC, count_ds DESC
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the distributed bar only a single metric can be sorted.

GROUP BY name
ORDER BY count_name DESC
LIMIT 10;
""",
client_id="client_id_1",
Expand Down