-layout = (g, state) ->
+drawState = (g, state) ->
+    size = 100
+
+    if state.children?
+        size += drawChildren(g, state.children)
+
+    return size
+
+
+drawChildren = (g, children) ->
     childNodes = []
     childLinks = []
     stateMap = {}
 
-    for child in state.children or []
+    for child in children
         child._idx = childNodes.length
         stateMap[child.name] = child
         childNodes.push({name: child.name})
 
-    for child in state.children or []
+    for child in children
         for tr in child.transitions or []
             target = stateMap[tr.target]
             childLinks.push({source: child._idx, target: target._idx})

      .enter().append('g')
        .attr('class', 'cell')

    size = 1000
    for child in state.children or []
        if child.children?
            size += layout(cell, child) * 5

    r = Math.sqrt(size)


      .append('g')
        .attr('transform', "translate(#{width/2}, #{height/2})")

    drawChildren(svg, tree)


demo([
