<commit_before>var d3 = require('d3-selection');
var filterMap = require('./filter-map.json');
var FilterComponent = require('./filter-component');
var filterCount = 0;
// var svg;

function Filter() {
  if (!(this instanceof Filter)) {
    return new Filter();
  }

  this.id = 'svg-filter-' + filterCount++;

  var defs = d3.select('body').append('svg').attr('height', 0).append('defs');

  this.filter = defs.append('filter');
  this.filter.attr('id', this.id);
}

module.exports = Filter;

Filter.prototype.toString = function() {
  return 'url(#' + this.id + ')';
};

Filter.prototype.append = function(name) {
  if (filterMap.hasOwnProperty(name)) {
    // create a new filter component and add it...
    return new FilterComponent(this, name);
  } else {
    for (var key in filterMap) {
      if (filterMap.hasOwnProperty(key)) {
        if (filterMap[key] === name) {
          return new FilterComponent(this, name);
        }
      }
    }

    // if theres no match just fall back to a regular
    // d3 append<commit_msg>re-use svg<commit_after>var d3 = require('d3-selection');
var filterMap = require('./filter-map.json');
var FilterComponent = require('./filter-component');
var filterCount = 0;
var svg;

function Filter() {
  if (!(this instanceof Filter)) {
    return new Filter();
  }

  this.id = 'svg-filter-' + filterCount++;

  if(!svg) {
    svg = d3.select('body').append('svg');
  }

  var defs = svg.attr('height', 0).append('defs');

  this.filter = defs.append('filter');
  this.filter.attr('id', this.id);
}

module.exports = Filter;

Filter.prototype.toString = function() {
  return 'url(#' + this.id + ')';
};

Filter.prototype.append = function(name) {
  if (filterMap.hasOwnProperty(name)) {
    // create a new filter component and add it...
    return new FilterComponent(this, name);
  } else {
    for (var key in filterMap) {
      if (filterMap.hasOwnProperty(key)) {
        if (filterMap[key] === name) {
          return new FilterComponent(this, name);
        }
      }
    }

    // if theres no match just fall back to a regular
    // d3 append
{'fraction_non_alphanumeric': 0.16610978520286396, 'fraction_numerical': 0.005727923627684964, 'mean_word_length': 3.085769980506823, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4839523', 'n_tokens_mistral': 675, 'n_tokens_neox': 660, 'n_words': 171}