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

Hell again,
    I am working on the next version of Image::OrgChart (which may soon be renamed Business::OrgChart) and while doing so, i have run into a bit of a problem. My original code was very crude. For the new version i am re-writting the function which calculates the image final height and width based on the data. Here is where my problem is. I have a big, harry hash ... the kind that eats llama's for breakfast. The format is :
$hash{'mgr'}{ 'mid-mgmt' => { coderA => {}, coderB => { 'regexp monkey' => {}, }, }, }; ## for quick ref : # /mgr # /mgr/mid-mgmt # /mgr/mid-mgmt/coderA # /mgr/mid-mgmt/coderB # /mgr/mid-mgmt/coderB/regexp monkey
    Because of the nature, this hash of hashes can be of any depth, with any number of keys at each level (seems there are a lot of mid-mgmt people). I have a recursive hash-walking algorithm i am using to find two variables ,$high_keys and $high_depth (2 and 4 respectivly in this case). But, given the maximum number of keys, and the maximum depth, the best i can do is calculate how the max-plausable height like this :
## all of the object stuff is gone, this is alg only # $height_of_a_box = font_height + all padding $height = ($height_of_a_box * ($high_keys*$high_depth));
    The problem with this is that it always calculates the height as if each level had the maximum number of keys.

What i am wondering is : can anyone think of a way, given the data hash described, to calculate the height of the image ?

    I am not sure i explained this well enough, but it is confussing stuff (for me). i look forward to any help.

Why not an ascii art version of the image, just incase it helps explain :
+-------+ | mgmt | +-------+ | +----------+ +----| mid-mgmt | +----------+ | +--------+ |----| coderA | | +--------+ | +--------+ +----| coderB | +--------+ | +--------+ +---| monkey | +--------+

can't sleep clowns will eat me
-- MZSanford

Replies are listed 'Best First'.
Re: hashes of doom !
by suaveant (Parson) on Sep 06, 2001 at 18:24 UTC
    Not really, yoy need better data... max depth and max keys isn't really useful, since if your max keys is 2 and your depth is 3 you could have...
    === +-=== +-=== +-===
    or...
    === +-=== | +-=== | | +-=== | | +-=== | +-=== | +-=== | +-=== +-=== +-=== | +-=== | +-=== +-=== +-=== +-===
    According to your ascii art... your image height is the total number of boxes times the height of your boxes... unless you have overlap somewhere...

                    - Ant
                    - Some of my best work - Fish Dinner

      you are completly correct. I had been intrenched in other work on the module for so long, i over looked the obvious.

      Thanks to suaveant and ariels who both caught this. This seems to be a case of 'the man' putting up a tree and blocking my view of the forest.
      can't sleep clowns will eat me
      -- MZSanford
Re (tilly) 1: hashes of doom !
by tilly (Archbishop) on Sep 06, 2001 at 18:35 UTC
    I suggest picking an indentation style that does not indent nearly so deeply, nearly so fast.

    It doesn't look as pretty, but a consistent indent somewhere between 2-4 characters will greatly improve comprehension. See the appropriate chapter of Code Complete for details and references to studies on which that statement is based.

      I was planning to add some more configurability at this version, because the first one was mostly a 'my-first-GD' attempt. Based on this, i have added the indent option (which is measured in characters), and defaulted to 4. Thanks for all of the help.
      can't sleep clowns will eat me
      -- MZSanford
        I am sorry if I was unclear.

        I was talking about the layout of the configuration bit, not the output.

        Sorry.