Labelmaker

john's Avatar

john

14 Mar, 2025 08:32 AM

SEE UPDATE BELOW.

Making labels is harder than you might think.

By "labels" I mean titles or short phrases inside boxes or dots or stars in an org chart, edge graph, family tree, flow chart or other such diagram. It's easy enough to make rectangles or ellipses, and you can use the fit_to node to put a textpath into those shapes, but if you do that, each label textpath will be a different size. Looks unprofessional.

What you want is to have all the labels the same size in the same font, regardless of what different shapes they might be enclosed in. And you want each type of shape to be the same size. And you want the shapes to fit nicely around the labels with a little padding but not too much. And if you have multi-word labels, you want that text to break in the right places, even if the lengths of the labels vary quite a bit.

Over the years I've had to make charts with labels like this and it's always a bit of pain to balance all these conflicting constraints. I end up having to do a lot of manual adjustments - which makes it harder to play freely and try different fonts, sizes, color combinations, etc..

So I finally decided to make a node that would make this process more automatic: labelmaker.

Labelmaker places and renders a list of label strings inside a shared container shape so that all the labels are in the same font at the same size. It takes the following parameters:

  • Container. A shape. The shape may scale to accommodate the labels, but each instance will be the same size and retain its coloring. When stretching shapes like rectangles or ovals, the exact width and height doesn't matter, just the ratio between the two.
  • Labels. A list of one or more strings.
  • Font Name. The font you want for your labels.
  • Font Size. The font size you want. This size will determine the final size of the container shape and the overall diagram.
  • Align. Left, Center, or Right. You will normally want Center, but may use Left for multi-line labels inside certain shapes like flags.
  • Adjust Text Width. The default of 0 uses the automatically assigned text width. Adjust this value up or down to change where the words break (more info below).
  • Label Color. The color of your label text. Background color of the shape is defined by colorizing the container.

You may notice that, unlike textpath, you do not have to enter a text width to control line breaks. Labelmaker attempts to do this automatically. It is not always possible to do this perfectly; designers may differ on how best to balance the competing needs for adequate negative space around the text in a given shape and the overall look and feel of how different line break patterns compare in neighboring labels with different lengths. Sometimes there is a word so long that leaving it unbroken would force many other labels to appear like fine print swimming inside too much space. Layout issues like this can be tricky,

My solution was to automatically choose a text width that's good enough or at least pretty close. You can then quickly and easily adjust this value by simply changing the "Adjust text width" setting from 0 up to accommodate longer words or down to squish labels into more compact profiles. Usually you don't have to change this value very far to get everything just right.

I also put in a fair amount of work to make this node as efficient as possible so that you can handle a large number of labels (a thousand or more at a time). It will run faster for some common container shapes that are symmetrical with a similar width/height ratio to text: rectangles, rounded rectangles, pills (severely rounded rectangles), and ellipses. Odder shapes like flags, triangles, pentagons, stars, etc will take just a little longer, but should fit nicely (using my inscribe node). Lists of a few hundred labels should update almost instantly.

All of this allows you to play with sizing, fonts, and colors fluidly and effortlessly. The attached demo shows a simple node graph that I threw together and polished in just a few minutes.

The graph uses a scatter node and my mesh node to create a random graph. For labels I used noun phrases from Lewis Carroll's Jabberwocky. I quickly stepped through dozens of possible color combinations for the label text and container background using my sanzo_color node (with the sort_colors node added so I could reverse colors with a single click).

That just left the container shape and the font size. I started with circles - which labelmazer was happy to fill - but on seeing it I realized the text would look better if I widened the ovals a bit. As I changed the width of the ellipse node the entire diagram updated automatically, so I could just drag until I got the look I wanted.

I used Nodebox's default font Vendana (Bold) so that everyone could see it; feel free to change this to other fonts in your system. Changing the font size caused the entire diagram to grow or shrink, so I set it to make the diagram fit into my usual demo canvas. The final step was to bump up the text width adjustment to prevent one or two labels from breaking in the wrong place. All of this was so quick and fluid that is was fun to play with.

I've been futzing with this node for days now. I think it's finally ready to share, but I reserve the right to keep tinkering with as I gain more experience using it in different situations. As always I would love to see what you all might do with this, and would welcome any suggestions for further improvement.

Go out and make some labels!

  1. Support Staff 1 Posted by john on 02 Jun, 2025 10:34 PM

    john's Avatar

    UPDATE

    A slight improvement:

    • I have removed the Label Color parameter. Instead, labelmaker now uses my contrast node to automatically assign a label color, either creamy white or dark gray, depending on the container background color.
    • In its place is a new option, container size, that allows you to make fine adjustments to the container size. By default, it is set to 100%, a snug fit for the largest label at the given font size. This works fine in most situations, but if the labels are TOO snug (or too loose) you may now increase or decrease this value. The labels will remain the same size, but the containers will grow or shrink around them.

    This change came after using labelmaker in various projects. In some cases I wasn't happy with how snug some of the labels sat in their containers, so needed a little extra control. Since I was already using all seven avalable parameters, one had to go.

    (Actually Nodebox allows more then seven, but I don't like the way it looks and seven is a good limit: exceeding it means you are probably trying to make one node do too much.)

    Of course it may still be desirable to pick your own label color. But I realized that label coloring should be broken out into a separate node, just as it is with the standard colorize node. Labelmaker will create legible labels, consistently sized and colored. If you want to adjust the label text color, OR provide different colors to different subsets of label backgrounds, you can use my new label_colors node - coming soon!

Reply to this discussion

Internal reply

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

Attaching KB article:

»

Already uploaded files

  • labelmaker_screenshot.png 563 KB
  • labelmaker_demo.ndbx.zip 35.4 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

25 Oct, 2025 02:52 AM
26 Sep, 2025 10:03 PM
19 Sep, 2025 03:34 PM
09 Sep, 2025 08:12 AM
09 Sep, 2025 12:45 AM

 

07 Sep, 2025 04:13 AM
03 Sep, 2025 04:20 AM
29 Aug, 2025 10:31 AM
29 Aug, 2025 03:56 AM
14 Aug, 2025 01:23 AM
12 Aug, 2025 08:17 PM