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

Some chart functions run out of colors (likely array index issue) #507

Open
schanzer opened this issue Feb 7, 2024 · 6 comments
Open

Some chart functions run out of colors (likely array index issue) #507

schanzer opened this issue Feb 7, 2024 · 6 comments

Comments

@schanzer
Copy link
Contributor

schanzer commented Feb 7, 2024

I think this issue exists in most of our chart functions, but some are more resilient than others.

In this starter file, we import a large dataset. Try evaluating stacked-bar-chart(shark-attacks-table, "ATTACK-TYPE", "COUNTRY"), and you'll see that we quickly run out of colors for all the countries....and default to black.

I believe one example of the bug can be traced to this line in bar charts, where we naively try to get a slice of the color_list object using the number of legends as our slice length. $10 says that when we access the color at index reallyBigNumber, the resulting undefined gets turned into a pyret color with zeros for all the fields. In fact, this will likely happen at notSoBigANumber, because the default color list is pretty short!

I think the general solution here is that all charts should cycle through their color lists if they need more colors than the list allows. Bonus points if they start tweaking the colors programmatically. I would love to send a PR for this myself, but I'm overloaded with curriculum and PD staffing right now. :(

(Could potentially be a great target for @asolove , if he's got an afternoon to kick around... 😉 )

@shriram
Copy link
Member

shriram commented Feb 7, 2024 via email

@schanzer
Copy link
Contributor Author

schanzer commented Feb 7, 2024

That's a great blog post. Two nits:

  1. It's "phillotactic", not "philogenic", right?
  2. There's no documentation of how a developer might use this infrastructure. If it's not listed in the API, can you give us a pointer to where it is in the codebase?

@shriram
Copy link
Member

shriram commented Feb 9, 2024 via email

@asolove
Copy link
Contributor

asolove commented Feb 10, 2024

I'm looking into this.

For reference: the color generation code used for error highlighting, under discussion above, is here:

var makePalette = function(){

@asolove
Copy link
Contributor

asolove commented Feb 11, 2024

@schanzer I can reproduce this in production, but am not able to get a similar stacked-bar-chart locally. Can you share with me (by email if sensitive) the content that's in the context used in that file, so I can call stacked-bar-chart locally?

@schanzer
Copy link
Contributor Author

@asolove of course! The entire context can be found here, but what matters is the definition of stacked-bar-chart on line 441.

Thank you for looking into this! 🙏

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

No branches or pull requests

3 participants