Datenstrukturen visualisieren mit GraphViz::Data::Grapher

Veröffentlicht von Thomas Fahle am (Permalink)

GraphViz::Data::Grapher von Léon Brocard ermöglicht die graphische Darstellung komplexer Datenstrukturen.

Dieser Beitrag geht auf folgende häufig anzutreffende Datenstrukturen ein

  • Arrays of Arrays
  • Hashes of Arrays
  • Arrays of Hashes
  • Hashes of Hashes
  • Hash mit komplexer Datenstruktur

und zeigt wie diese mit GraphViz::Data::Grapher visualisiert werden können.

 

Arrays of Arrays

#!/usr/bin/perl
use strict;
use warnings;

use GraphViz::Data::Grapher;

my @AoA = (
        [ "fred", "barney" ],
        [ "george", "jane", "elroy" ],
        [ "homer", "marge", "bart" ],
      );

my $graph = GraphViz::Data::Grapher->new(@AoA);
print $graph->as_png("AoA.png");

Das Programm erzeugt folgende Graphik:

AoA.png

 

Hashes of Arrays

#!/usr/bin/perl
use strict;
use warnings;

use GraphViz::Data::Grapher;

my  %HoA = (
        flintstones         => [ "fred", "barney" ],
        jetsons            => [ "george", "jane", "elroy" ],
        simpsons           => [ "homer", "marge", "bart" ],
      );
my $graph = GraphViz::Data::Grapher->new(%HoA);
print $graph->as_png("HoA.png");

Das Programm erzeugt folgende Graphik:

HoA.png

 

Arrays of Hashes

#!/usr/bin/perl 
use strict;
use warnings;

use GraphViz::Data::Grapher;

my @AoH = (
        {
            Lead     => "fred",
            Friend   => "barney",
        },
        {
            Lead     => "george",
            Wife     => "jane",
            Son      => "elroy",
        },
        {
            Lead     => "homer",
            Wife     => "marge",
            Son      => "bart",
        },
  );
my $graph = GraphViz::Data::Grapher->new(@AoH);
print $graph->as_png("AoH.png");

Das Programm erzeugt folgende Graphik:

AoH.png

 

Hashes of Hashes

#!/usr/bin/perl 
use strict;
use warnings;

use GraphViz::Data::Grapher;

my %HoH = (
        flintstones => {
                lead      => "fred",
                pal       => "barney",
        },
        jetsons     => {
                lead      => "george",
                wife      => "jane",
                "his boy" => "elroy",
        },
        simpsons    => {
                lead      => "homer",
                wife      => "marge",
                kid       => "bart",
        },
 );
my $graph = GraphViz::Data::Grapher->new(%HoH);
print $graph->as_png("HoH.png");

Das Programm erzeugt folgende Graphik:

HoH.png

 

Hash mit komplexer Datenstruktur

#!/usr/bin/perl 
use strict;
use warnings;

use GraphViz::Data::Grapher;
my      %TV = (
        flintstones => {
            series   => "flintstones",
            nights   => [ qw(monday thursday friday) ],
            members  => [
                { name => "fred",    role => "lead", age  => 36, },
                { name => "wilma",   role => "wife", age  => 31, },
                { name => "pebbles", role => "kid",  age  =>  4, },
            ],
        },

        jetsons     => {
            series   => "jetsons",
            nights   => [ qw(wednesday saturday) ],
            members  => [
                { name => "george",  role => "lead", age  => 41, },
                { name => "jane",    role => "wife", age  => 39, },
                { name => "elroy",   role => "kid",  age  =>  9, },
            ],
         },

        simpsons    => {
            series   => "simpsons",
            nights   => [ qw(monday) ],
            members  => [
                { name => "homer", role => "lead", age  => 34, },
                { name => "marge", role => "wife", age => 37, },
                { name => "bart",  role => "kid",  age  =>  11, },
            ],
         },
      );
my $graph = GraphViz::Data::Grapher->new(%TV);
print $graph->as_png("complex.png");

Das Programm erzeugt folgende Graphik:

complex.png

 

Siehe auch

Weitere Posts