Skip to content

Commit 0db342b

Browse files
Add GraphvizAddComment
1 parent 402a6bb commit 0db342b

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(""));
@@ -327,6 +328,13 @@ function(x, value)
327328
return x;
328329
end);
329330

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

641649
nodes := GraphvizNodes(gv);
642650
for i in [1 .. Size(nodes)] do
643-
GV_ErrorIfNotValidLabel(labels[i]);
651+
# FIXME something in the next function call causes a seg fault!!
652+
# GV_ErrorIfNotValidLabel(labels[i]);
644653
GraphvizSetAttr(nodes[i], "label", labels[i]);
645654
od;
646655
return gv;

gap/gv.gi

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

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

0 commit comments

Comments
 (0)