Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I style the ports of record based nodes in GraphViz?

I'm feeding this simple input script defining record based nodes to dot in order to create a SVG from it (the SVG part actually doesn't matter):

graph mygraph{
  node [shape=record, fontsize=10, fontname=Arial];
  rankdir=TB;
  ranksep=0.5;
  rank=max;
  splines=true;
  overlap=false;
  mindist=0.2;
  "d1" [style=solid, label="{\N|{<0> 0|<1> 1}}"];
  "d2" [style=solid, label="{\N|{<0> 0|<1> 1|<2> 2|<3> 3}}"];
  "d1":0 -- "d2":0[color=blue, penwidth=3, tooltip="d1:0 -- d2:0", URL="#"];
}

This yields a graph where ports 0 of d1 and port 0 of d2 are connected by a blue spline:

dot result

Fine.

Now I have the need to colorize the ports. For example: port 1 of d2 shall be green and port 2 of d2 shall be orange. Or something.

How do I achieve this?


Edit 1: the solid frame around the nodes is important. I need it solid for some nodes, dashed for others.

like image 816
eckes Avatar asked Feb 21 '14 12:02

eckes


People also ask

What is the shape of a node?

Shape nodes Holds an object's geometry attributes or attributes other than the object's transform node attributes. A shape node is the child of a transform node. A transform node has only one shape node.

How do you make a graph on graphviz?

Create a graph object, assemble the graph by adding nodes and edges, and retrieve its DOT source code string. Save the source code to a file and render it with the Graphviz installation of your system. Use the view option/method to directly inspect the resulting (PDF, PNG, SVG, etc.) file with its default application.

What is graphviz Neato?

neato is a reasonable default tool to use for undirected graphs that aren't too large (about 100 nodes), when you don't know anything else about the graph. neato attempts to minimize a global energy function, which is equivalent to statistical multi-dimensional scaling.


1 Answers

HTML-like labels give you a lot of flexibility in formatting labels. This code:

graph mygraph{
  node [shape=record, fontsize=10, fontname=Arial];
  rankdir=TB;
  ranksep=0.5;
  rank=max;
  splines=true;
  overlap=false;
  mindist=0.2;
  d1 [shape=none, margin=0, label=<
    <table border="0" cellborder="1" cellspacing="0" cellpadding="4">
        <tr><td colspan="2">d1</td></tr>
        <tr><td port="0">0</td><td>1</td></tr>
    </table>>];
  d2 [shape=none, margin=0, label=<
    <table border="0" cellborder="1" cellspacing="0" cellpadding="4">
        <tr><td colspan="4">d2</td></tr>
        <tr><td port="0">0</td><td bgcolor="green">1</td><td bgcolor="orange">2</td><td>3</td></tr>
    </table>>];
  d1:0 -- d2:0[color=blue, penwidth=3, tooltip="d1:0 -- d2:0", URL="#"];
}

Produces this graph:

enter image description here

Note the use of the port attribute to identify the port.

like image 76
SSteve Avatar answered Jan 01 '23 15:01

SSteve