0

I draw a simple graph as shown below and found different behavior of the color display.

digraph G {
     concentrate=true
    edge [dir=none]
     a  -> b [color=red]
     b -> c   
     c -> b 
     b -> a 
    }

Correct Image of graph

Graph show edge between a and b is red >> this one is correct.

But when I just change it to be

     digraph G {
     concentrate=true
    edge [dir=none]
     a  -> b 
     b -> c   
     c -> b 
     b -> a [color=red]
    }

Red color not show

This time the color of edge a and b is black not red color as I want. Could someone figure out what I do wrong here?

ben rudgers
  • 3,647
  • 2
  • 20
  • 32
Warin
  • 11
  • 1
  • 2

2 Answers2

3

You can use ports to prevent edges from overlap:

digraph G {
  concentrate=true
  edge [dir=none]
  a  -> b 
  b -> c   
  c -> b 
  b:nw -> a:se [color=red]
}

result

See also: https://graphviz.gitlab.io/_pages/doc/info/lang.html

astef
  • 8,575
  • 4
  • 56
  • 95
1

Analysis

Because the code in the question draws two edges one on top of the other, the color of the last edge drawn wins. The layout engine for Dot works either Bottom to Top or Right to Left. This means that the last edge drawn is the first one listed.

General Solution

Dot draws Digraphs. An undirected graph can be simulated using dir=none but then there should only be one edge:

digraph G {
  concentrate=true
  edge [dir=none]
  a -> b [color=red]
  b -> c
 }

digraph showing sue of dir=none property

Alternative

Keep in mind that dir=none is not primarily intended as a display property. If the goal is two directed edges, then dir=both is a better alternative:

digraph G {
  concentrate=true
  edge [dir=both]
  a -> b [color="red:black"]
  b -> c [color="black:black]
}

digraph showing use of dir=both attribute

Notes

It is useful to conceptually separate modeling the graph from the display properties. Dot doesn't make this particularly easy because it encourages inlining style information. But the price of separating concerns probably pays off in debugging time.

Community
  • 1
  • 1
ben rudgers
  • 3,647
  • 2
  • 20
  • 32
  • Your explanation is clear and thank you for alternative solution :D / Thank you very much. – Warin May 16 '15 at 14:07