DBIx::Class::Visualizer - Visualize a DBIx::Class schema
Version 0.0200, released 2016-09-19.
use DBIx::Class::Visualizer;
use The::DBIxClassSchema;
my $schema = The::DBIxClassSchema->connect;
my $svg = DBIx::Class::Visualizer->new(schema => $schema)->svg;
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.
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".
Required. An instance of a DBIx::Class::Schema class.
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.
Optional. An instance of Log::Handler.
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").
Optional. An array reference consisting of result source names (without the .*::Result:: prefix) you wish to not include in the output.
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
.
Boolean, defaults to 0
. If true, only primary and foreign key columns will be rendered.
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.
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;
The constructor.
Takes no arguments, and returns the graph as an svg string.
A shortcut for "run" in GraphViz2:
DBIx::Class::Visualizer->new(schema => $schema)->run(output_file => 'myschema.png', format => 'png');
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:
fill
, stroke
, font-family
) are removed so that styling can be done using css.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;
https://github.com/Csson/p5-DBIx-Class-Visualizer
https://metacpan.org/release/DBIx-Class-Visualizer
Erik Carlsson info@code301.com
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.