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

Persisting colors across chart type changes and field changes #2132

Draft
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

noahonyejese
Copy link
Contributor

@noahonyejese noahonyejese commented Feb 21, 2025

Closes #2097

What changes?
This PR allows colors to persist over chart type changes.

How to test

  1. Go to this link
  2. Create a visualization
  3. Choose Segmentation
  4. Select any color palette (custom or default)
  5. Change chart type
  6. See how colors persist ✅

How it's currently

  1. Go to this link
  2. Create a visualization
  3. Choose Segmentation
  4. Select any color palette (custom or default)
  5. Change chart type
  6. See how colors revert to default palette ❌

  • Add a CHANGELOG entry

@noahonyejese noahonyejese self-assigned this Feb 21, 2025
Copy link

vercel bot commented Feb 21, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
visualization-tool ❌ Failed (Inspect) Feb 24, 2025 8:21am

Copy link
Collaborator

@bprusinowski bprusinowski left a comment

Choose a reason for hiding this comment

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

Hey @noahonyejese, thanks for implementing this 🙇‍♂️

It goes into a good direction, but there are some tweaks need before we go further (e.g. we have an application crash when switching to a combo chart). Let me know if some of my comments are not clear 👍

Comment on lines +1032 to +1034
const maybeSegmentField = convertTableFieldsToSegmentFields({
fields: oldValue as TableFields,
});
Copy link
Collaborator

Choose a reason for hiding this comment

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

@noahonyejese I am not exactly sure where the code is wrong, but you can see that the colors are set wrongly when going to Photovoltaikanlagen cube, adding segmentation by Kanton, switching to a table chart and back to a column chart – we get all blue bars then 👀

Screenshot 2025-02-21 at 09 47 35

Copy link
Collaborator

@bprusinowski bprusinowski Feb 24, 2025

Choose a reason for hiding this comment

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

@noahonyejese I checked the same flow as above, and now it looks like it's the same (and we don't show a legend now) :(

Screenshot 2025-02-24 at 09 03 03

Comment on lines 1162 to 1166
color: ({ oldValue, newChartConfig }) => {
return produce(newChartConfig, (draft) => {
draft.fields.color = oldValue as BarFields["color"];
});
},
Copy link
Collaborator

Choose a reason for hiding this comment

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

@noahonyejese another thing I've noticed is when you go to a column chart in Photovoltaikanlagen cube, switch X axis to Kanton, add segmentation by year, switch to a line chart and then back to a column chart – the color is black then 🤔

Screenshot 2025-02-21 at 09 50 44

Copy link
Contributor Author

Choose a reason for hiding this comment

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

😵‍💫

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No longer at least not sure why it was happening before, or maybe I didn't replicate this properly 😅

Copy link
Collaborator

Choose a reason for hiding this comment

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

@noahonyejese this is also still the same unfortunately :(

Copy link
Collaborator

@bprusinowski bprusinowski left a comment

Choose a reason for hiding this comment

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

@noahonyejese it looks like the issues we had before are still there, could you take a look at them? 🙏

I think we also now have a new one – when switching from a pie chart to a column line chart in Photovoltaikanlagen, the application breaks (I think it might be related to migrating measures field without adjusting in pie chart).

Screenshot 2025-02-24 at 09 07 29

I think here it would be good to "click through" different chart types with and without segmentation and see how they behave, I've also noticed that sometimes the segment colors are all blue 🟦

Comment on lines +1543 to +1549
switch (oldValue.type) {
case "measures":
draft.fields.color = {
...oldValue,
type: "segment",
};
break;
Copy link
Collaborator

Choose a reason for hiding this comment

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

@noahonyejese I think this logic needs to be adjusted – if we switch from a combo chart to a pie chart, we can't take the old color mapping over, as it was based on measure ids, not on dimension values as needed in regular charts' segmentations. Due to this, now when we switch from a combo chart to a pie chart, we get all blue slices:

Screenshot 2025-02-24 at 08 55 32

Same for scatterplot 👍

Comment on lines +1744 to +1747
switch (oldValue.type) {
case "measures":
draft.fields.color = oldValue;
break;
Copy link
Collaborator

Choose a reason for hiding this comment

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

@noahonyejese looks like we have some duplicated logic, as the color field is being assigned both here and also in y -> componentIds adjuster. I think we should have only one place to do it – or did I miss something? 🤔 It's the same for other combo charts 👀

Comment on lines +1032 to +1034
const maybeSegmentField = convertTableFieldsToSegmentFields({
fields: oldValue as TableFields,
});
Copy link
Collaborator

@bprusinowski bprusinowski Feb 24, 2025

Choose a reason for hiding this comment

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

@noahonyejese I checked the same flow as above, and now it looks like it's the same (and we don't show a legend now) :(

Screenshot 2025-02-24 at 09 03 03

Comment on lines 1162 to 1166
color: ({ oldValue, newChartConfig }) => {
return produce(newChartConfig, (draft) => {
draft.fields.color = oldValue as BarFields["color"];
});
},
Copy link
Collaborator

Choose a reason for hiding this comment

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

@noahonyejese this is also still the same unfortunately :(

@noahonyejese noahonyejese changed the title feat: extended Adjuster types Persisting colors across chart type changes and field changes Feb 24, 2025
@noahonyejese noahonyejese marked this pull request as draft February 24, 2025 13:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Color Palette Settings should persist when user changes chart type
2 participants