| Search Locate Previous Next | Contents |
The data in a table are frequently part of some hierarchical structure. One way of indicating this structure is through the column titles. For example, the relationship of districts to regions in the sales report was made explicit by combining each district name with its associated region atop the appropriate column in the table. Ignoring the row titles and row totals for the moment, this produces:
North North South South South District 1 District 2 District 3 District 4 District 5 Total
However, the hierarchy becomes more visible by centring each region name above all of its constituent districts:
North South District 1 District 2 District 3 District 4 District 5 Total
NewLeaf supports the grouping and arrangement of column titles in this manner by means of the Depth property of the column titles. By default, each column title is assumed to be at the top level of a hierarchical tree structure that contains only one node, itself, that is located at a depth of 0 within the hierarchy. This is analogous to a number of directories that exist at the root level of a disk operating system.
To describe a hierarchical structure, the column titles, or nodes, of each tree in the structure are ordered from top to bottom (depth0 to depthn) and from left to right. The value of the depth property of each node is then set to indicate its relationship to the node immediately to its left in the list.
Each tree has one depth-0 node, and the depth of the first column title in the list is always zero. The column titles for the sales data have three trees: North region, containing two depth-1 nodes (Districts 1 and 2); South region, containing three depth-1 nodes (Districts 3, 4 and 5); and the totals, with no nodes other than itself. Observe how NewLeaf arranges the column titles to reflect the implied hierarchy:
leaf.Init ª leaf.Use'' leaf.table.Titles ('North'),(2districts),('South'),2districts leaf.table.TDepth 0 1 1 0 1 1 1 0 leaf.table.List salesQ1 View docleaf.Close
NewLeaf always resets the depth of the column titles to the default value whenever you specify the content of the column titles. NewLeaf also reshapes the depth vector to match the number of column titles. Because the title alignments correspond to the order of the title vector, you can right-align the district names while leaving the regions and total centre-aligned:
leaf.Init ª leaf.Use''
leaf.table.Titles ('North'),(2districts),('South'),2districts
leaf.table.TDepth 0 1 1 0 1 1 1 0
leaf.table.TAlign('centre' 'right')[1 + 0 1 1 0 1 1 1 0]
leaf.table.List salesQ1
View docleaf.Close
NewLeaf can handle column title structures containing trees that extend to different depths. Assume that South region is divided into two areas, East and West. These are depth-1 nodes. East contains one depth-2 node, District 3, and West contains two depth-2 nodes, Districts 4 and 5. Note also what happens to the vertical space allocated for the three nodes in the North tree:
salesTitles('North'),(2districts),('South' 'East'),12districts
salesTitlessalesTitles,('West'),3districts
leaf.Init ª leaf.Use''
leaf.table.Titles salesTitles
leaf.table.TDepth 0 1 1 0 1 2 1 2 2 0
leaf.table.List salesQ1
View docleaf.Close
Now, compare the North tree in the previous example to the following, where the district nodes are designated depth-2 nodes:
leaf.Init ª leaf.Use'' leaf.table.Titles salesTitles leaf.table.TDepth 0 2 2 0 1 2 1 2 2 0 leaf.table.List salesQ1 View docleaf.Close
So, for the deepest level column titles to appear at the same height immediately above the table, they must all have the same depth. In this case, it means that all nodes corresponding to districts are depth-2.
If there is no node at a particular depth within a tree, NewLeaf simply takes the vertical space that it would occupy and allocates it to the next node higher up the tree. If uniform spacing is important (for example, to keep the region names at the same level), use an empty text vector and an appropriate depth value for the column title of a non-existent node:
salesTitles('North' ''),(2districts), ('South' 'East'),12districts
salesTitlessalesTitles,('West'),3districts
leaf.Init ª leaf.Use''
leaf.table.Titles salesTitles
leaf.table.TDepth 0 1 2 2 0 1 2 1 2 2 0
leaf.table.List salesQ1
View docleaf.Close
The final modification to the sales report involves re-ordering the column titles, and setting the depth and alignment properties to put the appropriate districts beneath each of the two regions as described at the beginning of this topic:
leaf.Init ª leaf.Use''
leaf.table.Font ('TI,10'),((¯1+¯1½salesQ1)½'HE,10'),'HEB,10'
leaf.table.Qfmt (''),((¯1+¯1½salesQ1)½'CF8.1'),'CF9.1'
leaf.table.Align ('left'),(¯1½salesQ1)½'decimal1'
leaf.table.CellWidths 72×0.9,((¯1+¯1½salesQ1)½0.75),0.8
leaf.table.Gridlines 1,(0.5,(1-¯1½salesQ1)0.5),0
leaf.table.Spacing 1 1
leaf.table.TFont 'TI,10'
leaf.table.Titles ('' 'North'),(2districts),('South'),2districts
leaf.table.TDepth 0 0 1 1 0 1 1 1 0
leaf.table.TAlign ('centre' 'right')[1+ 0 0 1 1 0 1 1 1 0]
leaf.table.List ¯1[1]products,salesQ1
leaf.table.Rule 0.5
leaf.table.Spacing 3 3
leaf.table.List ¯1[1]products,salesQ1
View docleaf.Close