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(plugin-chart-echarts): invalid total label location for negative values in stacked bar chart #21032

Conversation

justinpark
Copy link
Member

SUMMARY

A stacked chart sets the total value only, the total label displays on top of the most latest non-null data index item.
When the data contains negative values, the stack chart places the item underneath the positive item.
Therefore the total value can be located within the stack bar when a negative value in the most latest index.
This commit fixes the extractShowValueIndexes logic by ignoring the negative values for onlyTotal option.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

Before:

Screen Shot 2022-08-08 at 4 17 59 PM

After:

Screen Shot 2022-08-08 at 4 18 14 PM

TESTING INSTRUCTIONS

Storybook

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

@ktmud
Copy link
Member

ktmud commented Aug 9, 2022

How does stacked bar chart work when a series group has a mix of negative and positive values? Is the total above the bars only the positive part or a sum of both positives and negatives?

Maybe we need to display both negative totals and positive totals separately, with positive totals on top of positive bars (if there are positive sums in a series) and negative totals below negative bars (if there are negatives).

@justinpark
Copy link
Member Author

How does stacked bar chart work when a series group has a mix of negative and positive values?

As shown, the total value will be shown on top of the positive stack item for onlyTotal

Screen_Shot_2022-08-08_at_4_18_14_PM

@justinpark
Copy link
Member Author

justinpark commented Aug 9, 2022

Maybe we need to display both negative totals and positive totals separately, with positive totals on top of positive bars (if there are positive sums in a series) and negative totals below negative bars (if there are negatives).

Displaying two total numbers can be confused. (because user expects to have one total value which means sum of positives and negatives)

++ user can highlight the each negative and positive value by the tooltip

Screen Shot 2022-08-09 at 11 54 18 AM

@codecov
Copy link

codecov bot commented Aug 9, 2022

Codecov Report

Merging #21032 (60a2e8e) into master (e13c5b2) will decrease coverage by 0.00%.
The diff coverage is 60.00%.

@@            Coverage Diff             @@
##           master   #21032      +/-   ##
==========================================
- Coverage   66.28%   66.28%   -0.01%     
==========================================
  Files        1770     1770              
  Lines       67497    67505       +8     
  Branches     7171     7177       +6     
==========================================
+ Hits        44738    44743       +5     
  Misses      20928    20928              
- Partials     1831     1834       +3     
Flag Coverage Δ
javascript 52.01% <60.00%> (+<0.01%) ⬆️

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

Impacted Files Coverage Δ
...gin-chart-echarts/src/Timeseries/transformProps.ts 54.65% <ø> (ø)
...lugin-chart-echarts/src/Timeseries/transformers.ts 50.00% <50.00%> (-0.40%) ⬇️
...d/plugins/plugin-chart-echarts/src/utils/series.ts 85.08% <62.50%> (-0.90%) ⬇️

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

@ktmud
Copy link
Member

ktmud commented Aug 9, 2022

Displaying two total numbers can be confused

You can argue both ways, visually it's not very intuitive that a taller bar may have smaller total number on top of it only because it also has a negative part. But I agree the actual totals may indeed be more useful in most cases.

@kamalkeshavani-aiinside
Copy link
Contributor

Here is a related issue I had reported(not for stack bars):
#20517

I think that in case of negative value, the label should be at the bottom of the bar not at the top of the bar. User would expect the label to be at the end of the bar, which would be the TOP for positive and BOTTOM for negative values. Please consider.

@justinpark
Copy link
Member Author

justinpark commented Aug 10, 2022

I think that in case of negative value, the label should be at the bottom of the bar not at the top of the bar. User would expect the label to be at the end of the bar, which would be the TOP for positive and BOTTOM for negative values. Please consider

@kamalkeshavani-aiinside I understand the position for the negative values but the problem is when values are combined with positives and negatives. In this case we should choose either top or bottom because echart only accepts one position for one series.

We can design the position to BOTTOM when most of combined values are negatives.
Here is the example of this case.
https://codepen.io/airbnb/pen/zYWLbJd

Other solution is using a default position(which is inside) for positive-negative combined values for bar chart only.

Use TOP for most positives series, BOTTOM for most negative series Use inside position for the combined case
Screen Shot 2022-08-10 at 2 15 39 PM Screen Shot 2022-08-10 at 2 16 21 PM

Which option seems better?

@kamalkeshavani-aiinside
Copy link
Contributor

@justinpark Thanks for the clarification. Personally, I prefer 1st option (TOP or BOTTOM based on most values), but 2nd option can be useful for others.
Can we add a checkbox to allow the user to select label position (outside/inside the bar)? This checkbox can be seen only if the users selects 'Show Values' option. Default can be outside, since it is the current behavior.

@villebro villebro changed the title fix(plugin-echarts-timeseries): invalid total label location for negative values in stacked bar chart fix(plugin-chart-echarts): invalid total label location for negative values in stacked bar chart Aug 11, 2022
@villebro
Copy link
Member

How does stacked bar chart work when a series group has a mix of negative and positive values? Is the total above the bars only the positive part or a sum of both positives and negatives?

Maybe we need to display both negative totals and positive totals separately, with positive totals on top of positive bars (if there are positive sums in a series) and negative totals below negative bars (if there are negatives).

@ktmud I agree that the best way to stack when positive and negative values are present is to have the negative values stacked below the line and respectively the positive ones above the line. I have a slightly related fix that I need to get in that's related to bumping ECharts to 5.3.3, so I'll see if I can tackle that at the same time.

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.

LGTM with minor nit regarding the storybook (thanks for adding it btw!)

chartType="echarts-timeseries"
width={width}
height={height}
queriesData={[{ data: negativeNumData }]}
Copy link
Member

Choose a reason for hiding this comment

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

I noticed that the storybook isn't formatting the temporal x-axis correctly:
image
Could we add an entry for __timestamp to colnames and coltypes which would normally be returned in the chart data payload so the formatting looks correct (2 comes from GenericDataType.TEMPORAL)? I believe this should fix it:

Suggested change
queriesData={[{ data: negativeNumData }]}
queriesData={[{ data: negativeNumData, colnames: ['__timestamp'], coltypes: [2] }]}

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for hotfix! I'll update accordingly

@justinpark justinpark force-pushed the fix--plugin-echart-timeseries-combined-negative-numbers branch from f60d21e to 60a2e8e Compare August 11, 2022 17:14
@justinpark
Copy link
Member Author

I have a slightly related fix that I need to get in that's related to bumping ECharts to 5.3.3, so I'll see if I can tackle that at the same time

Since villebro has a plan to fix the negative number position issue, I'll move forward as-is.

@ktmud ktmud merged commit a8ba544 into apache:master Aug 11, 2022
@justinpark justinpark deleted the fix--plugin-echart-timeseries-combined-negative-numbers branch August 11, 2022 18:51
justinpark added a commit to justinpark/superset that referenced this pull request Aug 11, 2022
john-bodley pushed a commit to airbnb/superset-fork that referenced this pull request Aug 17, 2022
…values in stacked bar chart (apache#21032)

(cherry picked from commit bb4ab9b)
eschutho pushed a commit that referenced this pull request Sep 20, 2022
…values in stacked bar chart (#21032)

(cherry picked from commit a8ba544)
Fahrenheit35 pushed a commit to Fahrenheit35/superset that referenced this pull request Nov 11, 2022
…values in stacked bar chart (apache#21032)

(cherry picked from commit a8ba544)
@mistercrunch mistercrunch added 🍒 2.0.1 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 2.1.0 and removed 🚢 2.1.3 labels Mar 13, 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 v2.0 v2.0.1 🍒 2.0.1 🚢 2.1.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants