8
$\begingroup$

This question already has an answer here:

The following code generates a graph.

LayeredGraphPlot[
    {{"i" -> "m", 1}, {"i" -> "...", 1}, {"i" -> "n", 1}, {"m" -> "j", 2}, {"..." -> "j", 2}, {"n" -> "j", 2}}, 
    DirectedEdges -> True, 
    VertexLabeling -> True, 
    PlotStyle -> {FontSize -> 14}, 
    EdgeRenderingFunction -> (Switch[#3, 1, {Dashed, Arrow[#1, .1]}, 2, {Arrow[#1, .1]}] &)]

enter image description here

My question is that is it possible to draw curves between "i" and each of "m", "...", "n" instead of straight lines, like the red curve below? Thank you. enter image description here

$\endgroup$

marked as duplicate by kglr plotting Apr 9 '15 at 0:59

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

12
$\begingroup$

You can construct a BezierCurve by adding two control points to the list of vertex coordinates for the two vertices (p[[1]] and p[[2]]) incident to an edge.

In the following function bC with three arguments ({t1,t2,t3}), the two additional points are obtained by taking two points on the line joining the two vertex coordinates, t1 p[[1]] + (1-t1) p[[2]] and t2 p[[1]] + (1-t2) p[[2]] where 0<= t1, t2 <=1, and adding to these points {0,t3} or {t3,0} to ensure that the resulting four points are not collinear. The default values for the three arguments are {t1,t2,t3}= {1/3,2/3,1/3}.

ClearAll[bC]
bC[t1_:(1/3),t2_:(2/3), t3_:(1/3)]:= With[{p=#}, 
    BezierCurve[{p[[1]],
                 t1 p[[1]]+(1-t1)p[[2]]+If[p[[1,1]]==p[[2,1]],{t3,0},{0,t3}],
                 t2 p[[1]]+(1-t2)p[[2]]-If[p[[1,1]]==p[[2,1]],{t3,0},{0,t3}],
                 p[[2]]}]]&;

LayeredGraphPlot[ {{"i" -> "m", 1}, {"i" -> "...", 1}, {"i" -> "n", 1}, 
                   {"m" -> "j", 2}, {"..." -> "j", 2}, {"n" -> "j", 2}}, 
    DirectedEdges -> True, VertexLabeling -> True, 
    PlotStyle -> {FontSize -> 14}, 
    EdgeRenderingFunction -> (Switch[#3, 1, {Dashed,Arrow[bC[][#],.1]}, 2, {Arrow[#1, .1]}] &)]

enter image description here

$\endgroup$
  • $\begingroup$ Why did you reopen this question, please? $\endgroup$ – Mr.Wizard Apr 8 '15 at 23:00
  • $\begingroup$ @Mr.Wizard, I was puzzling over why this q/a was reopened and appeared with a "modified by kguler" tag. I must have inadvertently clicked the reopen button. Sorry. $\endgroup$ – kglr Apr 8 '15 at 23:16
  • $\begingroup$ That's okay. It just surprised me as I didn't see any precipitating comments or recent edits. Why don't you close it now? I think this was the previous duplicate if I am reading the timeline correctly. $\endgroup$ – Mr.Wizard Apr 9 '15 at 0:57
  • $\begingroup$ Mr.Wizard, how come my accidental click made the previous close votes and links disappear? $\endgroup$ – kglr Apr 9 '15 at 1:01
  • 1
    $\begingroup$ You have the Gold tag badge for plotting (and list-manipulation) which gives you moderator-like single vote power to close (and apparently reopen) duplicates in this tag. Use it wisely. :-) (Possible duplicate: comments are automatically deleted when the close occurs.) $\endgroup$ – Mr.Wizard Apr 9 '15 at 1:22

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