Commit eb0a0b6b authored by Alexandre Duret-Lutz's avatar Alexandre Duret-Lutz

dot: use circles if state names are all short

* spot/twaalgos/dot.cc: Check for state names sizes.
* tests/core/readsave.test: Test the change.
* tests/core/tgbagraph.test: Adjust.
parent b11c07b3
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
#include <spot/twaalgos/sccinfo.hh> #include <spot/twaalgos/sccinfo.hh>
#include <cstdlib> #include <cstdlib>
#include <cstring> #include <cstring>
#include <algorithm>
#include <ctype.h> #include <ctype.h>
...@@ -541,9 +542,18 @@ namespace spot ...@@ -541,9 +542,18 @@ namespace spot
if (opt_shape_ == ShapeAuto) if (opt_shape_ == ShapeAuto)
{ {
if (sn_ || sprod_ || aut->num_states() > 100) if (sn_ || sprod_ || aut->num_states() > 100)
opt_shape_ = ShapeEllipse; {
opt_shape_ = ShapeEllipse;
// If all state names are short, prefer circles.
if (sn_ && std::all_of(sn_->begin(), sn_->end(),
[](const std::string& s)
{ return s.size() <= 2; }))
opt_shape_ = ShapeCircle;
}
else else
opt_shape_ = ShapeCircle; {
opt_shape_ = ShapeCircle;
}
} }
auto si = auto si =
std::unique_ptr<scc_info>(opt_scc_ ? new scc_info(aut) : nullptr); std::unique_ptr<scc_info>(opt_scc_ ? new scc_info(aut) : nullptr);
......
...@@ -538,6 +538,26 @@ EOF ...@@ -538,6 +538,26 @@ EOF
autfilt --dot=bao1 in | grep -v '>' >out autfilt --dot=bao1 in | grep -v '>' >out
diff out expected2 diff out expected2
cat >expected3 <<EOF
digraph G {
rankdir=LR
node [shape="circle"]
I [label="", style=invis, width=0]
0 [label="6", peripheries=2]
u0 [label="...", shape=none, width=0, height=0]
1 [label="0", peripheries=2]
2 [label="1", peripheries=2]
3 [label="2", peripheries=2]
4 [label="3", peripheries=2]
u4 [label="...", shape=none, width=0, height=0]
}
EOF
# States should be circled even if <5 causes all states to be named,
# because the names are smaller then 2 characters anyway.
ltl2tgba --det 'Ga | Gb | Gc' -d'<5' | grep -v '>' >out
diff out expected3
# Let's pretend that this is some used supplied input, as discussed in # Let's pretend that this is some used supplied input, as discussed in
# the comments of https://github.com/adl/hoaf/issues/39 # the comments of https://github.com/adl/hoaf/issues/39
......
...@@ -223,6 +223,7 @@ digraph G { ...@@ -223,6 +223,7 @@ digraph G {
} }
digraph G { digraph G {
rankdir=LR rankdir=LR
node [shape="circle"]
I [label="", style=invis, width=0] I [label="", style=invis, width=0]
I -> 2 I -> 2
0 [label="s1"] 0 [label="s1"]
...@@ -231,6 +232,7 @@ digraph G { ...@@ -231,6 +232,7 @@ digraph G {
} }
digraph G { digraph G {
rankdir=LR rankdir=LR
node [shape="circle"]
I [label="", style=invis, width=0] I [label="", style=invis, width=0]
I -> 0 I -> 0
0 [label="s3"] 0 [label="s3"]
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment