From: Tara L Andrews Date: Fri, 27 May 2011 23:01:45 +0000 (+0200) Subject: clean up svg output; allow non-linear GraphML graphs X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=a0093bf226790f5f78b96b7d94aa37b261b3fc17;p=scpubgit%2Fstemmatology.git clean up svg output; allow non-linear GraphML graphs --- diff --git a/lib/Text/Tradition/Collation.pm b/lib/Text/Tradition/Collation.pm index 90e7f31..03aed2a 100644 --- a/lib/Text/Tradition/Collation.pm +++ b/lib/Text/Tradition/Collation.pm @@ -407,6 +407,8 @@ sub collapse_graph_paths { # Don't list out every witness if we have more than half to list. my $majority = int( scalar( @{$self->tradition->witnesses} ) / 2 ) + 1; + # But don't compress if there are only a few witnesses. + $majority = 4 if $majority < 4; foreach my $node( $self->readings ) { my $newlabels = {}; # We will visit each node, so we only look ahead. @@ -420,7 +422,7 @@ sub collapse_graph_paths { my $label; my @compressed_wits = (); if( @{$newlabels->{$newdest}} < $majority ) { - $label = join( ', ', @{$newlabels->{$newdest}} ); + $label = join( ', ', sort( @{$newlabels->{$newdest}} ) ); } else { ## TODO FIX THIS HACK my @aclabels; @@ -431,7 +433,7 @@ sub collapse_graph_paths { push( @compressed_wits, $wit ); } } - $label = join( ', ', 'majority', @aclabels ); + $label = join( ', ', 'majority', sort( @aclabels ) ); } my $newpath = diff --git a/lib/Text/Tradition/Parser/GraphML.pm b/lib/Text/Tradition/Parser/GraphML.pm index dbeff7e..9842bdb 100644 --- a/lib/Text/Tradition/Parser/GraphML.pm +++ b/lib/Text/Tradition/Parser/GraphML.pm @@ -121,9 +121,13 @@ sub parse { foreach my $tn ( @$transposition_nodes ) { my $id_xpath = sprintf( './g:data[@key="%s"]/text()', $nodedata{'identical'} ); - $collation->reading( $node_id{ $tn->getAttribute( 'id' ) } )-> - set_identical( $collation->reading( - $node_name{ $xpc->findvalue( $id_xpath, $tn ) } ) ); + my $tn_reading = $collation->reading( $node_id{ $tn->getAttribute( 'id' ) } ); + my $main_reading = $collation->reading( $node_name{ $xpc->findvalue( $id_xpath, $tn ) } ); + if( $collation->linear ) { + $tn_reading->set_identical( $main_reading ); + } else { + $collation->merge_readings( $main_reading, $tn_reading ); + } } # Find the beginning and end nodes of the graph. The beginning node