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

feat: Add sort by metric for charts with multiple metrics #13057

Merged
merged 9 commits into from
Feb 22, 2021

Conversation

maloun96
Copy link
Contributor

@maloun96 maloun96 commented Feb 10, 2021

SUMMARY

Add sort by metric for pivot-table

Associated with: apache-superset/superset-ui#952

pivot-table

pivot

parallel-coordinates

parallel-coordinates

chart-rose

rose

partition

parallel-coordinates

treemap

treemap

nvd3-area

area

horizon

horizon

TEST PLAN

Select pivot table

ADDITIONAL INFORMATION

@codecov-io
Copy link

codecov-io commented Feb 10, 2021

Codecov Report

Merging #13057 (61349b9) into master (2ce7982) will increase coverage by 8.79%.
The diff coverage is 30.50%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #13057      +/-   ##
==========================================
+ Coverage   53.06%   61.85%   +8.79%     
==========================================
  Files         489      981     +492     
  Lines       17314    46368   +29054     
  Branches     4482     4505      +23     
==========================================
+ Hits         9187    28680   +19493     
- Misses       8127    17688    +9561     
Flag Coverage Δ
cypress 53.37% <28.57%> (+0.31%) ⬆️
python 66.92% <30.63%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...rontend/src/components/ListView/CardSortSelect.tsx 78.94% <ø> (ø)
...ontend/src/components/ListViewCard/ImageLoader.tsx 75.00% <0.00%> (ø)
...perset-frontend/src/views/CRUD/chart/ChartList.tsx 79.81% <ø> (+5.50%) ⬆️
...rontend/src/views/CRUD/dashboard/DashboardCard.tsx 76.00% <ø> (ø)
...end/src/views/CRUD/data/database/DatabaseModal.tsx 68.96% <ø> (ø)
superset-frontend/src/views/CRUD/utils.tsx 32.05% <ø> (ø)
...perset-frontend/src/views/CRUD/welcome/Welcome.tsx 2.94% <0.00%> (ø)
superset/config.py 90.68% <ø> (ø)
...s/260bf0649a77_migrate_x_dateunit_in_time_range.py 0.00% <0.00%> (ø)
superset/viz.py 56.94% <9.33%> (ø)
... and 531 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3e0681b...61349b9. Read the comment docs.

@@ -865,6 +865,12 @@ def query_obj(self) -> QueryObjectDict:
raise QueryObjectValidationError(_("Please choose at least one metric"))
if set(groupby) & set(columns):
raise QueryObjectValidationError(_("Group By' and 'Columns' can't overlap"))
sort_by = self.form_data.get("timeseries_limit_metric")
Copy link
Member

@zhaoyongjie zhaoyongjie Feb 10, 2021

Choose a reason for hiding this comment

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

I am curious, why use timeseries_limit_metric control in a not time-series chart.

Copy link
Member

Choose a reason for hiding this comment

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

I think this is just from legacy form_data field names. We'd need a db migration if we want to rename it.

Superset has a timeseries-first UI. Each pivot group can be considered a series since the base query has the ability to aggregate by time + pivot column.

Copy link
Member

Choose a reason for hiding this comment

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

Wait a minute, since this is a new field for pivot table and apache-superset/superset-ui#952 hasn't been merged, maybe we CAN rename it to something else?

Copy link
Member

Choose a reason for hiding this comment

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

Or we can keep it as timeseries_limit_metric to be able to reuse the existing code and do a wholesale migration later.

Copy link
Member

Choose a reason for hiding this comment

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

cc @villebro what do you think?

Copy link
Member

Choose a reason for hiding this comment

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

I was super confused by the name yesterday, and agree we need to get rid of it. I'm ok both ways, but I think it might be simpler to do a bulk rename later to avoid partially migrated names.

superset/viz.py Outdated
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 self.form_data.get("order_desc", True))]
Copy link
Member

Choose a reason for hiding this comment

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

it is may be more readable

Suggested change
d["orderby"] = [(sort_by, not self.form_data.get("order_desc", True))]
d["orderby"] = [(sort_by, bool(self.form_data.get("order_desc"))]

Copy link
Member

@ktmud ktmud Feb 11, 2021

Choose a reason for hiding this comment

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

This is incorrect. The second parameter in the orderby tuple is "is_ascending", which is the opposite meaning of order_desc. However, we also want the default to be order in descending in case order_desc is not set because it's the most sensible default when a sort by metric is specified.

Copy link
Member

Choose a reason for hiding this comment

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

thanks for the explanation, it's my fault

@junlincc junlincc added the explore:sort Related to sorting in Explore label Feb 11, 2021
@pull-request-size pull-request-size bot added size/M and removed size/S labels Feb 11, 2021
@maloun96 maloun96 changed the title feat: Add sort by metric for pivot-table feat: Add sort by metric for charts with multiple metrics Feb 11, 2021
@maloun96
Copy link
Contributor Author

maloun96 commented Feb 12, 2021

in this commit 61349b9
I added an if statement, if the checkbox is not selected then it will not sort by default "ASC

Copy link
Member

@villebro villebro left a comment

Choose a reason for hiding this comment

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

Code LGTM

@junlincc
Copy link
Member

junlincc commented Feb 15, 2021

@villebro those changes are relatively low risk, instead of pulling each PR, I will take a look once they are on master all at once. 🟢

@mistercrunch mistercrunch added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 1.2.0 labels Mar 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels explore:sort Related to sorting in Explore size/M 🚢 1.2.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants