@@ -10,8 +10,6 @@ DeclareOperation("GV_StringifyGraphHead", [IsGVGraph]);
10
10
DeclareOperation(" GV_StringifyDigraphHead" , [ IsGVGraph] );
11
11
DeclareOperation(" GV_StringifySubgraphHead" , [ IsGVGraph] );
12
12
DeclareOperation(" GV_StringifyContextHead" , [ IsGVGraph] );
13
- DeclareOperation(" GV_StringifyGraphEdge" , [ IsGVEdge] );
14
- DeclareOperation(" GV_StringifyDigraphEdge" , [ IsGVEdge] );
15
13
DeclareOperation(" GV_StringifyNode" , [ IsGVNode] );
16
14
DeclareOperation(" GV_StringifyGraphAttrs" , [ IsGVGraph] );
17
15
DeclareOperation(" GV_StringifyNodeEdgeAttrs" , [ IsGV_Map] );
@@ -375,50 +373,21 @@ end);
375
373
376
374
InstallMethod(ViewString, " for a graphviz graph" , [ IsGVGraph] ,
377
375
function (g )
378
- local result, edges, nodes;
379
- result := " " ;
380
- edges := Length(GraphvizEdges(g));
381
- nodes := Length(GV_MapNames(GraphvizNodes(g)));
382
-
383
- Append(result, StringFormatted(" <graphviz graph " , GraphvizName(g)));
384
-
385
- if GraphvizName(g) <> " " then
386
- Append(result, StringFormatted(" {} " , GraphvizName(g)));
387
- fi ;
388
-
389
- Append(result, StringFormatted(" with {} " , GV_Pluralize(nodes, " node" )));
390
- Append(result, StringFormatted(" and {}>" , GV_Pluralize(edges, " edge" )));
376
+ local result, edges, nodes, kind;
391
377
392
- return result;
393
- end );
394
-
395
- InstallMethod(ViewString, " for a graphviz digraph" , [ IsGVDigraph] ,
396
- function (g )
397
- local result, edges, nodes;
398
378
result := " " ;
399
379
edges := Length(GraphvizEdges(g));
400
380
nodes := Length(GV_MapNames(GraphvizNodes(g)));
401
381
402
- Append(result, StringFormatted(" <graphviz digraph " , GraphvizName(g)));
403
-
404
- if GraphvizName(g) <> " " then
405
- Append(result, StringFormatted(" {} " , GraphvizName(g)));
382
+ if IsGVDigraph(g) then
383
+ kind := " digraph" ;
384
+ elif IsGVContext(g) then
385
+ kind := " context" ;
386
+ else
387
+ kind := " graph" ;
406
388
fi ;
407
389
408
- Append(result, StringFormatted(" with {} " , GV_Pluralize(nodes, " node" )));
409
- Append(result, StringFormatted(" and {}>" , GV_Pluralize(edges, " edge" )));
410
-
411
- return result;
412
- end );
413
-
414
- InstallMethod(ViewString, " for a graphviz context" , [ IsGVContext] ,
415
- function (g )
416
- local result, edges, nodes;
417
- result := " " ;
418
- edges := Length(GraphvizEdges(g));
419
- nodes := Length(GV_MapNames(GraphvizNodes(g)));
420
-
421
- Append(result, StringFormatted(" <graphviz context " , GraphvizName(g)));
390
+ Append(result, StringFormatted(" <graphviz {} " , kind));
422
391
423
392
if GraphvizName(g) <> " " then
424
393
Append(result, StringFormatted(" {} " , GraphvizName(g)));
@@ -430,9 +399,9 @@ function(g)
430
399
return result;
431
400
end );
432
401
433
- # ###########################################################
402
+ # ###########################################################
434
403
# Getters
435
- # ###########################################################
404
+ # ###########################################################
436
405
InstallMethod(GraphvizName,
437
406
" for a graphviz object" ,
438
407
[ IsGVObject] ,
@@ -1059,33 +1028,19 @@ function(node)
1059
1028
end );
1060
1029
1061
1030
# @ Return DOT graph edge statement line.
1062
- InstallMethod(GV_StringifyGraphEdge, " for a graphviz edge" ,
1063
- [ IsGVEdge] ,
1064
- function (edge )
1065
- local head, tail, attrs;
1066
- head := GraphvizName(GraphvizHead(edge));
1067
- tail := GraphvizName(GraphvizTail(edge));
1068
- attrs := GraphvizAttrs(edge);
1069
-
1070
- # handle : syntax
1071
- return StringFormatted(" \t {} -- {}{}\n " ,
1072
- head,
1073
- tail,
1074
- GV_StringifyNodeEdgeAttrs(attrs));
1075
- end );
1076
-
1077
- # @ Return DOT digraph edge statement line.
1078
- InstallMethod(GV_StringifyDigraphEdge, " for a graphviz edge" ,
1079
- [ IsGVEdge] ,
1080
- function (edge )
1031
+ BindGlobal(" GV_StringifyEdge" ,
1032
+ function (edge, edge_str )
1081
1033
local head, tail, attrs;
1034
+ Assert (0 , IsGVEdge(edge));
1035
+ Assert (0 , IsString(edge_str));
1082
1036
head := GraphvizName(GraphvizHead(edge));
1083
1037
tail := GraphvizName(GraphvizTail(edge));
1084
1038
attrs := GraphvizAttrs(edge);
1085
1039
1086
1040
# handle : syntax
1087
- return StringFormatted(" \t {} -> {}{}\n " ,
1041
+ return StringFormatted(" \t {} {} {}{}\n " ,
1088
1042
head,
1043
+ edge_str,
1089
1044
tail,
1090
1045
GV_StringifyNodeEdgeAttrs(attrs));
1091
1046
end );
@@ -1233,9 +1188,9 @@ function(graph, is_subgraph)
1233
1188
Append(result, GV_StringifyNode(obj));
1234
1189
elif IsGVEdge(obj) then
1235
1190
if IsGVDigraph(GV_GetRoot(graph)) then
1236
- Append(result, GV_StringifyDigraphEdge (obj));
1191
+ Append(result, GV_StringifyEdge (obj, " -> " ));
1237
1192
else
1238
- Append(result, GV_StringifyGraphEdge (obj));
1193
+ Append(result, GV_StringifyEdge (obj, " -- " ));
1239
1194
fi ;
1240
1195
else
1241
1196
return ErrorNoReturn(" Invalid graphviz object type." );
0 commit comments