morgon has asked for the wisdom of the Perl Monks concerning the following question:

Hi

I have a data-structure that basically is a tree of objects that I want to visualize in a browser.

What I want is a rendering where each object would appear as a box, containing it's subordinate objects (as boxes within boxes and so on) and I need to be able to attach a link to each each box to allow for some "drilling down".

Unfortunately my css is a bit rusty (I never did much web-design work) so I wonder if there are any modules out there that could help me with this task.

At the moment beauty is not important so I would be happy with everything that works.

Many thanks!

  • Comment on Rendering a hierarchical data-structure as html

Replies are listed 'Best First'.
Re: Rendering a hierarchical data-structure as html
by Your Mother (Archbishop) on Jul 08, 2009 at 23:44 UTC

    What you probably want to do is a recursive print of the objects. Something like (total pseudo-code)-

    sub dump_tree { my $thing = shift; print "<div>"; dump_tree($_) for $thing->kids; print $thing if $thing->is_printable; print "</div>"; }

    And then your CSS basically takes care of itself. And you can do things like this-

    /* Take these as deep as you need/want and apply.class */ div { background-color: #111; } div>div { background-color: #611; } div>div>div{ background-color: #161; } div>div>div>div { background-color: #116; }

    Sadly, you can't recurse += with the CSS but you could certainly write the CSS with Perl to go as deep as you like/need and manipulate the layout variables programmatically/progressively.

    .