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