From: Ben Faga Date: Mon, 7 May 2007 20:58:56 +0000 (+0000) Subject: Applied Hilmar's patches. X-Git-Tag: v0.11008~361 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=027cebc7f50e5c669d26f5ed76a0c1dc4f4c8861;p=dbsrgits%2FSQL-Translator.git Applied Hilmar's patches. --- diff --git a/bin/sqlt-graph b/bin/sqlt-graph index 82d59dc..1df960d 100755 --- a/bin/sqlt-graph +++ b/bin/sqlt-graph @@ -1,7 +1,7 @@ #!/usr/bin/perl # ------------------------------------------------------------------- -# $Id: sqlt-graph,v 1.7 2006-10-16 15:24:12 duality72 Exp $ +# $Id: sqlt-graph,v 1.8 2007-05-07 20:58:56 mwz444 Exp $ # ------------------------------------------------------------------- # Copyright (C) 2002-4 SQLFairy Authors # @@ -47,6 +47,14 @@ sqlt-graph - Automatically create a graph from a database schema set to "0" to undefine) --width Image width (in inches, default "8.5", set to "0" to undefine) + --fontsize custom font size for node and edge labels + --fontname name of custom font (or full path to font file) for + node, edge, and graph labels + --nodeattr attribute name and value (in key=val syntax) for + nodes; this option may be repeated to specify + multiple node attributes + --edgeattr same as --nodeattr, but for edge attributes + --graphattr same as --nodeattr, but for graph attributes --natural-join Perform natural joins --natural-join-pk Perform natural joins from primary keys only --show-datatypes Show datatype of each field @@ -91,7 +99,7 @@ use Pod::Usage; use SQL::Translator; use vars '$VERSION'; -$VERSION = sprintf "%d.%02d", q$Revision: 1.7 $ =~ /(\d+)\.(\d+)/; +$VERSION = sprintf "%d.%02d", q$Revision: 1.8 $ =~ /(\d+)\.(\d+)/; # # Get arguments. @@ -100,9 +108,14 @@ my ( $layout, $node_shape, $out_file, $output_type, $db_driver, $add_color, $natural_join, $join_pk_only, $skip_fields, $show_datatypes, $show_sizes, $show_constraints, $debug, $help, $height, $width, - $no_fields + $no_fields, $fontsize, $fontname ); +# multi-valued options: +my %edgeattrs = (); +my %nodeattrs = (); +my %graphattrs = (); + GetOptions( 'd|db|f|from=s' => \$db_driver, 'o|output:s' => \$out_file, @@ -111,6 +124,11 @@ GetOptions( 't|output-type:s' => \$output_type, 'height:f' => \$height, 'width:f' => \$width, + 'fontsize=i' => \$fontsize, + 'fontname=s' => \$fontname, + 'nodeattr=s' => \%nodeattrs, + 'edgeattr=s' => \%edgeattrs, + 'graphattr=s' => \%graphattrs, 'c|color' => \$add_color, 'no-fields' => \$no_fields, 'natural-join' => \$natural_join, @@ -146,6 +164,11 @@ my $translator = SQL::Translator->new( show_constraints => $show_constraints, height => $height || 0, width => $width || 0, + fontsize => $fontsize, + fontname => $fontname, + nodeattrs => \%nodeattrs, + edgeattrs => \%edgeattrs, + graphattrs => \%graphattrs, show_fields => $no_fields ? 0 : 1, }, ) or die SQL::Translator->error; diff --git a/lib/SQL/Translator/Producer/GraphViz.pm b/lib/SQL/Translator/Producer/GraphViz.pm index 9249c4a..b86e844 100644 --- a/lib/SQL/Translator/Producer/GraphViz.pm +++ b/lib/SQL/Translator/Producer/GraphViz.pm @@ -1,7 +1,7 @@ package SQL::Translator::Producer::GraphViz; # ------------------------------------------------------------------- -# $Id: GraphViz.pm,v 1.12 2004-02-20 02:41:47 dlc Exp $ +# $Id: GraphViz.pm,v 1.13 2007-05-07 20:58:56 mwz444 Exp $ # ------------------------------------------------------------------- # Copyright (C) 2002-4 SQLFairy Authors # @@ -88,6 +88,31 @@ width (in inches) of the output graphic height (in inches) of the output grahic +=item * fontsize + +custom font size for node and edge labels (note that arbitrarily large +sizes may be ignored due to page size or graph size constraints) + +==item * fontname + +custom font name (or full path to font file) for node, edge, and graph +labels + +==item * nodeattrs + +reference to a hash of node attribute names and their values; these +may override general fontname or fontsize parameter + +==item * edgeattrs + +reference to a hash of edge attribute names and their values; these +may override general fontname or fontsize parameter + +==item * graphattrs + +reference to a hash of graph attribute names and their values; these +may override the general fontname parameter + =item * show_fields (DEFAULT: true) if set to a true value, the names of the colums in a table will @@ -157,7 +182,7 @@ use SQL::Translator::Schema::Constants; use SQL::Translator::Utils qw(debug); use vars qw[ $VERSION $DEBUG ]; -$VERSION = sprintf "%d.%02d", q$Revision: 1.12 $ =~ /(\d+)\.(\d+)/; +$VERSION = sprintf "%d.%02d", q$Revision: 1.13 $ =~ /(\d+)\.(\d+)/; $DEBUG = 0 unless defined $DEBUG; use constant VALID_LAYOUT => { @@ -221,6 +246,11 @@ sub produce { ? $args->{'width'} : 8.5; my $height = defined $args->{'height'} ? $args->{'height'} : 11; + my $fontsize = $args->{'fontsize'}; + my $fontname = $args->{'fontname'}; + my $edgeattrs = $args->{'edgeattrs'} || {}; + my $graphattrs = $args->{'graphattrs'} || {}; + my $nodeattrs = $args->{'nodeattrs'} || {}; my $show_fields = defined $args->{'show_fields'} ? $args->{'show_fields'} : 1; my $add_color = $args->{'add_color'}; @@ -262,11 +292,40 @@ sub produce { node => { shape => $node_shape, style => 'filled', - fillcolor => 'white' - } + fillcolor => 'white', + }, ); $args{'width'} = $width if $width; $args{'height'} = $height if $height; + # set fontsize for edge and node labels if specified + if ($fontsize) { + $args{'node'}->{'fontsize'} = $fontsize; + $args{'edge'} = {} unless $args{'edge'}; + $args{'edge'}->{'fontsize'} = $fontsize; + } + # set the font name globally for node, edge, and graph labels if + # specified (use node, edge, or graph attributes for individual + # font specification) + if ($fontname) { + $args{'node'}->{'fontname'} = $fontname; + $args{'edge'} = {} unless $args{'edge'}; + $args{'edge'}->{'fontname'} = $fontname; + $args{'graph'} = {} unless $args{'graph'}; + $args{'graph'}->{'fontname'} = $fontname; + } + # set additional node, edge, and graph attributes; these may + # possibly override ones set before + while (my ($key,$val) = each %$nodeattrs) { + $args{'node'}->{$key} = $val; + } + $args{'edge'} = {} if %$edgeattrs && !$args{'edge'}; + while (my ($key,$val) = each %$edgeattrs) { + $args{'edge'}->{$key} = $val; + } + $args{'graph'} = {} if %$edgeattrs && !$args{'graph'}; + while (my ($key,$val) = each %$graphattrs) { + $args{'graph'}->{$key} = $val; + } my $gv = GraphViz->new( %args ) or die "Can't create GraphViz object\n";