 class Node
   render: (ctx) ->
     ctx.save()
+    ctx.translate(@x, @y)
     setStyle(ctx, node_style)
     ctx.beginPath()
     ctx.arc(0,0,@radius,0,Math.PI*2)

      i += 1

  render: (ctx) ->
    for n in @nodes
      ctx.save()
      ctx.translate(n.x, n.y)
      n.render(ctx)
      ctx.restore()


      ctx.fillText(@label,0,2*@radius)

    ctx.fillText(@value, 0, 0)
    ctx.restore()

class Inner extends Node
  constructor: (@value, @child0, @child1) ->

  render: (ctx) ->
    ctx.save()
    setStyle(ctx, link_style)
    ctx.moveTo(@x, @y)
    ctx.lineTo(@child0.x, @child0.y)
    ctx.moveTo(@x, @y)
    ctx.lineTo(@child1.x, @child0.y)
    ctx.stroke()
    ctx.restore()

    super ctx

    ctx.save()
    ctx.translate(@x, @y)
    setStyle(ctx, node_text_style)
    ctx.textAlign = 'center'
    ctx.textBaseline = 'middle'

    ctx.fillText(@value, 0, 0)
    ctx.restore()
 
    @child0.render(ctx)
    @child1.render(ctx)

  forAll: (fn) ->
    if @child0.forAll?
      @child0.forAll(fn)
    else
      fn(@child0)

    if @child1.forAll?
      child1.forAll(fn)
    else
      fn(@child1)

    fn(this)

class NodeCollection
  constructor: () ->
