GraphRecipes.jl
GraphRecipes.jl copied to clipboard
TreePlot & linked lists
I’m trying to plot list-like tree structures using TreePlot and get various errors. Here is a minimal example.
using GraphRecipes, AbstractTrees, Plots
abstract type L end
struct E <: L end
struct N <: L n :: L end
Base.isempty(::E) = true
AbstractTrees.children(l :: N) = [ l.n ]
AbstractTrees.printnode(io::IO, ::E) = print(io, "E")
AbstractTrees.printnode(io::IO, ::N) = print(io, "N")
plot(TreePlot(E()))
plot(TreePlot(N(E())))
plot(TreePlot(N(N(E()))))
The first plot crashes with
MethodError: reducing over an empty collection is not allowed; consider supplying
initto the reducer
The second with
DimensionMismatch: new dimensions (4, 0) must be consistent with array size 2
The last one with
DivideError: integer division error