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(echarts-funnel): Implement % calculation type #26290

Merged
merged 3 commits into from
Dec 22, 2023

Conversation

kgabryje
Copy link
Member

SUMMARY

Add "% Calculation" field to Funnel chart's control panel. Currently, the % of each level of funnel chart is calculated as % of total. This PR allows user to also display % of each level as % of the first step or % of previous step.

Example of calculations:

Value Percent of total Calculate from first step Calculate from previous step
100 57% 100% 100%
50 28% 50% 50%
25 14% 25% 50%

The default value for new charts is "Calculate from first step". For existing charts, a migration was added to keep "Percent of total" as selected option.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

image image image

TESTING INSTRUCTIONS

  1. Create a funnel chart
  2. Verify that the calculated percents of each step match expected values for each option

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
      Current: 0.21 s
      10+: 0.21 s
      100+: 0.12 s
      1000+: 0.13 s
  • Introduces new feature or API
  • Removes existing feature or API

Copy link

codecov bot commented Dec 16, 2023

Codecov Report

Attention: 6 lines in your changes are missing coverage. Please review.

Comparison is base (5e85f5c) 69.18% compared to head (adec022) 69.18%.

Files Patch % Lines
.../plugin-chart-echarts/src/Funnel/transformProps.ts 57.14% 3 Missing and 3 partials ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##           master   #26290   +/-   ##
=======================================
  Coverage   69.18%   69.18%           
=======================================
  Files        1945     1945           
  Lines       75971    75981   +10     
  Branches     8467     8474    +7     
=======================================
+ Hits        52559    52566    +7     
  Misses      21225    21225           
- Partials     2187     2190    +3     
Flag Coverage Δ
hive 53.67% <ø> (ø)
javascript 56.52% <57.14%> (+<0.01%) ⬆️
mysql 78.06% <ø> (-0.03%) ⬇️
postgres 78.18% <ø> (ø)
presto 53.63% <ø> (ø)
python 82.86% <ø> (+<0.01%) ⬆️
sqlite 76.83% <ø> (ø)
unit 55.79% <ø> (ø)

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

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@eschutho eschutho left a comment

Choose a reason for hiding this comment

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

Looks great! Thanks for including the migration timings, too.

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.

Great improvement! Small theoretical scalability improvement for the migration, other than that LGTM

const isFiltered =
filterState.selectedValues && !filterState.selectedValues.includes(name);
const firstStepPercent = value / (data[0][metricLabel] as number);
const prevStepPercent =
index === 0 ? 1 : value / (data[index - 1][metricLabel] as number);
Copy link
Member

Choose a reason for hiding this comment

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

nit: maybe this slightly shortens it, although it's maybe less explicit..

Suggested change
index === 0 ? 1 : value / (data[index - 1][metricLabel] as number);
index ? value / (data[index - 1][metricLabel] as number) : 1;

Copy link
Member Author

Choose a reason for hiding this comment

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

TBH in case such as this, I think it's better to be explicit that we perform an operation only for the first element of an array, rather than when "index is not falsy"

Copy link
Member

Choose a reason for hiding this comment

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

Yes, very good point. This was mostly a knee-jerk reaction that I often get when I get when I see something that can be shortened with truthy/falsy checking. Carry on 👍

bind = op.get_bind()
session = db.Session(bind=bind)

for slc in session.query(Slice).filter(Slice.viz_type == "funnel"):
Copy link
Member

Choose a reason for hiding this comment

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

Could we use paginated_update here? I'm not expecting people to have 100k funnel charts, but as a principle, I think it's a good idea to always paginate updates when possible.

Copy link
Member

Choose a reason for hiding this comment

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

+1

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point!

bind = op.get_bind()
session = db.Session(bind=bind)

for slc in session.query(Slice).filter(Slice.viz_type == "funnel"):
Copy link
Member

Choose a reason for hiding this comment

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

Same here

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.

We should remove the explicit commit, as that's already happening in the paginator

if not percent_calculation:
params["percent_calculation_type"] = "total"
slc.params = json.dumps(params)
session.commit()
Copy link
Member

Choose a reason for hiding this comment

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

I don't think we should be committing on the changes (paginated_update should do that for us)

Suggested change
session.commit()

if percent_calculation:
del params["percent_calculation_type"]
slc.params = json.dumps(params)
session.commit()
Copy link
Member

Choose a reason for hiding this comment

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

same here

Suggested change
session.commit()

@kgabryje
Copy link
Member Author

We should remove the explicit commit, as that's already happening in the paginator

TIL 🙂 done

@kgabryje kgabryje merged commit 5400d30 into apache:master Dec 22, 2023
33 checks passed
sfirke pushed a commit to sfirke/superset that referenced this pull request Mar 22, 2024
@mistercrunch mistercrunch added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 4.0.0 labels Apr 17, 2024
vinothkumar66 pushed a commit to vinothkumar66/superset that referenced this pull request Nov 11, 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 size/L 🚢 4.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants