       child2 = decisionPoint.children[1]
       return (right - left) * child1.width / (child1.width + child2.width) + left
 
-  # Calculate the length of the 'chain' of nodes with one child,
-  # because they all share the root's x coordinate
-  calculateChainCount : (tree) ->
-
-    chainCount = 0
-    subTree = tree
-    while subTree.children.length == 1
-      subTree = subTree.children[0]
-      chainCount++
-
-    return chainCount
 
   # Calculate the top of the children
   calculateChildTreeTop : (mode, chainCount, top) ->

    @recordWidths(root)
    @drawTreeWithWidths(root, @NODE_RADIUS, @canvas.width() - @NODE_RADIUS, @nodeDistance, mode)

  drawTreeWithWidths : (tree, left, right, top, mode) ->

    # get the decision point
    decisionPoint = @getNextDecisionPoint(tree)

    # TODO: algorithm expects all decision points to be branch points
    # though a normal point with comment only has one child --> refactor this

    middle = @calculateTreeMiddle(decisionPoint, left, right)
    chainCount = @calculateChainCount(tree)
    rootX = middle # if decisionPoint is leaf, there's not much to do

    # if the decision point has 2 children, draw them and remember their position
    if decisionPoint.children.length > 1

      topChildren = @calculateChildTreeTop(mode, chainCount, top)
      c1 = @drawTreeWithWidths(decisionPoint.children[0], left,  middle, topChildren, mode)
      c2 = @drawTreeWithWidths(decisionPoint.children[1], middle, right, topChildren, mode)

      # set the root's x coordinate to be in between the decisionPoint's children
      rootX = (c1.rootX + c2.rootX) / 2

      # draw edges from last node in 'chain' (or root, if chain empty)
      # and the decisionPoint's children
      @drawEdge(rootX, topChildren - @nodeDistance, c1.rootX, c1.top)
      @drawEdge(rootX, topChildren - @nodeDistance, c2.rootX, c2.top)

    if mode == @MODE_NORMAL or chainCount < 3
      # Draw the chain and the root, connect them.
      node = tree
      for i in [0..chainCount]
        @drawNode(rootX, top + i * @nodeDistance, node.id)
        node = node.children[0]
        if i != 0

    # Because any node with children.length == 1 has
    # the same width as its child, we can skip those.

    decision = @getNextDecision(tree)

    # Leaves just have a width of one
    if decision.isLeaf
      decision.node.width = 1
      return 1

    decisionPoint = decision.node

    # edge case: system is made for binary trees only
    # allow a maximum of two
    if decision.node.children.length > 2
      decision.node.children = decision.node.children[0...2]

    # Branchpoints are as wide as its children combined.
    # But actually, we need the width of the children
    width = 0
    for child in decision.node.children
      child.width = @recordWidths(child)
      width += child.width

    return width


  getMaxTreeDepth : (tree, mode = @MODE_NORMAL, count = 0) ->
