superset icon indicating copy to clipboard operation
superset copied to clipboard

feat: Axis sort in the Bar Chart V2

Open zhaoyongjie opened this issue 2 years ago • 3 comments

Background

This PR intends to introduce a new control that XAxisSortControl and a new post-processing operator. The goal is to resolve whether the axis could be sorted by the x-axis or any metric.

Before introducing this feature, let's talk about some of the current sorting logic. There are two kinds of sorting logic on the current master branch.

  1. order by on the main query if Sort By is set on the control panel image

  2. order by on the main query and the sub-query if Series limit and Dimensions is given. image

Both of these sorting methods are sorting on query data results, which means that these sorting occurs at the database stage. The limitation of this approach is that we cannot sort the pivot results. For example, timeseries charts(echart version), are pivoted charts.

Purpose

Imagine that there are request for such analysis, but the data sorting is kept to a fixed metric(in the other words, the database should return static topN):

  1. Bar chart should sort the bar by one of several metrics, for example, there are sum(sales), max(sales) in the metrics, but the max(sales) should be sorted.
  2. Bar chart should sort the bar by the x-axis values.

This PR is designed for this purpose.

Limitation

The current design doesn't support multiple series(dimensions control in the control panel). The reason is that the extra query should be provided for this use case.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

image

TESTING INSTRUCTIONS

ADDITIONAL INFORMATION

  • [ ] Has associated issue:
  • [ ] Required feature flags:
  • [ ] Changes UI
  • [ ] Includes DB Migration (follow approval process in SIP-59)
    • [ ] Migration is atomic, supports rollback & is backwards-compatible
    • [ ] Confirm DB migration upgrade and downgrade tested
    • [ ] Runtime estimates and downtime expectations provided
  • [ ] Introduces new feature or API
  • [ ] Removes existing feature or API

zhaoyongjie avatar Nov 01 '22 14:11 zhaoyongjie

Codecov Report

Merging #21993 (c225baa) into master (b2fcdc5) will decrease coverage by 0.07%. The diff coverage is 52.83%.

@@            Coverage Diff             @@
##           master   #21993      +/-   ##
==========================================
- Coverage   66.92%   66.85%   -0.08%     
==========================================
  Files        1834     1841       +7     
  Lines       69986    70197     +211     
  Branches     7612     7662      +50     
==========================================
+ Hits        46837    46927      +90     
- Misses      21183    21296     +113     
- Partials     1966     1974       +8     
Flag Coverage Δ
hive 52.56% <33.33%> (-0.01%) :arrow_down:
javascript 53.67% <36.84%> (-0.08%) :arrow_down:
mysql 78.07% <73.33%> (-0.01%) :arrow_down:
postgres 78.14% <73.33%> (-0.01%) :arrow_down:
presto 52.46% <33.33%> (-0.01%) :arrow_down:
python 81.34% <93.33%> (+<0.01%) :arrow_up:
sqlite 76.60% <73.33%> (-0.01%) :arrow_down:
unit 50.87% <93.33%> (+0.01%) :arrow_up:

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

Impacted Files Coverage Δ
...superset-ui-core/src/query/types/PostProcessing.ts 100.00% <ø> (ø)
...ins/plugin-chart-echarts/src/BoxPlot/buildQuery.ts 66.66% <ø> (ø)
...s/plugin-chart-echarts/src/BoxPlot/controlPanel.ts 5.55% <ø> (ø)
...charts/src/Timeseries/Regular/Bar/controlPanel.tsx 35.71% <ø> (+4.46%) :arrow_up:
.../plugin-chart-echarts/src/Timeseries/buildQuery.ts 71.42% <ø> (ø)
.../plugin-chart-pivot-table/src/plugin/buildQuery.ts 42.85% <ø> (ø)
...ugin-chart-pivot-table/src/plugin/controlPanel.tsx 4.16% <0.00%> (ø)
...ntend/plugins/plugin-chart-table/src/buildQuery.ts 56.25% <ø> (ø)
...nd/plugins/plugin-chart-table/src/controlPanel.tsx 53.12% <0.00%> (ø)
...c/explore/components/controls/XAxisSortControl.tsx 0.00% <0.00%> (ø)
... and 28 more

:mega: We’re building smart automated test selection to slash your CI/CD build times. Learn more

codecov[bot] avatar Nov 04 '22 13:11 codecov[bot]

Ephemeral environment shutdown and build artifacts deleted.

github-actions[bot] avatar Nov 26 '22 14:11 github-actions[bot]

Sorting on the 2v bar graph is not working. Any suggestions for correction.

Cmagno13 avatar Feb 10 '23 16:02 Cmagno13

000000image

Cmagno13 avatar Feb 10 '23 16:02 Cmagno13

Mix chart need Axis sort too.

sunsikai avatar Mar 08 '23 02:03 sunsikai