=head1 NAME Graph::Renderer - draw the graph onto a real plane =cut package Graph::Renderer; use strict; use Carp qw (croak); use vars qw ($VERSION @ISA @EXPORT_OK); # $Id: Renderer.pm,v 1.3 2004/04/06 15:24:14 pasky Exp $ $VERSION = 0.02; =head1 SYNOPSIS my $graph = new Graph; ... use Graph::Layouter; Graph::Layouter::layout($graph); use Graph::Renderer; Graph::Renderer::render($graph, $img); =cut use base qw (Graph::Layouter); require Exporter; push @ISA, 'Exporter'; @EXPORT_OK = qw (render); =head1 DESCRIPTION This module provides an abstract class for drawing a given layouted graph (created usually by C) through various image creation interfaces (C, C). All the relevant layouting information used for nodes positioning is load from the graph, as saved by C (see its documentation for the relevant attributes description). In addition, relevant rendering information can be load from the graph attributes as well, if necessary and available. This module contains only the abstract class, you will probably want to get an instance of some particular drawing tool interface instead; C is bundled with this distribution. The general interface for all the subclasses is described below, but be sure consult also the particular class' documentation for remarks, special notes and specific extensions. =over 4 =cut use Graph; =item B This subroutine is the only entry point of this module, taking a given graph and rendering it accordingly to its attributes. The subroutine can be called in several ways: =over 4 =item I The subroutine can be called as a function (it is not automatically exported, but you can import it on your own if you really want; see the synopsis above). It takes two parameters, the C class (or any descendant) instance and instance of the appropriate image object (see subclasses documentation). It will load the rendering information from graph's both global and per-vertex attributes. =item I TODO =item I TODO =back The subroutine returns the image object if it all went well, undef otherwise. The common rendering attributes not generated by the layouter are: =over 4 =item I =over 4 =item B This should contain information about the font used for vertex titles; the specific format depends on the subclass. If this information is not made available by the caller, the given backend can try to figure it out but it might well fail. =back =item I =over 4 =item B This is identical to the global B attribute, but used only for the single vertex. =item B Title of the vertex, which is displayed nearby. The vertex number is displayed if no title is attached. You can attach an empty string to the vertex if you want no title shown at all. =back =back =cut sub render { my $graph = shift; croak "Graph::Renderer::render() called instead of something of a subclass!"; $graph; } # Internal use only, for subclasses; get maximal weight in the graph. sub _max_weight($) { my $graph = shift; my $max_weight = 0; my @edges = $graph->edges; while (my ($v1, $v2) = splice(@edges, 0, 2)) { my $weight = $graph->get_attribute('weight', $v1, $v2); $weight ||= 1; # TODO : configurable $max_weight = $weight if $max_weight < $weight; } $max_weight; } # Internal use only, for subclasses; maps virtual coord to physical pane sub _transpose_coord($$$$) { my ($virtual, $min, $max, $size) = @_; $max++ if $max == $min; # Division by zero protector $size * ($virtual - $min) / ($max - $min); } =back =head1 SEE ALSO C, C =head1 BUGS The object-oriented interface is missing as well as some more universal render calling interface (hash parameters). Also, some more rendering attributes (ie. color settings, own dimensions) are missing. =head1 COPYRIGHT Copyright 2004 by Petr Baudis Epasky@ucw.czE. This code is distributed under the same copyright terms as Perl itself. =head1 VERSION Version 0.02 $Id: Renderer.pm,v 1.3 2004/04/06 15:24:14 pasky Exp $ =cut 1;