<commit_before>var Layer = function(gridMap, options) {

  this.options = options || {};
  this.options.strokeColor = this.options.strokeColor || 'rgba(100,100,100,.8)';
  this.options.fillColor = this.options.fillColor ||  'rgba(237,178,48,1)';
  if (this.options.zIndex === undefined) {
    // zIndex of 0 is valid
    this.options.zIndex = 1;
  }
  if (!this.options.hasOwnProperty('renderOnAnimate')) {
    this.options.renderOnAnimate = true;
  }
  this.visible = true;

  var canvas = gridMap.container
    .append('canvas');

  canvas
    .style('position', 'absolute')
    .style('top', '0px')
    .style('left', '0px')
    .attr('width', gridMap.width)
    .attr('height', gridMap.height)
    .attr('z-index', this.options.zIndex)
    .data([this.options.zIndex]); // for layer sorting

  var context = canvas.node().getContext('2d');

  this.resize = function(width, height) {
    canvas.attr('width', width);
    canvas.attr('height', height);
  };

  this.remove = function() {
    canvas.remove();
  };

  this.renderGridToCanvas = function(grid, indexMap) {

    var image = context.getImageData(0, 0, gridMap.width, gridMap.height);
    var imageData = image.data;

    for (var i=0; i<indexMap.length; i++) {

      if ( !indexMap[i]) {
        // skip where grid is undef
        continue;
      }

      var imageIndexT4 = i*4;
      var gridIndexT4 = indexMap[i]*4;

      imageData[imageIndexT4] = grid.data[gridIndexT4];
      imageData[++imageIndexT4] = grid.data[++gridIndexT4];
      imageData[++imageIndexT4] = grid.data[++gridIndexT4];
      imageData[++imageIndexT4] = grid.data[++gridIndexT4];
    }

    context.putImageData(image, 0, 0);
  };

  this.drawGrid = function(grid) {
    var indexMap = grid.getIndexMap(gridMap);
    this.renderGridToCanvas(this.grid, indexMap);
  };

  this.drawGeoJSONLayer = function() {

    context.beginPath();

    if (this.simplified) {
      gridMap.simplifyingPath.context(context)(this.json);
    } else {
      gridMap.path.context(context)(this.json);
    }
    context.strokeStyle = this.options.strokeColor;
    context.lineWidth = 0.5;
    context.stroke();

    context.fillStyle = this.options.fillColor;
    context.fill();
  };

  this.clear = function() {
    context.clearRect(0, 0, gridMap.width, gridMap.height);
  };

  this.setVisible = function(visible) {
    this.visible = visible;
    canvas.style('display', visible ? 'block' : 'none');
  };
  this.hide = function() {this.setVisible(false); };
  this.show = function() {this.setVisible(true); };

  this.draw = function() {

    this.clear();

    if (!this.visible) {
      return;
    }

    if (this.grid) {
      this.drawGrid(this.grid);
    } else if (this.json) {
        this.drawGeoJSONLayer();
    }
  };

};

module.exports = Layer;
<commit_msg>Used Uint32Array to draw canvas for efficiency<commit_after>// IE 10 shim
if(window.CanvasPixelArray) {
    CanvasPixelArray.prototype.set = function(arr) {
        var l=this.length, i=0;
        for(;i<l;i++) {
            this[i] = arr[i];
        }
    };
}

var Layer = function(gridMap, options) {

  this.options = options || {};
  this.options.strokeColor = this.options.strokeColor || 'rgba(100,100,100,.8)';
  this.options.fillColor = this.options.fillColor ||  'rgba(237,178,48,1)';
  if (this.options.zIndex === undefined) {
    // zIndex of 0 is valid
    this.options.zIndex = 1;
  }
  if (!this.options.hasOwnProperty('renderOnAnimate')) {
    this.options.renderOnAnimate = true;
  }
  this.visible = true;

  var canvas = gridMap.container
    .append('canvas');

  canvas
    .style('position', 'absolute')
    .style('top', '0px')
    .style('left', '0px')
    .attr('width', gridMap.width)
    .attr('height', gridMap.height)
    .attr('z-index', this.options.zIndex)
    .data([this.options.zIndex]); // for layer sorting

  var context = canvas.node().getContext('2d');

  this.resize = function(width, height) {
    canvas.attr('width', width);
    canvas.attr('height', height);
  };

  this.remove = function() {
    canvas.remove();
  };

  this.renderGridToCanvas = function(grid, indexMap) {

    var image = context.getImageData(0, 0, gridMap.width, gridMap.height);
    var buf = new ArrayBuffer(image.data.length);
    var buf8 = new Uint8ClampedArray(buf);
    var imageData = new Uint32Array(buf);

    var gridData = new Uint32Array(grid.data.buffer);

    for (var i=0; i<indexMap.length; i++) {
      if ( !indexMap[i]) {
        // skip where grid is undef
        continue;
      }
      imageData[i] = gridData[indexMap[i]]
    }
    image.data.set(buf8);
    context.putImageData(image, 0, 0);
  };

  this.drawGrid = function(grid) {
    var indexMap = grid.getIndexMap(gridMap);
    this.renderGridToCanvas(this.grid, indexMap);
  };

  this.drawGeoJSONLayer = function() {

    context.beginPath();

    if (this.simplified) {
      gridMap.simplifyingPath.context(context)(this.json);
    } else {
      gridMap.path.context(context)(this.json);
    }
    context.strokeStyle = this.options.strokeColor;
    context.lineWidth = 0.5;
    context.stroke();

    context.fillStyle = this.options.fillColor;
    context.fill();
  };

  this.clear = function() {
    context.clearRect(0, 0, gridMap.width, gridMap.height);
  };

  this.setVisible = function(visible) {
    this.visible = visible;
    canvas.style('display', visible ? 'block' : 'none');
  };
  this.hide = function() {this.setVisible(false); };
  this.show = function() {this.setVisible(true); };

  this.draw = function() {

    this.clear();

    if (!this.visible) {
      return;
    }

    if (this.grid) {
      this.drawGrid(this.grid);
    } else if (this.json) {
        this.drawGeoJSONLayer();
    }
  };

};

module.exports = Layer;

{'fraction_non_alphanumeric': 0.162839248434238, 'fraction_numerical': 0.015657620041753653, 'mean_word_length': 3.0230930720783764, 'pattern_counts': {'":': 0, '<': 6, '<?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': '4375121', 'n_tokens_mistral': 2026, 'n_tokens_neox': 1930, 'n_words': 345}