1

I implemented a short python script using the graphviz library which parse a given documentation and automate the rendering of a simplified ER Diagram.

I achieved to render the entities and their relations, but the resulting layout is not optimal:

current_diagram

I would like something more human readable, landscape-oriented, like:

enter image description here

I tried to play with some of the attributes from the Graphviz documentation like size or ratio, and ended up with a script of this form:

digraph G {
    graph [overlap=false rankdir=LR ratio=3 size="5,8!" splines=true]
    node [fontname=Verdana fontsize=10 shape=record]
    edge [arrowhead=crow style=dashed]
    Tbl1 [label=<
            <table border="0" cellborder="1" cellspacing="0" cellpadding="4">
                <tr><td bgcolor="lightblue">Tbl1</td></tr>
                <tr><td port='0' align='left'>id  <i style='margin-left: 4px'>[int]</i></td></tr>
                <tr><td port='1' align='left'>field2  <i style='margin-left: 4px'>[int]</i></td></tr>
                <tr><td port='2' align='left'>field3  <i style='margin-left: 4px'>[date]</i></td></tr>
                <tr><td port='3' align='left'>Tbl2Id  <i style='margin-left: 4px'>[int]</i></td></tr>
            </table>
            > margin=0 shape=none]
    Tbl2 [label=<
            <table border="0" cellborder="1" cellspacing="0" cellpadding="4">
                <tr><td bgcolor="lightblue">Tbl2</td></tr>
                <tr><td port='0' align='left'>id  <i style='margin-left: 4px'>[int]</i></td></tr>
                <tr><td port='1' align='left'>field2  <i style='margin-left: 4px'>[int]</i></td></tr>
                <tr><td port='2' align='left'>field3  <i style='margin-left: 4px'>[str]</i></td></tr>
            </table>
            > margin=0 shape=none]
    Tbl3 [label=<
            <table border="0" cellborder="1" cellspacing="0" cellpadding="4">
                <tr><td bgcolor="lightblue">Tbl3</td></tr>
                <tr><td port='0' align='left'>id  <i style='margin-left: 4px'>[int]</i></td></tr>
                <tr><td port='1' align='left'>field2  <i style='margin-left: 4px'>[int]</i></td></tr>
                <tr><td port='2' align='left'>field3  <i style='margin-left: 4px'>[str]</i></td></tr>
                <tr><td port='3' align='left'>field4  <i style='margin-left: 4px'>[str]</i></td></tr>
                <tr><td port='4' align='left'>Tbl2Id  <i style='margin-left: 4px'>[str]</i></td></tr>
            </table>
            > margin=0 shape=none]
    Tbl1:3 -> Tbl2:0
    Tbl3:4 -> Tbl2:0
}

Is there something to do to achieve this? Should I use subgraphes? Some other graph or nodes attributes?

olinox14
  • 6,177
  • 2
  • 22
  • 39

0 Answers0