<commit_before>var SetupMixin = {
  componentWillMount: function() {
    this.setupSeries(this.props.series);
  },

  componentWillUpdate: function(nextProps) {
    this.setupSeries(nextProps.series);
  },

  setupSeries: function(series) {
    if(series === null || series.length === 0) {
      return;
    }

    this.setGroupedSeries(series);
    this.setYearValues(series);
  },

  setGroupedSeries: function(series) {
    if(series.length === 0) {
      return;
    }

    this.seriesMapping = [];
    this.seriesGrouping = [];

    series = series.slice(); //copies array

    var seriesLabels = this.props.schema.series;
    var valueLabel = this.props.schema.value;

    if(typeof seriesLabels === "string") {
      seriesLabels = [seriesLabels];
    }

    var sortFields = seriesLabels.slice();
    sortFields.push(valueLabel);
    
    series.sort(this.getSortFunction(sortFields));

    var seriesMapping = this.mapSeries(series);
    this.seriesMapping = seriesMapping;

    var seriesGrouping = [];

    if(seriesLabels.length === 1) {
      return;
    }

    var categoryStartIndex = 0;
    var seriesNames = seriesMapping[0].seriesNames;
    var currentCategory = seriesNames[seriesNames.length - 2];

    for(var i=1; i < seriesMapping.length; i++) {
      seriesNames = seriesMapping[i].seriesNames;
      var newCategory = seriesNames[seriesNames.length - 2];

      if(newCategory !== currentCategory) {
        seriesGrouping.push({
          categoryName: currentCategory,
          startIndex: categoryStartIndex,
          count: i - categoryStartIndex
        });

        currentCategory = newCategory;
        categoryStartIndex = i;
      }
    }

    seriesGrouping.push({
      categoryName: currentCategory,
      startIndex: categoryStartIndex,
      count: seriesMapping.length - categoryStartIndex
    });

    this.seriesGrouping = seriesGrouping;
  },

  mapSeries: function(sortedSeries) {
    var seriesLabels = this.props.schema.series;
    var valueLabel = this.props.schema.value;

    if(typeof seriesLabels === "string") {
      seriesLabels = [seriesLabels];
    }

    var seriesMapping = [];

    var coverage = [];
    var currentSeries = null;
    var start = null;
    var end = null;

    var colorIndeces = [];
    seriesLabels.forEach(function() { colorIndeces.push(0); });

    sortedSeries.forEach(function(item) {
      var value = item[valueLabel];

      if(currentSeries === null) {
        currentSeries = item;
        start = value;
        end = value;

        return;
      }
      
      var mismatchedIndex = this.getMismatchedIndex(item, currentSeries);

      if(mismatchedIndex !== -1) {
        coverage.push({start: start, end: end});

        var seriesNames = [];
        seriesLabels.forEach(function(label) {
          seriesNames.push(currentSeries[label]);
        });

        seriesMapping.push({seriesNames: seriesNames, coverage: coverage, colorIndeces: colorIndeces});


        colorIndeces = colorIndeces.slice(); //Copy array by value
        colorIndeces[mismatchedIndex] += 1;

        for(var i = mismatchedIndex + 1; i < colorIndeces.length; i++) {
          colorIndeces[i] = 0;
        }

        coverage = [];
        currentSeries = item;
        start = value;
      } else if(value > end + this.props.stepSize) {
        coverage.push({start: start, end: end});
        start = value;
      }
      
      end = value;
    }, this);

    //cleanup the last one
    coverage.push({start: start, end: end});

    var seriesNames = [];
    seriesLabels.forEach(function(label) {
      seriesNames.push(currentSeries[label]);
    });

    seriesMapping.push({seriesNames: seriesNames, coverage: coverage, colorIndeces: colorIndeces});<commit_msg>Fixed 1% coverage for no coverage issue (+1 squashed commit) Squashed commits: [d669a2c] Left out one spot with the 1% coverage bug<commit_after>var SetupMixin = {
  componentWillMount: function() {
    this.setupSeries(this.props.series);
  },

  componentWillUpdate: function(nextProps) {
    this.setupSeries(nextProps.series);
  },

  setupSeries: function(series) {
    if(series === null || series.length === 0) {
      return;
    }

    this.setGroupedSeries(series);
    this.setYearValues(series);
  },

  setGroupedSeries: function(series) {
    if(series.length === 0) {
      return;
    }

    this.seriesMapping = [];
    this.seriesGrouping = [];

    series = series.slice(); //copies array

    var seriesLabels = this.props.schema.series;
    var valueLabel = this.props.schema.value;

    if(typeof seriesLabels === "string") {
      seriesLabels = [seriesLabels];
    }

    var sortFields = seriesLabels.slice();
    sortFields.push(valueLabel);
    
    series.sort(this.getSortFunction(sortFields));

    var seriesMapping = this.mapSeries(series);
    this.seriesMapping = seriesMapping;

    var seriesGrouping = [];

    if(seriesLabels.length === 1) {
      return;
    }

    var categoryStartIndex = 0;
    var seriesNames = seriesMapping[0].seriesNames;
    var currentCategory = seriesNames[seriesNames.length - 2];

    for(var i=1; i < seriesMapping.length; i++) {
      seriesNames = seriesMapping[i].seriesNames;
      var newCategory = seriesNames[seriesNames.length - 2];

      if(newCategory !== currentCategory) {
        seriesGrouping.push({
          categoryName: currentCategory,
          startIndex: categoryStartIndex,
          count: i - categoryStartIndex
        });

        currentCategory = newCategory;
        categoryStartIndex = i;
      }
    }

    seriesGrouping.push({
      categoryName: currentCategory,
      startIndex: categoryStartIndex,
      count: seriesMapping.length - categoryStartIndex
    });

    this.seriesGrouping = seriesGrouping;
  },

  mapSeries: function(sortedSeries) {
    var seriesLabels = this.props.schema.series;
    var valueLabel = this.props.schema.value;

    if(typeof seriesLabels === "string") {
      seriesLabels = [seriesLabels];
    }

    var seriesMapping = [];

    var coverage = [];
    var currentSeries = null;
    var start = null;
    var end = null;

    var colorIndeces = [];
    seriesLabels.forEach(function() { colorIndeces.push(0); });

    sortedSeries.forEach(function(item) {
      var value = item[valueLabel];

      if(currentSeries === null) {
        currentSeries = item;
        start = value;
        end = value;

        return;
      }
      
      var mismatchedIndex = this.getMismatchedIndex(item, currentSeries);

      if(mismatchedIndex !== -1) {
        if(start !== null && end !== null) {
          coverage.push({start: start, end: end});
        }

        var seriesNames = [];
        seriesLabels.forEach(function(label) {
          seriesNames.push(currentSeries[label]);
        });

        seriesMapping.push({seriesNames: seriesNames, coverage: coverage, colorIndeces: colorIndeces});


        colorIndeces = colorIndeces.slice(); //Copy array by value
        colorIndeces[mismatchedIndex] += 1;

        for(var i = mismatchedIndex + 1; i < colorIndeces.length; i++) {
          colorIndeces[i] = 0;
        }

        coverage = [];
        currentSeries = item;
        start = value;
      } else if(value > end + this.props.stepSize) {
        coverage.push({start: start, end: end});
        start = value;
      }
      
      end = value;
    }, this);

    //cleanup the last one
    if(start !== null && end !== null) {
      coverage.push({start: start, end: end});
    }

    var seriesNames = [];
    seriesLabels.forEach(function(label) {
      seriesNames.push(currentSeries[label]);
    });

    seriesMapping.push({seriesNames: seriesNames, coverage: coverage, colorIndeces: colorIndeces});
{'fraction_non_alphanumeric': 0.12230589457283822, 'fraction_numerical': 0.004284601402233186, 'mean_word_length': 2.6507109004739338, 'pattern_counts': {'":': 0, '<': 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': '5268592', 'n_tokens_mistral': 2277, 'n_tokens_neox': 2191, 'n_words': 458}