rlm@78: #!/usr/bin/perl -w rlm@78: use strict; rlm@78: use SVG; rlm@78: rlm@78: # create an SVG object rlm@78: my $svg= SVG->new(width=>200,height=>200); rlm@78: #or rlm@78: my $svg= SVG->new(width=>200,height=>200); rlm@78: rlm@78: # use explicit element constructor to generate a group element rlm@78: my $y=$svg->group( rlm@78: id => 'group_y', rlm@78: style => { stroke=>'red', fill=>'green' } rlm@78: ); rlm@78: rlm@78: # add a circle to the group rlm@78: $y->circle(cx=>100, cy=>100, r=>50, id=>'circle_in_group_y'); rlm@78: rlm@78: # or, use the generic 'tag' method to generate a group element by name rlm@78: my $z=$svg->tag('g', rlm@78: id => 'group_z', rlm@78: style => { rlm@78: stroke => 'rgb(100,200,50)', rlm@78: fill => 'rgb(10,100,150)' rlm@78: } rlm@78: ); rlm@78: rlm@78: # create and add a circle using the generic 'tag' method rlm@78: $z->tag('circle', cx=>50, cy=>50, r=>100, id=>'circle_in_group_z'); rlm@78: rlm@78: # create an anchor on a rectangle within a group within the group z rlm@78: my $k = $z->anchor( rlm@78: id => 'anchor_k', rlm@78: -href => 'http://test.hackmare.com/', rlm@78: target => 'new_window_0' rlm@78: )->rectangle( rlm@78: x => 20, y => 50, rlm@78: width => 20, height => 30, rlm@78: rx => 10, ry => 5, rlm@78: id => 'rect_k_in_anchor_k_in_group_z' rlm@78: ); rlm@78: rlm@78: # now render the SVG object, implicitly use svg namespace rlm@78: print $svg->xmlify; rlm@78: rlm@78: # or render a child node of the SVG object without rendering the entire object rlm@78: print $k->xmlify; #renders the anchor $k above containing a rectangle, but does not rlm@78: #render any of the ancestor nodes of $k rlm@78: rlm@78: rlm@78: # or, explicitly use svg namespace and generate a document with its own DTD rlm@78: print $svg->xmlify(-namespace=>'svg'); rlm@78: rlm@78: # or, explicitly use svg namespace and generate an in-line docunent rlm@78: print $svg->xmlify( rlm@78: -namespace => "svg", rlm@78: -pubid => "-//W3C//DTD SVG 1.0//EN", rlm@78: -inline => 1 rlm@78: );