From: Tara L Andrews Date: Thu, 6 Oct 2011 08:13:25 +0000 (+0200) Subject: allow automatic sizing of stemma; put more data into the visualizer X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=e367f5c07b97362a0b60dba97fcc0ce944a4a08a;p=scpubgit%2Fstemmatology.git allow automatic sizing of stemma; put more data into the visualizer --- diff --git a/TreeOfTexts/lib/TreeOfTexts/Controller/Root.pm b/TreeOfTexts/lib/TreeOfTexts/Controller/Root.pm index 14fd49f..2cd3a76 100644 --- a/TreeOfTexts/lib/TreeOfTexts/Controller/Root.pm +++ b/TreeOfTexts/lib/TreeOfTexts/Controller/Root.pm @@ -31,15 +31,24 @@ sub index :Path :Args(0) { my ( $self, $c ) = @_; my $m = $c->model('Analysis'); - $c->stash->{svg} = $m->{'svg'}; - $c->stash->{variants} = $m->{'variants'}; - $c->stash->{text_title} = $m->{'title'}; - $c->stash->{total} = $m->{'variant_count'}; - $c->stash->{genealogical} = $m->{'genealogical_count'}; - $c->stash->{conflict} = $m->{'conflict_count'}; - $c->stash->{template} = 'index.tt'; + my $i = 0; + my @all_texts = map { $_->{'title'} } @{$m->{'data'}}; + $c->stash->{texts} = \@all_texts; + $c->stash->{template} = 'frontpage.tt'; } +sub view_text :Local { + my( $self, $c ) = @_; + my $m = $c->model('Analysis'); + my $t = $m->{'data'}->[ $c->request->params->{'textid'} ]; + $c->stash->{svg} = $t->{'svg'}; + $c->stash->{variants} = $t->{'variants'}; + $c->stash->{text_title} = $t->{'title'}; + $c->stash->{total} = $t->{'variant_count'}; + $c->stash->{genealogical} = $t->{'genealogical_count'}; + $c->stash->{conflict} = $t->{'conflict_count'}; + $c->stash->{template} = 'index.tt'; +} =head2 default Standard 404 error page diff --git a/TreeOfTexts/lib/TreeOfTexts/Model/Analysis.pm b/TreeOfTexts/lib/TreeOfTexts/Model/Analysis.pm index 3894f3d..3a2b8b9 100644 --- a/TreeOfTexts/lib/TreeOfTexts/Model/Analysis.pm +++ b/TreeOfTexts/lib/TreeOfTexts/Model/Analysis.pm @@ -7,8 +7,14 @@ use base 'Catalyst::Model::Adaptor'; __PACKAGE__->config( class => 'Text::Tradition::Analysis', - args => { 'file' => TreeOfTexts->path_to( 't', 'data', 'florilegium.xml' ), + args => { 'traditions' => [ + { 'file' => TreeOfTexts->path_to( 't', 'data', 'florilegium.xml' ), 'stemmadot' => TreeOfTexts->path_to( 't', 'data', 'stemma_a.dot' ) }, + { 'file' => TreeOfTexts->path_to( 't', 'data', 'heinrichi.xml' ), + 'stemmadot' => TreeOfTexts->path_to( 't', 'data', 'stemma_h.dot' ) }, + { 'file' => TreeOfTexts->path_to( 't', 'data', 'parzival.xml' ), + 'stemmadot' => TreeOfTexts->path_to( 't', 'data', 'stemma_p.dot' ) }, + ] }, ); 1; \ No newline at end of file diff --git a/TreeOfTexts/root/src/frontpage.tt b/TreeOfTexts/root/src/frontpage.tt new file mode 100644 index 0000000..0444fce --- /dev/null +++ b/TreeOfTexts/root/src/frontpage.tt @@ -0,0 +1,21 @@ + + + + + + [% INCLUDE style.tt2 %] + + +

Stexaminer

+

Choose a text to examine

+
+
+ + diff --git a/TreeOfTexts/root/src/style.tt2 b/TreeOfTexts/root/src/style.tt2 index 390ebc1..c5ec1cb 100644 --- a/TreeOfTexts/root/src/style.tt2 +++ b/TreeOfTexts/root/src/style.tt2 @@ -8,8 +8,8 @@ body { } #svg_graph { float: left; - width: 450px; - height: 550px; + width: 600pt; + height: 550pt; border-right: 1px #c6dcf1 solid; } #variants_table { diff --git a/lib/Text/Tradition/Analysis.pm b/lib/Text/Tradition/Analysis.pm index 3b8888b..b14f597 100644 --- a/lib/Text/Tradition/Analysis.pm +++ b/lib/Text/Tradition/Analysis.pm @@ -9,7 +9,10 @@ sub new { my( $class, $args ) = @_; my $self = {}; bless( $self, $class ); - $self->run_analysis( $args->{'file'}, $args->{'stemmadot'} ); + $self->{'data'} = []; + foreach my $t ( @{$args->{'traditions'}} ) { + $self->run_analysis( $t->{'file'}, $t->{'stemmadot'} ); + } return $self; } @@ -18,6 +21,7 @@ sub run_analysis { # What we will return my $svg; my $variants = []; + my $data = {}; # Read in the file and stemma my $tradition = Text::Tradition->new( @@ -25,17 +29,15 @@ sub run_analysis { 'file' => $file, 'linear' => 1, ); - $self->{'title'} = $tradition->name; + $data->{'title'} = $tradition->name; my $stemma = Text::Tradition::Stemma->new( 'collation' => $tradition->collation, 'dot' => $stemmadot, ); # We will return the stemma picture - $svg = $stemma->as_svg; - ### DIRTY HACK - $svg =~ s/transform=\"scale\(1 1\)/transform=\"scale\(0.7 0.7\)/; - $self->{'svg'} = $svg; + $svg = $stemma->as_svg( { size => "8,7.5" } );; + $data->{'svg'} = $svg; # We have the collation, so get the alignment table with witnesses in rows. # Also return the reading objects in the table, rather than just the words. @@ -131,10 +133,11 @@ sub run_analysis { } # Populate self with our analysis data. - $self->{'variants'} = $variants; - $self->{'variant_count'} = $total; - $self->{'conflict_count'} = $conflicts; - $self->{'genealogical_count'} = $genealogical; + $data->{'variants'} = $variants; + $data->{'variant_count'} = $total; + $data->{'conflict_count'} = $conflicts; + $data->{'genealogical_count'} = $genealogical; + push( @{$self->{'data'}}, $data ); } # variant_row -> genealogical diff --git a/lib/Text/Tradition/Stemma.pm b/lib/Text/Tradition/Stemma.pm index 880260c..23fbbcc 100644 --- a/lib/Text/Tradition/Stemma.pm +++ b/lib/Text/Tradition/Stemma.pm @@ -83,7 +83,7 @@ after 'graph' => sub { # Render the stemma as SVG. sub as_svg { - my $self = shift; + my( $self, $opts ) = @_; # TODO add options for display, someday my $dgraph = Graph::Convert->as_graph_easy( $self->graph ); # Set some class display attributes for 'hypothetical' and 'extant' nodes @@ -98,13 +98,19 @@ sub as_svg { } # Render to svg via graphviz + my @lines = split( /\n/, $dgraph->as_graphviz() ); + # Add the size attribute + if( $opts->{'size'} ) { + my $sizeline = " graph [ size=\"" . $opts->{'size'} . "\" ]"; + splice( @lines, 1, 0, $sizeline ); + } my @cmd = qw/dot -Tsvg/; my( $svg, $err ); my $dotfile = File::Temp->new(); ## TODO REMOVE # $dotfile->unlink_on_destroy(0); binmode $dotfile, ':utf8'; - print $dotfile $dgraph->as_graphviz(); + print $dotfile join( "\n", @lines ); push( @cmd, $dotfile->filename ); run( \@cmd, ">", binary(), \$svg ); $svg = decode_utf8( $svg );