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

feat(dashboard): make color indices referable #23657

Merged
merged 1 commit into from
Apr 12, 2023

Conversation

villebro
Copy link
Member

@villebro villebro commented Apr 12, 2023

SUMMARY

Currently it's only possible to assign series colors on dashboards based on the color names (e.g. "red") or hex codes (e.g. "#FF0000"). This tends to be impractical, as it's often only necessary to ensure that the colors stay constant across charts. In addition, assigning fixed hex colors will fail to change if color schemes are updated.

This PR adds the option to assign colors based on the color scheme index. This ensures that the color will be fixed, but also makes it adapt to whichever color scheme is chosen. This is done by letting the CategoricalColorScale objects swap out the index based color reference of the parentForcedColors that's passed to it in the constructor (the parentForcedColors object is mutated by charts as series are populated, hence it's ok to make changes to the object here, too).

SCREENSHOT

Here we're using the "D3 category 10" scheme, and assign index 2 (=the third value) for "boy" and the fixed color "red" for "girl":
image

After we do that, the charts update accordingly:
image

If we then change the scale to the "ECharts 5.0" scheme, the dashboard updates accordingly (notice "boy" turns yellow, which is the third color in that scheme, while "girl" stays unchanged):
image
image

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

parentForcedColors?: ColorsLookup;
parentForcedColors: ColorsLookup;
Copy link
Member Author

Choose a reason for hiding this comment

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

This is never undefined (see that it defaults to {} in the constructor)

Comment on lines -168 to +178
* @param range Array of range values.
* @param newRange Array of range values.
Copy link
Member Author

Choose a reason for hiding this comment

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

bycatch - incorrect @param name

Copy link
Member

@kgabryje kgabryje left a comment

Choose a reason for hiding this comment

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

Lgtm!

@villebro villebro merged commit c8fa44e into apache:master Apr 12, 2023
sebastianliebscher pushed a commit to sebastianliebscher/superset that referenced this pull request Apr 28, 2023
@mistercrunch mistercrunch added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 3.0.0 labels Mar 13, 2024
@villebro villebro deleted the villebro/color-index-2 branch April 25, 2024 00:37
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/M 🚢 3.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants