OK, so someone asked what context my ugly reference question was in yesterday, and since what I'm doing might be useful for someone else, I thought I'd post the problem and my solution to see if (a) someone else could use it or (b) I'm reinventing the wheel and there's a better way commonly known.
OK, so this page structure on a web site:
1
|_2
| \_5
|_3
\_4
is stored as 'treepaths', like this:
1 => 001:000:000
2 => 001:002:000
3 => 001:003:000
4 => 001:003:004
5 => 001:002:005
that way, sorting them on these values brings them out in the desired display order.
Now, I want to display a lovely graphical tree depicting this, so I have 5 graphics and assign them values:
- a blank square (0)
|#| - a page icon (1)
|_ - an 'L' shape icon (2)
| - a vertical pipe icon (4)
|- - a "t' shape icon (6)
So to create the correct matrix, I take the following rules:
- create an initial matrix by sorting the treepaths and then splitting them on ':' and converting to a number
1 0 0
1 2 0
1 2 5
1 3 0
1 3 4
- Then, parsing from right to left,
- change 1st non-zero element to '1'
- change next to '2'
- change remaining to '0'
ie
1 0 0
2 1 0
0 2 1
2 1 0
0 2 1
- Finally, parse each element, going from bottom right to top left with the rule "For this element, if this element !=1 and the one below it is >=2, add 4. ie
1 0 0
6 1 0
4 2 1
2 1 0
0 2 1
Then just convert each number to the relevant icon and you have a pretty tree structure.
Or am I making a mountain out of a molehill?
cLive ;-)
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.