<commit_before>(function () {
  /**
   *
   * @param settings
   * @constructor
   */
  function Points(settings) {
    Points.instances.push(this);
    this.settings = defaults(settings, Points.defaults);

    if (!settings.data) throw new Error('no "data" array setting defined');
    if (!settings.map) throw new Error('no leaflet "map" object setting defined');

    this.active = true;

    var self = this,
      glLayer = this.glLayer = L.canvasOverlay(function() {
          self.drawOnCanvas();
        })
        .addTo(settings.map),
      canvas = this.canvas = glLayer.canvas;

    canvas.width = canvas.clientWidth;
    canvas.height = canvas.clientHeight;
    canvas.style.position = 'absolute';
    if (settings.className) {
      canvas.className += ' ' + settings.className;
    }

    this.gl = canvas.getContext('webgl') || canvas.getContext('experimental-webgl');

    this.pixelsToWebGLMatrix = new Float32Array(16);
    this.mapMatrix = L.glify.mapMatrix();
    this.vertexShader = null;
    this.fragmentShader = null;
    this.program = null;
    this.uMatrix = null;
    this.verts = null;
    this.latLngLookup = null;

    this
      .setup()
      .render();
  }

  Points.defaults = {
    map: null,
    data: [],
    debug: false,
    vertexShaderSource: function() { return L.glify.shader.vertex; },
    fragmentShaderSource: function() { return L.glify.shader.fragment.dot; },
    pointThreshold: 10,
    click: null,
    color: 'random',
    opacity: 0.6,
    size: null,
    className: '',
    sensitivity: 2
  };

  //statics
  Points.instances = [];

  Points.prototype = {
    maps: [],
    /**
     *
     * @returns {Points}
     */
    setup: function () {
      var self = this,
        settings = this.settings,
        map = settings.map,
        xy,
        point,
        latLng;

      if (settings.click) {
        if (this.maps.indexOf(settings.map) < 0) {
          this.maps.push(map);
          map.on('click', function (e) {
            point = self.closest(e.latlng, Points.instances.map(function(instance) {
              return instance.lookup(e.latlng);
            }));

            if (point !== null) {
              latLng = L.latLng(point[0], point[1]);
              xy = map.latLngToLayerPoint(latLng);
              if (self.pointInCircle(xy, e.layerPoint, self.pointSize() * settings.sensitivity)) {
                settings.click(point, {
                  latLng: latLng,
                  xy: xy
                }, e);
              }
            }

            if (settings.debug) {
              self.debugPoint(e.containerPoint);
            }
          });
        }
      }

      return this
        .setupVertexShader()
        .setupFragmentShader()
        .setupProgram();
    },

    /**
     *
     * @returns {Points}
     */
    render: function () {

      this.resetVertices();

      //look up the locations for the inputs to our shaders.
      var gl = this.gl,
        canvas = this.canvas,
        program = this.program,
        glLayer = this.glLayer,
        uMatrix = this.uMatrix = gl.getUniformLocation(program, 'uMatrix'),
        opacity = gl.getUniformLocation(program, 'opacity'),
        colorLocation = gl.getAttribLocation(program, 'aColor'),
        vertexLocation = gl.getAttribLocation(program, 'aVertex'),
        vertexBuffer = gl.createBuffer(),
        vertexArray = new Float32Array(this.verts),
        fsize = vertexArray.BYTES_PER_ELEMENT;

      gl.aPointSize = gl.getAttribLocation(program, 'aPointSize');

      //set the matrix to some that makes 1 unit 1 pixel.
      this.pixelsToWebGLMatrix.set([2 / canvas.width, 0, 0, 0, 0, -2 / canvas.height, 0, 0, 0, 0, 0, 0, -1, 1, 0, 1]);

      gl.viewport(0, 0, canvas.width, canvas.height);
      gl.uniformMatrix4fv(uMatrix, false, this.pixelsToWebGLMatrix);
      gl.uniform1f(opacity, this.settings.opacity);
      gl.bindBuffer(gl.ARRAY_BUFFER, vertexBuffer);
      gl.bufferData(gl.ARRAY_BUFFER, vertexArray, gl.STATIC_DRAW);
      gl.vertexAttribPointer(vertexLocation, 2, gl.FLOAT, false, fsize * 5, 0);
      gl.enableVertexAttribArray(vertexLocation);

      //offset for color buffer
      gl.vertexAttribPointer(colorLocation, 3, gl.FLOAT, false, fsize * 5, fsize * 2);
      gl.enableVertexAttribArray(colorLocation);

      glLayer.redraw();

      return this;
    },
    resetVertices: function () {
      //empty verts and repopulate
      this.latLngLookup = {};
      this.verts = [];

      // -- data
      var verts = this.verts,
        settings = this.settings,
        data = settings.data,
        colorKey = settings.color,
        colorFn = null,
        color,
        i = 0,
        max = data.length,
        latLngLookup = this.latLngLookup,
        latLng,
        pixel,
        lookup,
        key;

      //see if colorKey is actually a function
      if (typeof colorKey === 'function') {
        colorFn = colorKey;
      }
      //we know that colorKey isn't a function, but L.glify.color[key] might be, check that here
      else {
        color = L.glify.color[colorKey] || color;

        if (typeof color === 'function') {
          colorFn = color;
        }
      }<commit_msg>color key check<commit_after>(function () {
  /**
   *
   * @param settings
   * @constructor
   */
  function Points(settings) {
    Points.instances.push(this);
    this.settings = defaults(settings, Points.defaults);

    if (!settings.data) throw new Error('no "data" array setting defined');
    if (!settings.map) throw new Error('no leaflet "map" object setting defined');

    this.active = true;

    var self = this,
      glLayer = this.glLayer = L.canvasOverlay(function() {
          self.drawOnCanvas();
        })
        .addTo(settings.map),
      canvas = this.canvas = glLayer.canvas;

    canvas.width = canvas.clientWidth;
    canvas.height = canvas.clientHeight;
    canvas.style.position = 'absolute';
    if (settings.className) {
      canvas.className += ' ' + settings.className;
    }

    this.gl = canvas.getContext('webgl') || canvas.getContext('experimental-webgl');

    this.pixelsToWebGLMatrix = new Float32Array(16);
    this.mapMatrix = L.glify.mapMatrix();
    this.vertexShader = null;
    this.fragmentShader = null;
    this.program = null;
    this.uMatrix = null;
    this.verts = null;
    this.latLngLookup = null;

    this
      .setup()
      .render();
  }

  Points.defaults = {
    map: null,
    data: [],
    debug: false,
    vertexShaderSource: function() { return L.glify.shader.vertex; },
    fragmentShaderSource: function() { return L.glify.shader.fragment.dot; },
    pointThreshold: 10,
    click: null,
    color: 'random',
    opacity: 0.6,
    size: null,
    className: '',
    sensitivity: 2
  };

  //statics
  Points.instances = [];

  Points.prototype = {
    maps: [],
    /**
     *
     * @returns {Points}
     */
    setup: function () {
      var self = this,
        settings = this.settings,
        map = settings.map,
        xy,
        point,
        latLng;

      if (settings.click) {
        if (this.maps.indexOf(settings.map) < 0) {
          this.maps.push(map);
          map.on('click', function (e) {
            point = self.closest(e.latlng, Points.instances.map(function(instance) {
              return instance.lookup(e.latlng);
            }));

            if (point !== null) {
              latLng = L.latLng(point[0], point[1]);
              xy = map.latLngToLayerPoint(latLng);
              if (self.pointInCircle(xy, e.layerPoint, self.pointSize() * settings.sensitivity)) {
                settings.click(point, {
                  latLng: latLng,
                  xy: xy
                }, e);
              }
            }

            if (settings.debug) {
              self.debugPoint(e.containerPoint);
            }
          });
        }
      }

      return this
        .setupVertexShader()
        .setupFragmentShader()
        .setupProgram();
    },

    /**
     *
     * @returns {Points}
     */
    render: function () {

      this.resetVertices();

      //look up the locations for the inputs to our shaders.
      var gl = this.gl,
        canvas = this.canvas,
        program = this.program,
        glLayer = this.glLayer,
        uMatrix = this.uMatrix = gl.getUniformLocation(program, 'uMatrix'),
        opacity = gl.getUniformLocation(program, 'opacity'),
        colorLocation = gl.getAttribLocation(program, 'aColor'),
        vertexLocation = gl.getAttribLocation(program, 'aVertex'),
        vertexBuffer = gl.createBuffer(),
        vertexArray = new Float32Array(this.verts),
        fsize = vertexArray.BYTES_PER_ELEMENT;

      gl.aPointSize = gl.getAttribLocation(program, 'aPointSize');

      //set the matrix to some that makes 1 unit 1 pixel.
      this.pixelsToWebGLMatrix.set([2 / canvas.width, 0, 0, 0, 0, -2 / canvas.height, 0, 0, 0, 0, 0, 0, -1, 1, 0, 1]);

      gl.viewport(0, 0, canvas.width, canvas.height);
      gl.uniformMatrix4fv(uMatrix, false, this.pixelsToWebGLMatrix);
      gl.uniform1f(opacity, this.settings.opacity);
      gl.bindBuffer(gl.ARRAY_BUFFER, vertexBuffer);
      gl.bufferData(gl.ARRAY_BUFFER, vertexArray, gl.STATIC_DRAW);
      gl.vertexAttribPointer(vertexLocation, 2, gl.FLOAT, false, fsize * 5, 0);
      gl.enableVertexAttribArray(vertexLocation);

      //offset for color buffer
      gl.vertexAttribPointer(colorLocation, 3, gl.FLOAT, false, fsize * 5, fsize * 2);
      gl.enableVertexAttribArray(colorLocation);

      glLayer.redraw();

      return this;
    },
    resetVertices: function () {
      //empty verts and repopulate
      this.latLngLookup = {};
      this.verts = [];

      // -- data
      var verts = this.verts,
        settings = this.settings,
        data = settings.data,
        colorKey = settings.color,
        colorFn = null,
        color,
        i = 0,
        max = data.length,
        latLngLookup = this.latLngLookup,
        latLng,
        pixel,
        lookup,
        key;

      //see if colorKey is actually a function
      if (typeof colorKey === 'function') {
        colorFn = colorKey;
      }
      //we know that colorKey isn't a function, but L.glify.color[key] might be, check that here
      else {
        color = L.glify.color[colorKey] || colorKey;

        if (typeof color === 'function') {
          colorFn = color;
        }
      }
{'fraction_non_alphanumeric': 0.12783187120408754, 'fraction_numerical': 0.008290754844307337, 'mean_word_length': 2.0646971935007388, 'pattern_counts': {'":': 0, '<': 5, '<?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': '1965926', 'n_tokens_mistral': 3232, 'n_tokens_neox': 3120, 'n_words': 688}