       @drawEdge(rootX, top, rootX, top + 0.5 * @nodeDistance)
       @drawChainIndicator(rootX, top + 0.5 * @nodeDistance, top + 1.5 * @nodeDistance, hasActiveNode)
       @drawEdge(rootX, top + 1.5 * @nodeDistance, rootX, top + 2 * @nodeDistance)
-      @drawNode(rootX, top + 2 * @nodeDistance, decisionPoint.id)
+      @drawNode(rootX, top + 2 * @nodeDistance, decision.node.id)
 
     return { rootX, top }
 

    @ctx.lineWidth = 1


  getNextDecisionPoint : (tree) ->

    # Decision point is any point with point.children.length != 1
    while tree.children.length == 1
      tree = tree.children[0]
    return tree


  recordWidths : (tree) ->

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


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

    # get the decision point
    decision = @getNextDecision(tree)
    middle = @calculateTreeMiddle(decision.node, left, right)
    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 decision.isBranch

      topChildren = @calculateChildTreeTop(mode, decision.chainCount, top)
      leftTree = @drawTreeWithWidths(decision.node.children[0], left,  middle, topChildren, mode)
      rightTree = @drawTreeWithWidths(decision.node.children[1], middle, right, topChildren, mode)

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

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

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