<commit_before>//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
// function that will wrap and resize SVG text
//-------------------------------------------------------------------

d3plus.utils.wordwrap = function(params) {
  
  var parent = params.parent,
      width = params.width ? params.width : 20000,
      height = params.height ? params.height : 20000,
      resize = params.resize,
      font_max = params.font_max ? params.font_max : 40,
      font_min = params.font_min ? params.font_min : 9,
      text_array = params.text.slice(0),
      split = ["-","/",";",":","%","&"],
      regex = new RegExp("[^\\s\\"+split.join("\\")+"]+\\"+split.join("?\\")+"?","g")
      
  if (text_array instanceof Array) wrap(String(text_array.shift()).match(regex))
  else wrap(String(text_array).match(regex))
  
  function wrap(words) {
    
    if (resize) {
      
      // Start by trying the largest font size
      var size = font_max
      size = Math.floor(size)
      d3.select(parent).attr("font-size",size)
    
      // Add each word to it's own line (to test for longest word)
      d3.select(parent).selectAll("tspan").remove()
      for(var i=0; i<words.length; i++) {
        if (words.length == 1) var t = words[i]
        else var t = words[i]+"..."
        d3.select(parent).append("tspan").attr("x",0).text(t)
      }
    
      // If the longest word is too wide, make the text proportionately smaller
      if (parent.getBBox().width > width) size = size*(width/parent.getBBox().width)
      
      // If the new size is too small, return NOTHING
      if (size < font_min) {
        d3.select(parent).selectAll("tspan").remove();
        if (typeof text_array == "string" || text_array.length == 0) return;
        else wrap(String(text_array.shift()).match(regex))
        return;
      }

      // Use new text size
      size = Math.floor(size)
      d3.select(parent).attr("font-size",size);
    
      // Flow text into box
      flow();
      
      // If text doesn't fit height-wise, shrink it!
      if (parent.childNodes.length*parent.getBBox().height > height) {
        var temp_size = size*(height/(parent.childNodes.length*parent.getBBox().height))
        if (temp_size < font_min) size = font_min
        else size = temp_size
        size = Math.floor(size)
        d3.select(parent).attr("font-size",size)
      } else finish();
    
    }
  
    flow();
    truncate();
    finish();
  
    function flow() {
    
      d3.select(parent).selectAll("tspan").remove()
      
      var x_pos = parent.getAttribute("x")
      
      var tspan = d3.select(parent).append("tspan")
        .attr("x",x_pos)
        .text(words[0])

      for (var i=1; i < words.length; i++) {
        
        var current = tspan.text(),
            last_char = current.slice(-1),
            joiner = split.indexOf(last_char) >= 0 ? "" : " "
        
        tspan.text(current+joiner+words[i])
      
        if (tspan.node().getComputedTextLength() > width) {<commit_msg>fixed space not appearing after colon when wrapping text<commit_after>//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
// function that will wrap and resize SVG text
//-------------------------------------------------------------------

d3plus.utils.wordwrap = function(params) {
  
  var parent = params.parent,
      width = params.width ? params.width : 20000,
      height = params.height ? params.height : 20000,
      resize = params.resize,
      font_max = params.font_max ? params.font_max : 40,
      font_min = params.font_min ? params.font_min : 9,
      text_array = params.text.slice(0),
      split = ["-","/",";",":","%","&"],
      regex = new RegExp("[^\\s\\"+split.join("\\")+"]+\\"+split.join("?\\")+"?","g"),
      current_text = ""
      
  if (text_array instanceof Array) {
    current_text = String(text_array.shift())
  }
  else {
    current_text = String(text_array)
  }
  
  wrap()
  
  function wrap() {
    
    var words = current_text.match(regex)
    
    if (resize) {
      
      // Start by trying the largest font size
      var size = font_max
      size = Math.floor(size)
      d3.select(parent).attr("font-size",size)
    
      // Add each word to it's own line (to test for longest word)
      d3.select(parent).selectAll("tspan").remove()
      for(var i=0; i<words.length; i++) {
        if (words.length == 1) var t = words[i]
        else var t = words[i]+"..."
        d3.select(parent).append("tspan").attr("x",0).text(t)
      }
    
      // If the longest word is too wide, make the text proportionately smaller
      if (parent.getBBox().width > width) size = size*(width/parent.getBBox().width)
      
      // If the new size is too small, return NOTHING
      if (size < font_min) {
        d3.select(parent).selectAll("tspan").remove();
        if (typeof text_array == "string" || text_array.length == 0) return;
        else {
          current_text = String(text_array.shift())
          wrap()
        }
        return;
      }

      // Use new text size
      size = Math.floor(size)
      d3.select(parent).attr("font-size",size);
    
      // Flow text into box
      flow();
      
      // If text doesn't fit height-wise, shrink it!
      if (parent.childNodes.length*parent.getBBox().height > height) {
        var temp_size = size*(height/(parent.childNodes.length*parent.getBBox().height))
        if (temp_size < font_min) size = font_min
        else size = temp_size
        size = Math.floor(size)
        d3.select(parent).attr("font-size",size)
      } else finish();
    
    }
  
    flow();
    truncate();
    finish();
  
    function flow() {
    
      d3.select(parent).selectAll("tspan").remove()
      
      var x_pos = parent.getAttribute("x")
      
      var tspan = d3.select(parent).append("tspan")
        .attr("x",x_pos)
        .text(words[0])

      for (var i=1; i < words.length; i++) {
        
        var current = tspan.text(),
            last_char = current.slice(-1),
            next_char = current_text.charAt(current_text.indexOf(current)+current.length)
            joiner = next_char == " " ? " " : ""
            
        tspan.text(current+joiner+words[i])
      
        if (tspan.node().getComputedTextLength() > width) {
{'fraction_non_alphanumeric': 0.19196428571428573, 'fraction_numerical': 0.00972576530612245, 'mean_word_length': 2.1146971201588878, 'pattern_counts': {'":': 2, '<': 11, '<?xml version=': 0, '>': 10, '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': '7352989', 'n_tokens_mistral': 2000, 'n_tokens_neox': 1961, 'n_words': 418}