Using dot, I’m trying to create a rounded node with a complex label encoded using an HTML table. The top title row needs a color background, and the remaining rows need to be white.
I have it almost working in terms of basic behavior, but it seems to add a small border of the table background color even with cellpadding="0"
set on the table. This occurs in both PNG and SVG output. Looking at SVG output it looks like a single “pixel” border gets added.
Is there any way to avoid this, short of post-processing the SVG?
Example DOT graph that generated the above is:
digraph render_graph
{
rankdir="LR"
node [shape="none"]
mynode [label=<
<table bgcolor="#FF0000" border="1" cellspacing="0" cellborder="0" style="rounded">
<tr>
<td cellpadding="2">Title</td>
</tr>
<tr>
<td cellpadding="10" bgcolor="#FFFFFF">Data</td>
</tr>
</table>
>]
}
Note, you need to set the background color on the table so that it clips to the rounded border. Setting it on the table row results in the background color rendering outside of the rounded corner.
Best workaround I’ve found so far is to edit the SVG generated by dot
as a post-process.
The white cell background is rendered using an SVG polygon of the form:
<polygon fill="#ffffff" stroke="transparent"
points="8.5,-132.5 8.5,-194.5 111.5,-194.5 111.5,-132.5 8.5,-132.5"/>
… which is relatively easy to pattern-match reliably in our diagrams, as they are the only polygons with 5 points and a white fill.
Once we’ve found them we just need to rewrite the coordinates of each to push the left-most two points -1 in X, the right-most two points +1 in X, and the bottom-most two points +1 in Y, enlarging the box enough to cover the bleeding table background.
Not ideal, so would love to know if anyone finds a pure DOT solution.
Does this work? Note where border is added & color See before & after:
digraph render_graph
{
rankdir="LR"
node [shape="none"]
mynode [label=<
<table bgcolor="#FF0000" border="1" cellspacing="0" cellborder="0" style="rounded">
<tr>
<td cellpadding="2">Title</td>
</tr>
<tr>
<td cellpadding="10" bgcolor="#FFFFFF">Data</td>
</tr>
</table>
>]
tryTryAgain [ label=<
<table bgcolor="#FF0000" border="1" cellspacing="0" cellborder="0" style="rounded">
<tr>
<td border="0" cellpadding="2">Try #X</td>
</tr>
<tr>
<td color="#FFFFFF" border="1" cellpadding="10" bgcolor="#FFFFFF">Data</td>
</tr>
</table>
>]
}
2