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: Time shifts calculation for ECharts plugins #28432

Merged

Conversation

michael-s-molina
Copy link
Member

@michael-s-molina michael-s-molina commented May 10, 2024

SUMMARY

As part of of [SIP-50] Proposal for using ECharts as our main charting library, we're currently testing Line and Area chart migrations using Airbnb's production data. During these tests, we found many problems when comparing how legacy and ECharts plugins calculate and display time shifts. This PR fixes the following issues:

Time shifts when the their granularity do not match the chart's granularity

In this example, we have a chart with a monthly granularity but with a 52 weeks offset. This is how the legacy line chart correctly renders the chart:
Screenshot 2024-05-10 at 14 35 24

The ECharts line chart was incorrectly calculating the time shift when applying the 52 weeks offset due to differences in terms of granularity. Observe how the peak in November 2003 (296) does not match the time shift in 2004 (70).
Screenshot 2024-05-10 at 14 57 56

Now the ECharts line chart correctly calculates the time shift and matches its legacy version.
Screenshot 2024-05-10 at 14 35 52

How time shifts are displayed when there's missing data

Previously, when time shift data was not available, the chart was rendered with line gaps which is different than the legacy version.
Screenshot 2024-05-10 at 14 37 19

Now, the line gaps are gone and the dots are connected without a data point which is exactly how the legacy chart displays this scenario.
Screenshot 2024-05-10 at 14 35 52

There is also an error about how the legacy version displays missing data depending on the chosen granularity. In this example we have a chart with daily granularity and we only have time shift data for some data points. The legacy chart displays a line for every data point and assumes that the time shift is the same as the series which is not correct.
Screenshot 2024-05-10 at 14 32 53

With this fix, only available time shifts are displayed and the tooltip display the correct information when a time shift is not available.
Screenshot 2024-05-10 at 14 33 37

How multiple time shifts are displayed

Previously, multiple time shifts were displayed using the same line pattern, which is confusing and require users to check the tooltips to see the actual time shift.
Screenshot 2024-05-10 at 14 52 42

Now, it behaves exactly as the legacy version where each time shift is displayed using a different line pattern.
Screenshot 2024-05-10 at 14 51 19

TESTING INSTRUCTIONS

To test the PR use the Advanced Analytics controls and play with different time shift settings. I tested the algorithm using Airbnb's production data using more than 100 charts and added extra unit tests.

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

@apache apache deleted a comment from eschutho May 13, 2024
@apache apache deleted a comment from github-actions bot May 13, 2024
Copy link

codecov bot commented May 14, 2024

Codecov Report

Attention: Patch coverage is 86.27451% with 7 lines in your changes are missing coverage. Please review.

Project coverage is 70.18%. Comparing base (76d897e) to head (48f467f).
Report is 109 commits behind head on master.

Files Patch % Lines
...gin-chart-echarts/src/Timeseries/transformProps.ts 33.33% 5 Missing and 1 partial ⚠️
superset/common/query_context_processor.py 97.36% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #28432      +/-   ##
==========================================
+ Coverage   60.48%   70.18%   +9.69%     
==========================================
  Files        1931     1944      +13     
  Lines       76236    77322    +1086     
  Branches     8568     8672     +104     
==========================================
+ Hits        46114    54265    +8151     
+ Misses      28017    20933    -7084     
- Partials     2105     2124      +19     
Flag Coverage Δ
hive 49.09% <10.52%> (-0.08%) ⬇️
javascript 57.73% <53.84%> (+0.02%) ⬆️
mysql 77.13% <89.47%> (?)
postgres 77.24% <89.47%> (?)
presto 53.64% <10.52%> (-0.16%) ⬇️
python 83.41% <97.36%> (+19.92%) ⬆️
sqlite 76.69% <89.47%> (?)
unit 58.85% <78.94%> (+1.23%) ⬆️

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.

@michael-s-molina michael-s-molina marked this pull request as ready for review May 14, 2024 16:18
@dosubot dosubot bot added viz:charts:area Related to the Area chart viz:charts:echarts Related to Echarts viz:charts:line Related to the Line chart labels May 14, 2024
@michael-s-molina michael-s-molina requested a review from a team May 14, 2024 17:17
Copy link
Member

@john-bodley john-bodley left a comment

Choose a reason for hiding this comment

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

Thanks @michael-s-molina for the fix. Overall this LGTM, especially given we synced up offline to discuss the underlying logic.

superset/common/query_context_processor.py Outdated Show resolved Hide resolved
superset/common/query_context_processor.py Show resolved Hide resolved
superset/common/query_context_processor.py Outdated Show resolved Hide resolved
superset/common/query_context_processor.py Show resolved Hide resolved
tests/unit_tests/common/test_time_shifts.py Show resolved Hide resolved
@michael-s-molina michael-s-molina requested review from john-bodley and a team May 14, 2024 18:11
Copy link
Member

@Antonio-RiveroMartnez Antonio-RiveroMartnez left a comment

Choose a reason for hiding this comment

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

LGTM!

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.

lgtm

@michael-s-molina michael-s-molina merged commit 821c7d7 into apache:master May 15, 2024
34 checks passed
Copy link
Contributor

Ephemeral environment shutdown and build artifacts deleted.

@michael-s-molina michael-s-molina added the v4.0 Label added by the release manager to track PRs to be included in the 4.0 branch label May 15, 2024
michael-s-molina added a commit that referenced this pull request May 15, 2024
jzhao62 pushed a commit to jzhao62/superset that referenced this pull request May 16, 2024
@john-bodley john-bodley removed the review:checkpoint Last PR reviewed during the daily review standup label May 23, 2024
EnxDev pushed a commit to EnxDev/superset that referenced this pull request May 31, 2024
@mistercrunch mistercrunch added 🍒 4.0.2 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels labels Jul 24, 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 packages plugins size/XL v4.0 Label added by the release manager to track PRs to be included in the 4.0 branch viz:charts:area Related to the Area chart viz:charts:echarts Related to Echarts viz:charts:line Related to the Line chart 🍒 4.0.2
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants