The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

DBIx::Class::Visualizer - Visualize a DBIx::Class schema

Requires Perl 5.10.1+ Travis status Distribution kwalitee CPAN Testers result coverage 89.2%

VERSION

Version 0.0200, released 2016-09-19.

SYNOPSIS

    use DBIx::Class::Visualizer;
    use The::DBIxClassSchema;

    my $schema = The::DBIxClassSchema->connect;
    my $svg = DBIx::Class::Visualizer->new(schema => $schema)->svg;

DESCRIPTION

DBIx::Class::Visualizer is a GraphViz2 renderer for DBIx::Class schemas. It is designed to be used as a backend to web applications that can display the rendered graph in a more user friendly way. See Mojolicious::Plugin::DbicSchemaViewer.

STATUS

Backwards compatability between even minor releases is currently not a goal. That said, the public interface is small and most breaking changes are likely to be in "transformed_svg".

ATTRIBUTES

schema

Required. An instance of a DBIx::Class::Schema class.

logger_conf

Optional array reference. GraphViz2 uses Log::Handler, so this distribution does that too. By default it noisily prints to screen. Not used if logger is set.

logger

Optional. An instance of Log::Handler.

wanted_result_source_names

Optional. An array reference consisting of result source names (without the .*::Result:: prefix) you wish to include in the output. This can be useful to focus on a small part of large schemas.

If it is not set all result sources will be rendered (minus "skip_result_source_names").

skip_result_source_names

Optional. An array reference consisting of result source names (without the .*::Result:: prefix) you wish to not include in the output.

degrees_of_separation

Optional. A non-negative integer that is used together with "wanted_result_source_names". In addition to the wanted result sources, this attribute defines how many relationship steps should be followed to other result sources that also should be included in the output.

Default is 1.

only_keys

Boolean, defaults to 0. If true, only primary and foreign key columns will be rendered.

graphviz_conf

Optional hashref. This hashref is passed to the GraphViz2 constructor. The output from "transformed_svg" is adapted to the default settings, so using these two together might cause a less usable svg document.

Won't be used if you pass graph to the constructor.

graph

Optional. A GraphViz2 object. Pass this if you need to use an already constructed graph.

After "new" has run it can be useful if you, for example, wishes to see the arguments to the dot renderer:

    my $visualizer = DBIx::Class::Visualizer->new(schema => $schema);
    my $svg = $visualizer->svg;

    my $dotfile = $visualizer->graph->dot_input;

METHODS

new

The constructor.

svg

Takes no arguments, and returns the graph as an svg string.

run

A shortcut for "run" in GraphViz2:

    DBIx::Class::Visualizer->new(schema => $schema)->run(output_file => 'myschema.png', format => 'png');

transformed_svg

Takes no arguments. Returns an svg string that is more useful than that from "svg" Using this method requires Mojolicious.

This method improves the svg generated by graphviz in several ways:

  • All layout attributes (eg. fill, stroke, font-family) are removed so that styling can be done using css.

  • There are occasional minor gaps between the various elements in edges, these are removed (or at least reduced).

  • This distribution adds some padding between texts and borders to avoid overlapping. These are removed so that no unnecessary elements remain.

  • All edges, nodes and column name elements get relevant values for their id attributes.

  • Several data- attributes are added to edges, nodes and column attributes containing a lot of information about the schema.

As an example, this is a column element as rendered by graphviz (whitespace added for readability:

    <text text-anchor="start"
           x="700.391"
           y="-17.9"
           font-family="Helvetica,sans-Serif"
           font-weight="bold"
           font-size="10.00"
           fill="#222222">a_column_id</text>

After passing through transformed_svg the same column looks like this:

    <text id="column-TableName-a_column_id"
          class="column-name"
          y="-17.9"
          x="700.391"
          text-anchor="start"
          data-is-primary="1"
          data-column-name="a_column_id"
          data-column-info="{
            "name": "a_column_id",
            "data_type": "integer",
            "is_primary_key": 1
            "is_auto_increment": 1,
            "is_nullable": 0,
            "is_foreign_key": 0,
            "is_numeric": 1,
            "extra": {},
            "relations":[
                {
                    "origin_table": "TableName",
                    "origin_column": "a_column_id",
                    "destination_table": "AnotherTableName"
                    "destination_column": "a_column_id",
                    "relation_type": "has_many",
                    "cascade_delete": 1,
                },
                ...
            ],
          }">a_column_id</text>

The data-column-info attribute is a json object that is directly usable by something like jQuery:

    # has_many
    $('#column-TableName-a_column_id').data('column-info').relations[0].relation_type;

SEE ALSO

SOURCE

https://github.com/Csson/p5-DBIx-Class-Visualizer

HOMEPAGE

https://metacpan.org/release/DBIx-Class-Visualizer

AUTHOR

Erik Carlsson <info@code301.com>

COPYRIGHT AND LICENSE

This software is copyright (c) 2016 by Erik Carlsson.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.