<commit_before>/**
 * Main JS for Simple Map (D3).
 */
var SimpleMapD3 = (function() {
  // Private variables and functions
  var defaults = {
  
  };
  
  // Constructor
  var SimpleMapD3 = function(options) {
    this.options = options;
    
    // Check if data was given, or if data source was given
    if (this.options.data === Object(this.options.data)) {
      this.data = this.options.data;
      this.dataLoaded(this.data);
    }
    else if (toString.call(this.options.datasource) == '[object String]') {
      this.getData();
    }
  };
  
  // Prototype "public" methods
  SimpleMapD3.prototype.constructor = SimpleMapD3,
  
  // Get data
  SimpleMapD3.prototype.getData = function() {
    var thisMap = this;
    
    d3.json(this.options.datasource, function(data) {
      thisMap.data = data;
      thisMap.loadData();
    });
  };
  
  // Handle data once loaded
  SimpleMapD3.prototype.loadData = function(data) {
    if (this.data === void 0) {
      this.data = data;
    }
    this.createCanvas();
    this.project();
    this.render();
  };
  
  // Load up canvas, set size to container
  SimpleMapD3.prototype.createCanvas = function() {
    this.container = d3.select(this.options.container);
    this.width = parseFloat(this.container.style('width'));
    this.height = parseFloat(this.container.style('height'));
    this.canvas = this.container.append('svg')
      .attr('width', this.width)
      .attr('height', this.height);
  };
  
  // Project data into the canvas
  SimpleMapD3.prototype.project = function() {
    this.proj = d3.geo.mercator().scale(1).translate([0,0]);
    this.projection = this.projection || {};
    
    // Variables
    var margin = this.width * 0.02;
    var bounds0 = d3.geo.bounds(this.data);
    var bounds = bounds0.map(this.proj);
    var xscale = (this.width - 2 * margin) / Math.abs(bounds[1][0] - bounds[0][0]);
    var yscale = (this.height - 2 * margin) / Math.abs(bounds[1][1] - bounds[0][1]);
    var pscale = Math.min(xscale, yscale);
    var wscale = pscale;
    var d, widthd, heightd;
    
    // Handle projection
    this.proj.scale(pscale);
    this.proj.translate(this.proj([-bounds0[0][0], -bounds0[1][1]]));
    this.projection.path = d3.geo.path().projection(this.proj);
    
    // Handle svg canvas, dpeneding on orientation
    if (xscale > yscale) {
      d = xscale * Math.abs(bounds[1][0] - bounds[0][0]) - yscale * Math.abs(bounds[1][0] - bounds[0][0]);
      this.canvas.attr('transform', 'translate(' + d / 2 + ', 0)');
    }
    else {
      d = yscale * Math.abs(bounds[1][1] - bounds[0][1]) - xscale * Math.abs(bounds[1][1] - bounds[0][1]);
      this.canvas.attr('transform', 'translate(0, ' + d / 5 + ')');
    }
    
    // Handle offset, depending on orientation
    widthd = this.proj(bounds0[0])[1];
    heightd = this.proj(bounds0[1])[0];
    if (xscale > yscale) {
      this.projection.offsetxd = (this.width / 2 - widthd / 2);
      this.projection.offsetyd = margin;
    }
    else {
      this.projection.offsetxd = margin;
      this.projection.offsetyd = (this.height / 2 - heightd / 2);
    }
  };
  
  // Render
  SimpleMapD3.prototype.render = function() {
    this.canvas
      .selectAll('path')
        .data(this.data.features)
      .enter().append('path')
        .attr('d', this.projection.path)
        .attr('stroke', '#EDEDED')
        .attr('transform', 'translate(' + this.projection.offsetxd + ', ' + this.projection.offsetyd + ')');
  };
  
  // return module
  return SimpleMapD3;
})();<commit_msg>Adding some options for fill and stroke.<commit_after>/**
 * Main JS for Simple Map (D3).
 */
var SimpleMapD3 = (function() {
  // Private variables and functions
  var defaults = {
    stroke: '#898989',
    fill: '#FFFFFF',
  };
  
  // Constructor
  var SimpleMapD3 = function(options) {
    // Extend defaults
    var extended = defaults;
    for (var prop in options) {
      extended[prop] = options[prop];
    }
    this.options = extended;
    
    // Check if data was given, or if data source was given
    if (this.options.data === Object(this.options.data)) {
      this.data = this.options.data;
      this.dataLoaded(this.data);
    }
    else if (toString.call(this.options.datasource) == '[object String]') {
      this.getData();
    }
  };
  
  // Prototype "public" methods
  SimpleMapD3.prototype.constructor = SimpleMapD3,
  
  // Get data
  SimpleMapD3.prototype.getData = function() {
    var thisMap = this;
    
    d3.json(this.options.datasource, function(data) {
      thisMap.data = data;
      thisMap.loadData();
    });
  };
  
  // Handle data once loaded
  SimpleMapD3.prototype.loadData = function(data) {
    if (this.data === void 0) {
      this.data = data;
    }
    this.createCanvas();
    this.project();
    this.render();
  };
  
  // Load up canvas, set size to container
  SimpleMapD3.prototype.createCanvas = function() {
    this.container = d3.select(this.options.container);
    this.width = parseFloat(this.container.style('width'));
    this.height = parseFloat(this.container.style('height'));
    this.canvas = this.container.append('svg')
      .attr('width', this.width)
      .attr('height', this.height);
  };
  
  // Project data into the canvas
  SimpleMapD3.prototype.project = function() {
    this.proj = d3.geo.mercator().scale(1).translate([0,0]);
    this.projOptions = this.projOptions || {};
    
    // Variables
    var margin = this.width * 0.02;
    var bounds0 = d3.geo.bounds(this.data);
    var bounds = bounds0.map(this.proj);
    var xscale = (this.width - 2 * margin) / Math.abs(bounds[1][0] - bounds[0][0]);
    var yscale = (this.height - 2 * margin) / Math.abs(bounds[1][1] - bounds[0][1]);
    var pscale = Math.min(xscale, yscale);
    var wscale = pscale;
    var d, widthd, heightd;
    
    // Handle projection
    this.proj.scale(pscale);
    this.proj.translate(this.proj([-bounds0[0][0], -bounds0[1][1]]));
    this.projOptions.path = d3.geo.path().projection(this.proj);
    
    // Handle svg canvas, dpeneding on orientation
    if (xscale > yscale) {
      d = xscale * Math.abs(bounds[1][0] - bounds[0][0]) - yscale * Math.abs(bounds[1][0] - bounds[0][0]);
      this.canvas.attr('transform', 'translate(' + d / 2 + ', 0)');
    }
    else {
      d = yscale * Math.abs(bounds[1][1] - bounds[0][1]) - xscale * Math.abs(bounds[1][1] - bounds[0][1]);
      this.canvas.attr('transform', 'translate(0, ' + d / 5 + ')');
    }
    
    // Handle offset, depending on orientation
    widthd = this.proj(bounds0[0])[1];
    heightd = this.proj(bounds0[1])[0];
    if (xscale > yscale) {
      this.projOptions.offsetxd = (this.width / 2 - widthd / 2);
      this.projOptions.offsetyd = margin;
    }
    else {
      this.projOptions.offsetxd = margin;
      this.projOptions.offsetyd = (this.height / 2 - heightd / 2);
    }
  };
  
  // Render
  SimpleMapD3.prototype.render = function() {
    this.canvas
      .selectAll('path')
        .data(this.data.features)
      .enter().append('path')
        .attr('d', this.projOptions.path)
        .attr('stroke', this.options.stroke)
        .attr('fill', this.options.fill)
        .attr('transform', 'translate(' + this.projOptions.offsetxd + ', ' + this.projOptions.offsetyd + ')');
  };
  
  // return module
  return SimpleMapD3;
})();
{'fraction_non_alphanumeric': 0.1678992056970693, 'fraction_numerical': 0.02026841961106546, 'mean_word_length': 2.6387643248629797, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '5068299', 'n_tokens_mistral': 2513, 'n_tokens_neox': 2456, 'n_words': 486}