Skip to content

Commit

Permalink
More fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
james-d-mitchell committed May 9, 2024
1 parent e83ebfe commit d252fde
Show file tree
Hide file tree
Showing 15 changed files with 224 additions and 447 deletions.
17 changes: 9 additions & 8 deletions gap/dot.gi
Original file line number Diff line number Diff line change
Expand Up @@ -1285,7 +1285,7 @@ function(graph)
end);

InstallMethod(GV_StringifyNodeEdgeAttrs,
"for a record",
"for a GV_Map",
[IsGV_Map],
function(attrs)
local result, keys, key, val, n, i, tmp;
Expand All @@ -1304,12 +1304,13 @@ function(attrs)
if "label" = key and StartsWith(tmp, "<<") and EndsWith(tmp, ">>") then
val := StringFormatted("{}", val);
else
if ' ' in key then
key := StringFormatted("\"{}\"", key);
fi;
if ' ' in val then
val := StringFormatted("\"{}\"", val);
fi;
if ' ' in key then
key := StringFormatted("\"{}\"", key);
fi;
if ' ' in val or '>' in val or '^' in val or '#' in val then
# TODO avoid code duplication here, and below
val := StringFormatted("\"{}\"", val);
fi;
fi;

Append(result,
Expand All @@ -1329,7 +1330,7 @@ function(attrs)
if ' ' in key then
key := StringFormatted("\"{}\"", key);
fi;
if ' ' in val or '>' in val then
if ' ' in val or '>' in val or '^' in val or '#' in val then
# TODO what are the allowed things in the value?
val := StringFormatted("\"{}\"", val);
fi;
Expand Down
91 changes: 74 additions & 17 deletions tst/examples/angles.tst
Original file line number Diff line number Diff line change
Expand Up @@ -66,23 +66,80 @@ gap> GraphvizSetAttr(cluster2, "label",
<graphviz digraph cluster_2 with 9 nodes and 0 edges>
gap> GraphvizAddEdge(g, "n5", "n14");
<graphviz edge (n5, n14)>
gap> AsString(g);
"//dot\ndigraph G {\n\tbgcolor=blue \nsubgraph cluster_1 {\n\tfontcolor=white \
node[shape=circle, style=filled,fillcolor=\"white:black\", gradientangle=360, \
label=\"n9:n360\",fontcolor=black] label=\"Linear Angle Variations (white to b\
lack gradient)\" \n\tn9\n\tn8 [gradientangle=315, label=\"n8:315\"]\n\tn7 [gra\
dientangle=270, label=\"n7:270\"]\n\tn6 [gradientangle=225, label=\"n6:225\"]\
\n\tn5 [gradientangle=180, label=\"n5:180\"]\n\tn4 [gradientangle=135, label=\
\"n4:135\"]\n\tn3 [gradientangle=90, label=\"n3:90\"]\n\tn2 [gradientangle=45,\
label=\"n2:45\"]\n\tn1 [gradientangle=0, label=\"n1:0\"]\n}\nsubgraph cluster\
_2 {\n\tfontcolor=white node[shape=circle, style=radial,fillcolor=\"white:blac\
k\", gradientangle=360,label=\"n9:n360\", fontcolor=black] label=\"Radial Angl\
e Variations (white to black gradient)\" \n\tn18\n\tn17 [gradientangle=315, la\
bel=\"n17:315\"]\n\tn16 [gradientangle=270, label=\"n16:270\"]\n\tn15 [gradien\
tangle=225, label=\"n15:225\"]\n\tn14 [gradientangle=180, label=\"n14:180\"]\n\
\tn13 [gradientangle=135, label=\"n13:135\"]\n\tn12 [gradientangle=90, label=\
\"n12:90\"]\n\tn11 [gradientangle=45, label=\"n11:45\"]\n\tn10 [gradientangle=\
0, label=\"n10:0\"]\n}\n\tn5 -> n14\n}\n"

#@if CompareVersionNumbers(GAPInfo.Version, "4.12.0")
gap> Print(AsString(g));
//dot
digraph G {
bgcolor=blue
subgraph cluster_1 {
fontcolor=white node[shape=circle, style=filled,fillcolor="white:black", grad\
ientangle=360, label="n9:n360",fontcolor=black] label="Linear Angle Variations\
(white to black gradient)"
n9
n8 [gradientangle=315, label="n8:315"]
n7 [gradientangle=270, label="n7:270"]
n6 [gradientangle=225, label="n6:225"]
n5 [gradientangle=180, label="n5:180"]
n4 [gradientangle=135, label="n4:135"]
n3 [gradientangle=90, label="n3:90"]
n2 [gradientangle=45, label="n2:45"]
n1 [gradientangle=0, label="n1:0"]
}
subgraph cluster_2 {
fontcolor=white node[shape=circle, style=radial,fillcolor="white:black", grad\
ientangle=360,label="n9:n360", fontcolor=black] label="Radial Angle Variations\
(white to black gradient)"
n18
n17 [gradientangle=315, label="n17:315"]
n16 [gradientangle=270, label="n16:270"]
n15 [gradientangle=225, label="n15:225"]
n14 [gradientangle=180, label="n14:180"]
n13 [gradientangle=135, label="n13:135"]
n12 [gradientangle=90, label="n12:90"]
n11 [gradientangle=45, label="n11:45"]
n10 [gradientangle=0, label="n10:0"]
}
n5 -> n14
}
#@else
gap> Print(AsString(g));
//dot
digraph G {
bgcolor=blue
subgraph cluster_1 {
fontcolor=white node[shape=circle, style=filled,fillcolor="white:black", grad\
ientangle=360, la\
bel="n9:n360",fontcolor=black] label="Linear Angle Variations (white to black \
gradient)"
n9
n8 [gradientangle=315, label="n8:315"]
n7 [gradientangle=270, label="n7:270"]
n6 [gradientangle=225, label="n6:225"]
n5 [gradientangle=180, label="n5:180"]
n4 [gradientangle=135, label="n4:135"]
n3 [gradientangle=90, label="n3:90"]
n2 [gradientangle=45, label="n2:45"]
n1 [gradientangle=0, label="n1:0"]
}
subgraph cluster_2 {
fontcolor=white node[shape=circle, style=radial,fillcolor="white:black", grad\
ientangle=360,lab\
el="n9:n360", fontcolor=black] label="Radial Angle Variations (white to black \
gradient)"
n18
n17 [gradientangle=315, label="n17:315"]
n16 [gradientangle=270, label="n16:270"]
n15 [gradientangle=225, label="n15:225"]
n14 [gradientangle=180, label="n14:180"]
n13 [gradientangle=135, label="n13:135"]
n12 [gradientangle=90, label="n12:90"]
n11 [gradientangle=45, label="n11:45"]
n10 [gradientangle=0, label="n10:0"]
}
n5 -> n14
}
#@fi

#
gap> STOP_TEST("graphviz package: angles.tst");
51 changes: 13 additions & 38 deletions tst/examples/btree.tst
Original file line number Diff line number Diff line change
Expand Up @@ -55,44 +55,19 @@ gap> GraphvizAddEdge(s, "node4:f2", "node6:f1");
<graphviz edge (node4:f2, node6:f1)>
gap> GraphvizAddEdge(s, "node4:f0", "node5:f1");
<graphviz edge (node4:f0, node5:f1)>
gap> Print(AsString(s));
//dot
digraph g {
node [shape=record, height=.1]
node0 [label="<f0> |<f1> G|<f2>"]
node1 [label="<f0> |<f1> E|<f2>"]
node2 [label="<f0> |<f1> B|<f2>"]
node3 [label="<f0> |<f1> F|<f2>"]
node4 [label="<f0> |<f1> R|<f2>"]
node5 [label="<f0> |<f1> H|<f2>"]
node6 [label="<f0> |<f1> Y|<f2>"]
node7 [label="<f0> |<f1> A|<f2>"]
node8 [label="<f0> |<f1> C|<f2>"]
node0:f2
node4:f1
node0:f2 -> node4:f1
node0:f0
node1:f1
node0:f0 -> node1:f1
node1:f0
node2:f1
node1:f0 -> node2:f1
node1:f2
node3:f1
node1:f2 -> node3:f1
node2:f2
node8:f1
node2:f2 -> node8:f1
node2:f0
node7:f1
node2:f0 -> node7:f1
node4:f2
node6:f1
node4:f2 -> node6:f1
node4:f0
node5:f1
node4:f0 -> node5:f1
}
gap> AsString(s) =
> "//dot\ndigraph g {\n\tnode [shape=record, height=.1] \n\tnode0 [label=\"<f0> \
> |<f1> G|<f2>\"]\n\tnode1 [label=\"<f0> |<f1> E|<f2>\"]\n\tnode2 [label=\"<f0> \
> |<f1> B|<f2>\"]\n\tnode3 [label=\"<f0> |<f1> F|<f2>\"]\n\tnode4 [label=\"<f0> \
> |<f1> R|<f2>\"]\n\tnode5 [label=\"<f0> |<f1> H|<f2>\"]\n\tnode6 [label=\"<f0> \
> |<f1> Y|<f2>\"]\n\tnode7 [label=\"<f0> |<f1> A|<f2>\"]\n\tnode8 [label=\"<f0> \
> |<f1> C|<f2>\"]\n\tnode0:f2\n\tnode4:f1\n\tnode0:f2 -> node4:f1\n\tnode0:f0\n\
> \tnode1:f1\n\tnode0:f0 -> node1:f1\n\tnode1:f0\n\tnode2:f1\n\tnode1:f0 -> node\
> 2:f1\n\tnode1:f2\n\tnode3:f1\n\tnode1:f2 -> node3:f1\n\tnode2:f2\n\tnode8:f1\n\
> \tnode2:f2 -> node8:f1\n\tnode2:f0\n\tnode7:f1\n\tnode2:f0 -> node7:f1\n\tnode\
> 4:f2\n\tnode6:f1\n\tnode4:f2 -> node6:f1\n\tnode4:f0\n\tnode5:f1\n\tnode4:f0 -\
> > node5:f1\n}\n";
true

#
gap> STOP_TEST("graphviz package: btree.tst");
42 changes: 8 additions & 34 deletions tst/examples/cluster.tst
Original file line number Diff line number Diff line change
Expand Up @@ -74,40 +74,14 @@ gap> GraphvizSetAttr(graph["end"], "shape", "Msquare");
<graphviz node end>

#
gap> Print(AsString(graph));
//dot
digraph G {
subgraph cluster_0 {
color="lightgrey" style="filled" node [color="white", style="filled"] label="\
process #1"
a0
a1
a0 -> a1
a2
a1 -> a2
a3
a2 -> a3
}
subgraph cluster_1 {
color="blue" node [style="filled"] label="process #2"
b0
b1
b0 -> b1
b2
b1 -> b2
b3
b2 -> b3
}
start [shape=Mdiamond]
start -> a0
start -> b0
a1 -> b3
b2 -> a3
a3 -> a0
end [shape=Msquare]
a3 -> end
b3 -> end
}
gap> AsString(graph);
"//dot\ndigraph G {\nsubgraph cluster_0 {\n\tcolor=\"lightgrey\" style=\"fille\
d\" node [color=\"white\", style=\"filled\"] label=\"process #1\" \n\ta0\n\ta1\
\n\ta0 -> a1\n\ta2\n\ta1 -> a2\n\ta3\n\ta2 -> a3\n}\nsubgraph cluster_1 {\n\tc\
olor=\"blue\" node [style=\"filled\"] label=\"process #2\" \n\tb0\n\tb1\n\tb0 \
-> b1\n\tb2\n\tb1 -> b2\n\tb3\n\tb2 -> b3\n}\n\tstart [shape=Mdiamond]\n\tstar\
t -> a0\n\tstart -> b0\n\ta1 -> b3\n\tb2 -> a3\n\ta3 -> a0\n\tend [shape=Msqua\
re]\n\ta3 -> end\n\tb3 -> end\n}\n"

#
gap> STOP_TEST("graphviz package: cluster.tst");
33 changes: 5 additions & 28 deletions tst/examples/cluster_edge.tst
Original file line number Diff line number Diff line change
Expand Up @@ -53,34 +53,11 @@ gap> GraphvizSetAttr(e, "ltail", "cluster0");
<graphviz edge (c, e)>
gap> GraphvizAddEdge(g, "d", "h");
<graphviz edge (d, h)>
gap> Print(AsString(g));
//dot
digraph G {
compound=true
subgraph cluster0 {
a
b
a -> b
c
a -> c
d
b -> d
c -> d
}
subgraph cluster1 {
e
g
e -> g
f
e -> f
}
b -> f [lhead=cluster1]
d -> e
c -> g [lhead=cluster1, ltail=cluster0]
c -> e [ltail=cluster0]
h
d -> h
}
gap> AsString(g);
"//dot\ndigraph G {\n\tcompound=true \nsubgraph cluster0 {\n\ta\n\tb\n\ta -> b\
\n\tc\n\ta -> c\n\td\n\tb -> d\n\tc -> d\n}\nsubgraph cluster1 {\n\te\n\tg\n\t\
e -> g\n\tf\n\te -> f\n}\n\tb -> f [lhead=cluster1]\n\td -> e\n\tc -> g [lhead\
=cluster1, ltail=cluster0]\n\tc -> e [ltail=cluster0]\n\th\n\td -> h\n}\n"

#
gap> STOP_TEST("graphviz package: cluster_edge.tst");
13 changes: 5 additions & 8 deletions tst/examples/colors.tst
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,15 @@ gap> GraphvizSetAttr(node, "fillcolor", "deeppink");
<graphviz node name: deeppink>

#
gap> Print(AsString(g));
gap> AsString(g);
#I invalid node name RGB: #40e0d0 using "RGB: #40e0d0" instead
#I invalid node name RGBA: #ff000042 using "RGBA: #ff000042" instead
#I invalid node name HSV: 0.051 0.718 0.627 using "HSV: 0.051 0.718 0.627" instead
#I invalid node name name: deeppink using "name: deeppink" instead
//dot
graph {
"RGB: #40e0d0" [fillcolor="#40e0d0", style=filled]
"RGBA: #ff000042" [fillcolor="#ff000042", style=filled]
"HSV: 0.051 0.718 0.627" [fillcolor="0.051 0.718 0.627", style=filled]
"name: deeppink" [fillcolor=deeppink, style=filled]
}
"//dot\ngraph {\n\t\"RGB: #40e0d0\" [fillcolor=\"\"#40e0d0\"\", style=filled]\
\n\t\"RGBA: #ff000042\" [fillcolor=\"\"#ff000042\"\", style=filled]\n\t\"HSV: \
0.051 0.718 0.627\" [fillcolor=\"0.051 0.718 0.627\", style=filled]\n\t\"name:\
deeppink\" [fillcolor=deeppink, style=filled]\n}\n"

#
gap> STOP_TEST("graphviz package: colors.tst");
63 changes: 18 additions & 45 deletions tst/examples/er.tst
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
gap> START_TEST("graphviz package: examples/er.tst");
gap> LoadPackage("graphviz");
true

#
gap> e := GraphvizGraph("ER");
<graphviz graph ER with 0 nodes and 0 edges>
gap> GraphvizSetAttr(e, "engine=\"neato\"");
Expand Down Expand Up @@ -102,7 +104,7 @@ gap> GraphvizSetAttr(e, "fontsize=\"20\"");
<graphviz graph ER with 0 nodes and 12 edges>

#
gap> Print(AsString(e));
gap> AsString(e);
#I invalid node name C-I using "C-I" instead
#I invalid node name S-C using "S-C" instead
#I invalid node name S-I using "S-I" instead
Expand All @@ -112,50 +114,21 @@ gap> Print(AsString(e));
#I invalid node name S-I using "S-I" instead
#I invalid node name S-C using "S-C" instead
#I invalid node name S-C using "S-C" instead
//dot
graph ER {
engine="neato" label="Entity Relation Diagram
drawn by NEATO" fontsize="20"
// context_start context
node[shape="box"]
course
institute
student
engine="neato" label="Entity Relation Diagram
drawn by NEATO" fontsize="20"

// context1 context
node [shape="ellipse"]
name0 [label=name]
name1 [label=name]
name2 [label=name]
code
grade
number
engine="neato" label="Entity Relation Diagram
drawn by NEATO" fontsize="20"

// context2 context
node [shape="diamond", style="filled", color="lightgrey"]
"C-I"
"S-C"
"S-I"
engine="neato" label="Entity Relation Diagram
drawn by NEATO" fontsize="20"

name0 -- course
code -- course
"C-I" -- course [label=n, len=1.00]
institute -- "C-I" [label=1, len=1.00]
name1 -- institute
"S-I" -- institute [label=1, len=1.00]
student -- "S-I" [label=n, len=1.00]
grade -- student
name2 -- student
number -- student
"S-C" -- student [label=m, len=1.00]
course -- "S-C" [label=n, len=1.00]
}
"//dot\ngraph ER {\n\tengine=\"neato\" label=\"Entity Relation Diagram\ndrawn \
by NEATO\" fontsize=\"20\" \n// context_start context \n\tnode[shape=\"box\"] \
\n\tcourse\n\tinstitute\n\tstudent\n\tengine=\"neato\" label=\"Entity Relation\
Diagram\ndrawn by NEATO\" fontsize=\"20\" \n\n// context1 context \n\tnode [s\
hape=\"ellipse\"] \n\tname0 [label=name]\n\tname1 [label=name]\n\tname2 [label\
=name]\n\tcode\n\tgrade\n\tnumber\n\tengine=\"neato\" label=\"Entity Relation \
Diagram\ndrawn by NEATO\" fontsize=\"20\" \n\n// context2 context \n\tnode [sh\
ape=\"diamond\", style=\"filled\", color=\"lightgrey\"] \n\t\"C-I\"\n\t\"S-C\"\
\n\t\"S-I\"\n\tengine=\"neato\" label=\"Entity Relation Diagram\ndrawn by NEAT\
O\" fontsize=\"20\" \n\n\tname0 -- course\n\tcode -- course\n\t\"C-I\" -- cour\
se [label=n, len=1.00]\n\tinstitute -- \"C-I\" [label=1, len=1.00]\n\tname1 --\
institute\n\t\"S-I\" -- institute [label=1, len=1.00]\n\tstudent -- \"S-I\" [\
label=n, len=1.00]\n\tgrade -- student\n\tname2 -- student\n\tnumber -- studen\
t\n\t\"S-C\" -- student [label=m, len=1.00]\n\tcourse -- \"S-C\" [label=n, len\
=1.00]\n}\n"

#
gap> STOP_TEST("graphviz package: er.tst");
Loading

0 comments on commit d252fde

Please sign in to comment.