6
$\begingroup$

I have a graph where I want to add edges which should be visible therefore they must be curved sometimes. enter image description here

Here the one edge on the left (from c2cd [top left] to d5de [bottom left]) should be curved.

My current code:

    g := Graph[{"s" -> "s1sc", "s1sc" ->  "s2sa", "s2sa" -> "s3sb", 
   "s1sc" -> "s3fj", "s3fj" -> "s5gk", "s3fj" -> "f9hd", 
   "s1sc" -> "g8ie", "f" -> "f3fj", "f3fj" -> "f5gk", 
   "f5gk" -> "f9hd", "f5gk" -> "g6gc", "f3fj" -> "g8ie", 
   "a" -> "a2cd", "a2cd" -> "a2ae", "a2ae" -> "a6ad", 
   "a2ae" -> "a9hd", "a2cd" -> "c8ie", "g" -> "g5gk", 
   "g5gk" -> "g6gc", "g5gk" -> "g8ie", "g5gk" -> "h9hd", 
   "c" -> "c2cd", "c2cd" -> "c8ie", "c2cd" -> "h9hd", "k" -> "k1ki", 
   "k1ki" -> "k3kt", "k3kt" -> "k6kj", "k1ki" -> "k8ie", 
   "k1ki" -> "h9hd", "b" -> "b2bc", "b2bc" -> "b8ie", 
   "b2bc" -> "h9hd", "h" -> "h8ie", "h8ie" -> "h9hd", "d" -> "d5de", 
   "d5de" -> "d8ie", "i" -> "i8ie", "c2cd" -> "d5de"}, 
  EdgeStyle -> {("s1sc" -> "s2sa") -> Green, ("s2sa" -> "s3sb") -> 
     Green, ("k1ki" -> "k3kt") -> Green, ("k3kt" -> "k6kj") -> 
     Green, ("a2ae" -> "a6ad") -> Green, ("g5gk" -> "g6gc") -> 
     Green, ("f5gk" -> "g6gc") -> Green, ("s" -> "s1sc") -> 
     Gray, ("f" -> "f3fj") -> Gray, ("a" -> "a2cd") -> 
     Gray, ("g" -> "g5gk") -> Gray, ("c" -> "c2cd") -> 
     Gray, ("k" -> "k1ki") -> Gray, ("b" -> "b2bc") -> 
     Gray, ("h" -> "h8ie") -> Gray, ("d" -> "d5de") -> 
     Gray, ("i" -> "i8ie") -> Gray}, VertexLabels -> "Name", 
  DirectedEdges -> True, 
  VertexCoordinates -> {{10.708343333333334`, -0.7083433333333335`}, \
{10.708343333333334`, -1.7083433333333335`}, {11.708343333333334`, \
-2.7083433333333335`}, {11.708343333333334`, -3.7083433333333335`}, \
{10.708343333333334`, -2.7083433333333335`}, {10.708343333333334`, \
-3.7083433333333335`}, {9.708343333333334`, -3.7083433333333335`}, \
{8.708343333333334`, -2.7083433333333335`}, {9.708343333333334`, \
-0.7083433333333335`}, {9.708343333333334`, -1.7083433333333335`}, \
{9.708343333333334`, -2.7083433333333335`}, {7.7083433333333335`, \
-3.7083433333333335`}, {2.7083433333333335`, -0.7083433333333335`}, \
{2.7083433333333335`, -1.7083433333333335`}, {2.7083433333333335`, \
-2.7083433333333335`}, {2.7083433333333335`, -3.7083433333333335`}, \
{3.7083433333333335`, -3.7083433333333335`}, {0.7083433333333335`, \
-2.7083433333333335`}, {7.7083433333333335`, -0.7083433333333335`}, \
{7.7083433333333335`, -1.7083433333333335`}, {4.7083433333333335`, \
-2.7083433333333335`}, {0.7083433333333335`, -0.7083433333333335`}, \
{0.7083433333333335`, -1.7083433333333335`}, {5.7083433333333335`, \
-0.7083433333333335`}, {5.7083433333333335`, -1.7083433333333335`}, \
{6.7083433333333335`, -2.7083433333333335`}, {6.7083433333333335`, \
-3.7083433333333335`}, {5.7083433333333335`, -2.7083433333333335`}, \
{3.7083433333333335`, -0.7083433333333335`}, {3.7083433333333335`, \
-1.7083433333333335`}, {3.7083433333333335`, -2.7083433333333335`}, \
{4.7083433333333335`, -0.7083433333333335`}, {4.7083433333333335`, \
-1.7083433333333335`}, {0.7083433333333335`, -5.125030000000001`}, \
{0.7083433333333335`, -6.125030000000001`}, {0.7083433333333335`, \
-7.125030000000001`}, {6.916686666666667`, -5.625030000000001`}, \
{6.916686666666667`, -6.625030000000001`}}]

Is it possible to make the edge curved explicitly? I know that sometimes mathematica make an edge curved on it's own...

$\endgroup$
1
  • $\begingroup$ related: 34181 $\endgroup$
    – Kuba
    Aug 18, 2016 at 12:37

2 Answers 2

8
$\begingroup$
SetProperty[{g, "c2cd" -> "d5de"}, EdgeShapeFunction -> 
 ({Arrowheads[{Large}], Arrow[GraphElementData[{"CurvedArc", "Curvature" -> -3}][##]]} &)]

enter image description here

To make all edges curved:

SetProperty[g, EdgeShapeFunction ->
 ({Arrowheads[{Large}], Arrow[GraphElementData[{"CurvedArc", "Curvature" -> -1}][##]]} &)]

Mathematica graphics

$\endgroup$
1
  • $\begingroup$ Very nice, looks much better than the other attempt! $\endgroup$
    – Jason B.
    Aug 18, 2016 at 22:37
2
$\begingroup$

This is a silly little hack, but maybe it will help here. You can make a function that draws a half-circle between two points, and use that as your EdgeShapeFunction,

ef = (Arrow[
    CirclePoints[
      Mean@#1[[{1, -1}]], {(EuclideanDistance @@ #1[[{1, -1}]])/2, 
       VectorAngle[Subtract @@ #1[[{1, -1}]], {1, 0}]}, 
      100][[;; 51]]] &);

You could give the option , EdgeShapeFunction -> ef to the Graph if you like, getting this output:

Mathematica graphics

But if you only want a specific edge to be modified, then replace the line "c2cd" -> "d5de" in your list of edges with Property["c2cd" -> "d5de", EdgeShapeFunction -> ef], resulting in this:

Mathematica graphics

If you've already got g defined as the graph, then you could achieve the same result via

SetProperty[g, 
 EdgeShapeFunction -> {DirectedEdge["c2cd", "d5de"] -> ef}]
$\endgroup$
7
  • $\begingroup$ Thanks but I hoped there is a more automatic function because I will need a lot of different curves. $\endgroup$
    – Wikunia
    Aug 18, 2016 at 14:05
  • $\begingroup$ There are a lot of different graph layouts, but you don't have access to them because you've specified the coordinates yourself. $\endgroup$
    – Jason B.
    Aug 18, 2016 at 14:08
  • $\begingroup$ Yeah I want the graph twice (one without these edges) and want them to look nearly the same :D Probably I will use only a part of it for better readability :) $\endgroup$
    – Wikunia
    Aug 18, 2016 at 14:10
  • $\begingroup$ Are you looking for an automated way to find out which edges are going through other vertices that aren't part of the edge, which is the case for this particular edge? $\endgroup$
    – Jason B.
    Aug 18, 2016 at 14:11
  • $\begingroup$ Yeah kind of and curve them in an automated way. I have high standards but well it's mathematica ... $\endgroup$
    – Wikunia
    Aug 18, 2016 at 14:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.