# New Node Shape: Typed Node

**URL:** <https://forum.graphviz.org/t/new-node-shape-typed-node/2034>\
**Category:** Uncategorized\
**Created:** [February 20, 2024, 6:03pm UTC](https://forum.graphviz.org/t/new-node-shape-typed-node/2034 "2024-02-20T18:03:13Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vithanco](https://sea2.discourse-cdn.com/graphviz/user_avatar/forum.graphviz.org/vithanco/32/292_2.png) [@Vithanco](https://forum.graphviz.org/u/Vithanco)\
**Post date:** [February 20, 2024, 6:03pm UTC](https://forum.graphviz.org/t/new-node-shape-typed-node/2034/1 "2024-02-20T18:03:13Z")

</div>

This is a continuation of [How to create a new node type? - #3 by Vithanco](https://forum.graphviz.org/t/how-to-create-a-new-node-type/1096/3). Thanks especially to [steveroush](https://forum.graphviz.org/u/steveroush) for the help provided then.

I still think of node shapes. I would like to have a new node shape as used here:

 ![BBS Schema](https://global.discourse-cdn.com/graphviz/original/2X/8/834547047fb29cd3926d038ec74ed5d231f476b8.jpeg)  
I will use “Typed Node” or “TNode” for this.

So, a TNode shows a border (edge radius, thickness?) and a class name (font, size, colour) with a background colour - as in the picture. The node text is then shown inside the box.

I believe the right way to create a TNode is to do so within Graphviz itself (most likely as a separate Node Shape), as it should be accessible even in the WASM version, providing SVG output.

Questions:

- What key concepts need to be understood for this task? I think most of the stuff, such as Node size, shape type and other existing attributes, must be improved. But maybe we need to consider concepts that “break” when this would happen (e.g. I could imagine that there is an impact on ports)
- What problems would need to be solved for this to succeed? Which classes/packages/methods need to be improved? What new functionality would need to be created? Would we want to refactor things first to create further node class styles?
- What are some starting points within the code to start this task? Any hints on where changes will be needed would be helpful.
- How would we need to test this? What would be considered “good” for test cases in this case? Would we need to create an additional test harness for existing functionality as we will touch them?
- How much work is this? What are the complexities that you see? Any (wild?) guess is welcome.

This is high level, and I would love to get input from the community on what they think. Is this even the right way to go? Would anyone from the community be interested? Would anyone want to cooperate on this? All comments are welcome.

---

<div class="post-metadata">

**Author:** ![steveroush](https://avatars.discourse-cdn.com/v4/letter/s/a9adbd/32.png) [@steveroush](https://forum.graphviz.org/u/steveroush)\
**Post date:** [February 20, 2024, 10:26pm UTC](https://forum.graphviz.org/t/new-node-shape-typed-node/2034/2 "2024-02-20T22:26:26Z")

</div>

[disclaimer: these are my guesses, I’m not speaking for the team. And I am the _least_ knowledgeable about the code]

Before you start, I suggest experimenting with HTML-like nodes. Even if you don’t like the syntax, can you get reliable results that look the way you want? If not, work with us to try to fix the problems. Then, either declare success or see below.

- no existing **shape** has sub-fields for text and/or fill colors. Not an awful idea to enhance the shape concept, but probably a slog
- instead think of a new **label** type, like **record** & **HTML**. They seem to be good models.
- _lib/common/shapes.c_ has much of the info you need to think about shapes & record-labeled nodes. (not sure where the HTML code is)
- when thinking about a model for a new **label** type:
  - **record** does not support fill colors or images
  - **record** cause certain layout problems for “flat” edges between nodes on the same rank
  - **HTML** seems to support all the features you want, with possible exception of correctly rounded table edges

Possibilities:

- if **HTML** works for you, but you dislike the syntax, create a preprocessor outside Graphviz: your syntax-to-HTML and declare success
- enhance the capabilities of all **shapes** to support “sub-fields” then add your new shape. This would seem to require additions to the node data structure - extra text fields, extra fill colors, … (guess: a **big** slog, probably requiring code changes all over)
- enhance the **record** (and **Mrecord** ) **label** type, adding multiple fill colors & image inclusion. (guess: the image inclusion might be a bit of work) (remember the layout issues for **records** )
- create a new **label** type, based on a copy of **record** (similar to above)
- create a new **label** type that would really be a wrapper for the **HTML** type, just with simpler syntax. You would add the parser for your new syntax, similar to _parse\_reclbl_ in _shapes.c_ to translate to **HTML**.
- create a new **label** type somewhat from scratch (slog?)

Did this help in any way?

---

<div class="post-metadata">

**Author:** ![jcolonfzenpr](https://sea2.discourse-cdn.com/graphviz/user_avatar/forum.graphviz.org/jcolonfzenpr/32/1303_2.png) [@jcolonfzenpr](https://forum.graphviz.org/u/jcolonfzenpr)\
**Post date:** [February 21, 2024, 7:43pm UTC](https://forum.graphviz.org/t/new-node-shape-typed-node/2034/3 "2024-02-21T19:43:47Z")

</div>

As recommended by steveroush I think the HTML-like nodes option is the easiest way to go.

 ![Screenshot from 2024-02-21 15-39-55](https://global.discourse-cdn.com/graphviz/original/2X/0/064c57253ae9ffeabdf824dd75cfe91381f974f9.png)

All this diagram is practically nodes where the Label is an HTML table.

---

<div class="post-metadata">

**Author:** ![steveroush](https://avatars.discourse-cdn.com/v4/letter/s/a9adbd/32.png) [@steveroush](https://forum.graphviz.org/u/steveroush)\
**Post date:** [February 22, 2024, 12:33am UTC](https://forum.graphviz.org/t/new-node-shape-typed-node/2034/4 "2024-02-22T00:33:00Z")

</div>

You can get very close with HTML (see below). The only problem I see is that the fill-color is a rectangle, even if the style is rounded (look carefully at the attached image).  
**bgcolor** works correctly as an attribute of the table (then fill with white for the other fields), but gets messy with images or third fill-colors.

```auto
digraph i{
 {rank=same
  n1 [shape=plaintext,label=<
  <TABLE style="rounded" CELLSPACING="0" CELLPADDING="0" BORDER="1" cellborder="0"> 
  <TR><TD FIXEDSIZE="true" height="20" width="20"><IMG SRC="image_dir/cow.png" scale="true"/></TD><TD>some text<BR/>goes here<BR/>some text<BR/>goes away</TD></TR>
  </TABLE> > ]

  n2 [shape=plaintext,label=<
  <TABLE style="rounded" CELLSPACING="0" CELLPADDING="0" BORDER="1" cellborder="0" >
  <TR><TD colspan="2" bgcolor="green1">Step #1</TD></TR>
  <TR><TD FIXEDSIZE="true" height="20" width="20"><IMG SRC="image_dir/cow.png" scale="true"/></TD><TD>some text<BR/>goes here</TD></TR>
  </TABLE> > ]

  n3 [shape=plaintext,label=<
  <TABLE style="rounded" CELLSPACING="0" CELLPADDING="0" BORDER="1" cellborder="0" >
  <TR><TD colspan="2" bgcolor="green1">Step</TD></TR>
  <TR><TD FIXEDSIZE="true" height="20" width="20"><IMG SRC="image_dir/cow.png" scale="true"/></TD><TD>some text</TD></TR>
 <TR><TD colspan="2"></TD></TR>
 <HR/>
 <TR><TD >age:</TD><TD >old</TD></TR>
 <HR/>
 <TR><TD colspan="2" bgcolor="lightpink" >Warning: geeky</TD></TR>
  </TABLE> > ]
  n1 -> n2 -> n3
  }

n4 [shape=Mrecord label="{Mrecord|and some more\nstuff}" style=filled color=green]
n1 -> n4
} 

```

Giving:  
 ![yaSimpleTable1](https://global.discourse-cdn.com/graphviz/original/2X/3/3093cc3aafb969c4d28fe742cc2d1c15dd61cef4.png)

---

<div class="post-metadata">

**Author:** ![smattr](https://sea2.discourse-cdn.com/graphviz/user_avatar/forum.graphviz.org/smattr/32/85_2.png) [@smattr](https://forum.graphviz.org/u/smattr)\
**Post date:** [February 22, 2024, 6:32am UTC](https://forum.graphviz.org/t/new-node-shape-typed-node/2034/5 "2024-02-22T06:32:27Z")

</div>

There have been numerous requests for new node shapes in the past. E.g. [[Dot] Add logic gate shapes (#99) · Issues · graphviz / graphviz · GitLab](https://gitlab.com/graphviz/graphviz/-/issues/99) is one that is repeatedly requested by multiple people. I’m not aware of any current effort to actually address these requests though.

As Steve said, lib/common/shapes.c is the place to look. It even has ASCII art drawings of the existing shapes.

> How would we need to test this?

Take a look at tests/test\_regression.py. This is a kitchen sink of test cases, with the full expressibility of Python available to you. I imagine you could construct something in here that renders to an output format of your choosing and then somehow programmatically ask “does the rendered image look close enough to my shape?”

I’m not aware of any barriers to adding new shapes (with the exception of the effort required to do so), so I’m supportive of this.

---

<div class="post-metadata">

**Author:** ![Vithanco](https://sea2.discourse-cdn.com/graphviz/user_avatar/forum.graphviz.org/vithanco/32/292_2.png) [@Vithanco](https://forum.graphviz.org/u/Vithanco)\
**Post date:** [February 28, 2024, 10:30am UTC](https://forum.graphviz.org/t/new-node-shape-typed-node/2034/6 "2024-02-28T10:30:57Z")

</div>

Thank you all for the great input. I am looking to get this one “right”, so the node should look good.

It might be easiest would be to look at how to cut off the filled corners of the HTML table to make it look right.

But I will look into shapes.c as well. Is there a way how to provide a shape with more than one colour if it is defined as a polygon or a record? Or would that require much more work?

---

<div class="post-metadata">

**Author:** ![jjlong](https://sea2.discourse-cdn.com/graphviz/user_avatar/forum.graphviz.org/jjlong/32/887_2.png) [@jjlong](https://forum.graphviz.org/u/jjlong)\
**Post date:** [February 28, 2024, 12:45pm UTC](https://forum.graphviz.org/t/new-node-shape-typed-node/2034/7 "2024-02-28T12:45:34Z")

</div>

I think you can achieve what you need using a combination of existing shapes (rectangle), styles (rounded,filled), and Gradient fill parameters (70% Azure, 30% Blue fill, with a gradient angle of 90 degrees). For example, these attributes:

```dot
labelloc="top" shape="rect" height="0.75" width="1.5" gradientangle="90" fillcolor="Azure;0.70:Blue" color="SeaGreen4" penwidth="2" fontname="Arial" fontsize="14" fontcolor="Red" style="rounded,filled"

```

along with a html-like label such as:

```html
<<b>Heading</b><br/><BR/>Some Text<BR/>More Text>

```

will create this shape:

![image](https://global.discourse-cdn.com/graphviz/original/2X/7/77dda7707552afc4f7a12eb2ce81d77de5303096.png)

I’m assuming you can get a more precise layout in the label by using a table, but you get the point.

Shameless plug, this node definition was created using the “Style Designer” worksheet in the [Excel to Graphviz](https://exceltographviz.com/) Relationship Visualizer spreadsheet.

 ![image](https://global.discourse-cdn.com/graphviz/original/2X/9/91efa745abc781dae021274ab0364ce9caf75aa7.png)

---

<div class="post-metadata">

**Author:** ![BartB](https://avatars.discourse-cdn.com/v4/letter/b/848f3c/32.png) [@BartB](https://forum.graphviz.org/u/BartB)\
**Post date:** [March 1, 2024, 8:55am UTC](https://forum.graphviz.org/t/new-node-shape-typed-node/2034/8 "2024-03-01T08:55:00Z")

</div>

It might be usefull to add this usage of color gradients in the documentation and sample gallery of [graphviz.org](http://graphviz.org). It is not obvious from the current documentation this is possible, but nevertheless very useful.
