 
   node
 
-rgbToHex = (red, green, blue) ->
-  '#' + ((1 << 24) + (red << 16) + (green << 8) + blue).toString(16).substr(1)
-
-randomizeColor = (rgb) ->
-    # generates a random integer between -FLAME_DIFF / 2 and FLAME_DIFF / 2
-    offset = (color) ->
-      color + Math.round((Math.random() * constants.FLAME_DIFFERENTIAL) - (constants.FLAME_DIFFERENTIAL * 0.5))
-
-    "rgb(#{offset(rgb[0])}, #{offset(rgb[1])}, #{offset(rgb[2])})"
-
-maxY = 0
 maxDepth = (node) ->
   return 0 if not node
   return 1 if not node.children

            @["_#{accessor}"] = newValue
            return @

  return new FlameGraph('#d3-flame-graph').width(1200).height(600)

d3.json "data/profile-large.json", (err, data) ->
  window.flameGraph = d3.flameGraph()
  flameGraph.data(convert(data.profile))
    .render()
    .interactivity()

  node.children.forEach (child) ->
    depth = maxDepth(child)
    max = depth if depth > max

  return max + 1


getLastTwoTokens = (str) ->
  tokens = str.split(".")
  tokens.slice(tokens.length - 2).join(".")

d3.flameGraph = ->

  class FlameGraph
    constructor: () ->
      @_generateAccessors([
        'width',
        'height',
        'cellHeight',
        'containerId',
        'colorScheme'])
      @_allData = []

    data: (data) ->
      return @_data if not data
      @_allData.push(data)

      @_data = d3.layout.partition()
        .sort((a,b) -> a.name.localeCompare(b.name))
        .nodes(data)
      @

    breadcrumbs: () ->
      breadcrumbData = @_allData.map((prevData, idx) -> { name: prevData.name, value: idx })
      breadcrumbs = d3.select('.breadcrumb')
        .selectAll('li')
        .data(breadcrumbData)
