Skip to content

feat(stack by dimension): add a stack by dimension dropdown list #32707

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 13 commits into
base: master
Choose a base branch
from

Conversation

jpchev
Copy link
Contributor

@jpchev jpchev commented Mar 17, 2025

SUMMARY

feature for bar chart, to stack by dimension, see
#32496

basically, this is a new option to let users select a dimension to 'stack by', see the video here

stackByDimension.mp4

the dimension to 'stack by' can be selected between the dimensions defined by the user, in the Customize tab

@dosubot dosubot bot added the viz:charts:bar Related to the Bar chart label Mar 17, 2025
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 Fix Detected
Functionality Missing conditional visibility for stack dimension control ▹ view
Readability Redundant shouldMapStateToProps Function ▹ view
Functionality Incorrect Operator Precedence in Dimension Index Calculation ▹ view
Files scanned
File Path Reviewed
superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/constants.ts
superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/types.ts
superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/Regular/Bar/controlPanel.tsx
superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/transformProps.ts

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

Need a new review? Comment /korbit-review on this PR and I'll review your latest changes.

Korbit Guide: Usage and Customization

Interacting with Korbit

  • You can manually ask Korbit to review your PR using the /korbit-review command in a comment at the root of your PR.
  • You can ask Korbit to generate a new PR description using the /korbit-generate-pr-description command in any comment on your PR.
  • Too many Korbit comments? I can resolve all my comment threads if you use the /korbit-resolve command in any comment on your PR.
  • On any given comment that Korbit raises on your pull request, you can have a discussion with Korbit by replying to the comment.
  • Help train Korbit to improve your reviews by giving a 👍 or 👎 on the comments Korbit posts.

Customizing Korbit

  • Check out our docs on how you can make Korbit work best for you and your team.
  • Customize Korbit for your organization through the Korbit Console.

Feedback and Support

Comment on lines 427 to 428
const idxSelectedDimension = formData.metrics.length > 1 ? 1 : 0
+ chartProps.rawFormData.groupby.indexOf(stackdimension);

This comment was marked as resolved.

@jpchev jpchev changed the title stack by dimension feat(stack by dimension): add a stack by dimension dropdown list Mar 17, 2025
@villebro
Copy link
Member

@jpchev please add a comprehensive description + screens to this PR so reviewers can first validate the design, and then look at the implementation details. I know these may be covered by the linked GH Issue, but the discussion is pretty lengthy. I think the feature is great, but I feel we need to be very careful of how this is implemented to ensure we don't pile on technical/design debt that will be difficult to clean up later.

@rusackas
Copy link
Member

This is looking cool!

Do you need to add the "Stack by" dimension to the "Dimensions" input? If so, this works fine as-is.

If you don't, I'd be still be happy with:
• Renaming "Dimension" to "Split By"
• Moving the "Stack By" to the main control panel
• Killing the checkbox

... but if that entails a lot of work (which it might) then I still like this improvement :)

@jpchev
Copy link
Contributor Author

jpchev commented Mar 17, 2025

@villebro I added a description for this PR

@michael-s-molina
Copy link
Member

How is this going to interact with the Stack control that already exists?

@sadpandajoe
Copy link
Member

I'm a little bit confused about this since not everything is stacked according to your video. Is this more of a group by dimension or something?

@villebro
Copy link
Member

@jpchev I reviewed the video and in general I think this is an elegant and backwards compatible solution to the problem 👍 I will review in more detail in the coming days.

@jpchev
Copy link
Contributor Author

jpchev commented Mar 18, 2025

How is this going to interact with the Stack control that already exists?

as far as I understand, the new feature has no interaction with the existing stack control

@jpchev
Copy link
Contributor Author

jpchev commented Mar 18, 2025

I'm a little bit confused about this since not everything is stacked according to your video. Is this more of a group by dimension or something?

yes, this is a sort of 'group by', but it's called 'stack' in the Apache Echarts vocabulary (see https://echarts.apache.org/handbook/en/how-to/chart-types/bar/stacked-bar/).
Actually the feature propagates a 'stack' parameter in the underlying Echarts component

@michael-s-molina
Copy link
Member

Wouldn't be better to offer a control to define how things are stacked AFTER you set Stacked Style to Stack? Right now, it find really confusing that we have 2 controls for stacking.

@jpchev
Copy link
Contributor Author

jpchev commented Mar 18, 2025

Wouldn't be better to offer a control to define how things are stacked AFTER you set Stacked Style to Stack? Right now, it find really confusing that we have 2 controls for stacking.

I don't know, what is the existing stack doing?

@michael-s-molina
Copy link
Member

michael-s-molina commented Mar 18, 2025

I don't know, what is the existing stack doing?

It's stacking the bars under a common name. That's why all bars appear in the same stacking group. It seems you're trying to offer a way to modify this logic and that's why I think they are related.

@jpchev
Copy link
Contributor Author

jpchev commented Mar 20, 2025

I don't know, what is the existing stack doing?

It's stacking the bars under a common name. That's why all bars appear in the same stacking group. It seems you're trying to offer a way to modify this logic and that's why I think they are related.

yes, they are probably related and I think that the existing stack feature should become a particular case of a broader feature which should let user stack by a label in each series. This label would work as a group by criteria, as it is implemented in Apache Echarts

@b4s36t4
Copy link

b4s36t4 commented Mar 25, 2025

Hi, @jpchev. I'm trying to implement the stacked chart as you did above for the below dataset.

id,sprint,stories,p0_issues,p1_p2_issues,effieciency
1,2023#07,24,1,5,4
7,2023#06,25,4,10,1.785714286
2,2023#05,26,4,12,1.625
3,2023#04,26,8,20,0.7878787879
4,2023#03,22,10,30,0.55
5,2023#02,23,9,40,0.4693877551
6,2023#01,21,15,28,0.488372093

Can you help me understand by giving a demo for this, I'm not able to build the chart for the dataset as you did.
You can hit me @b4s36t4 in discord or telegram we can take things over there. Thanks for the help!

@jpchev
Copy link
Contributor Author

jpchev commented Mar 25, 2025

Hi, @jpchev. I'm trying to implement the stacked chart as you did above for the below dataset.

id,sprint,stories,p0_issues,p1_p2_issues,effieciency
1,2023#07,24,1,5,4
7,2023#06,25,4,10,1.785714286
2,2023#05,26,4,12,1.625
3,2023#04,26,8,20,0.7878787879
4,2023#03,22,10,30,0.55
5,2023#02,23,9,40,0.4693877551
6,2023#01,21,15,28,0.488372093

Can you help me understand by giving a demo for this, I'm not able to build the chart for the dataset as you did. You can hit me @b4s36t4 in discord or telegram we can take things over there. Thanks for the help!

hello,
if you want to stack together p0_issues and p1_p2_issues, and keep 'stories' in a separate stack, in order to use my approach you can change your dataset (you can always modify your SQL query) like the following dataset (I put only the data for the sprint '2023#07'): getting one row per measure, measures types are stored in the 'type' column and their values are in the 'val' column. The the 'cat' column lets you separate the stacks, and that's the dimension you can stack by.

id,    sprint,           cat,       type,                 no,
1,      2023#07,         S1,         stories,             24
1,      2023#07,         S2,         p0_issues,           1
1,      2023#07,         S2,         p1_p2_issues,        5
1,      2023#07,         S3,         efficiency,          4

@sadpandajoe sadpandajoe requested a review from villebro March 25, 2025 15:59
@michael-s-molina
Copy link
Member

@sadpandajoe You requested my review but I didn't see any change since my suggestion to implement this feature as a sub-control of the existing Stacked Style control.

Copy link
Contributor

github-actions bot commented Apr 7, 2025

@rusackas Processing your ephemeral environment request here. Action: up. More information on how to use or configure ephemeral environments

@rusackas
Copy link
Member

rusackas commented Apr 7, 2025

Spinning up an ephemeral environment so we can all play around with this and figure out if it's the behavior we want.

I see from the video that adding a Stack dimension automatically checks the Stack checkbox (awesome), but I what I might expect is something like:

  • Stack dimension input is not shown until the checkbox is checked
  • When you check the box and don't pick a dimension, it acts like it does today (no change in behavior)
  • When you select a Stack By dimension, the new logic is applied. I'm a little confused by the actual logic here like @sadpandajoe is, but I'll play with it on the ephemeral and see if I can make heads or tails of it.

Also, for what it's worth, someone was just asking me about this exact feature, so I'm very excited about this getting merged once we all agree on the details :D

Copy link
Contributor

github-actions bot commented Apr 7, 2025

@rusackas Ephemeral environment spinning up at http://35.93.186.138:8080. Credentials are 'admin'/'admin'. Please allow several minutes for bootstrapping and startup.

@michael-s-molina
Copy link
Member

Stack dimension input is not shown until the checkbox is checked

@rusackas I don't think a checkbox is necessary here. The way I can see this working would be to offer a control to change the stack group after you set the Stacked Style control to Stack. The stack group is what ECharts use to group the dimensions. In Superset, this value is defined here.

@rusackas
Copy link
Member

rusackas commented Apr 7, 2025

@rusackas I don't think a checkbox is necessary here.

Doh! 🤦 You're right. I forgot about the Select powering stacked mode... I thought the checkbox was there all along. So basically, would it make sense to do this? (cc @kasiazjc)
Pasted_Image_4_7_25__3_04 PM

Also, just kicking the tires here, I'm a little bit unsure of this working correctly. On the ephemeral/test workspace, I set up this chart. As you'll see, if you "stack by" with the "status" column, you get a stack of countries, and if you "stack by" the "country" column, you get a stack of statuses per country. It feels like the logic is inverted.
Pasted_Image_4_7_25__3_08 PM

@jpchev
Copy link
Contributor Author

jpchev commented Apr 8, 2025

Also, just kicking the tires here, I'm a little bit unsure of this working correctly. On the ephemeral/test workspace, I set up >this chart. As you'll see, if you "stack by" >with the "status" column, you get a stack of countries, and if you "stack by" the "country" column, you get a stack of >statuses per country. It feels like the logic is inverted.

Isn't "stack by" intended as "group by" in SQL ?

If you stack by status, you get one vertical stack per each status (a "group" per each status), where each segment in the vertical stack is a country (the other dimension).
If you stack by country, you get one vertical stack per each country (a "group" per each country), where each segment in the vertical stack is a status (the other dimension).

That's the behaviour of the "stack" parameter in Apache Echarts: "The value of stack explained what series will be stacked up together"

see https://echarts.apache.org/handbook/en/how-to/chart-types/bar/stacked-bar/

@rusackas
Copy link
Member

Also, just kicking the tires here, I'm a little bit unsure of this working correctly. On the ephemeral/test workspace, I set up >this chart. As you'll see, if you "stack by" >with the "status" column, you get a stack of countries, and if you "stack by" the "country" column, you get a stack of >statuses per country. It feels like the logic is inverted.

Isn't "stack by" intended as "group by" in SQL ?

If you stack by status, you get one vertical stack per each status (a "group" per each status), where each segment in the vertical stack is a country (the other dimension). If you stack by country, you get one vertical stack per each country (a "group" per each country), where each segment in the vertical stack is a status (the other dimension).

That's the behaviour of the "stack" parameter in Apache Echarts: "The value of stack explained what series will be stacked up together"

see https://echarts.apache.org/handbook/en/how-to/chart-types/bar/stacked-bar/

Ahh... I see your logic. I guess this is a bit of confusion on my part, but I can't help but wonder if I'm alone here.

When you say "stack by," and select "country" I was expecting to see a stack of countries. In the current code, it's what I'd expect for a "split by" or "group by" control. It's a little weird to me that you select "stack by" and that's not what's stacked up!

Curious if @villebro / @mistercrunch / @kasiazjc have opinions on the matter. I'd be OK merging this as-is, if others are happy with it. The confusion may be all mine.

@michael-s-molina
Copy link
Member

I'd be OK merging this as-is, if others are happy with it. The confusion may be all mine.

For me, we would need to remove the checkbox, to avoid creating confusion with the Stacked Style control, and show the additional control to change the stack group once Stacked Style = Stacked.

@kgabryje
Copy link
Member

I agree with @michael-s-molina and @rusackas - it feels more intuitive for Dimension to stack by control to appear only when Stacked style is set to Stack. Overall a great feature though!

@@ -317,6 +318,52 @@ const config: ControlPanelConfig = {
label: t('Chart Options'),
expanded: true,
controlSetRows: [
[
{
name: 'stackbydimension',
Copy link
Member

Choose a reason for hiding this comment

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

nit: can we use camelCase for the name?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure

],
[
{
name: 'stackdimension',
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
Contributor Author

Choose a reason for hiding this comment

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

ok

@jpchev
Copy link
Contributor Author

jpchev commented Apr 10, 2025

ok, I can implement the suggested changes.

An important point: do I need to implement something for the persistency in the database? Honestly I have missed that point, I don't know whether the fields in the form are all taken into account automatically when saving a chart

@mistercrunch
Copy link
Member

do I need to implement something for the persistency in the database?

Nope, this will happen on its own. As you alter the controls and related logic in the database, all of this automatically end up in serialized JSON payload for the chart given chart. For reference, I'm pretty sure it lands in here ->

params = Column(utils.MediumText())
. Another interesting to know is around "what happens with the missing params for older charts?". The short answer is we simply use the defaults defined for the unreferenced controls when loading the chart, so it's important to make sure that defaults won't change the charts in anyways.

Now in some fairly rare cases where we want to change control semantics or structure, it sometimes requires a chart database migration, where it's possible to alter the params strucuture of existing charts. I don't think we need anything like that in this particular case.

@jpchev
Copy link
Contributor Author

jpchev commented Apr 16, 2025

@kgabryje @michael-s-molina @rusackas I've removed the checkbox and bound the visibility of the "dimension to stack by" dropdown to the value "Stack" of the existing "Stacked style" control.

Can you please have a look?

Copy link
Contributor

@michael-s-molina Processing your ephemeral environment request here. Action: up. More information on how to use or configure ephemeral environments

Copy link
Contributor

@michael-s-molina Ephemeral environment spinning up at http://35.167.64.30:8080. Credentials are 'admin'/'admin'. Please allow several minutes for bootstrapping and startup.

@rusackas
Copy link
Member

Added a test chart here. Controls look a lot cleaner with the conditional rendering now, thank you! Seems to work well in both vertical and horizontal mode. I still feel the dimension added to "Stack by" feels more like a "Split by" or "Create Stacks for" but again, maybe it's just me expecting "Stack by" to be the dimension that IS stacked. I think the tooltip does help explain the situation, though.

@jpchev
Copy link
Contributor Author

jpchev commented Apr 22, 2025

Added a test chart here. Controls look a lot cleaner with the conditional rendering now, thank you! Seems to work well in both vertical and horizontal mode. I still feel the dimension added to "Stack by" feels more like a "Split by" or "Create Stacks for" but again, maybe it's just me expecting "Stack by" to be the dimension that IS stacked. I think the tooltip does help explain the situation, though.

Good, thanks for reviewing, can we consider having the feature merged? I can change the labels if that's better (replace "Stack by")

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.

8 participants