Search code examples
graphvizdot

In graphviz how to force a straight edge between two nodes?


Here is my graphviz code:

digraph G {
  rankdir="LR"
  node [shape=square]
  exDNS [label="External DNS"]
  inDNS [label="Internal DNS"]
  tm [label="Traffic Manager"]
  pri [label="App Service\nPrimary Region"]
  sec [label="App Service\nSecondary Region"]
  Browser -> {inDNS,exDNS} -> Imperva-> tm -> {pri,sec}
  Browser -> Imperva -> {pri,sec}
}

It produces the following result: enter image description here I would the edge Browser -> Imperva to go straight between the nodes External DNS and Internal DNS.

How can I do it?

I am using the dot renderer.


Solution

  • It is difficult to make edges behave (explicitly position them). But by attaching edges to ports, you can have some influence on edge locations.
    I think this is what you're after:

    digraph G {
      rankdir="LR"
    //  graph [splines=polyline]
      node [shape=square]
      exDNS [label="External DNS"]
      inDNS [label="Internal DNS"]
      tm [label="Traffic Manager"]
      pri [label="App Service\nPrimary Region"]
      sec [label="App Service\nSecondary Region"]
      Browser:ne -> exDNS -> Imperva
      Browser:e -> Imperva 
      Browser:se -> inDNS -> Imperva
      Imperva-> tm -> {pri,sec}
      Imperva -> {pri,sec}
    }
    

    enter image description here