#!/usr/bin/perl use strict; use warnings; use feature qw(say); use Data::Dumper; use Fancy::Join qw(join_defined); use SVG (); sub gen_y { my $gen = shift; my $multiplier = $gen - 1; my $gen_y = 36 + ( 76 * $multiplier); return $gen_y; } sub family_y { my ($gen, $two_parents, $one_parent) = @_; my $multiplier = $gen - 1; my $modifier = $two_parents ? 0 : $one_parent ? 18 : 38; my $family_y = (-18 + (-76 * $multiplier)) + $modifier; return $family_y; } my $width = 620; my $height = 220; my $chart_trans_y = $height - 5; my $chart_title_y = ($chart_trans_y - 12) * -1; my $family = 'Noyb'; my $source = 'me'; my $svg = SVG->new( 'xmlns' => "http://www.w3.org/2000/svg", 'xmlns:xlink' => "http://www.w3.org/1999/xlink", 'xmlns:rdf' => "http://www.w3.org/1999/02/22-rdf-syntax-ns#", 'xmlns:dc' => "http://purl.org/dc/elements/1.1/", 'xmlns:cc' => "http://creativecommons.org/ns#", viewBox => "0 0 $width $height", width => $width, height => $height ); $svg->tag('title', id => "svg_title" )->cdata(ucfirst "The $family family from $source"); my $metadata = $svg->tag('metadata', id => "Family_metadata"); my $md_rdf = $metadata->tag('rdf:RDF'); my $rdf_cc = $md_rdf->tag('cc:work', 'rdf:about' => ''); $rdf_cc->tag('dc:format')->cdata('image/svg+xml'); $rdf_cc->tag('dc:type', 'rdf:resource' => 'http://purl.org/dc/dcmitype/StillImage'); $rdf_cc->tag('dc:title')->cdata("The $family family from $source"); my $cc_creator = $rdf_cc->tag('dc:creator'); my $dc_creator = $cc_creator->tag('cc:agent'); $dc_creator->tag('dc:title')->cdata('me'); $rdf_cc->tag('dc:language')->cdata('en-US'); $rdf_cc->tag('dc:date')->cdata('2020-03'); $svg->tag('style', id => "Family_styles", type => "text/css")->cdata(q( @import url(../../../css/family_tree.css); g.deceased.male rect { fill: url(#m_dead); } g.deceased.female rect { fill: url(#f_dead); } )); my $defs = $svg->tag('defs', id => "Family_defs"); my $m_dead_grad = $defs->gradient( -type => "radial", id => "m_dead"); $m_dead_grad->stop( id => 'mds1', offset => '75%', style => 'stop-color:#ccccff;stop-opacity:0.85;'); $m_dead_grad->stop( id => 'mds2', offset => '25%', style => 'stop-color:#eeeeff;stop-opacity:0.85;'); my $f_dead_grad = $defs->gradient( -type => "radial", id => "f_dead"); $f_dead_grad->stop( id => 'fds1', offset => '75%', style => 'stop-color:#ffcccc;stop-opacity:0.85;'); $f_dead_grad->stop( id => 'fds2', offset => '25%', style => 'stop-color:#ffeeee;stop-opacity:0.85;'); my $tree = $svg->group( id => $source, class => 'graph', transform => "translate(5, $chart_trans_y)" ); $tree->tag('title')->cdata(''); $tree->text( x => $width / 2, y => $chart_title_y, class => 'chart_title')->cdata("The $family family from $source"); my $text = $svg->xmlify; print "$text\n";