assign color by lookup?
Hi - I am the definition of a total beginner so hopefully this isn't totally obvious, lol. I'm wondering if there's any way to assign colors based one value in a csv rather than having a bunch of colors repeat.
so for example in this i have the name of a book & the length of the book in pages showing. i would like to color code each bar (&associated title??) by the key "Genre." I'm fine doing this with random colors for the moment but ideally I'd love to be able to set my own. I started playing around on the left of my network but I got stuck pretty fast.
Any help appreciated - thanks!!
- books-nodebox.zip 7.32 KB
Keyboard shortcuts
Generic
? | Show this help |
---|---|
ESC | Blurs the current field |
Comment Form
r | Focus the comment reply box |
---|---|
^ + ↩ | Submit the comment |
You can use Command ⌘
instead of Control ^
on Mac
Support Staff 1 Posted by john on 05 Feb, 2020 06:06 AM
Hi Micaela,
Welcome to the NodeBox community.
You managed to get 95% of the way to your goal. You made the rest of your ring, isolated the distinct possible values of genre and assigned colors to them.
The problem is that you have 211 books but only 12 distinct genres. How do you map those 12 genres back onto the 211 books?
The solution is to make a little genre color lookup table before you create your book ring.
You already have the distinct list of genres and distinct list of colors. All I did was add a make table node to turn that into a two-column lookup table.
Now all you have to do is, for each line of your table, filter that lookup table to the genre of each book. The filter node will return one row of your lookup table with the genre and the color. Then all you have to do is lookup the color in that table and apply it to your labels and rectangles.
Updated ndbx file and screenshot attached.
If you want to use specific colors instead of hue spectrum, just build those colors with 12 color nodes and 2 combine nodes, or just type the RGB codes into a spreadsheet and read them in. Whatever colors you put in your lookup table will be applied to the ring.
Fun little problem! Thanks for sharing it.
John
2 Posted by micaela on 06 Feb, 2020 12:30 AM
wow, thank you so much!! this is perfect. i appreciate it!