How to draw directed acyclic graphs (DAGs) in ASCII code for terminal display in Julia?

I’m working on a project in Julia where I need to visualize Directed Acyclic Graphs (DAG) directly in the terminal. I’m searching for a way to represent these graphs using ASCII characters.

The idea is to have nodes and edges of the graph represented in ASCII code. This would ideally work for any DAG, not just binary trees. My use case involves having nodes with potentially multiple outgoing edges, and nodes can be on various ‘levels’ of the graph.

Could anyone provide some guidance or point me towards any resources, algorithms, or existing packages that could aid in creating ASCII representations of DAGs? Any advice would be greatly appreciated!

3 Likes

Perhaps UnicodePlots.jl? With a layout created by GraphPlot.jl

Sorry, I still do not understand how this works. Which layout are we talking about?

The layout describes the coordinate of the nodes, which is one of the pain points when drawing a graph.
GraphPlot.jl doesn’t interface with Plots.jl or UnicodePlots.jl, so you cannot use it directly for plotting in the terminal. However, you may be able to use it to define the layout, which you then feed to UnicodePlots.jl explicitly

1 Like

I would also be looking forward for this. Perhaps worthwhile opening an issue in UnicodePlots…

I think the more worthwhile approach would be a rewrite of GraphPlot.jl to use plot recipes, this making it compatible with the whole JuliaPlots ecosystem

Would be great to have this compatible with UnicodePlots!

Another way could be to wrap Graph::Easy somehow (it’s a Perl package, I don’t know if this is possible as a jll binary). The results are very nice, you can try it here: https://dot-to-ascii.ggerganov.com/

There is also this Python package that ported the DAG printing of git.

Is this Python package only for plotting Git commit graphs?

I never tried the Python library, but it seems as if you can plot any DAG (see example in the readme). It is not very pretty though