         return entry.id
 
 
-  nodeIdHasComment : (id) ->
-
-    return @RENDER_COMMENTS and @comments.hasCommentWithNodeId(id)
-
-
+  clearBackground : ->
+
+    @ctx.clearRect(0, 0, @canvas.width(), @canvas.height())
+
+
+  setupColors : ->
+
+    # apply color scheme
+    if app.oxalis.view.theme == Constants.THEME_BRIGHT
+      @vgColor = "black"
+      @commentColor = "red"
+    else
+      @vgColor = "white"
+      @commentColor = "blue"
+
+
+  renderComments : (renderComments) ->
+
+    @RENDER_COMMENTS = renderComments
+
+
+  setDimensions : ({width, height}) ->
+
+    $(@canvas).css({width, height})
+    @canvas[0].width = width
+    @canvas[0].height = height

    @ctx.lineWidth = 1


  drawCommentChain : (decision, left, right, top, mode) ->

    topChild = @calculateTop(decision.chainCount, top, mode)
    extent = @drawTreeWithWidths(decision.node, left, right, topChild, mode)
    return extent.middle


  drawBranch : (decision, left, right, top, mode) ->

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

    # set the root's x coordinate to be in between the decisionPoint's children
    middle = @calculateMiddle(leftTree.middle, rightTree.middle)

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

    return middle


  drawChainFromTo : (top, left, root, decision) ->

    # Draw the chain and the root, connect them.
    node = root
    for i in [0..decision.chainCount]
      @addNode(left, top + i * @nodeDistance, node.id)
      node = node.children[0]
      if i != 0
        @drawEdge(left, top + (i - 1) * @nodeDistance, left, top + i * @nodeDistance)


  drawChainWithChainIndicatorFromTo : (top, middle, tree, decision) ->

    # Draw root, chain indicator and decision point
    @addNode(middle, top, tree.id)
    @drawEdge(middle, top, middle, top + 0.5 * @nodeDistance)
    @drawChainIndicator(middle, top + 0.5 * @nodeDistance, top + 1.5 * @nodeDistance, decision.hasActiveNode)
    @drawEdge(middle, top + 1.5 * @nodeDistance, middle, top + 2 * @nodeDistance)
    @addNode(middle, top + 2 * @nodeDistance, decision.node.id)


  addNode : (x, y, id) ->

    # put it in nodeList
    @nodeList.push({x : x, y : y, id : id})


  drawAllNodes : ->

    for {x, y, id} in @nodeList
      @drawNode(x, y, id)


  getNextDecision : (tree) ->

    # Decision point is any point with point.children.length == 2 (branch point)
    # or leaves
    # or any point that has a comment.
    # Decision points will definitely be drawn.

    chainCount = 0
    hasActiveNode = false

    # skip comment check on first node
    if tree.children.length == 1
        tree = tree.children[0]
        chainCount++

    while tree.children.length == 1 and !@nodeIdHasComment(tree.id)
      if !hasActiveNode
          hasActiveNode = tree.id == @activeNodeId
      tree = tree.children[0]
      chainCount++

    return {
      node: tree,
      chainCount,
      isBranch: tree.children.length > 1
      isLeaf: tree.children.length == 0
      hasActiveNode: hasActiveNode
    }


  recordWidths : (tree) ->

    @width = width
    @height = height
    @nodeList = []


  drawTree : (tree, @activeNodeId, @comments) ->
