Search code examples
pythonpython-3.xgraphvizpygraphviz

Make a node not affect graph layout


I am trying to make a node without affecting the positioning of connected nodes. When I plot the graph, it centers the parent node between the children nodes; this is causing the staggered effect. How can I make the failure node not affect the layout of the other nodes? I have already made the lines straight like they are in the desired photo, but it still has the staggered layout.

Current style:

Current style

Desired style:

Desired Style

EDIT: Dot Code

strict graph "" {
graph [bb="0,0,562,490",
    bgcolor="#666666",
    fontcolor=white,
    fontname=monospace,
    label="ACI MSC - Create Bridge Domain - L3",
    labelfontsize=40,
    labelloc=t,
    lheight=0.19,
    lp="281,479",
    lwidth=3.30,
    newrank=yes,
    nodesep=0.2,
    outputorder=edgesfirst,
    overlap=compress,
    ranksep=0.5,
    splines=spline
];
node [fillcolor=white,
    fixedsize=True,
    fontcolor=black,
    fontname=monospace,
    label="\N",
    shape=rectangle,
    style=filled,
    width=5.125
];
edge [fontname=monospace,
    fontsize=15,
    penwidth=2
];
Start    [color=white,
    fillcolor=blue,
    fixedsize=false,
    fontcolor=white,
    height=0.5,
    pos="377.5,450",
    shape=oval,
    width=1];
"ACIMSC-CreateSchemaandAddTemplate-Sub"  [height=0.5,
    pos="377.5,378"];
Start -- "ACIMSC-CreateSchemaandAddTemplate-Sub"     [color=green,
    pos="377.5,431.83 377.5,421 377.5,407.29 377.5,396.41"];
"ACIMSC-AddBridgeDomaintoTemplate"   [height=0.5,
    pos="274.5,306"];
"ACIMSC-CreateSchemaandAddTemplate-Sub" -- "ACIMSC- 
AddBridgeDomaintoTemplate"   [color=green,
    pos="351.51,359.83 335.89,348.92 316.1,335.08 300.48,324.16"];
Fail     [color=white,
    fillcolor=red,
    fixedsize=false,
    fontcolor=white,
    height=0.5,
    pos="421.5,18",
    shape=oval,
    weight=0,
    width=1];
"ACIMSC-CreateSchemaandAddTemplate-Sub" -- Fail  [color=red,
    pos="423.22,359.95 439.3,351.39 455.96,339.56 466.5,324 
    489.24,290.42 481.5,274.55 481.5,234 481.5,234 481.5,234 
    481.5,162 
    481.5,120.71 \
    475.54,109.6 458.5,72 452.5,58.75 443.25,45.25 435.5,35.063"];
"ACIMSC-AddBridgeDomaintoTemplate" -- Fail   [color=red,
    pos="356.37,288 391.19,278.55 426.17,266.02 436.5,252 
    485.39,185.63 447.55,77.845 429.6,35.692"];
VscaleACIMultisiteAddSubnettoBridgeDomain    [height=0.5,
    pos="244.5,234"];
"ACIMSC-AddBridgeDomaintoTemplate" -- 
VscaleACIMultisiteAddSubnettoBridgeDomain    [color=green,
    pos="266.93,287.83 262.42,277 256.7,263.29 252.17,252.41"];
VscaleACIMultisiteAddSubnettoBridgeDomain -- Fail    [color=red,
    pos="325.05,215.91 360.06,206.35 395.58,193.76 406.5,180 
    439.94,137.85 431.92,68.723 425.62,36.11"];
"ACIMSC-AddL3OuttoSiteBridgeDomain-Sub"  [height=0.5,
    pos="214.5,162"];
VscaleACIMultisiteAddSubnettoBridgeDomain -- "ACIMSC- 
AddL3OuttoSiteBridgeDomain-Sub"  [color=green,
    pos="236.93,215.83 232.42,205 226.7,191.29 222.17,180.41"];
"ACIMSC-AddL3OuttoSiteBridgeDomain-Sub" -- Fail  [color=red,
    pos="309.72,143.87 333.49,135.88 357.57,124.41 376.5,108 
    398.54,88.885 410.97,56.41 416.96,36.139"];
"ACIMSC-DeployTemplatetoSites"   [height=0.5,
    pos="184.5,90"];
"ACIMSC-AddL3OuttoSiteBridgeDomain-Sub" -- "ACIMSC- 
DeployTemplatetoSites"   [color=green,
    pos="206.93,143.83 202.42,133 196.7,119.29 192.17,108.41"];
"ACIMSC-DeployTemplatetoSites" -- Fail   [color=red,
    pos="244,71.924 290.62,57.761 353.6,38.629 390.65,27.373"];
Complete     [color=white,
    fillcolor="#129112",
    fixedsize=false,
    fontcolor=white,
    height=0.5,
    pos="184.5,18",
    shape=oval,
    width=1.3321];
"ACIMSC-DeployTemplatetoSites" -- Complete   [color=green,
    pos="184.5,71.831 184.5,61 184.5,47.288 184.5,36.413"];
}

Solution

  • I couldn't render your code to achieve your picture, but the techniques I'm about to suggest should work anyway.

    I've composed a similar basic example code:

    digraph {
        node [shape=rect]
    
        a -> b -> c -> d -> e -> f
        success [shape=oval]
        f -> success
        {
            rank=max
            failure [shape=oval]
        }
        {a b c d e f} -> failure
    }
    

    This gives following picture with your issue reproduced:

    First possible solution may be to add constraint=false attribute to the edges leading to falure node. This attribute does just that - prevents the edge from affecting the layout.

    digraph {
        node [shape=rect]
    
        a -> b -> c -> d -> e -> f
        success [shape=oval]
        f -> success
        {
            rank=max
            failure [shape=oval]
        }
        {a b c d e f} -> failure [constraint=false]
    }
    

    Result:

    Second possible solution would be to increase the weight attribute of the edges which you need to remain straight. Edges with higher weight tend to be shorter and straighter than the others:

    digraph {
        node [shape=rect]
    
        a -> b -> c -> d -> e -> f [weight=10]
        success [shape=oval]
        f -> success
        {
            rank=max
            failure [shape=oval]
        }
        {a b c d e f} -> failure
    }
    

    Result: