Pairing SVG icon to a value

Jenny's Avatar


27 Feb, 2019 09:10 AM

Hi! I have a question about using svg icons. Is it possible to pair a group of icons to numbers, one to one, based one the value of the number and then place them where the number indicators are on the coordinate? Thank you!

  1. Support Staff 1 Posted by john on 27 Feb, 2019 09:04 PM

    john's Avatar


    Yes - this is easy. Build two lists: one list of svg icons, one list of numbers. As long as you keep them in the same order, the nth number can be associated with the nth icon.

    You can convert each number into a coordinate (using a make_point node or many other possible ways) and then move each icon to each coordinate by feeding both lists into a translate node.

    To demo this I found six free public domain icons from the Wikipedia commons and loaded them in a single file. I then ungroup them, scale them, and align them to form a list of svgs.

    To get the numbers I built a little table of icon names and popularity using random numbers. I then lookup each name and number to build a chart.

    To calculate the coordinates where I want to place each icon, I take the end points of the bar chart lines and scoot them a little to the right. I now have a list of coordinates.

    To place the icons all I do is feed my SVG list and my coordinate list into a translate node. Viola!

    Zipped demo files and screenshot attached. Please let me know if this helped and if you have any more questions.


  2. 2 Posted by Jenny on 01 Mar, 2019 12:26 AM

    Jenny's Avatar

    Hi John, thanks very much for the reply. It helps a lot to make sense of using SVG file in Nodebox. Going a step further down the path, instead of pairing one icon to one number, can we also pair each icon to a range of numbers? So the order of the icon doesn't depend on how it's arranged in SVG but by the value of the numbers?

  3. Support Staff 3 Posted by john on 01 Mar, 2019 05:14 AM

    john's Avatar

    Hi Jenny,

    I don't understand what you mean. You say you have a "group of icons" that are "arranged in SVG". Do you have a group of SVG paths stored inside a single SVG file or a set of different SVG files?

    You say you want to associate each icon to a "range of numbers". I'm not sure what you mean by this or how doing that would mean the order of the icon would no longer depend on how it's arranged. Are you talking about complex icons with multiple contours?

    NodeBox does not have a way of tagging individual paths (icons). If each icon is in a different file, you could use the filenames to identify each one. If they are bunched together in a single file, the only simple way to tell them apart is by the order in which they are stored.

    This doesn't mean you can't associate each icon with more than one number or change that order or sort or filter those numbers or do random access on the icon list. You can. The trick is to build an icon ID table. Each row represents an icon. The first column is the icon ID - which is based on the icons *original* order: 0, 1, 2, etc. You can then add as many additional columns as you want to hold numbers (or strings) you wish to associate with that icon.

    You can then sort and filter that table to your heart's content. If ever you need to retrieve the icon associated with a given row, just look up the icon's ID and use it as the start value of a slice node attached to the original list of icons.

    If you could describe more clearly exactly what it is you are trying to do, I could make another demo to show you how to use an icon ID table.


  4. 4 Posted by Jenny on 03 Mar, 2019 11:08 PM

    Jenny's Avatar

    Hi John, the SVG icons are in separate files. Sorry i haven’t done a good job explaining the task. Let me try again. For example I have a group of numbers like 0.5, 0.7, 1.2, 1.6, 2.3, 2.5… and I want to pair 3 icons to these numbers, so icon 1 pairs to numbers that are smaller than 1; icon 2 to numbers between 1 and 2 ; and icon 3 pairs to the numbers between 2 and 3, etc. Is this the kind of task that icon ID table are built for? Thank you.

  5. Support Staff 5 Posted by john on 04 Mar, 2019 03:36 AM

    john's Avatar

    Oh, I see now.

    New demo attached. You don't even need an icon ID table for this. Just turn your numbers into an icon ID and use that to slice the icon list directly.

    For the demo I imported three different icons and combined them into a list. Icon 0 is the gear, icon 1 is the magnifying glass, and icon 2 is the wrench.

    I turned the numbers you suggested into a list and then shuffled them to prove that the order doesn't matter. To pair an icon for each number I just used the floor node which rounds down. So any number between 0 and 1 gets a 0, any between 1 and 2 gets a 1, etc. You could substitute whatever method you actually use to assign numbers to icons.

    These floor values work as icon IDs. To pull an icon from the icon list, just slice the list with start set to the ID and size set to 1.

    We now have a number and a paired icon. To make this pairing visible I created a subnetwork called make_row. Make_row takes the number (converted to a path) and the icon, places them into a row, and groups them. Once each pair is turned into a row you can stack the rows to form a list.

    It was necessary to create a subnetwork because we need to pair each number with its icon one at a time. If you feed a list of numbers and list of icons into a combine node you will get all of the numbers then all of the icons. By turning that combine node into a subnetwork, the subnetwork node will fire once each time a new pair arrives. In this case it will fire six times to create six rows.

    If you want to do something other than place them in a row, just replace the inside of the make_row subnetwork with whatever you want.

    To demonstrate that you can access the icons in any order, change the seed value on the shuffle node.

    Hope that clears things up. Let me know if you have any more questions.


Reply to this discussion

Internal reply

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

Attaching KB article:


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


? 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

04 Dec, 2023 10:18 PM
04 Dec, 2023 10:14 PM
04 Dec, 2023 11:38 AM
29 Nov, 2023 05:30 AM
28 Nov, 2023 12:38 AM


27 Nov, 2023 04:40 AM
26 Nov, 2023 10:02 AM
22 Nov, 2023 09:33 AM
20 Nov, 2023 08:54 PM
17 Nov, 2023 01:43 AM
15 Nov, 2023 06:58 AM