1
$\begingroup$

How could I make both vertices and edges moveable like this.
(source: https://csacademy.com/app/graph_editor/)

(In the image only nodes are movable but I would like to do this for edges as well) enter image description here

Graph[{1, 2, 3, 4, 5, 6}, {1 \[UndirectedEdge] 3, 
  1 \[UndirectedEdge] 5, 1 \[UndirectedEdge] 6, 2 \[UndirectedEdge] 5,
   2 \[UndirectedEdge] 6, 1 \[UndirectedEdge] 6, 
  3 \[UndirectedEdge] 4, 3 \[UndirectedEdge] 5, 3 \[UndirectedEdge] 6,
   5 \[UndirectedEdge] 6}, VertexLabels -> "Name"]
$\endgroup$
2
  • 2
    $\begingroup$ Something like this is coming in the next version of the IGraph/M package, if I ever get to it ... stay tuned! $\endgroup$
    – Szabolcs
    Commented Feb 19, 2022 at 22:53
  • $\begingroup$ @Szabolcs that's nice. Is there any sample so I can try now? $\endgroup$
    – hana
    Commented Feb 19, 2022 at 23:01

1 Answer 1

3
$\begingroup$

Use the option PerformanceGoal -> "Quality" in Graph

g1 = Graph[{1 -> 2, 2 <-> 3, 3 -> 1, 1 -> 3}, 
  VertexLabels -> Placed["Name", Center], VertexSize -> {v_ :> v/10}, 
  VertexStyle -> Directive[EdgeForm[{Thick, Black}], White], 
  VertexLabelStyle -> Large, PerformanceGoal -> "Quality"]

To move vertices interactively (with the edges adjusting automatically to new vertex locations), use Show @ g1 to get a Graphics object which can be interactively manipulated after double-clicking on it:

Show @ g1

enter image description here

$\endgroup$
2
  • $\begingroup$ Would it be possible to move the edges as you like? I tried but the edges got separated. $\endgroup$
    – hana
    Commented Feb 20, 2022 at 0:33
  • 1
    $\begingroup$ @hana, can't think of a simple way to get full interactivity. See these Q/As on DynamicLocation for some examples that you might find useful. $\endgroup$
    – kglr
    Commented Feb 20, 2022 at 2:21

Your Answer

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

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