Treemap

john's Avatar

john

27 Nov, 2017 01:11 AM

Treemaps are a great way to visualize relative proportions within a hierarchy. Most Treemap algorithms require recursion so are hard to do entirely within NodeBox. I implemented this version using a custom node.

The treemap subnetwork takes a list of values and a bounding rectangle. It outputs the rectangles which comprise the treetop. The rectangles are colored but you will generally want to re-color them to express categories or some other dimension like intensity.

The list of values can be unordered and unnormalized, but will be sorted in descending order to create the treemap. Therefor you will generally want to sort them in descending order yourself beforehand so that you can correlate them to associated information like labels.

The attached demo shows two examples. The first, consisting of only three nodes, plots a set of random numbers. Adjust the number of random values and the size of the rectangle to see how the treemap adapts.

The second example shows how to make a compound colored treemap with labels and a legend. The top-level treemap shows the relative proportion of instruments in four stages of the evolution of orchestras. Those four rectangles are colored with a thicker border. The rectangles are then fed into another treemap subnet so that each is further subdivided. I also provide a labels subnet that automatically sizes each minor box label, rotating when necessary.

Inside the treemap subnet is the make_map custom node which does the actual work, using the squarify algorithm. You will need to add the treemap.py file to your code library whenever using this node. If you want thicker borders around a top level treemap you can change the function call (in the node's Metadata under Settings) from treemap/squarify to treemap/padded_squarify.

If you make anything interesting with this subnet please share it on the forum. Enjoy!

John

  1. Support Staff 1 Posted by john on 27 Dec, 2017 07:25 AM

    john's Avatar

    Could someone please try downloading this demo and see if it works?

    A fellow Nodeboxer keeps getting an error which prevents him from opening the demo network, but when I try it, it seems fine. If someone else could try it we could figure out whether the problem is at my end or his.

    Thanks!

    John

  2. Support Staff 2 Posted by lucasnijs on 27 Dec, 2017 08:58 AM

    lucasnijs's Avatar

    Hello John,

    works fine with me.
    Is he using 3.0.50? Else the make_table node will not exist and cause an error.
    What error does he get?

    grtz,

    best wishes for 2018!

    Lucas

  3. Support Staff 3 Posted by john on 27 Dec, 2017 11:52 PM

    john's Avatar

    Thanks, Lucas.

    Your hunch was correct. He was getting an error about make_table and apparently had not downloaded 3.0.50.

    Glad to hear that my custom node is working OK. Best wishes back to you and everyone at NodeBox central.

    John

Reply to this discussion

Internal reply

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

Attaching KB article:

»

Already uploaded files

  • Treemap_Screenshot.png 474 KB
  • treemap.zip 6.91 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

20 May, 2018 09:12 PM
20 May, 2018 01:35 AM
16 May, 2018 07:43 PM
11 May, 2018 09:56 AM
10 May, 2018 09:39 AM

 

09 May, 2018 06:37 PM
08 May, 2018 10:19 AM
07 May, 2018 04:30 AM
03 May, 2018 11:03 AM
03 May, 2018 07:15 AM
30 Apr, 2018 06:41 PM