A while back I stumbled across Tim Bunce's Treemap blog and thought I'd have a go at producing an SVG output module based on the Treemap module.

I want to produce a version that drills down through the data revealing more detail at each level. To do this I need to produce an hierarchical SVG document. But the existing Treemap module only passes on drawing data (coordinates, colour and text) when invoking the output objects methods.

Example of use below:

Input data:

<children name="main" size="6" colour="antiquewhite"> <children name="Treemap" size="4" colour="#FF0000"> <children name="xmlify" size="2" colour="#00FF00" /> <children name="save01" size="2" colour="#00FF00" link="save01.ht +ml" /> </children> <children name="Treemap::Output::SVG" size="6" colour="#FFFF00" > <children name="rect" size="1" colour="#00FFFF" /> <children name="text01" size="4" colour="whitesmoke"> <children name="text02" size="2" colour="#00FF00" > <children name="text02_01" size="1" colour="#F0F0F0" /> <children name="text02_02" size="1" colour="#F0F0F0" /> </children> <children name="text03" size="1" colour="#00FF00" /> <children name="text04" size="1" colour="cyan" /> </children> <children name="save02" size="1" colour="gray" /> </children> </children>

Creating an SVG output file:

use Treemap; use Treemap::Input::XML; use Treemap::Output::SVG; # read the XML input file my $in = Treemap::Input::XML->new(); $in->load( "inputfile.xml" ); my $out = Treemap::Output::SVG->new(); my $treemap = Treemap->new( INPUT=>$in, OUTPUT=>$out); # create a treemap in SVG using the XML input file provided $treemap->map(); # save the results to a file $out->save( "outputfile.svg" );

In reply to Object sub-classing advice sought by waldo

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.