#!/usr/bin/perl -w # Usage: # build/gen_manual >attributes.html use strict; use Carp; use Time::HiRes qw/time/; use File::Spec; BEGIN { $|++; chdir 'doc' if -d 'doc'; use lib 'lib', '../lib'; } my $path = shift || 'manual'; use Graph::Easy 0.62; use Graph::Easy::Parser; use Graph::Easy::Manual; my $start = time(); my $tpl = read_file('attributes.tpl'); # make copy of entries to preserve ARRAY refs my $e = Graph::Easy->_attribute_entries(); my $entries = {}; for my $k (keys %$e) { for my $k1 (keys %{$e->{$k}}) { $entries->{$k}->{$k1} = [ @{$e->{$k}->{$k1}} ]; } } my $parser = Graph::Easy::Parser->new(); my $example_graph_id = ''; for my $class (qw/node edge graph group/) { my $css = ''; my $start_time = time(); my $cur_tpl = read_file('att_' . $class . 's.tpl'); my $txt = ''; my $idx = "\n"; $cur_tpl =~ s/##$class##/$idx$txt/; $cur_tpl =~ s/##css##/$css/; $cur_tpl =~ s/##time##/ scalar localtime(); /eg; $cur_tpl =~ s/##version##/$Graph::Easy::Manual::VERSION/g; my $took = sprintf("%0.4fs", time() - $start_time); $cur_tpl =~ s/##took##/$took/g; write_file(File::Spec->catfile($path,$file),$cur_tpl); # insert the index $tpl =~ s/##$class##/$idx/; } my $took = sprintf("%0.4fs", time() - $start); $tpl =~ s/##took##/$took/g; $tpl =~ s/##time##/ scalar localtime(); /eg; write_file(File::Spec->catfile($path,'attributes.html'),$tpl); ############################################################################# # insert the list of colors as one table per colorscheme $start = time(); $tpl = read_file('att_colors.tpl'); my $schemes = Graph::Easy->color_names(); my $list = ''; for my $scheme ('w3c', 'x11') { my $colors = $schemes->{$scheme}; my $limit = 6; $list .= "$scheme color scheme:
\n\n\n"; my $o = 0; for my $clr (sort { my $ac = $colors->{$a}; $ac =~ /#([a-fA-F0-9]{2})([a-fA-F0-9]{2})([a-fA-F0-9]{2})/; $ac = hex($1) * hex($1) + hex($2) * hex($2) + hex($3) * hex($3); my $bc = $colors->{$b}; $bc =~ /#([a-fA-F0-9]{2})([a-fA-F0-9]{2})([a-fA-F0-9]{2})/; $bc = hex($1) * hex($1) + hex($2) * hex($2) + hex($3) * hex($3); $ac <=> $bc; } keys %$colors) { next if $clr =~ /^(transparent|inherit)\z/; # skip these next if $clr =~ /grey/; $list .= _color_entry($clr,$colors->{$clr}); if ($o++ > $limit) { $o = 0; $list .= "\n"; } } $list =~ s/\n\z//; # remove last $list .= "
\n"; } # ColorBrewer schemes: $list .= "

ColorBrewer schemes:

\n"; for my $scheme (sort keys %$schemes) { my $colors = $schemes->{$scheme}; # do w3c and x11 later next if $scheme =~ /^(w3c|x11)\z/; $list .= "$scheme color scheme:
\n\n\n"; for my $clr (sort { $a <=> $b } keys %$colors) { $list .= _color_entry($clr,$colors->{$clr}); } $list =~ s/\n\z//; # remove last $list .= "
\n"; } # end for all schemes $tpl =~ s/##colors##/$list/; $tpl =~ s/##time##/ scalar localtime(); /eg; $took = sprintf("%0.4fs", time() - $start); $tpl =~ s/##took##/$took/g; write_file(File::Spec->catfile($path,'att_colors.html'),$tpl); # re-generate the dataflow.png picture `graph-easy --png ../examples/overview.txt manual/img/dataflow.png`; ############################################################################# sub _color_entry { # create on color entry my ($name, $color) = @_; $color =~ /#([a-fA-F0-9]{2})([a-fA-F0-9]{2})([a-fA-F0-9]{2})/; my $ac = hex($1) * hex($1) + hex($2) * hex($2) + hex($3) * hex($3); my $class = ''; $class = ' class="w"' if $ac < (256*170); "$name\n"; } sub read_file { my $f = shift; open FILE, "$f" or die ("Cannot read '$f': $!"); local $/ = undef; my $input = ; close FILE; $input; } sub write_file { my ($file,$txt) = @_; # create the directory unless it already exists my ($vol,$dir,$f) = File::Spec->splitpath($file); my @dirs = File::Spec->splitdir($dir); my $comb = ''; $comb = File::Spec->curdir() unless File::Spec->file_name_is_absolute($dirs[0]); foreach my $d (@dirs) { $comb = File::Spec->catdir($comb,$d); if (!-d $comb) { die ("Couldn't create dir $comb: $!") unless mkdir $comb, 0750; } } print "Writing $file...\n"; open FILE, ">$file" or die ("Cannot write '$file': $!"); binmode FILE, ':utf8' or die ("binmode $file, ':utf8' failed: $!"); print FILE $txt; close FILE; }