GraphRecipes.jl icon indicating copy to clipboard operation
GraphRecipes.jl copied to clipboard

TreePlot & linked lists

Open vbgl opened this issue 1 year ago • 0 comments

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 init to 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

vbgl avatar Dec 04 '23 12:12 vbgl