Search code examples
graphvizspline

How to draw a spline curve between 2 points with a control points with graphviz?


I would like to create a spline curve between the blue point and the green point with the red point as a control point.

Graphviz documentation says :

  1. splines attribute, of type bool or string, is valid on Graphs
  2. splineType with the pattern : spline ( ';' spline )* is a valid type for pos attribute
  3. pos attribute is valid on Edges and Nodes

I Tried this graph

graph G{     
layout ="neato" outputorder="edgesfirst" splines="true"
a[shape="point" pos="0,0!"        color="blue"]
b[shape="point" pos="1,0!"        color="green"]
c[shape="point" pos=" 0.5,0.5!"   color="red"]
a -- b [pos="e,1,0 s,0,0 0.5,0.5!"]   
}

then on Windows 10 PowerShell :

neato.exe -Tsvg .\spline.dot > .\spline.svg

with

neato - graphviz version 2.49.3 (20211023.0002)

result enter image description here

What is the proper way of achieving this?

Thanks.


Solution

  • Close, but ...

    So:

    graph G{
    // default units for pos values are in points (72/inch)
    // multiplied by 100 out of laziness 
    // ! only applies to nodes, not edges
    layout ="neato"
    outputorder="edgesfirst"  // why???
    splines="true"
    
    a[shape="point" pos="0,0!"        color="blue"]
    b[shape="point" pos="100,0!"        color="green"]
    c[shape="point" pos="50,50!"   color="red"]
    // "s" arrowhead must preceed "e" arrowhead,  so swaped them
    // BUT, "--" says non-directed graph, NO arrowheads, so they are deleted
    // also need 4, 7, 11, ... points NOT including arrowhead points
    // so added points (just guesses)
    a -- b [pos="0,0 30,66 70,66 100,0"]   
    }
    

    Gives:
    enter image description here

    Whew