 NODE_RADIUS = 2
 MAX_NODE_DISTANCE = 100
 CLICK_TRESHOLD = 4
+
+MODE_NORMAL = 0     # draw every node and the complete tree
+MODE_NOCHAIN = 1    # draw only decision points
 
 class AbsractTreeViewer
   constructor : (width, height) ->


    # if the decision point has (2) children, draw them and remember their prosition
    if decisionPoint.children.length > 0
      c1 = @drawTreeWithWidths(decisionPoint.children[0], left,  m, top + (chainCount + 1) * @nodeDistance)
      c2 = @drawTreeWithWidths(decisionPoint.children[1], m, right, top + (chainCount + 1) * @nodeDistance)
      # set the root's x coordinate to be in between the decisionPoint's childs
      xr = (c1[0] + c2[0]) / 2
      # draw edges from last node in 'chain' (or root, if chain empty)
      # and the decisionPoint's children
      @drawEdge(xr, top + chainCount * @nodeDistance, c1[0], c1[1])
      @drawEdge(xr, top + chainCount * @nodeDistance, c2[0], c2[1])
    else
      # if decisionPoint is leaf, there's not much to do
      xr = m
    
    # Draw the chain and the root, connect them.
    node = tree
    for i in [0..chainCount]
      @drawNode(xr, top + i * @nodeDistance, node.id)
      node = node.children[0]
      if i != 0
        @drawEdge(xr, top + (i - 1) * @nodeDistance, xr, top + i * @nodeDistance)

    return [xr, top]


      result += child.width
    return result

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

    # One decision point
    count++

    # Count non decision points
    chainCount = 0
    while tree.children.length == 1
      tree = tree.children[0]
      chainCount++
    if mode == MODE_NOCHAIN
      chainCount = Math.min(chainCount, 2)
    count += chainCount

    if tree.children.length == 0
      return count
    return Math.max(@getMaxTreeDepth(tree.children[0], mode, count),
              @getMaxTreeDepth(tree.children[1], mode, count))

  onClick : (evt) =>
    id = @getIdFromPos(evt.offsetX, evt.offsetY)
