Skip to content

Commit

Permalink
Add sort by for dist bar chart (#13049)
Browse files Browse the repository at this point in the history
  • Loading branch information
maloun96 authored Feb 22, 2021
1 parent 87d6ad2 commit e8d5035
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion superset/viz.py
Original file line number Diff line number Diff line change
Expand Up @@ -1709,7 +1709,18 @@ def query_obj(self) -> QueryObjectDict:
raise QueryObjectValidationError(_("Pick at least one metric"))
if not fd.get("groupby"):
raise QueryObjectValidationError(_("Pick at least one field for [Series]"))
d["orderby"] = [(metric, False) for metric in d["metrics"]]

sort_by = fd.get("timeseries_limit_metric")
if sort_by:
sort_by_label = utils.get_metric_name(sort_by)
if sort_by_label not in d["metrics"]:
d["metrics"].append(sort_by)
d["orderby"] = [(sort_by, not fd.get("order_desc", True))]
elif d["metrics"]:
# Legacy behavior of sorting by first metric by default
first_metric = d["metrics"][0]
d["orderby"] = [(first_metric, not fd.get("order_desc", True))]

return d

def get_data(self, df: pd.DataFrame) -> VizData:
Expand Down

0 comments on commit e8d5035

Please sign in to comment.