<commit_before>import Cell from "./cell";
import dimension from "./dimension";

function mesh() {
  var x = dimension().id("x"),
      y = dimension().id("y"),
      size = { x: 1, y: 0 },
      data = [[]];

  //TODO: appendRow/Col
  //TODO: a fancy .get(indices) that appends when out of bounds
  //TODO: fix indentation (damn vim :/)

  // Public - map data to a 2D array of cells
  //
  // Returns a 2D array of Cells
  var mesh = function() {
      var xs = x(size.x),
          ys = y(size.y);

      function mapColumn(col, i) {
          return col.map(
              function(data, j) {
                  return new Cell([xs[i], ys[j]], data);
              }
          );
      }

      return data.map(mapColumn);
  }


  // Public - set or get data
  // 
  // _ - new data (optional)
  //
  // Returns dimension or mesh
  //
  // Note: setter may store a modified value
  mesh.data = function(_) {
    return arguments.length ? (
      data = enclose(_),
      mesh
    ) : data;
  };

  // Public - set or get x attribute
  //
  // _ - new x value (optional)
  //
  // Returns dimension or mesh
  mesh.x = function(_) {
    return arguments.length ? (
      x = _,
      mesh
    ) : x;
  };

  // Public - set or get y attribute
  //
  // _ - new y value (optional)
  //
  // Returns dimension or mesh
  mesh.y = function(_) {
    return arguments.length ? (
      y = _,
      mesh
    ) : y;
  };

  // Private - get size of the enclosing array
  function enclosingSize(arr) {
    var x = arr.length;
    var y = Math.max.apply(
        0,
        arr.map(function(col) { return col.length; } )
    );
    return { x: x, y: y };
  }

  //Private - build an enclosing array from data
  //
  // arr - a 2D array (an array of columns)
  //
  // Returns a new 2d array
  function enclose(arr) {
    
    function fillColumn(col, targetLen) {
        var fill = new Array(targetLen - col.length).fill(null);
        return col.concat(fill);
    }

    size = enclosingSize(arr);

    return arr.map(
        function(col) { return fillColumn(col, size.y); }
    ); 
  }

  return mesh;
};

export default mesh;
<commit_msg>mesh stores xs and ys; added recompute()<commit_after>import Cell from "./cell";
import dimension from "./dimension";

function mesh() {
  var x = dimension().id("x"),
      y = dimension().id("y"),
      xs = [{ 'a': 0, 'b': 1 }],
      ys = [],
      data = [[]];

  //TODO: appendRow/Col
  //TODO: a fancy .get(indices) that appends when out of bounds
  //TODO: fix indentation (damn vim :/)

  // Public - map data to a 2D array of cells
  //
  // Returns a 2D array of Cells
  var mesh = function() {

      function mapColumn(col, i) {
          return col.map(
              function(data, j) {
                  return new Cell([xs[i], ys[j]], data);
              }
          );
      }

      return data.map(mapColumn);
  }


  // Public - set or get data
  // 
  // _ - new data (optional)
  //
  // Returns dimension or mesh
  //
  // Note: setter may store a modified value
  mesh.data = function(_) {
    return arguments.length ? (
      recompute(_),
      mesh
    ) : data;
  };

  // Public - set or get x attribute
  //
  // _ - new x value (optional)
  //
  // Returns dimension or mesh
  mesh.x = function(_) {
    return arguments.length ? (
      x = _,
      mesh
    ) : x;
  };

  // Public - set or get y attribute
  //
  // _ - new y value (optional)
  //
  // Returns dimension or mesh
  mesh.y = function(_) {
    return arguments.length ? (
      y = _,
      mesh
    ) : y;
  };

  // Private - get size of the enclosing array
  function enclosingSize(arr) {
    var x = arr.length;
    var y = Math.max.apply(
        0,
        arr.map(function(col) { return col.length; } )
    );
    return { x: x, y: y };
  }

  // Private - build an enclosing array from data
  //
  // arr - a 2D array (an array of columns)
  // size - an object { x: int, y: int }
  //
  // Returns a new 2d array
  function enclose(arr, size) {
    
    function fillColumn(col, targetLen) {
        var fill = new Array(targetLen - col.length).fill(null);
        return col.concat(fill);
    }

    return arr.map(
        function(col) { return fillColumn(col, size.y); }
    ); 
  }
  
  // Private - comopute all internal params to fit data
  //
  // arr - a 2D array
  function recompute(arr) {
     var size = enclosingSize(arr);

     data = enclose(arr, size);
     xs = x(size.x);
     ys = y(size.y);
  }

  return mesh;
};

export default mesh;

{'fraction_non_alphanumeric': 0.1408262994224789, 'fraction_numerical': 0.0033318525099955577, 'mean_word_length': 1.7591911764705883, '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': '167502', 'n_tokens_mistral': 1534, 'n_tokens_neox': 1467, 'n_words': 457}