<commit_before>var globals = require('../globals'),
  util = require('../util'),
  schema = require('../schema/schema');

module.exports = {
  setSize: setSize
};

function getCardinality(encoding, encType, stats) {
  var field = encoding.fieldName(encType);
  if (encoding.bin(encType)) {
    var bins = util.getbins(stats[field]);
    return (bins.stop - bins.start) / bins.step;
  }
  return stats[field].cardinality;
}

function setSize(encoding, stats) {
  var hasRow = encoding.has(ROW),
      hasCol = encoding.has(COL),
      hasX = encoding.has(X),
      hasY = encoding.has(Y);

  // HACK to set chart size
  // NOTE: this fails for plots driven by derived values (e.g., aggregates)
  // One solution is to update Vega to support auto-sizing
  // In the meantime, auto-padding (mostly) does the trick
  //
  var colCardinality = hasCol ? getCardinality(encoding, COL, stats) : 1,
    rowCardinality = hasRow ? getCardinality(encoding, ROW, stats) : 1;

  var cellWidth = hasX ?
      +encoding.config('cellWidth') || encoding.config('width') * 1.0 / colCardinality :
      encoding.marktype() === 'text' ?
        +encoding.config('textCellWidth') :
        schema.band.properties.size.default,
    cellHeight = hasY ?
      +encoding.config('cellHeight') || encoding.config('height') * 1.0 / rowCardinality :
      schema.band.properties.size.default,
    cellPadding = encoding.config('cellPadding'),
    bandPadding = encoding.config('bandPadding'),
    width = encoding.config('_minWidth'),
    height = encoding.config('_minHeight');

  if (hasX && (encoding.isType(X, O) || encoding.bin(X))) { //ordinal field will override parent
    // bands within cell use rangePoints()
    var xCardinality = getCardinality(encoding, X, stats);
    cellWidth = (xCardinality + bandPadding) * +encoding.config('bandSize');
  }
  // Cell bands use rangeBands(). There are n-1 padding.  Outerpadding = 0 for cells
  width = cellWidth * ((1 + cellPadding) * (colCardinality - 1) + 1);

  if (hasY && (encoding.isType(Y, O) || encoding.bin(Y))) {
    // bands within cell use rangePoint()
    var yCardinality = getCardinality(encoding, Y, stats);
    cellHeight = (yCardinality + bandPadding) * +encoding.config('bandSize');
  }
  // Cell bands use rangeBands(). There are n-1 padding.  Outerpadding = 0 for cells
  height = cellHeight * ((1 + cellPadding) * (rowCardinality - 1) + 1);

  return {
    cellWidth: cellWidth,<commit_msg>remove `_minWidth` access since they have been removed from the config for a long time<commit_after>var globals = require('../globals'),
  util = require('../util'),
  schema = require('../schema/schema');

module.exports = {
  setSize: setSize
};

function getCardinality(encoding, encType, stats) {
  var field = encoding.fieldName(encType);
  if (encoding.bin(encType)) {
    var bins = util.getbins(stats[field]);
    return (bins.stop - bins.start) / bins.step;
  }
  return stats[field].cardinality;
}

function setSize(encoding, stats) {
  var hasRow = encoding.has(ROW),
      hasCol = encoding.has(COL),
      hasX = encoding.has(X),
      hasY = encoding.has(Y);

  // HACK to set chart size
  // NOTE: this fails for plots driven by derived values (e.g., aggregates)
  // One solution is to update Vega to support auto-sizing
  // In the meantime, auto-padding (mostly) does the trick
  //
  var colCardinality = hasCol ? getCardinality(encoding, COL, stats) : 1,
    rowCardinality = hasRow ? getCardinality(encoding, ROW, stats) : 1;

  var cellWidth = hasX ?
      +encoding.config('cellWidth') || encoding.config('width') * 1.0 / colCardinality :
      encoding.marktype() === 'text' ?
        +encoding.config('textCellWidth') :
        schema.band.properties.size.default,
    cellHeight = hasY ?
      +encoding.config('cellHeight') || encoding.config('height') * 1.0 / rowCardinality :
      schema.band.properties.size.default,
    cellPadding = encoding.config('cellPadding'),
    bandPadding = encoding.config('bandPadding');

  if (hasX && (encoding.isType(X, O) || encoding.bin(X))) { //ordinal field will override parent
    // bands within cell use rangePoints()
    var xCardinality = getCardinality(encoding, X, stats);
    cellWidth = (xCardinality + bandPadding) * +encoding.config('bandSize');
  }
  // Cell bands use rangeBands(). There are n-1 padding.  Outerpadding = 0 for cells
  var width = cellWidth * ((1 + cellPadding) * (colCardinality - 1) + 1);

  if (hasY && (encoding.isType(Y, O) || encoding.bin(Y))) {
    // bands within cell use rangePoint()
    var yCardinality = getCardinality(encoding, Y, stats);
    cellHeight = (yCardinality + bandPadding) * +encoding.config('bandSize');
  }
  // Cell bands use rangeBands(). There are n-1 padding.  Outerpadding = 0 for cells
  var height = cellHeight * ((1 + cellPadding) * (rowCardinality - 1) + 1);

  return {
    cellWidth: cellWidth,
{'fraction_non_alphanumeric': 0.14224049331963, 'fraction_numerical': 0.0065775950668037, 'mean_word_length': 3.5097312326227987, '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': '2719991', 'n_tokens_mistral': 1559, 'n_tokens_neox': 1512, 'n_words': 403}