assign color by lookup?

micaela's Avatar

micaela

05 Feb, 2020 04:42 AM

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!!

  1. Support Staff 1 Posted by john on 05 Feb, 2020 06:06 AM

    john's Avatar

    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. 2 Posted by micaela on 06 Feb, 2020 12:30 AM

    micaela's Avatar

    wow, thank you so much!! this is perfect. i appreciate it!

Reply to this discussion

Internal reply

Formatting help / Preview (switch to plain text) No formatting (switch to Markdown)

Attaching KB article:

»

Already uploaded files

  • books-nodebox.zip 7.32 KB

Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

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

Recent Discussions

16 Feb, 2025 11:13 AM
15 Feb, 2025 12:51 PM
06 Feb, 2025 01:37 AM
04 Feb, 2025 06:32 AM
04 Feb, 2025 05:04 AM

 

30 Jan, 2025 09:31 AM
30 Jan, 2025 09:08 AM
30 Jan, 2025 08:40 AM
24 Jan, 2025 07:50 AM
22 Jan, 2025 11:42 PM
21 Jan, 2025 09:43 AM