Change the curvature of an edge

Hi everyone,

I am drawing an entity–relationship diagram with dot:

digraph {
graph [pad="0.1", nodesep="0.5", ranksep="1.5"];
node [shape=plain, fontname="Courier New", fontsize="11"];
rankdir=LR;

persons [label=<<table border="0" cellborder="1" cellspacing="0">
<tr><td>persons</td></tr>
<tr><td port="p_id">p_id INT UNSIGNED NOT NULL AUTO_INCREMENT</td></tr>
<tr><td port="p_firstname">p_firstname VARCHAR(256) NOT NULL</td></tr>
<tr><td port="p_lastname">p_lastname VARCHAR(256)</td></tr>
<tr><td port="p_birth_year">p_birth_year SMALLINT UNSIGNED NOT NULL</td></tr>
<tr><td port="p_boss">p_boss INT UNSIGNED </td></tr>
</table>>];

cars [label=<<table border="0" cellborder="1" cellspacing="0">
<tr><td>cars</td></tr>
<tr><td port="c_id">c_id INT UNSIGNED NOT NULL AUTO_INCREMENT</td></tr>
<tr><td port="c_owner">c_owner INT UNSIGNED </td></tr>
<tr><td port="c_reg_number">c_reg_number VARCHAR(64)</td></tr>
</table>>];

persons:p_boss:w -> persons:p_id:w;
cars:c_owner -> persons:p_id;
}

The problem is that one of the edges is overlapping table cars. I could easily (a) increase a horizontal distance between the tables or (b) draw this edge to the right of table persons so that it would not be overlapping anymore. However, I would prefer to change the curvature of this edge so that its leftmost point would be much closer to table persons.

Could you please tell me if/how it can be done in Graphviz?

1 Like

Semi-short answer: not in this case. You could try various values for the splines attribute (Attributes | Graphviz), but they won’t do what you ask in this case. (I did try them, and no joy. I had hopes for curved, but nope.)
Longer answer: this is a semi-common request. Tweaking edges is pretty difficult (except maybe for straight-line segments) Here is a pointer to a fix - a program that I wrote (cough, self aggrandizement) that can “fix” individual edges A program to "fix" simple edges.

Your input with one line changed:

digraph {
graph [pad="0.1", nodesep="0.5", ranksep="1.5"];
node [shape=plain, fontname="Courier New", fontsize="11"];
rankdir=LR;

persons [label=<<table border="0" cellborder="1" cellspacing="0">
<tr><td>persons</td></tr>
<tr><td port="p_id">p_id INT UNSIGNED NOT NULL AUTO_INCREMENT</td></tr>
<tr><td port="p_firstname">p_firstname VARCHAR(256) NOT NULL</td></tr>
<tr><td port="p_lastname">p_lastname VARCHAR(256)</td></tr>
<tr><td port="p_birth_year">p_birth_year SMALLINT UNSIGNED NOT NULL</td></tr>
<tr><td port="p_boss">p_boss INT UNSIGNED </td></tr>
</table>>];

cars [label=<<table border="0" cellborder="1" cellspacing="0">
<tr><td>cars</td></tr>
<tr><td port="c_id">c_id INT UNSIGNED NOT NULL AUTO_INCREMENT</td></tr>
<tr><td port="c_owner">c_owner INT UNSIGNED </td></tr>
<tr><td port="c_reg_number">c_reg_number VARCHAR(64)</td></tr>
</table>>];

persons:p_boss:w -> persons:p_id:w [edgeType=curved edgeDirection=cw edgeOffset="34"];   // note changes
cars:c_owner -> persons:p_id;
}

The command line:
dot myfile.gv | gvpr -cf alterSimpleEdge.gvpr | neato -n2 -Tpng > myfile.png

Giving:

1 Like