When laying out a graph via graphdrawing with the spring electrical layout, and the graph includes both sublayouts and "top-level" nodes (not in the sublayout) connected to each other, an error is thrown.
Here's a minimal example:
\documentclass{minimal} \usepackage{tikz} \usetikzlibrary{graphdrawing} \usegdlibrary{force} \usegdlibrary{trees} \begin{document} \tikz[spring electrical layout] { \node (a) {a}; \node (b) {b}; \begin{scope}[tree layout] \node (1) {1}; \node (2) {2}; \draw (1) edge (2); \end{scope} \draw (a) edge (1) (a) edge (b); } \end{document}
Compiling this throws the following error:
! LuaTeX error ...graphdrawing/lua/pgf/gd/interface/InterfaceToDisplay.lua:213: ...eneric/pgf/graphdrawing/lua/pgf/gd/force/CoarseGraph.lua:411: attempt to comp are number with nil stack traceback: [C]: in function 'assert' ...graphdrawing/lua/pgf/gd/interface/InterfaceToDisplay.lua:213: in function 'resumeGraphDrawingCoroutine' ...graphdrawing/lua/pgf/gd/interface/InterfaceToDisplay.lua:182: in function 'runGraphDrawingAlgorithm' [\directlua]:1: in main chunk. \pgfgdendscope ...lay.runGraphDrawingAlgorithm() } \pgfutil@loop \ifpgfgdresu... l.21 }
The error is resolved if the top-level layout is changed to spring layout, for example. Also, removing either of the two edges at the bottom (a--1, a--b) resolves the problem; all three edges must be present to cause the error. This occurs with both the Hu and Walshaw spring electric layout algorithms. Unless I grossly misunderstood the layout algorithms, I would expect this to work with spring electric as it does for the others.
I've dug into it a bit more and it seems that somehow during the sublayout process, nodes lose their options. Of primary concern is
electric charge
, which is used to setnode.weight
in the twospring electric layout
algorithms. Since that option isnil
,node.weight
is set tonil
. This then breaks the graph-coarsening algorithm as well as the force calculations.Attached are some trivial patches that do not fix the underlying problem but at least allow such documents to compile.
Here's the other patch (only one attachment per post?)
Blech...sorry, I left the full paths in the patches.
Thank you for reporting. The bug is fixed now.