<commit_before><!DOCTYPE html>
<html>
  <head>
    <title>Clustered Network</title>
    <script type="text/javascript" src="../../d3.js"></script>
    <script type="text/javascript" src="../../d3.geom.min.js"></script>
    <script type="text/javascript" src="force.js"></script>
    <style type="text/css">
svg {
  border: 1px solid #ccc;
}
body {
  font: 10px sans-serif;
}
circle.node {
  fill: lightsteelblue;
}
circle.leaf {
  fill: white;
  stroke: black;
}
path.hull {
  fill: lightsteelblue;
  opacity: 0.3;
}
line.link {
  stroke: #333;
  opacity: 0.5;
}
    </style>
  </head>
  <body>
    <script type="text/javascript">
var w = 960,     // svg width
    h = 600,     // svg height
    dr = 4,      // default point radius
    off = 15,    // cluster hull offset
    expand = {}, // expanded clusters
    data, net, force, hullg, hull, linkg, link, nodeg, node,
    curve = d3.svg.line().interpolate("cardinal-closed").tension(.85);

function noop() { return false; }

function nodeid(n) {
  return n.size ? "_g_"+n.group : n.name;
}

function linkid(l) {
  var u = nodeid(l.source),
      v = nodeid(l.target);
  return u<v ? u+"|"+v : v+"|"+u;
}

var nodeKeys = {
  nodeKey: function(n) { return n.getAttribute("id"); },
  dataKey: nodeid
}

var linkKeys = {
  nodeKey: function(n) { return n.getAttribute("id"); },
  dataKey: linkid
}

function getGroup(n) { return n.group; }

// constructs the network to visualize
function network(data, prev, index, expand) {
  expand = expand || {};
  var gm = {},    // group map
      nm = {},    // node map
      lm = {},    // link map
      gn = {},    // previous group nodes
      gc = {},    // previous group centroids
      nodes = [], // output nodes
      links = []; // output links

  // process previous nodes for reuse or centroid calculation
  if (prev) {
    prev.nodes.forEach(function(n) {
      var i = index(n), o;
      if (n.size > 0) {
        gn[i] = n;
        n.size = 0;
      } else {
        o = gc[i] || (gc[i] = {x:0,y:0,count:0});
        o.x += n.x;
        o.y += n.y;
        o.count += 1;
      }
    });
  }

  // determine nodes
  for (var k=0; k<data.nodes.length; ++k) {
    var n = data.nodes[k],
        i = index(n);

    if (expand[i]) {
      // the node should be directly visible
      nm[n.name] = nodes.length;
      nodes.push(n);
      if (gn[i]) {
        // place new nodes at cluster location (plus jitter)
        n.x = gn[i].x + Math.random();
        n.y = gn[i].y + Math.random();
      }
    } else {
      // the node is part of a collapsed cluster
      var l = gm[i] || (gm[i]=gn[i]) || (gm[i]={group:i, size:0, nodes:[]});
      if (l.size == 0) {
        // if new cluster, add to set and position at centroid of leaf nodes
        nm[i] = nodes.length;
        nodes.push(l);
        if (gc[i]) {
          l.x = gc[i].x / gc[i].count;
          l.y = gc[i].y / gc[i].count;
        }
      }
      l.size += 1;
      l.nodes.push(n);
    }
  }

  // determine links
  for (k=0; k<data.links.length; ++k) {
    var e = data.links[k],
        u = index(e.source),
        v = index(e.target);
    u = expand[u] ? nm[e.source.name] : nm[u];
    v = expand[v] ? nm[e.target.name] : nm[v];
    var i = (u<v ? u+"|"+v : v+"|"+u),
        l = lm[i] || (lm[i] = {source:u, target:v, size:0});
    l.size += 1;
  }
  for (i in lm) { links.push(lm[i]); }

  return {nodes: nodes, links: links};
}

function convexHulls(nodes, index, offset) {
  var h = {};

  // create point sets
  for (var k=0; k<nodes.length; ++k) {
    var n = nodes[k];
    if (n.size) continue;
    var i = index(n),
        l = h[i] || (h[i] = []);
    l.push([n.x-offset, n.y-offset]);
    l.push([n.x-offset, n.y+offset]);
    l.push([n.x+offset, n.y-offset]);
    l.push([n.x+offset, n.y+offset]);
  }

  // create convex hulls
  var hulls = [];
  for (i in h) {
    var p = d3.geom.hull(h[i]);
    p.push(p[0]); // close the loop
    hulls.push({group: i, path: p});
  }

  return hulls;
}

function drawCluster(d) {
  return curve(d.path); // 0.8
}

function drag(n) {
  var active = null;
  n.on("mouseover", function(d) { if (d != active) d.fixed = true; })
   .on("mouseout", function(d) { if (d != active) d.fixed = false; })
   .on("mousedown", function(d) {
    if (typeof event !== 'undefined' && event.preventDefault) { event.preventDefault(); }
    active = d;

    // unregister drag listeners
    body.on("mouseup", function(d) {
      active = null;
      body.on("mouseup", noop)<commit_msg>Use `d3.event` to reference current event.<commit_after><!DOCTYPE html>
<html>
  <head>
    <title>Clustered Network</title>
    <script type="text/javascript" src="../../d3.js"></script>
    <script type="text/javascript" src="../../d3.geom.min.js"></script>
    <script type="text/javascript" src="force.js"></script>
    <style type="text/css">
svg {
  border: 1px solid #ccc;
}
body {
  font: 10px sans-serif;
}
circle.node {
  fill: lightsteelblue;
}
circle.leaf {
  fill: white;
  stroke: black;
}
path.hull {
  fill: lightsteelblue;
  opacity: 0.3;
}
line.link {
  stroke: #333;
  opacity: 0.5;
}
    </style>
  </head>
  <body>
    <script type="text/javascript">
var w = 960,     // svg width
    h = 600,     // svg height
    dr = 4,      // default point radius
    off = 15,    // cluster hull offset
    expand = {}, // expanded clusters
    data, net, force, hullg, hull, linkg, link, nodeg, node,
    curve = d3.svg.line().interpolate("cardinal-closed").tension(.85);

function noop() { return false; }

function nodeid(n) {
  return n.size ? "_g_"+n.group : n.name;
}

function linkid(l) {
  var u = nodeid(l.source),
      v = nodeid(l.target);
  return u<v ? u+"|"+v : v+"|"+u;
}

var nodeKeys = {
  nodeKey: function(n) { return n.getAttribute("id"); },
  dataKey: nodeid
}

var linkKeys = {
  nodeKey: function(n) { return n.getAttribute("id"); },
  dataKey: linkid
}

function getGroup(n) { return n.group; }

// constructs the network to visualize
function network(data, prev, index, expand) {
  expand = expand || {};
  var gm = {},    // group map
      nm = {},    // node map
      lm = {},    // link map
      gn = {},    // previous group nodes
      gc = {},    // previous group centroids
      nodes = [], // output nodes
      links = []; // output links

  // process previous nodes for reuse or centroid calculation
  if (prev) {
    prev.nodes.forEach(function(n) {
      var i = index(n), o;
      if (n.size > 0) {
        gn[i] = n;
        n.size = 0;
      } else {
        o = gc[i] || (gc[i] = {x:0,y:0,count:0});
        o.x += n.x;
        o.y += n.y;
        o.count += 1;
      }
    });
  }

  // determine nodes
  for (var k=0; k<data.nodes.length; ++k) {
    var n = data.nodes[k],
        i = index(n);

    if (expand[i]) {
      // the node should be directly visible
      nm[n.name] = nodes.length;
      nodes.push(n);
      if (gn[i]) {
        // place new nodes at cluster location (plus jitter)
        n.x = gn[i].x + Math.random();
        n.y = gn[i].y + Math.random();
      }
    } else {
      // the node is part of a collapsed cluster
      var l = gm[i] || (gm[i]=gn[i]) || (gm[i]={group:i, size:0, nodes:[]});
      if (l.size == 0) {
        // if new cluster, add to set and position at centroid of leaf nodes
        nm[i] = nodes.length;
        nodes.push(l);
        if (gc[i]) {
          l.x = gc[i].x / gc[i].count;
          l.y = gc[i].y / gc[i].count;
        }
      }
      l.size += 1;
      l.nodes.push(n);
    }
  }

  // determine links
  for (k=0; k<data.links.length; ++k) {
    var e = data.links[k],
        u = index(e.source),
        v = index(e.target);
    u = expand[u] ? nm[e.source.name] : nm[u];
    v = expand[v] ? nm[e.target.name] : nm[v];
    var i = (u<v ? u+"|"+v : v+"|"+u),
        l = lm[i] || (lm[i] = {source:u, target:v, size:0});
    l.size += 1;
  }
  for (i in lm) { links.push(lm[i]); }

  return {nodes: nodes, links: links};
}

function convexHulls(nodes, index, offset) {
  var h = {};

  // create point sets
  for (var k=0; k<nodes.length; ++k) {
    var n = nodes[k];
    if (n.size) continue;
    var i = index(n),
        l = h[i] || (h[i] = []);
    l.push([n.x-offset, n.y-offset]);
    l.push([n.x-offset, n.y+offset]);
    l.push([n.x+offset, n.y-offset]);
    l.push([n.x+offset, n.y+offset]);
  }

  // create convex hulls
  var hulls = [];
  for (i in h) {
    var p = d3.geom.hull(h[i]);
    p.push(p[0]); // close the loop
    hulls.push({group: i, path: p});
  }

  return hulls;
}

function drawCluster(d) {
  return curve(d.path); // 0.8
}

function drag(n) {
  var active = null;
  n.on("mouseover", function(d) { if (d != active) d.fixed = true; })
   .on("mouseout", function(d) { if (d != active) d.fixed = false; })
   .on("mousedown", function(d) {
    if (d3.event.preventDefault) { d3.event.preventDefault(); }
    active = d;

    // unregister drag listeners
    body.on("mouseup", function(d) {
      active = null;
      body.on("mouseup", noop)
{'fraction_non_alphanumeric': 0.1934586717098676, 'fraction_numerical': 0.009678495939481589, 'mean_word_length': 2.2049910873440286, 'pattern_counts': {'":': 0, '<': 45, '<?xml version=': 0, '>': 37, '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': '2822297', 'n_tokens_mistral': 3522, 'n_tokens_neox': 3402, 'n_words': 841}