From: Ian Jackson Date: Thu, 6 Feb 2014 00:54:19 +0000 (+0000) Subject: graphviz: new output, with -g option X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?p=appendix-a6.git;a=commitdiff_plain;h=fc423b02d1ffbff365954a1e89cb5fd00889092f graphviz: new output, with -g option --- diff --git a/compute b/compute index c544437..6b0e79d 100755 --- a/compute +++ b/compute @@ -55,6 +55,7 @@ use autodie; use Data::Printer; use Graph::Directed; +use Graph::Writer::GraphViz; binmode STDIN, 'encoding(UTF-8)'; binmode STDOUT, 'encoding(UTF-8)'; @@ -67,6 +68,19 @@ our @invotes_cc; our $defcho; our $quorum = 0; +our $gfile; + +while (@ARGV && $ARGV[0] =~ /^-/) { + local $_ = shift @ARGV; + if (m/^--?$/) { + last; + } elsif (s/^-g//) { + $gfile = $_; + } else { + die "bad usage\n"; + } +} + sub addchoice { my $choname = shift @_; my $cho = $choices{$choname} = { @@ -311,6 +325,8 @@ sub weaker ($$) { return 0; } +our $showg = $defeats->deep_copy(); + our $schwartz; for (;;) { @@ -391,6 +407,20 @@ if ($schwartz->vertices() == 1) { printf " %-5s %s\n", $_, $choices{$_}{Desc} foreach ($schwartz->vertices()); +if (defined $gfile) { + foreach my $cho (values %choices) { + my $chn = $choices[$cho->{Index}]; + my $label = "\\N\n$cho->{Desc}"; + if ($cho->{Dropped}) { + $label .= "\nDropped: $cho->{Dropped}"; + } + $showg->set_vertex_attribute($chn, 'label', $label); + } + + my $gwriter = new Graph::Writer::GraphViz -format => 'ps'; + $gwriter->write_graph($showg, $gfile); +} + print ".\n"; #p %choices;