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

automatic color identity scale #673

Merged
merged 6 commits into from
Jan 18, 2022
Merged

automatic color identity scale #673

merged 6 commits into from
Jan 18, 2022

Conversation

mbostock
Copy link
Member

@mbostock mbostock commented Jan 16, 2022

Alternative to #660. For the color scale, if at least one value is defined and all defined values (from the domain if specified, and otherwise from channels) are valid color strings, default to an identity scale rather than some other type.

@mbostock mbostock requested a review from Fil January 16, 2022 18:24
@Fil
Copy link
Contributor

Fil commented Jan 16, 2022

There is always going to be a situation in which these default colors are surprising. In this case, if the categories are ["orange", "apple", "banana"] only the orange will show; but if they are ["apple", "banana", "orange"], everything will show (and the "orange" category will be blue or something).

This situation is what I had in mind when I suggested that there could be a different type of default ordinal color scale which would be (roughly) a pass-thru for valid css colors, and turbo10 for the others.

Also identity doesn't allow to have a legend, so we can't use the legend to inspect what the invalid fields are.

@mbostock
Copy link
Member Author

There is always going to be a situation in which these default colors are surprising.

Totally, but the idea is that you can address those by setting the scale’s type explicitly. And this test is cheap and consistent with our other tests (e.g., to disambiguate ordinal from quantitative or temporal data).

Also identity doesn't allow to have a legend, so we can't use the legend to inspect what the invalid fields are.

I think that’s also expected and desirable. And if you want a legend, you just set the scale type to ordinal or whatever.

@mbostock
Copy link
Member Author

One other thing is that we could explicitly disallow named CSS colors (and thereby require rgb(…) or #rrggbb etc.). I suspect named colors will be responsible for nearly all the ambiguous cases. Of course then folks still might get confused why () => "red" doesn’t give you red.

@mbostock mbostock mentioned this pull request Jan 17, 2022
Copy link
Contributor

@Fil Fil left a comment

Choose a reason for hiding this comment

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

👍 this feels quite comfortable.

// valueOf to work correctly with InternMap.
export function isColor(value) {
if (!(typeof value === "string")) return false;
value = value.toLowerCase();
Copy link
Contributor

Choose a reason for hiding this comment

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

that's new. css colors are case-insensitive, so should we mention it as a bugfix?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, this does fix a bug. I’d be surprised if anyone encountered it, but we could mention it.

@mbostock mbostock merged commit 8d07b26 into main Jan 18, 2022
@mbostock mbostock deleted the mbostock/color-identity branch January 18, 2022 15:38
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.

2 participants