       for child in neuron.children
         @setChildren(child)
 
-  showDetails: (node) ->
+  hideChildren: (node) ->
+    node.hidden = true
+    return unless node.children
+    node._children = node.children
+    node.children = null
+    for child in node._children
+      @hideChildren(child)
+    null
+
+  showChildren: (node) ->
+    node.hidden = false
+    return unless node._children
+    node.children = node._children
+    node._children = null
+    for child in node.children
+      @showChildren(child)
+    null
+
+  filterShownNeurons: ->
+    @shownNeurons = @neurons.filter (neuron) ->
+      !neuron.hidden
+
+  toggleNode: (node) ->
+    if node.children
+      @hideChildren(node)
+      node.hidden = false
+    else
+      @showChildren(node)
+    @filterShownNeurons()
+
+    d3.select(@selector).html("")
+    @createD3Elements()
+    @drawSVG()
+    @drawLinks()
+    @drawNeurons()
+    @drawWithoutParent()
+
+  showDetails: (node, text) ->
     $popover = $(".popover")
     # format:
     $popover.find(".popover-title").html(node.title)

    @setChildren(@rootNeuron)

    @neurons = @tree.nodes(@rootNeuron)

    @drawLinks()
    @drawNeurons()

                  )
    neuron.append("circle")
          .attr("r", 4.5)
          .style("fill", (d) ->
            if d._children then "lightsteelblue" else "#fff"
          ).on "click", (node) =>
            @toggleNode(node)

    neuron.append('text')
          .attr('dx', -8)
