Sha256: a0b77a6a812c696833d6c3e327fd0369e732870820315276802d70b4d6298c2e

Contents?: true

Size: 1.33 KB

Versions: 8

Compression:

Stored size: 1.33 KB

Contents

Visualisation.convertDiffStatsToTree = (data) ->
  lines = data.split("\n")
  json = {}
  filename = undefined
  size = undefined
  cols = undefined
  elements = undefined
  current = undefined
  lines.forEach (line) ->
    cols = line.split(/\s/)
    add = parseInt(cols[0])
    del = parseInt(cols[1])
    return if !add && !del
    filename = cols[2]
    return if filename is "total"
    return unless filename
    elements = filename.split(/[\/\\]/)
    current = json
    elements.forEach (element) ->
      current[element] = {}  unless current[element]
      current = current[element]

    current.add = add
    current.del = del

  json.children = getChildren(json)
  json

getChildren = (json) ->
  children = []
  return children  if json.language
  for key of json
    child = name: key
    if json[key].add || json[key].del
      
      # value node
      child.add = json[key].add
      child.del = json[key].del
      child.language = json[key].language
    else
      
      # children node
      childChildren = getChildren(json[key])
      child.children = childChildren  if childChildren
    children.push child
    delete json[key]
  children

# Recursively count all elements in a tree
countElements = (node) ->
  nbElements = 1
  if node.children
    nbElements += node.children.reduce((p, v) ->
      p + countElements(v)
    , 0)
  nbElements

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
git-visualiser-0.0.11 lib/application/public/javascripts/data_convert.coffee
git-visualiser-0.0.7 lib/application/javascripts/data_convert.coffee
git-visualiser-0.0.6 lib/application/javascripts/data_convert.coffee
git-visualiser-0.0.5 lib/application/javascripts/data_convert.coffee
git-visualiser-0.0.4 lib/application/javascripts/data_convert.coffee
git-visualiser-0.0.3 lib/application/javascripts/data_convert.coffee
git-visualiser-0.0.2 lib/application/javascripts/data_convert.coffee
git-visualiser-0.0.1 lib/application/javascripts/data_convert.coffee