X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FSQL%2FTranslator%2FProducer%2FDiagram.pm;h=34cd56b55d010cef6f36da80adc739bd1061b6c8;hb=bf75adec88e7d32b300af8897772a1522955d185;hp=3c2cad4b515f641400369b98f2dc9e572c8a5cd9;hpb=60dcc9806d04644c9f7a0e552c9436ae056f14fb;p=dbsrgits%2FSQL-Translator.git diff --git a/lib/SQL/Translator/Producer/Diagram.pm b/lib/SQL/Translator/Producer/Diagram.pm index 3c2cad4..34cd56b 100644 --- a/lib/SQL/Translator/Producer/Diagram.pm +++ b/lib/SQL/Translator/Producer/Diagram.pm @@ -1,9 +1,7 @@ package SQL::Translator::Producer::Diagram; # ------------------------------------------------------------------- -# $Id: Diagram.pm,v 1.10 2004-02-11 21:30:19 kycl4rk Exp $ -# ------------------------------------------------------------------- -# Copyright (C) 2002-4 SQLFairy Authors +# Copyright (C) 2002-2009 SQLFairy Authors # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License as @@ -30,18 +28,9 @@ Use via SQL::Translator: use SQL::Translator; - my $t = SQL::Translator->new( parser => 'MySQL', '...' ); + my $t = SQL::Translator->new( producer => 'Diagram', '...' ); $t->translate; -Or use more directly: - - use SQL::Translator; - use SQL::Translator::MySQL 'parse'; - - my $t = SQL::Translator->new( filename => '...' );; - parse( $t, - - =cut use strict; @@ -51,7 +40,7 @@ use SQL::Translator::Schema::Constants; use SQL::Translator::Utils qw(debug); use vars qw[ $VERSION $DEBUG ]; -$VERSION = sprintf "%d.%02d", q$Revision: 1.10 $ =~ /(\d+)\.(\d+)/; +$VERSION = '1.59'; $DEBUG = 0 unless defined $DEBUG; use constant VALID_FONT_SIZE => { @@ -80,6 +69,7 @@ sub produce { my $font_size = $args->{'font_size'} || 'medium'; my $imap_file = $args->{'imap_file'} || ''; my $imap_url = $args->{'imap_url'} || ''; + my $gutter = $args->{'gutter'} || 30; # distance b/w columns my $no_columns = $args->{'no_columns'}; my $no_lines = $args->{'no_lines'}; my $add_color = $args->{'add_color'}; @@ -89,10 +79,23 @@ sub produce { my $skip_fields = $args->{'skip_fields'}; my %skip = map { s/^\s+|\s+$//g; $_,1 } split (/,/, $skip_fields); - $schema->make_natural_joins( - join_pk_only => $join_pk_only, - skip_fields => $args->{'skip_fields'}, - ) if $natural_join; +# my @tables = $schema->get_tables; + my @table_names; + if ( $natural_join ) { + $schema->make_natural_joins( + join_pk_only => $join_pk_only, + skip_fields => $args->{'skip_fields'}, + ); + + my $g = $schema->as_graph_pm; + my $d = Graph::Traversal::DFS->new( $g, next_alphabetic => 1 ); + $d->preorder; + + @table_names = $d->dfs; + } + else { + @table_names = map { $_->name } $schema->get_tables; + } die "Invalid image type '$output_type'" unless VALID_IMAGE_TYPE ->{ $output_type }; @@ -102,12 +105,13 @@ sub produce { # # Layout the image. # - my $font = - $font_size eq 'small' ? gdTinyFont : - $font_size eq 'medium' ? gdSmallFont : - $font_size eq 'large' ? gdLargeFont : gdGiantFont; - my @tables = $schema->get_tables; - my $no_tables = scalar @tables; + my $font + = $font_size eq 'small' ? gdTinyFont + : $font_size eq 'medium' ? gdSmallFont + : $font_size eq 'large' ? gdLargeFont + : gdGiantFont; + + my $no_tables = scalar @table_names; $no_columns = 0 unless $no_columns =~ /^\d+$/; $no_columns ||= sprintf( "%.0f", sqrt( $no_tables ) + .5 ); $no_columns ||= .5; @@ -120,7 +124,6 @@ sub produce { my $cur_col = 1; # the current column my $no_this_col = 0; # number of tables in current column my $this_col_x = $x; # current column's x - my $gutter = 30; # distance b/w columns my %nj_registry; # for locations of fields for natural joins my @fk_registry; # for locations of fields for foreign keys my %table_x; # for max x of each table @@ -129,9 +132,9 @@ sub produce { my @imap_coords; # for making clickable image map my %legend; - for my $table ( @tables ) { - my $table_name = $table->name; - my $top = $y; + for my $table_name ( @table_names ) { + my $table = $schema->get_table( $table_name ); + my $top = $y; push @shapes, [ 'string', $font, $this_col_x, $y, $table_name, 'black' ]; $y += $font->height + 2;