Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I suggest drawing the tree linewise. You do this by using some kind of moving "drawing cursor".</p> <p>You could store an attribute <code>width</code> for each node which is calculated as follows:</p> <ul> <li>the <code>width</code> of a leave is 1</li> <li>the <code>width</code> of an inner node is the sum of all childrens' <code>width</code>s</li> </ul> <p>Then, you draw the root "in the first line" in the middle, which means, you just take root's <code>width</code>'s half.</p> <p>Then, you generate a grid over the image such that each gridline corresponds to one line resp. one step from left to right and each intersection of grid lines can contain a node and each node has enough space.</p> <p>Then, you iterate through the childs and while iterating, you accumulate the children's <code>width</code>s and draw the children "in the next line". To draw <code>currentChild</code>, you move your drawing cursor <code>currentWidth/2</code> to the right, draw <code>currentChild</code>, and move the drawing cursor the remaining <code>currentWidth/2</code> to the right.</p> <p>In order to get the nodes in a good order, you might consider a breadth first search.</p> <p>I hope my explanation is clear, but I think it will be better, if I draw a little picture.</p> <p>This is our tree (<code>x</code> are nodes, everything else edges)</p> <pre><code> +-------x--+-------+ | | | +-x-+ +-+x+-+ +-x-+ | | | | | | | | | x x x x x x x x x </code></pre> <p>So, you calculate the leaf's <code>width</code>s:</p> <pre><code> +-------x--+-------+ | | | +-x-+ +-+x+-+ +-x-+ | | | | | | | | | 1 1 1 1 1 1 1 1 1 </code></pre> <p>Then, bottom up, the <code>width</code>s as sums of childrens' <code>width</code>s:</p> <pre><code> +-------9--+-------+ | | | +-2-+ +-+4+-+ +-3-+ | | | | | | | | | 1 1 1 1 1 1 1 1 1 </code></pre> <p>So, you start at the root (<code>width</code> 9) and go 4.5 steps to the rigt in the first line.</p> <p>Then, you move your "drawing cursor" to the second line, "column 0" (go to left).</p> <p>The first child has <code>width</code> 2, so we go <code>2/2=1</code> grid lines to the right and draw the node and move the drawing cursor the remaining 1 grid lines to the right in order to finish the node. So, the next node has <code>width</code> 4, which means, that we go right 4/2=2 grid lines, draw, go the remaining 2 steps, and so on.</p> <p>And so on with the next line. At the end (or in intermediate steps), connect the nodes.</p> <p>This procedure ensures that there are no overlapping nodes (if grid lines are far enough from each other), but it might lead to quite large tree diagrams that could use the space more efficiently.</p> <p>In order to detect unused space, one might just scan the lines after the above process and look if there are unused grid line intersections and then possibly realign some nodes in order to fill space.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload