NAME

Graph::Easy::Introspect::Renderer - Base renderer class for Graph::Easy AST output

SYNOPSIS

use Graph::Easy::Introspect::Renderer;

my $r = Graph::Easy::Introspect::Renderer->new;

Subclassing:

package My::Renderer;
use parent 'Graph::Easy::Introspect::Renderer';

sub draw_box
{
my ($self, $x, $y, $w, $h, $text) = @_;
# real output here
}

DESCRIPTION

Base class for renderers that consume the AST produced by Graph::Easy::Introspect.

The default implementation of every drawing method prints its name and arguments to STDERR. This makes the base class immediately useful for verifying what a graph produces without writing any real rendering code.

To build a real renderer, subclass this module and override whichever methods are relevant. Unoverridden methods continue to print to STDERR, making it easy to discover which calls are being made during development.

All coordinate arguments are in character space as provided by the AST. See Graph::Easy::Introspect for the definition of character space.

METHODS

new

my $r = Graph::Easy::Introspect::Renderer->new;

Constructs a renderer instance. The base class holds no state; subclasses may use the blessed hashref for their own purposes.

draw_box($x, $y, $w, $h, $text)

Draw a rectangular node. $x and $y are the character-space top-left corner of the box. $w and $h are the rendered width and height in character columns and rows. $text is the display label.

draw_rounded_box($x, $y, $w, $h, $text)

Draw a node with rounded corners. Arguments identical to draw_box.

draw_diamond($x, $y, $w, $h, $text)

Draw a diamond-shaped node. Arguments identical to draw_box.

draw_circle($x, $y, $w, $h, $text)

Draw a circle or ellipse node. Arguments identical to draw_box.

draw_point($x, $y)

Draw a point node. No border and no label; only a position is needed.

draw_invisible($x, $y, $w, $h)

Called for nodes with shape invisible. The node occupies layout space but nothing is drawn.

draw_arrow($start_style, $end_style, \@points)

Draw a routed edge as a polyline.

$start_style and $end_style each take one of the values 'none' or 'arrow'. For a directed edge $end_style is 'arrow' and $start_style is 'none'. For a bidirectional edge both are 'arrow'. For an undirected edge both are 'none'.

\@points is an arrayref of waypoint hashrefs in path order from source to target, forming a rectilinear polyline in character space. Each waypoint has char_x and char_y. Corner waypoints additionally carry type (e.g. N_W, S_E) to identify the bend direction. The first waypoint is the from-node face attachment point; the last is the to-node face attachment point. HOR and VER segments are implicit between consecutive waypoints and contribute no entries of their own.

draw_self_loop($x, $y, $w, $h, $side)

Draw a self-loop anchored to a node. $x, $y, $w, $h are the character-space box of the node. $side is the face the loop exits and re-enters: one of 'left', 'right', 'top', 'bottom', or 'unknown'.

draw_edge_label($x, $y, $text)

Draw a floating edge label. $x and $y are the character-space position of the label cell as determined by Graph::Easy's layout.

draw_group($x, $y, $w, $h, $text)

Draw the border of a node group. $x, $y, $w, $h are the character-space extent of the group boundary including its border cells. $text is the group label.

draw_graph_label($x, $y, $total_w, $text)

Draw the graph-level title. $x and $y are the character-space top-left of the label area. $total_w is the total character width of the rendered output, available for centering. $text is the label string.

SEE ALSO

Graph::Easy::Introspect, the graph_easy_render script.

AUTHOR

Nadim Khemir <nadim.khemir@gmail.com>

LICENSE

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