<commit_before>width = 960
height = 500

color = d3.scale.category20()

svg = d3.select('body').append('svg')
    .attr('width', width)
    .attr('height', height)

tree = [
    {name: "A", children: [
        {name: "A1", transitions: [{target: "A2"}]},
        {name: "A2", transitions: [{target: "A3"}]},
        {name: "A3", transitions: [{target: "A1"}]},
    ], transitions: [{target: "B"}]},
    {name: "B", children: [
        {name: "B1", transitions: [{target: "B2"}]},
        {name: "B2", transitions: [{target: "B3"}]},
        {name: "B3", transitions: [{target: "B1"}]},
    ], transitions: [{target: "C"}]},
    {name: "C", children: [
        {name: "C1", transitions: [{target: "C2"}]},
        {name: "C2", transitions: [{target: "C3"}]},
        {name: "C3", transitions: [{target: "C1"}]},
    ], transitions: [{target: "A"}]},
]


layout = (g, stateList) ->
    nodes = []
    links = []
    stateMap = {}

    for state in stateList
        state._idx = nodes.length
        stateMap[state.name] = state
        nodes.push({name: state.name})

    for state in stateList
        for tr in state.transitions
            target = stateMap[tr.target]
            links.push({source: state._idx, target: target._idx})

    force = d3.layout.force()
        .charge(-120)
        .linkDistance(30)
        .size([width, height])

    force
        .nodes(nodes)
        .links(links)
        .start()

    link = g.selectAll('.link')
        .data(links)
      .enter().append('line')
        .attr('class', 'link')
        .style('stroke-width', (d) -> Math.sqrt(d.value))

    node = g.selectAll('.node')
        .data(nodes)
      .enter().append('circle')
        .attr('class', 'node')
        .attr('r', 5)
        .style('fill', (d) -> color(d.group))
        .call(force.drag)

    node.append('title')
        .text((d) -> d.name)

    force.on 'tick', ->
      link.attr('x1', (d) -> d.source.x)
          .attr('y1', (d) -> d.source.y)
          .attr('x2', (d) -> d.target.x)
          .attr('y2', (d) -> d.target.y)

      node.attr('cx', (d) -> d.x)
          .attr('cy', (d) -> d.y)<commit_msg>nodes are 'g' elements<commit_after>width = 960
height = 500

color = d3.scale.category20()

svg = d3.select('body').append('svg')
    .attr('width', width)
    .attr('height', height)

tree = [
    {name: "A", children: [
        {name: "A1", transitions: [{target: "A2"}]},
        {name: "A2", transitions: [{target: "A3"}]},
        {name: "A3", transitions: [{target: "A1"}]},
    ], transitions: [{target: "B"}]},
    {name: "B", children: [
        {name: "B1", transitions: [{target: "B2"}]},
        {name: "B2", transitions: [{target: "B3"}]},
        {name: "B3", transitions: [{target: "B1"}]},
    ], transitions: [{target: "C"}]},
    {name: "C", children: [
        {name: "C1", transitions: [{target: "C2"}]},
        {name: "C2", transitions: [{target: "C3"}]},
        {name: "C3", transitions: [{target: "C1"}]},
    ], transitions: [{target: "A"}]},
]


layout = (g, stateList) ->
    nodes = []
    links = []
    stateMap = {}

    for state in stateList
        state._idx = nodes.length
        stateMap[state.name] = state
        nodes.push({name: state.name})

    for state in stateList
        for tr in state.transitions
            target = stateMap[tr.target]
            links.push({source: state._idx, target: target._idx})

    force = d3.layout.force()
        .charge(-120)
        .linkDistance(30)
        .size([width, height])

    force
        .nodes(nodes)
        .links(links)
        .start()

    link = g.selectAll('.link')
        .data(links)
      .enter().append('line')
        .attr('class', 'link')
        .style('stroke-width', (d) -> Math.sqrt(d.value))

    node = g.selectAll('.node')
        .data(nodes)
      .enter().append('g')
        .attr('class', 'node')

    node.append('circle')
        .attr('r', 5)
        .style('fill', (d) -> color(d.group))
        .append('title')
          .text((d) -> d.name)

    force.on 'tick', ->
      link.attr('x1', (d) -> d.source.x)
          .attr('y1', (d) -> d.source.y)
          .attr('x2', (d) -> d.target.x)
          .attr('y2', (d) -> d.target.y)

      node.attr('transform', (d) -> "translate(#{d.x},#{d.y})")
          .attr('cy', (d) -> d.y)
{'fraction_non_alphanumeric': 0.22634032634032633, 'fraction_numerical': 0.01818181818181818, 'mean_word_length': 2.1644542772861355, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 25, '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': '292164', 'n_tokens_mistral': 1556, 'n_tokens_neox': 1515, 'n_words': 322}