Skip to content

fix crash on null color legend #757

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

Closed
wants to merge 1 commit into from
Closed

fix crash on null color legend #757

wants to merge 1 commit into from

Conversation

Fil
Copy link
Contributor

@Fil Fil commented Feb 13, 2022

(refs: #746 & #756)

Copy link
Member

@mbostock mbostock left a comment

Choose a reason for hiding this comment

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

I don’t think this is the right place to fix this problem (because the issue of a scale being null is not unique to color legends). I think we need to fix it inside legendor exposeLegends?

For example, after #756, the if (isObject(scale)) is no longer sufficient to check whether a scale exists.

@mbostock
Copy link
Member

mbostock commented Feb 14, 2022

Should this return undefined? Or should it throw an error?

Plot.legend({color: {}})

I guess it should throw an error (either unknown legend type or missing scale).

But the current behavior of exposeLegends is that it should return undefined.

@Fil
Copy link
Contributor Author

Fil commented Feb 14, 2022

I'm fine with both of these choices.

@mbostock
Copy link
Member

Okay. I think my recommendation is that it behaves the same as Plot.legend({}) in the sense that there’s no scale defined, which is an error.

@mbostock
Copy link
Member

This is pretty tricky, because there are three places where we’re using isObject as a proxy for “is a given scale defined?”

At the top-level when iterating over the passed in options:

if (isObject(scale)) { // e.g., ignore {color: "red"}

For a symbol scale to check whether there’s also a color scale:

const {fill, stroke = fill === undefined && isObject(options.color) ? "color" : undefined} = options;

In legendsSymbol to check whether there’s also a color scale:

key => isObject(options[key]) ? normalizeScale(key, options[key]) : null

It makes me wonder if #756 was a mistake since now the test for “is a scale defined” is more involved than testing whether the option exists.

@mbostock mbostock mentioned this pull request Feb 15, 2022
@mbostock
Copy link
Member

Superseded by #759.

@mbostock mbostock closed this Feb 15, 2022
@Fil Fil deleted the fil/color-undefined branch April 5, 2023 15:00
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