<commit_before>//d3.svg.axisSmart

export default function axisSmart() {

  return function d3_axis_smart(_super) {

    var VERTICAL = 'vertical axis';
    var HORIZONTAL = 'horizontal axis';
    var X = 'labels stack side by side';
    var Y = 'labels stack top to bottom';

    var OPTIMISTIC = 'optimistic approximation: labels have different lengths';
    var PESSIMISTIC = 'pessimistic approximation: all labels have the largest length';
    var DEFAULT_LOGBASE = 10;

    function onlyUnique(value, index, self) {
      return self.indexOf(value) === index;
    }

    function axis(g) {
      if(highlightValue != null) {
        axis.highlightValueRun(g);
        return;
      }

      // measure the width and height of one digit
      var widthSampleG = g.append("g").attr("class", "tick widthSampling");
      var widthSampleT = widthSampleG.append('text').text('0');
      if(!options.cssMargin) options.cssMargin = {};
      options.cssMargin.top = widthSampleT.style("margin-top");
      options.cssMargin.bottom = widthSampleT.style("margin-bottom");
      options.cssMargin.left = widthSampleT.style("margin-left");
      options.cssMargin.right = widthSampleT.style("margin-right");
      options.widthOfOneDigit = widthSampleT[0][0].getBBox().width;
      options.heightOfOneDigit = widthSampleT[0][0].getBBox().height;
      widthSampleG.remove();

      // run label factory - it will store labels in tickValues property of axis
      axis.labelFactory(options);

      // construct the view (d3 constructor is used)
      if(options.transitionDuration > 0) {
        _super(g.transition().duration(options.transitionDuration));
      } else {
       _super(g);
      }
      
      //identify the orientation of axis and the direction of labels
      var orient = axis.orient() == "top" || axis.orient() == "bottom" ? HORIZONTAL : VERTICAL;
      var dimension = (orient == HORIZONTAL && axis.pivot() || orient == VERTICAL && !axis.pivot()) ? Y : X;

      //add an invisible element that would represent hovered value
      g.selectAll('.vzb-axis-value')
        .data([null])
        .enter().append('g')
        .attr("class", 'vzb-axis-value')
        .classed("vzb-hidden", true)
        .append("text")
      
      // patch the label positioning after the view is generated
      var tickSizeWithPadding = axis.tickPadding() + axis.tickSize();
      g.selectAll("text")
        .each(function(d, i) {
          if(axis.pivot() == null) return;

          var view = d3.select(this);
          view.attr("transform", "rotate(" + (axis.pivot() ? -90 : 0) + ")");
          view.style("text-anchor", dimension == X ? "middle" : "end");
          view.attr("x", dimension == X ? (orient == VERTICAL ? -tickSizeWithPadding : 0) : -tickSizeWithPadding);
          view.attr("y", dimension == X ? (orient == VERTICAL ? 0 : tickSizeWithPadding) : 0);
          view.attr("dx", dimension == X ? (orient == VERTICAL ? tickSizeWithPadding : 0) : 0);
          view.attr("dy", dimension == X ? (orient == VERTICAL ? -tickSizeWithPadding : ".72em") : ".32em");
        });
      
      //apply label repositioning: first and last visible values would shift away from the borders
      if(axis.repositionLabels() != null){
        g.selectAll(".tick")
          .each(function(d) {
            var view = d3.select(this).select("text");
            var shift = axis.repositionLabels()[d] || {x: 0, y: 0};
            view.attr("x", +view.attr("x") + shift.x);
            view.attr("y", +view.attr("y") + shift.y);
          });
      }
      
      //hide axis labels that are outside the available viewport
      var scale = axis.scale();
      if(options.viewportLength){
        g.selectAll(".tick")
          .classed("vzb-hidden", function(d) {return scale(d)<0 || scale(d)>options.viewportLength})
      }

      // add minor ticks. if none exist add an empty array
      if(axis.tickValuesMinor() == null) axis.tickValuesMinor([]);
      var minorTicks = g.selectAll(".tickMinor").data(tickValuesMinor);
      minorTicks.exit().remove();
      minorTicks.enter().append("line")
        .attr("class", "tickMinor");

      var tickLengthOut = axis.tickSizeMinor().outbound;
      var tickLengthIn = axis.tickSizeMinor().inbound;
      minorTicks
        .classed("vzb-hidden", function(d) {return scale(d)<0 || scale(d)>options.viewportLength})
        .attr("y1", orient == HORIZONTAL ? (axis.orient() == "top" ? 1 : -1) * tickLengthIn : scale)
        .attr("y2", orient == HORIZONTAL ? (axis.orient() == "top" ? -1 : 1) * tickLengthOut : scale)
        .attr("x1", orient == VERTICAL ? (axis.orient() == "right" ? -1 : 1) * tickLengthIn : scale)
        .attr("x2", orient == VERTICAL ? (axis.orient() == "right" ? 1 : -1) * tickLengthOut : scale);

      //adjust axis rake 
      g.selectAll("path").remove();
      var rake = g.selectAll(".vzb-axis-line").data([0]);
      rake.exit().remove();
      rake.enter().append("line")
        .attr("class", "vzb-axis-line");
        
      if(options.viewportLength){
        rake 
          .attr("x1", orient == VERTICAL ? 0 : -1)
          .attr("x2", orient == VERTICAL ? 0 : options.viewportLength)
          .attr("y1", orient == HORIZONTAL ? 0 : 0)
          .attr("y2", orient == HORIZONTAL ? 0 : options.viewportLength)      
      }else{
        //TODO: this will not work for the "ordinal" scaleType
        rake 
          .attr("x1", orient == VERTICAL ? 0 : d3.min(scale.range()) - (options.bump||0) - 1)
          .attr("x2", orient == VERTICAL ? 0 : d3.max(scale.range()) + (options.bump||0))
          .attr("y1", orient == HORIZONTAL ? 0 : d3.min(scale.range()) - (options.bump||0))
          .attr("y2", orient == HORIZONTAL ? 0 : d3.max(scale.range()) + (options.bump||0))
      }
    };


    axis.highlightValueRun = function(g) {

      //if viewport is defined and HL value is outside then behave as reset HL
      if(options.viewportLength && (
        axis.scale()(highlightValue) > options.viewportLength ||
        axis.scale()(highlightValue) < 0
      )) highlightValue = "none";
      
      //identify the orientation of axis and the direction of labels
      var orient = axis.orient() == "top" || axis.orient() == "bottom" ? HORIZONTAL : VERTICAL;
      var dimension = (orient == HORIZONTAL && axis.pivot() || orient == VERTICAL && !axis.pivot()) ? "y" : "x";
      var pivot = axis.pivot() ? -1 : 1;
      
      //set content and visibility of HL value
      g.select('.vzb-axis-value')
        .classed("vzb-hidden", highlightValue == "none")
        .select("text")
        .text(options.formatter(highlightValue == "none" ? 0 : highlightValue));
      
      // measure its width and height for collision resolving
      var bbox = g.select('.vzb-axis-value').node().getBBox();
      
      // clone a known options object (because we don't want to overwrite widthOfOneDigit / heightOfOneDigit in the original one
      var o = {};
      o.bump = options.bump;<commit_msg>Fix error when unhovering bubbles (wrong syntax)<commit_after>//d3.svg.axisSmart

export default function axisSmart() {

  return function d3_axis_smart(_super) {

    var VERTICAL = 'vertical axis';
    var HORIZONTAL = 'horizontal axis';
    var X = 'labels stack side by side';
    var Y = 'labels stack top to bottom';

    var OPTIMISTIC = 'optimistic approximation: labels have different lengths';
    var PESSIMISTIC = 'pessimistic approximation: all labels have the largest length';
    var DEFAULT_LOGBASE = 10;

    function onlyUnique(value, index, self) {
      return self.indexOf(value) === index;
    }

    function axis(g) {
      if(highlightValue != null) {
        axis.highlightValueRun(g);
        return;
      }

      // measure the width and height of one digit
      var widthSampleG = g.append("g").attr("class", "tick widthSampling");
      var widthSampleT = widthSampleG.append('text').text('0');
      if(!options.cssMargin) options.cssMargin = {};
      options.cssMargin.top = widthSampleT.style("margin-top");
      options.cssMargin.bottom = widthSampleT.style("margin-bottom");
      options.cssMargin.left = widthSampleT.style("margin-left");
      options.cssMargin.right = widthSampleT.style("margin-right");
      options.widthOfOneDigit = widthSampleT[0][0].getBBox().width;
      options.heightOfOneDigit = widthSampleT[0][0].getBBox().height;
      widthSampleG.remove();

      // run label factory - it will store labels in tickValues property of axis
      axis.labelFactory(options);

      // construct the view (d3 constructor is used)
      if(options.transitionDuration > 0) {
        _super(g.transition().duration(options.transitionDuration));
      } else {
       _super(g);
      }
      
      //identify the orientation of axis and the direction of labels
      var orient = axis.orient() == "top" || axis.orient() == "bottom" ? HORIZONTAL : VERTICAL;
      var dimension = (orient == HORIZONTAL && axis.pivot() || orient == VERTICAL && !axis.pivot()) ? Y : X;

      //add an invisible element that would represent hovered value
      g.selectAll('.vzb-axis-value')
        .data([null])
        .enter().append('g')
        .attr("class", 'vzb-axis-value')
        .classed("vzb-hidden", true)
        .append("text")
      
      // patch the label positioning after the view is generated
      var tickSizeWithPadding = axis.tickPadding() + axis.tickSize();
      g.selectAll("text")
        .each(function(d, i) {
          if(axis.pivot() == null) return;

          var view = d3.select(this);
          view.attr("transform", "rotate(" + (axis.pivot() ? -90 : 0) + ")");
          view.style("text-anchor", dimension == X ? "middle" : "end");
          view.attr("x", dimension == X ? (orient == VERTICAL ? -tickSizeWithPadding : 0) : -tickSizeWithPadding);
          view.attr("y", dimension == X ? (orient == VERTICAL ? 0 : tickSizeWithPadding) : 0);
          view.attr("dx", dimension == X ? (orient == VERTICAL ? tickSizeWithPadding : 0) : 0);
          view.attr("dy", dimension == X ? (orient == VERTICAL ? -tickSizeWithPadding : ".72em") : ".32em");
        });
      
      //apply label repositioning: first and last visible values would shift away from the borders
      if(axis.repositionLabels() != null){
        g.selectAll(".tick")
          .each(function(d) {
            var view = d3.select(this).select("text");
            var shift = axis.repositionLabels()[d] || {x: 0, y: 0};
            view.attr("x", +view.attr("x") + shift.x);
            view.attr("y", +view.attr("y") + shift.y);
          });
      }
      
      //hide axis labels that are outside the available viewport
      var scale = axis.scale();
      if(options.viewportLength){
        g.selectAll(".tick")
          .classed("vzb-hidden", function(d) {return scale(d)<0 || scale(d)>options.viewportLength})
      }

      // add minor ticks. if none exist add an empty array
      if(axis.tickValuesMinor() == null) axis.tickValuesMinor([]);
      var minorTicks = g.selectAll(".tickMinor").data(tickValuesMinor);
      minorTicks.exit().remove();
      minorTicks.enter().append("line")
        .attr("class", "tickMinor");

      var tickLengthOut = axis.tickSizeMinor().outbound;
      var tickLengthIn = axis.tickSizeMinor().inbound;
      minorTicks
        .classed("vzb-hidden", function(d) {return scale(d)<0 || scale(d)>options.viewportLength})
        .attr("y1", orient == HORIZONTAL ? (axis.orient() == "top" ? 1 : -1) * tickLengthIn : scale)
        .attr("y2", orient == HORIZONTAL ? (axis.orient() == "top" ? -1 : 1) * tickLengthOut : scale)
        .attr("x1", orient == VERTICAL ? (axis.orient() == "right" ? -1 : 1) * tickLengthIn : scale)
        .attr("x2", orient == VERTICAL ? (axis.orient() == "right" ? 1 : -1) * tickLengthOut : scale);

      //adjust axis rake 
      g.selectAll("path").remove();
      var rake = g.selectAll(".vzb-axis-line").data([0]);
      rake.exit().remove();
      rake.enter().append("line")
        .attr("class", "vzb-axis-line");
        
      if(options.viewportLength){
        rake 
          .attr("x1", orient == VERTICAL ? 0 : -1)
          .attr("x2", orient == VERTICAL ? 0 : options.viewportLength)
          .attr("y1", orient == HORIZONTAL ? 0 : 0)
          .attr("y2", orient == HORIZONTAL ? 0 : options.viewportLength)      
      }else{
        //TODO: this will not work for the "ordinal" scaleType
        rake 
          .attr("x1", orient == VERTICAL ? 0 : d3.min(scale.range()) - (options.bump||0) - 1)
          .attr("x2", orient == VERTICAL ? 0 : d3.max(scale.range()) + (options.bump||0))
          .attr("y1", orient == HORIZONTAL ? 0 : d3.min(scale.range()) - (options.bump||0))
          .attr("y2", orient == HORIZONTAL ? 0 : d3.max(scale.range()) + (options.bump||0))
      }
    };


    axis.highlightValueRun = function(g) {

      //if viewport is defined and HL value is outside then behave as reset HL
      if(options.viewportLength && highlightValue != "none" && (
        axis.scale()(highlightValue) > options.viewportLength ||
        axis.scale()(highlightValue) < 0
      )) highlightValue = "none";
      
      //identify the orientation of axis and the direction of labels
      var orient = axis.orient() == "top" || axis.orient() == "bottom" ? HORIZONTAL : VERTICAL;
      var dimension = (orient == HORIZONTAL && axis.pivot() || orient == VERTICAL && !axis.pivot()) ? "y" : "x";
      var pivot = axis.pivot() ? -1 : 1;
      
      //set content and visibility of HL value
      g.select('.vzb-axis-value')
        .classed("vzb-hidden", highlightValue == "none")
        .select("text")
        .text(options.formatter(highlightValue == "none" ? 0 : highlightValue));
      
      // measure its width and height for collision resolving
      var bbox = g.select('.vzb-axis-value').node().getBBox();
      
      // clone a known options object (because we don't want to overwrite widthOfOneDigit / heightOfOneDigit in the original one
      var o = {};
      o.bump = options.bump;
{'fraction_non_alphanumeric': 0.15732098325614535, 'fraction_numerical': 0.01040256501603135, 'mean_word_length': 2.5943661971830987, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, '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': '2633307', 'n_tokens_mistral': 4422, 'n_tokens_neox': 4281, 'n_words': 1053}