diff --git a/gap/dot.gi b/gap/dot.gi index d67649b..466f232 100644 --- a/gap/dot.gi +++ b/gap/dot.gi @@ -41,7 +41,8 @@ function(name) Attrs := [], Parent := fail, Idx := 1, - Counter := 1)); + Counter := 1, + Comments := [])); end); InstallMethod(GraphvizDigraph, "for no args", [], {} -> GraphvizDigraph("")); @@ -328,6 +329,13 @@ function(x, value) return x; end); +InstallMethod(GraphvizAddComment, "for a graphviz (di)graph and string", +[IsGraphvizGraphDigraphOrContext, IsString], +function(gv, comment) + Append(gv!.Comments, SplitString(comment, "\n")); + return gv; +end); + ############################################################################# # GraphvizAddNode ############################################################################# @@ -642,7 +650,8 @@ function(gv, labels) nodes := GraphvizNodes(gv); for i in [1 .. Size(nodes)] do - GV_ErrorIfNotValidLabel(labels[i]); + # FIXME something in the next function call causes a seg fault!! + # GV_ErrorIfNotValidLabel(labels[i]); GraphvizSetAttr(nodes[i], "label", labels[i]); od; return gv; diff --git a/gap/gv.gi b/gap/gv.gi index fdf82f7..5d12023 100644 --- a/gap/gv.gi +++ b/gap/gv.gi @@ -136,10 +136,9 @@ function(graph, name) ErrorNoReturn("the 2nd argument (string/node name) cannot be empty"); fi; out := Objectify(GV_NodeType, - rec( - Name := name, - Attrs := GV_Map(), - Idx := GV_GetCounter(graph))); + rec(Name := name, + Attrs := GV_Map(), + Idx := GV_GetCounter(graph))); GV_IncCounter(graph); return out; end); @@ -667,7 +666,8 @@ InstallMethod(GV_StringifyGraph, "for a graphviz graph and a string", [IsGraphvizGraphDigraphOrContext, IsBool], function(graph, is_subgraph) - local result, obj; + local result, comment, obj; + result := ""; # get the correct head to use @@ -679,6 +679,9 @@ function(graph, is_subgraph) fi; elif IsGraphvizDigraph(graph) then Append(result, "//dot\n"); + for comment in graph!.Comments do + Append(result, StringFormatted("// {}\n", comment)); + od; Append(result, GV_StringifyDigraphHead(graph)); elif IsGraphvizGraph(graph) then Append(result, "//dot\n");