Did you know that Graphviz can also
output its own dot format, but that the output contains layout information? That might help you get started with the 2nd part. There's also an extended dot[1] format with more information
1: https://www.graphviz.org/doc/info/output.html#d:xdot