#!/usr/bin/perl -w use strict; use Data::Dumper; use Surface; use Node; use Graph::Directed; use Math::Trig; my $output_file = $ARGV[0] or die "Usage: $0 image_file_name\n"; $output_file .= '.png'; # #dataset # # { john => { public => 20, paul => 30, }, # paul => { public => 40, john => 30, george => 20, ringo => 10, }, # george => { public => 10, john => 10, paul => 10, ringo => 10, }, # ringo => { }, }; # Use an IRC log for data, instead. my $data = eval qx{./parse_irc.perl $output_file}; #die Dumper($data), "\n"; my $graph = Graph::Directed->new; my $max = 0; # Compute the sum of the data and find the maximum out of all the data. # Create the node and add it to the graph. while (my ($key, $val) = each %$data) { my $sum = 0; $sum += $_ for values %$val; $data->{$key} = Node->new(name => $key, data => $val, total => $sum); $graph->add_vertex($data->{$key}); # Accumulate the total talk. # $max += $sum; # Use the "top-talker" as the plot center. $max = $sum if $sum > $max; } die "This graph has no dimension.\n" unless $max; # Set the visual attributes of each node. my $size = 6; for (values %$data) { $_->position($_->get_coord($max)); $_->size($size); } # Draw the node-picture. my $image = Surface->new(size => 2 * $max, name => $output_file); for my $node (values %$data) { $image->draw_node($node); for (keys %{ $node->data }) { next if $_ eq 'public' || !exists $data->{$_}; $graph->add_edge($node, $data->{$_}); $image->draw_edge($node, $data->{$_}); } } # Tell 'em what they've won, Don Pardo! $image->pic_output; exit;