Skip to content

feat: Improves waterfall chart #33146

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

Open
wants to merge 10 commits into
base: master
Choose a base branch
from

Conversation

anantaoutlook
Copy link

@anantaoutlook anantaoutlook commented Apr 16, 2025

SUMMARY

This PR includes the following improvements:

1.) Horizontal waterfall in addition to vertical.
image

2.) Axis label fixes to word-wrap longer labels instead of hiding them. This is extremely important for readability/usability.
For example. Prior to these fixes, roughly half of the following labels in this chart were hidden:
image

3.) Sorting of Waterfall: It is now possible to sort the waterfall by a field other than the field indicated in the waterfall column headers. Again, extremely important. As an example, in the following chart, we are bridging from gross revenue to Profit. It's vital that these grouping appear in the correct order:
image
image

4.) Added option to use first value as subtotal, and bold first value as subtotal. These are important optional settings for the waterfall. In the example, these allow the Gross Revenue bar to be presented as a subtotal (full bar and grey), and the label for Gross Revenue is bold.
Before:
image
After:
image

5.) Cross-filtering is now feasible for the waterfall chart.

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

Copy link

@korbit-ai korbit-ai bot left a comment

Choose a reason for hiding this comment

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

Review by Korbit AI

Korbit automatically attempts to detect when you fix issues in new commits.
Category Issue Status
Readability Deeply nested complex function ▹ view ✅ Fix detected
Readability Scattered series transformation logic ▹ view ✅ Fix detected
Readability Suspicious file suffix in types import ▹ view ✅ Fix detected
Functionality Inaccurate Text Wrapping Calculation ▹ view ✅ Fix detected
Functionality Order Direction Control Not Dependent on Column Selection ▹ view ✅ Fix detected
Readability Remove or implement commented validators ▹ view ✅ Fix detected
Readability Type inconsistency in default value ▹ view ✅ Fix detected
Error Handling Inadequate Error Handling for Invalid Label Distance ▹ view ✅ Fix detected
Functionality Inconsistent Mixed-Type Data Sorting ▹ view ✅ Fix detected
Documentation Missing documentation for complex click handler ▹ view
Files scanned
File Path Reviewed
superset-frontend/plugins/plugin-chart-echarts/src/Waterfall/buildQuery.ts
superset-frontend/plugins/plugin-chart-echarts/src/Waterfall/types.ts
superset-frontend/plugins/plugin-chart-echarts/src/Waterfall/index.ts
superset-frontend/plugins/plugin-chart-echarts/src/Waterfall/transformProps.ts
superset-frontend/plugins/plugin-chart-echarts/src/Waterfall/controlPanel.tsx
superset-frontend/plugins/plugin-chart-echarts/src/Waterfall/EchartsWaterfall.tsx

Explore our documentation to understand the languages and file types we support and the files we ignore.

Check out our docs on how you can make Korbit work best for you and your team.

Loving Korbit!? Share us on LinkedIn Reddit and X

@rusackas
Copy link
Member

Can you add some details to the Description so we know the intent of the change? Thanks!

@anantaoutlook
Copy link
Author

anantaoutlook commented Apr 21, 2025

Can you add some details to the Description so we know the intent of the change? Thanks!

Details are attached. Please let me know if you need more info.
waterfall-changes doc.pdf

@rea725
Copy link

rea725 commented Apr 24, 2025

The work performed on Superset by @anantaoutlook in this PR includes the following improvements:

1.) Horizontal waterfall in addition to vertical.
image

2.) Axis label fixes to word-wrap longer labels instead of hiding them. This is extremely important for readability/usability.
For example. Prior to these fixes, roughly half of the following labels in this chart were hidden:
image

3.) Sorting of Waterfall: It is now possible to sort the waterfall by a field other than the field indicated in the waterfall column headers. Again, extremely important. As an example, in the following chart, we are bridging from gross revenue to Profit. It's vital that these grouping appear in the correct order:
image
image

4.) Added option to use first value as subtotal, and bold first value as subtotal. These are important optional settings for the waterfall. In the example, these allow the Gross Revenue bar to be presented as a subtotal (full bar and grey), and the label for Gross Revenue is bold.
Before:
image
After:
image

5.) Cross-filtering is now feasible for the waterfall chart.

@michael-s-molina
Copy link
Member

Thanks @anantaoutlook @rea725 for the great improvements! I updated the PR description with @rea725's comment.

2.) Axis label fixes to word-wrap longer labels instead of hiding them.

ECharts automatically calculates what labels will be displayed to avoid label overlaps when the number of bars is high. I think the solution here would be to provide a checkbox to show all labels (disabled by default). The same feature is currently being discussed in #33191 so please check the comments of that PR.

4.) Added option to use first value as subtotal, and bold first value as subtotal.

Can we assume that if the first value is used as a subtotal, it's always displayed with bold? It's good to avoid additional controls if possible.

@michael-s-molina michael-s-molina changed the title improve waterfall feat: Improves waterfall chart Apr 24, 2025
@michael-s-molina
Copy link
Member

@anantaoutlook Could you also fill the Testing Instructions part of the PR description?

Copy link
Member

@michael-s-molina michael-s-molina left a comment

Choose a reason for hiding this comment

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

First-pass comments. Great work!

Copy link
Member

@michael-s-molina michael-s-molina left a comment

Choose a reason for hiding this comment

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

@anantaoutlook Could you make sure all labels of all controls and select values follow the sentence case which capitalizes only the first letter of the first word in a sentence?

}

// get the width of xAxis to calculate the maxCharsPerLine
const getAxisRange = (options: EChartsCoreOption) => {
Copy link
Member

Choose a reason for hiding this comment

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

I'm still trying to understand why all these calculations are needed given that ECharts makes most of them already. There is even an option to force all labels to be rendered. What use case is not covered by ECharts? Can you create an example using their code editor?

Copy link
Member

@michael-s-molina michael-s-molina May 2, 2025

Choose a reason for hiding this comment

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

For example, using a combination of interval, overflow, and width, I can have something like:

axisLabel.interval = 0;
axisLabel.overflow = 'break';
axisLabel.width = 25;
Screenshot 2025-05-02 at 16 25 13

Here's a live editor where you can play with the settings.

Copy link
Author

Choose a reason for hiding this comment

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

I'm still trying to understand why all these calculations are needed given that ECharts makes most of them already. There is even an option to force all labels to be rendered. What use case is not covered by ECharts? Can you create an example using their code editor?

Here the label break arbitrarily on any point
https://echarts.apache.org/examples/en/editor.html?c=bar-waterfall2&code=PYBwLglsB2AEC[…]JlyPLW3bNv630Olm2jzlmrnpc52jfR47A2oI5jsCvDp2rygkHmwM3qiNEAA
but the current change supports breaking at the end of word

image (39)

Copy link
Member

Choose a reason for hiding this comment

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

@villebro As one of maintainers of ECharts, are we missing some configuration here or ECharts doesn't support this? I'm just worried that this problem affects all charts and it's not an exclusivity of the Waterfall.

Copy link
Author

Choose a reason for hiding this comment

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

I fixed this issue now, used a combination of overflow, width and interval

@@ -16,16 +16,46 @@
* specific language governing permissions and limitations
* under the License.
*/
import React from 'react';
Copy link
Member

Choose a reason for hiding this comment

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

You shoudn't need a React import... there are two linting errors caused by this.

Copy link
Author

Choose a reason for hiding this comment

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

fixed

@@ -25,6 +25,7 @@ import {
formatSelectOptions,
sharedControls,
} from '@superset-ui/chart-controls';
import React from 'react';
Copy link
Member

Choose a reason for hiding this comment

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

Here's the other one. You shouldn't need it.

Copy link
Author

Choose a reason for hiding this comment

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

fixed

Copy link
Member

@michael-s-molina michael-s-molina left a comment

Choose a reason for hiding this comment

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

Thanks for the changes @anantaoutlook. Second-pass review below.

},
],
[
{
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 when interacting with the bold control, the x-axis labels are getting misaligned.
Screenshot 2025-05-15 at 11 36 40

Copy link
Author

Choose a reason for hiding this comment

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

fixed

Comment on lines 237 to 253
[
{
name: 'sort_x_axis',
config: {
type: 'SelectControl',
label: t('Sort x axis'),
default: 'none',
choices: [
['none', t('None')],
['asc', t('Ascending')],
['desc', t('Descending')],
],
renderTrigger: true,
description: t('Sort X axis in ascending or descending order'),
},
},
],
Copy link
Member

Choose a reason for hiding this comment

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

Isn't this the same as Order direction?

Suggested change
[
{
name: 'sort_x_axis',
config: {
type: 'SelectControl',
label: t('Sort x axis'),
default: 'none',
choices: [
['none', t('None')],
['asc', t('Ascending')],
['desc', t('Descending')],
],
renderTrigger: true,
description: t('Sort X axis in ascending or descending order'),
},
},
],

Copy link
Author

Choose a reason for hiding this comment

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

fixed

@@ -28,6 +28,25 @@ export default function buildQuery(formData: QueryFormData) {
...ensureIsArray(x_axis || granularity_sqla),
...ensureIsArray(groupby),
];

if (columns.indexOf(formData.seriesOrderByColumn) === -1) {
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 you're adding the Order series by column to the GROUP BY clause which will produce incorrect results. Take this chart as an example where we have year broke down by product_line.

Screenshot 2025-05-15 at 11 54 35

If we set Order series by column to status the chart will be further broke down splitting Classic Cars into multiple values.

Screenshot 2025-05-15 at 11 54 55

This control should not affect the original breakdown. If your intention is to allow more than one breakdown, we would need to change the Breakdown control to support multiple values.

Copy link
Author

Choose a reason for hiding this comment

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

This one I need some time to figure out (edited)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants