<commit_before>//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
// Dynamic Tooltip
//-------------------------------------------------------------------

vizwhiz.tooltip.dynamic = function(data) {
  
  var width = 200,
      padding = 10,
      triangle_size = 20,
      stroke_width = 2
  
  var group = data.parent.append("g")
  
  var box = group.append("rect")
    .attr("width",width+"px")
    .attr("ry","3")
    .attr("rx","3")
    .attr("fill","white")
    .attr("stroke","#cccccc")
    .attr("stroke-width",stroke_width)
  
  if (data.title) {
    var text = group.append("text")
      .attr("fill","#000000")
      .attr("font-size","16px")
      .style("font-weight","bold")
      .attr("x",padding+"px")
      .attr("y",padding*0.75+"px")
      .attr("text-anchor","start")
      .attr("font-family","Helvetica")
      .each(function(dd){vizwhiz.utils.wordWrap(data.title,this,width-(padding*2),width,false);})
  }
    
  var y_offset = padding + text.node().getBBox().height
  
  for (var d in data.data) {
    if (typeof data.data[d] == "number") var t = d+": "+vizwhiz.utils.format_num(data.data[d])
    else var t = d+": "+data.data[d]
    text = group.append("text")
      .attr("fill","#333333")
      .attr("font-size","12px")
      .style("font-weight","normal")
      .attr("x",padding+"px")
      .attr("y",y_offset+"px")
      .attr("text-anchor","start")
      .attr("font-family","Helvetica")
      .each(function(dd){vizwhiz.utils.wordWrap(t,this,width-(padding*2),width,false);})
    y_offset += text.node().getBBox().height
  }
  
  var box_height = y_offset+padding
  
  if (data.y-data.offset-padding < box_height+triangle_size/2) {
    var tooltip_y = data.y+data.offset+(triangle_size/2),
        triangle_y = 0,
        p = "M "+(-triangle_size/2)+" 0 L 0 "+(-triangle_size/2)+" L "+(triangle_size/2)+" 0";
  } else {
    var tooltip_y = data.y-data.offset-box_height-(triangle_size/2),
        triangle_y = box_height,
        p = "M "+(-triangle_size/2)+" 0 L 0 "+(triangle_size/2)+" L "+(triangle_size/2)+" 0";
  }
  
  if (data.x-data.offset-padding < width/2) var tooltip_x = padding
  else if (data.x+data.offset+padding > data.width-(width/2)) var tooltip_x = data.width-width-padding
  else var tooltip_x = data.x-(width/2)
  
  group.append("line")
    .attr("x1",(data.x-tooltip_x-triangle_size/2+1))
    .attr("x2",(data.x-tooltip_x+triangle_size/2-1))
    .attr("y1",triangle_y)
    .attr("y2",triangle_y)
    .attr("stroke-width",stroke_width*2)
    .attr("stroke","white")
    
  group.append("path")
    .attr("d",p)
    .attr("fill","white")
    .attr("stroke","#cccccc")
    .attr("stroke-width",stroke_width)
    .attr("transform","translate("+(data.x-tooltip_x)+","+triangle_y+")");
  
  group.attr("transform","translate("+tooltip_x+","+tooltip_y+")")
    
  box
    .attr("height",box_height+"px")

}

//===================================================================<commit_msg>created remove function, determined window_width based off of parent svg, and added support to remove the arrow<commit_after>//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
// Create a Tooltip
//-------------------------------------------------------------------

vizwhiz.tooltip.create = function(data) {
  
  var tooltip_width = 200,
      window_width = parseInt(data.svg.attr("width"),10),
      padding = 10,
      triangle_size = 20,
      stroke_width = 2
      
  if (data.arrow) var triangle_size = 20
  else var triangle_size = 0
      
  var group = data.svg.append("g")
    .attr("class","vizwhiz_tooltip")
    
  if (data.id) group.attr("id","vizwhiz_tooltip_"+data.id)
  
  var box = group.append("rect")
    .attr("width",tooltip_width+"px")
    .attr("ry","3")
    .attr("rx","3")
    .attr("fill","white")
    .attr("stroke","#cccccc")
    .attr("stroke-width",stroke_width)
  
  if (data.title) {
    var text = group.append("text")
      .attr("fill","#000000")
      .attr("font-size","16px")
      .style("font-weight","bold")
      .attr("x",padding+"px")
      .attr("y",padding*0.75+"px")
      .attr("text-anchor","start")
      .attr("font-family","Helvetica")
      .each(function(dd){vizwhiz.utils.wordWrap(data.title,this,tooltip_width-(padding*2),tooltip_width,false);})
      var y_offset = padding + text.node().getBBox().height
  } else var y_offset = padding
    
  
  for (var d in data.data) {
    if (typeof data.data[d] == "number") var t = vizwhiz.utils.format_num(data.data[d])
    else var t = data.data[d]
    group.append("text")
      .attr("fill","#333333")
      .attr("font-size","12px")
      .style("font-weight","normal")
      .attr("x",padding+"px")
      .attr("y",y_offset+"px")
      .attr("dy","12px")
      .attr("text-anchor","start")
      .attr("font-family","Helvetica")
      .text(d+":")
    text = group.append("text")
      .attr("fill","#333333")
      .attr("font-size","12px")
      .style("font-weight","normal")
      .attr("x",tooltip_width-padding+"px")
      .attr("y",y_offset+"px")
      .attr("dy","12px")
      .attr("text-anchor","end")
      .attr("font-family","Helvetica")
      .text(t)
    y_offset += text.node().getBBox().height
  }
  
  var box_height = y_offset+padding
  
  if (data.y-data.offset-padding < box_height+triangle_size/2) {
    var tooltip_y = data.y+data.offset+(triangle_size/2),
        triangle_y = 0,
        p = "M "+(-triangle_size/2)+" 0 L 0 "+(-triangle_size/2)+" L "+(triangle_size/2)+" 0";
  } else {
    var tooltip_y = data.y-data.offset-box_height-(triangle_size/2),
        triangle_y = box_height,
        p = "M "+(-triangle_size/2)+" 0 L 0 "+(triangle_size/2)+" L "+(triangle_size/2)+" 0";
  }
  
  if (data.x-data.offset-padding < tooltip_width/2) var tooltip_x = padding
  else if (data.x+data.offset+padding > window_width-(tooltip_width/2)) var tooltip_x = window_width-tooltip_width-padding
  else var tooltip_x = data.x-(tooltip_width/2)
  
  if (data.arrow) {
    group.append("line")
      .attr("x1",(data.x-tooltip_x-triangle_size/2+1))
      .attr("x2",(data.x-tooltip_x+triangle_size/2-1))
      .attr("y1",triangle_y)
      .attr("y2",triangle_y)
      .attr("stroke-width",stroke_width*2)
      .attr("stroke","white")
    
    group.append("path")
      .attr("d",p)
      .attr("fill","white")
      .attr("stroke","#cccccc")
      .attr("stroke-width",stroke_width)
      .attr("transform","translate("+(data.x-tooltip_x)+","+triangle_y+")");
  }
  
  group.attr("transform","translate("+tooltip_x+","+tooltip_y+")")
    
  box
    .attr("height",box_height+"px")

}

//===================================================================

//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
// Destroy Tooltips
//-------------------------------------------------------------------

vizwhiz.tooltip.remove = function(id) {
  
  if (id) d3.select("g#vizwhiz_tooltip_"+id).remove()
  else d3.selectAll("g.vizwhiz_tooltip").remove()

}

//===================================================================
{'fraction_non_alphanumeric': 0.2752984650369528, 'fraction_numerical': 0.019329164297896533, 'mean_word_length': 3.039609644087256, 'pattern_counts': {'":': 3, '<': 7, '<?xml version=': 0, '>': 5, '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': '4636972', 'n_tokens_mistral': 2554, 'n_tokens_neox': 2450, 'n_words': 342}