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

1

1

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.

Mclemore answered 16/12, 2021 at 12:2 Comment(3)
Is this the final goal, or just part of a bigger project?Prefatory
@sroush, it's indeed part of a bigger project. It seems that it's possible when I read the documentation, but impossible so far to use it properly and I didn't find any examples.Mclemore
DIY splines are a pain, but doable - though fully automating would be a super pain. To combine with a "normal" dot graph, think about starting with "dot -Tdot" for the main graphPrefatory
P
2

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

Prefatory answered 16/12, 2021 at 18:50 Comment(1)
thanks! about the outputorder="edgesfirst" , if you comment this and rerender you will see that the edge overlay the blue and green points, of course, you may need to zoom a little bit to notice that.Mclemore

© 2022 - 2024 — McMap. All rights reserved.