Indenting Trees

The snow has nearly all gone, just in time for the next batch! It was a douzy of a storm, fun driving conditions, amazing how much you forget over the hot dry 'roaded' summer. My newly licensed son was itching to get out there. Mom wouldn't let him, I had to agree, our insurance couldn't take it and we have way too many trees near our house. The trees looked very pretty thou and speaking of trees (what a segue) I have been asked numerous times if BIP can generate a tree structure, the more ambitious ask for an org chart. I plan to take a look at how to do the org chart another time, for now, how about a nice tree structure.

Between the two of us, Rob (colleague and data modeler extraordinaire) came up with a solution for a customer to generate this:

Tree1.jpg

Its a tree of sorts, nothing fancy, we just wanted to get the structure right, so there are no details under the headings. Its getting the indenting correct that was the trick. The customer had a pretty fixed data structure and did not want to use nested tables.

The template is pretty simple, just a funky trick to get the indenting working. I mentioned the customer had a pretty fixed data structure. It made life easier, they only had 3 levels to worry about so the code to handle the indenting could be pretty straightforward and somewhat 'hard coded' for the data set.

tree4.jpg

It also has the advantage that the tree is in the right order ie

Level1
-Level2
-Level2
-- Level3
-Level2
Level1
Level1
...

The template looks like this

Tree2.jpg

the fields contain

Tree3.jpg

Of course the most interesting field is the C

<?if:number(LEVELS)=1?>
<?ORG_LONG_NAME?>
<?end if?>
<?if:number(LEVELS)=2?>
<?attribute@inblock:start-indent;'20.0pt'? > <?ORG_LONG_NAME?>
<?end if?>
<?if:number(LEVELS)=3?>
<?attribute@inblock:start-indent;'30.0pt'?> <?ORG_LONG_NAME?>
<?end if?>

A chhose statement would have worked just as well. You can see the dependence on the data order and the structure or more specifically LEVELS element. We need to check that to know how big the indentation should be.
The @block is also important, we need that to get the indentation to show only on the current text and not affect anything else. If we had been using tables we could have gotten around that.
Now we could have been a little smarter and written something to handle any number of levels ... answers on the back on a new Mac Book Pro 15-inch: 2.8GHz 4Gb 500Gb HD :0)

Comments:

Hi Tim, You've some missing fields in the "C" text - you need to have ORG_LONG_NAME in each of the if statements including LEVELS=2 and 3 where ORG_LONG_NAME is missing. The screendump seems correct. The technique used is similar to that I used to get around recursive subtemplates described here: http://garethroberts.blogspot.com/2009/11/bi-xml-publisher-54pt-start-indent.html Regards, Gareth

Posted by Gareth Roberts on November 05, 2009 at 08:59 AM MST #

Hi Gareth Thanks, danged HTML encoding I missed. Once the server decides to come back I'll change it <?if:number(LEVELS)=1?> <?ORG_LONG_NAME?> <?end if?> <?if:number(LEVELS)=2?> <?attribute@inblock:start-indent;'20.0pt'? > <?ORG_LONG_NAME?> <?end if?> <?if:number(LEVELS)=3?> <?attribute@inblock:start-indent;'30.0pt'?> <?ORG_LONG_NAME?> <?end if?>

Posted by tim on November 05, 2009 at 09:10 AM MST #

I discovered your blog from a collection of it on exactly the same topic. I am happy that I made the right choice

Posted by Francisco Scifres on March 14, 2010 at 08:24 AM MDT #

Post a Comment:
  • HTML Syntax: NOT allowed
About

Follow bipublisher on Twitter Find Us on Facebook BI Publisher Youtube ChannelDiscussion Forum

Join our BI Publisher community to get the most and keep updated with the latest news, How-to, Solutions! Share your feedback and let us hear your voice @bipublisher on Twitter, on our official Facebook page, and Youtube!

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today