#!/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
#
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
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.
$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,
'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,
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;
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
#
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
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 => {
? $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'};
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";