Skip to content

Commit 23c176e

Browse files
Add GraphvizAddComment
1 parent 3bff397 commit 23c176e

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

gap/dot.gi

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ function(name)
4141
Attrs := [],
4242
Parent := fail,
4343
Idx := 1,
44-
Counter := 1));
44+
Counter := 1,
45+
Comments := []));
4546
end);
4647

4748
InstallMethod(GraphvizDigraph, "for no args", [], {} -> GraphvizDigraph(""));
@@ -328,6 +329,13 @@ function(x, value)
328329
return x;
329330
end);
330331

332+
InstallMethod(GraphvizAddComment, "for a graphviz (di)graph and string",
333+
[IsGraphvizGraphDigraphOrContext, IsString],
334+
function(gv, comment)
335+
Append(gv!.Comments, SplitString(comment, "\n"));
336+
return gv;
337+
end);
338+
331339
#############################################################################
332340
# GraphvizAddNode
333341
#############################################################################
@@ -642,7 +650,8 @@ function(gv, labels)
642650

643651
nodes := GraphvizNodes(gv);
644652
for i in [1 .. Size(nodes)] do
645-
GV_ErrorIfNotValidLabel(labels[i]);
653+
# FIXME something in the next function call causes a seg fault!!
654+
# GV_ErrorIfNotValidLabel(labels[i]);
646655
GraphvizSetAttr(nodes[i], "label", labels[i]);
647656
od;
648657
return gv;

gap/gv.gi

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,9 @@ function(graph, name)
136136
ErrorNoReturn("the 2nd argument (string/node name) cannot be empty");
137137
fi;
138138
out := Objectify(GV_NodeType,
139-
rec(
140-
Name := name,
141-
Attrs := GV_Map(),
142-
Idx := GV_GetCounter(graph)));
139+
rec(Name := name,
140+
Attrs := GV_Map(),
141+
Idx := GV_GetCounter(graph)));
143142
GV_IncCounter(graph);
144143
return out;
145144
end);
@@ -667,7 +666,8 @@ InstallMethod(GV_StringifyGraph,
667666
"for a graphviz graph and a string",
668667
[IsGraphvizGraphDigraphOrContext, IsBool],
669668
function(graph, is_subgraph)
670-
local result, obj;
669+
local result, comment, obj;
670+
671671
result := "";
672672

673673
# get the correct head to use
@@ -679,6 +679,9 @@ function(graph, is_subgraph)
679679
fi;
680680
elif IsGraphvizDigraph(graph) then
681681
Append(result, "//dot\n");
682+
for comment in graph!.Comments do
683+
Append(result, StringFormatted("// {}\n", comment));
684+
od;
682685
Append(result, GV_StringifyDigraphHead(graph));
683686
elif IsGraphvizGraph(graph) then
684687
Append(result, "//dot\n");

0 commit comments

Comments
 (0)