<commit_before>/**
 * Child Class
 *
 * Defines a visualization child.
 *
 * Options:
 *  height - Integer
 *  width - Integer
 *  flotr - A set of flotr options
 */
(function () { 

var

  V = Humble.Vis,

  CN_CHILD = 'humble-vis-child',

  T_CHILD       = '<div class="' + CN_CHILD + '"></div>',
  T_CONTAINER   = '<div class="' + CN_CHILD + '-container"></div>',

  DEFAULTS = Humble.Vis.flotr.defaultOptions;

function Child(options) {

  this.options    = options || {};
  this.container  = bonzo.create(T_CONTAINER)[0];
  this.node       = bonzo.create(T_CHILD);

  if (options.name) bonzo(this.node).addClass(options.name);
  bonzo(this.node).append(this.container);

  this.flotr = null;
  this._flotrDefaultOptions();
}

Child.prototype = {

  getFlotr : function () { return this.flotr; },
  getData : function () { return this.options.data; },

  render : function (element) {

    var o = this.options;

    if (!element) throw 'No element to render within.';
    if (!o.width) throw 'No width.';
    if (!o.height) throw 'No height.';

    bonzo(element).append(this.node);
    bonzo(this.container).css({width : o.width, height : o.height});

    this.draw(o.data, o.flotr);
  },

  draw : function (data, flotr) {

    var
      o           = this.options,
      flotr       = _.clone(flotr),
      data        = data || o.data,
      fData       = [],
      container   = this.container;

    if (flotr) {
      _.extend(o.flotr, flotr);
      this._flotrDefaultOptions(flotr);
    }
    flotr = o.flotr;
    o.data = data;
    min = flotr.xaxis.min;
    max = flotr.xaxis.max;

    data = this._getDataArray(data);
    if (o.skipPreprocess) {
      fData = data;
    } else {
      _.each(data, function (d, index) {
        if (!_.isArray(d)) {
          fData[index] = _.clone(d);
          fData[index] = this._processData(d.data);
        } else {
          fData[index] = this._processData(d);
        }
      }, this);
    }

    if (!flotr) throw 'No graph submitted.'

    this.flotr = Flotr.draw(container, fData, flotr);
  },

  getNode : function () {
    return this.node;
  },

  _processData : function (data) {

    var
      resolution  = this.options.width,
      axis        = this.options.flotr.xaxis,
      min         = axis.min,
      max         = axis.max,
      datum       = new V.Data(data);

    datum
      .bound(min, max)
      .subsampleMinMax(resolution);

    return datum.data;
  },

  _getDataArray : function (data) {

    if (data[0] && (!_.isArray(data[0]) || (data[0][0] && _.isArray(data[0][0]))))
      return data;
    else
      return [data];
  },

  _flotrDefaultOptions : function (options) {

    var o = options || this.options.flotr,
      i;

    for (i in DEFAULTS) {
      if (_.isUndefined(o[i])) {
        o[i] = DEFAULTS[i];
      } else {
        _.defaults(o[i], DEFAULTS[i]);
      }
    }
  }
};

Humble.Vis.Child = Child;

})();
<commit_msg>Made data processing configurable.<commit_after>/**
 * Child Class
 *
 * Defines a visualization child.
 *
 * Options:
 *  height - Integer
 *  width - Integer
 *  flotr - A set of flotr options
 */
(function () { 

var

  V = Humble.Vis,

  CN_CHILD = 'humble-vis-child',

  T_CHILD       = '<div class="' + CN_CHILD + '"></div>',
  T_CONTAINER   = '<div class="' + CN_CHILD + '-container"></div>',

  DEFAULTS = Humble.Vis.flotr.defaultOptions;

function Child(options) {

  this.options    = options || {};
  this.container  = bonzo.create(T_CONTAINER)[0];
  this.node       = bonzo.create(T_CHILD);

  if (options.name) bonzo(this.node).addClass(options.name);
  bonzo(this.node).append(this.container);

  this.flotr = null;
  this._flotrDefaultOptions();
}

Child.prototype = {

  getFlotr : function () { return this.flotr; },
  getData : function () { return this.options.data; },

  render : function (element) {

    var o = this.options;

    if (!element) throw 'No element to render within.';
    if (!o.width) throw 'No width.';
    if (!o.height) throw 'No height.';

    bonzo(element).append(this.node);
    bonzo(this.container).css({width : o.width, height : o.height});

    this.draw(o.data, o.flotr);
  },

  draw : function (data, flotr) {

    var
      o           = this.options,
      flotr       = _.clone(flotr),
      data        = data || o.data,
      fData       = [],
      container   = this.container;

    if (flotr) {
      _.extend(o.flotr, flotr);
      this._flotrDefaultOptions(flotr);
    }
    flotr = o.flotr;
    o.data = data;
    min = flotr.xaxis.min;
    max = flotr.xaxis.max;

    data = this._getDataArray(data);
    if (o.skipPreprocess) {
      fData = data;
    } else {
      _.each(data, function (d, index) {
        if (!_.isArray(d)) {
          fData[index] = _.clone(d);
          fData[index] = this._processData(d.data);
        } else {
          fData[index] = this._processData(d);
        }
      }, this);
    }

    if (!flotr) throw 'No graph submitted.'

    this.flotr = Flotr.draw(container, fData, flotr);
  },

  getNode : function () {
    return this.node;
  },

  _processData : function (data) {

    var
      options     = this.options,
      process     = options.processData,
      resolution  = options.width,
      axis        = options.flotr.xaxis,
      min         = axis.min,
      max         = axis.max,
      datum       = new V.Data(data);

    if (process) {
      process.apply(this, [{
        datum : datum,
        min : min,
        max : max,
        resolution : resolution
      }]);
    } else {
      datum
        .bound(min, max)
        .subsampleMinMax(resolution);
    }

    return datum.data;
  },

  _getDataArray : function (data) {

    if (data[0] && (!_.isArray(data[0]) || (data[0][0] && _.isArray(data[0][0]))))
      return data;
    else
      return [data];
  },

  _flotrDefaultOptions : function (options) {

    var o = options || this.options.flotr,
      i;

    for (i in DEFAULTS) {
      if (_.isUndefined(o[i])) {
        o[i] = DEFAULTS[i];
      } else {
        _.defaults(o[i], DEFAULTS[i]);
      }
    }
  }
};

Humble.Vis.Child = Child;

})();

{'fraction_non_alphanumeric': 0.1574635425200721, 'fraction_numerical': 0.002293953793216451, 'mean_word_length': 2.1366906474820144, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '6672381', 'n_tokens_mistral': 2226, 'n_tokens_neox': 2168, 'n_words': 437}