Skip to content

Commit

Permalink
person() now expects a hash reference.
Browse files Browse the repository at this point in the history
  • Loading branch information
Dave Cross committed Jun 17, 2016
1 parent e69dbb3 commit d8c3fc3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
15 changes: 8 additions & 7 deletions Genealogy/Chart/SVG.pm
Expand Up @@ -148,28 +148,29 @@ sub BUILD {
# Produce a bar containing the details of one person.
sub person {
my $self = shift;
my ($person) = @_;
my ( $n, $name, $b, $d ) = @_;

my $gen = ahnen($n)->generation;
my $gen = ahnen($person->{id})->generation;

my $until = $d || $self->left;
my $until = $person->{death} || $self->left;

$self->rect(
x => ( $self->left - $until ) * $self->pixels_per_year,
y => ( $self->height * y_pos($n) ) - ( $self->bar_height / 2 ),
width => ( $until - $b ) * $self->pixels_per_year,
y => ( $self->height * y_pos($person->{id}) ) - ( $self->bar_height / 2 ),
width => ( $until - $person->{birth} ) * $self->pixels_per_year,
height => $self->bar_height,
fill => $self->colours->[$gen],
stroke => $self->bar_outline_colour,
'stroke-width' => 1
);

my $text = "$n: $name ($b - ";
$text .= $d if $d;
my $text = "$person->{id}: $person->{name} ($person->{birth} - ";
$text .= $person->{death} if $person->{death};
$text .= ')';
$self->text(
x => ( $self->left - $until + 1 ) * $self->pixels_per_year,
y => ( $self->height * y_pos($n) )
y => ( $self->height * y_pos($person->{id}) )
+ ( $self->bar_height / 2 )
- ( 2 * $self->bar_padding ),
'font-size' => $self->bar_height - $self->bar_padding,
Expand Down
10 changes: 7 additions & 3 deletions chart
Expand Up @@ -36,16 +36,20 @@ use Genealogy::Chart::SVG;

my $chart = Genealogy::Chart::SVG->new;

my @cols = qw[id name birth death];

while (<>) {
chomp;
my ($line) = split /#/;
next unless $line && $line =~ /\S/;
my @person = split /,/, $line;
if (@person < 3) {
my @data = split /,/, $line;
if (@data < 3) {
warn "Invalid record: $_\n";
next;
}
$chart->person(@person);
my %person;
@person{@cols} = @data;
$chart->person(\%person);
}

print $chart->xmlify;

0 comments on commit d8c3fc3

Please sign in to comment.