Graphviz and Friends

Slide 5/16 -- First Previous Next Last
Write in Perl - And use GraphViz2

#!/usr/bin/env perl
# Test # 7: jointed.eges.pl.
use strict;
use warnings;

use File::Spec;

use GraphViz2;

# ---------------

my($graph) = GraphViz2 -> new
	(
	 edge   => {color => 'grey'},
	 global => {directed => 1},
	 graph  => {rankdir => 'TB'},
	 logger => $logger,
	 node   => {shape => 'oval'},
	);

$graph -> default_node(style => 'filled');

$graph -> add_node(name => 'Carnegie',    color => 'aquamarine');
$graph -> add_node(name => 'Murrumbeena', color => 'bisque');
$graph -> add_node(name => 'Oakleigh',    color => 'blueviolet');

# This is the 1st of 2 nodes used as the junction of 3 edges.

my(%junction) = (label => '', style => 'filled', fillcolor => 'white', fixedsize => 1, width => 0, height => 0);

$graph -> add_node(name => 'one', %junction);

my(%headless_arrow) = (arrowhead => 'none', samehead => 1);

$graph -> add_edge(from => 'Murrumbeena', to => 'one', %headless_arrow);
$graph -> add_edge(from => 'Carnegie',    to => 'one', %headless_arrow);
$graph -> add_edge(from => 'one',         to => 'Oakleigh', sametail => 1);

my($format)      = shift || 'svg';
my($suffix)      = $format eq 'png:gd' ? 'png' : $format;
my($output_file) = shift || File::Spec -> catfile('html', "jointed.edges.$suffix");

$graph -> run(format => $format, output_file => $output_file);