<commit_before>// Housekeeping
var vinci = {}

// Get input
vinci.input = function () {
  return document.querySelector("textarea").value
}

document.querySelector("textarea").addEventListener("drop", function (event) {
  event.preventDefault()

  var file = event.dataTransfer.files[0]
    , reader = new FileReader()

  reader.addEventListener("load", function (evt) {
    document.querySelector("textarea").value = evt.target.result
  })

  reader.readAsText(file)
}, false)


// Process data
vinci.output = function (data) {
  try {
    data = JSON.parse(data)
  } catch (e) {
    data = false
  }
  return data
}

// Give output
document.querySelector("button").addEventListener("click", function () {
  var data = vinci.output(vinci.input())

  if (data) {

    var payload = []

    for (var i in data) {
      var tmp = {
        name: i
      }
      delete data[i]
      payload.push(tmp)
    }

    data.name = "Viz"
    data.children = payload

    document.querySelector("pre").innerHTML = JSON.stringify(data, null, "\t")

    var tree = d3.layout.tree().size([300,150])
      , svg = d3.select("#viz").append("svg")
                .attr("width", 640)
                .attr("height", 640)
                .append("g")
                .attr("transform", "translate(40, 0)")

      , diagonal = d3.svg.diagonal()
                    .projection(function(d) { return [d.y, d.x] })

      , nodes = tree.nodes(data)

      , links = tree.links(nodes)

      , link = svg.selectAll("pathlink")
                    .data(links).enter().append("path")
                    .attr("class", "link").attr("d", diagonal)

      , node = svg.selectAll("g.node")
                    .data(nodes).enter().append("g")
                    .attr("transform", function(d) {
                      return "translate(" + d.y + "," + d.x + ")"
                    })

      node.append("circle").attr("r", 3.5)
      node.append("text")
          .attr("dx", function(d) { return d.children ? -8 : 8 })
          .attr("dy", 3)
          .attr("text-anchor", function(d) { return d.children ? "end" : "start" })
          .text(function(d) { return d.name })
  } else {
    document.querySelector("pre").innerHTML = "Input could not be parsed as JSON"
  }
}, false)
<commit_msg>Second level recursion of the Tree layout - Needed change in svg form-factor - Now shows the second level elements, post-processed - JSON stringifier argument altered for better legibility<commit_after>// Housekeeping
var vinci = {}

// Get input
vinci.input = function () {
  return document.querySelector("textarea").value
}

document.querySelector("textarea").addEventListener("drop", function (event) {
  event.preventDefault()

  var file = event.dataTransfer.files[0]
    , reader = new FileReader()

  reader.addEventListener("load", function (evt) {
    document.querySelector("textarea").value = evt.target.result
  })

  reader.readAsText(file)
}, false)


// Process data
vinci.output = function (data) {
  try {
    data = JSON.parse(data)
  } catch (e) {
    data = false
  }
  return data
}

// Give output
document.querySelector("button").addEventListener("click", function () {
  var data = vinci.output(vinci.input())

  if (data) {

    var payload = []

    for (var i in data) {
      var tmp = {
        name: i,
        children: (function () {
          var arr = []
          for (var j in data[i]) {
            arr.push({
              "name": (function () {
                var tmp = data[i][j].split("-")
                tmp.pop()
                return tmp.join("-")
              })()
            })
          }
          return arr
        })()
      }
      delete data[i]
      payload.push(tmp)
    }

    data.name = "Viz"
    data.children = payload

    document.querySelector("pre").innerHTML = JSON.stringify(data, null, "  ")

    var tree = d3.layout.tree().size([2000,250])
      , svg = d3.select("#viz").append("svg")
                .attr("width", 640)
                .attr("height", 2048)
                .append("g")
                .attr("transform", "translate(40, 0)")

      , diagonal = d3.svg.diagonal()
                    .projection(function(d) { return [d.y, d.x] })

      , nodes = tree.nodes(data)

      , links = tree.links(nodes)

      , link = svg.selectAll("pathlink")
                    .data(links).enter().append("path")
                    .attr("class", "link").attr("d", diagonal)

      , node = svg.selectAll("g.node")
                    .data(nodes).enter().append("g")
                    .attr("transform", function(d) {
                      return "translate(" + d.y + "," + d.x + ")"
                    })

      node.append("circle").attr("r", 3.5)
      node.append("text")
          .attr("dx", function(d) { return d.children ? -8 : 8 })
          .attr("dy", 3)
          .attr("text-anchor", function(d) { return d.children ? "end" : "start" })
          .text(function(d) { return d.name })
  } else {
    document.querySelector("pre").innerHTML = "Input could not be parsed as JSON"
  }
}, false)

{'fraction_non_alphanumeric': 0.16488730723606168, 'fraction_numerical': 0.009885330170027679, 'mean_word_length': 2.031156381066507, 'pattern_counts': {'":': 1, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '587633', 'n_tokens_mistral': 1583, 'n_tokens_neox': 1514, 'n_words': 324}