<commit_before>/* ========================================================================
 *                         GitGraph v0.1.0
 *             https://github.com/nicoespeon/gitgraph.js
 * ========================================================================
 * Copyright (c) 2013 <NAME> (@nicoespeon) ٩(^‿^)۶
 * Copyright (c) 2013 <NAME> (@fabien0102) ✌(✰‿✰)✌
 *
 * GitGraph.js may be freely distributed under the MIT Licence
 * ======================================================================== */

/**
 * GitGraph
 *
 * @constructor
 *
 * @param {Object} options - GitGraph options
 * @param {String} [options.elementId = 'gitGraph'] - Id of <canvas> container
 * @param {Template} [options.template] - Template, default template if nothing here
 * @param {String} [options.author = '<NAME> <<EMAIL>>'] - Default author for commits
 *
 * @this GitGraph
 **/
function GitGraph(options) {
  // Options
  options = (typeof options === 'object') ?
    options : {};
  this.elementId = (typeof options.elementId === 'string') ?
    options.elementId : "gitGraph";
  this.author = (typeof options.author === 'string') ?
    options.author : '<NAME> <<EMAIL>>';
  
  // Template gestion
  if (typeof options.template === 'string') options.template =  new Template().get(options.template);
  this.template = (options.template instanceof Template) ?
    options.template : new Template();

  // Canvas init
  this.canvas = document.getElementById(this.elementId);
  this.context = this.canvas.getContext('2d');

  // Navigations vars
  this.HEAD = null;
  this.branchs = [];

  // Utilities
  this.columnMax = 0; // nb of column for message position
  this.commitOffsetX = 0;
  this.commitOffsetY = 0;

  // Error: no render()
  this.context.fillStyle = 'red';
  this.context.font = 'bold 15pt Calibri';
  this.context.fillText('Error: No render() at the end', 150, 100);
}

/**
 * Create new branch
 *
 * @param {(String | Object)} options - Branch name | Options of Branch
 * @see Branch
 * @this GitGraph
 **/
GitGraph.prototype.branch = function (options) {
  // Options
  if (typeof (options) == 'string') {
    var name = options;
    options = {};
    options.name = name;
  }

  options = (typeof options === 'object') ? options : {};
  options.parent = this;
  options.parentBranch = options.parentBranch || this.HEAD;

  // Calcul origin of branch
  if (options.parentBranch instanceof Branch) {
    options.originX = options.parentBranch.commits[options.parentBranch.commits.length - 1].x - this.template.commit.spacingX - options.parentBranch.offsetX;
    options.originY = options.parentBranch.commits[options.parentBranch.commits.length - 1].y - this.template.commit.spacingY - options.parentBranch.offsetY;
  }

  // Add branch
  var branch = new Branch(options);
  this.branchs.push(branch);

  // Return
  return branch;
};

/**
 * Commit on HEAD
 *
 * @param {Object} options - Options of commit
 * @see Commit
 * @this GitGraph
 **/
GitGraph.prototype.commit = function (options) {
  this.HEAD.commit(options);
};

/**
 * Render the canvas
 *
 * @this GitGraph
 **/
GitGraph.prototype.render = function () {
  // Resize canvas
  this.canvas.height = this.branchs[0].updateSize().height || this.branchs[this.branchs.length - 1].offsetY + this.template.commit.dot.size * 3;
  this.canvas.width = this.branchs[0].updateSize().width || 1000;

  // Clear All
  this.context.clearRect(0, 0, this.canvas.width, this.canvas.height);

  // Add some margin
  this.context.translate(this.template.commit.dot.size * 2, this.template.commit.dot.size * 2);

  // Translate for inverse orientation
  if (this.template.commit.spacingY > 0)
    this.context.translate(0, this.canvas.height - this.template.commit.dot.size * 3);<commit_msg>Little enhancement on commit() method: chaining (for HEAD operations)<commit_after>/* ========================================================================
 *                         GitGraph v0.1.0
 *             https://github.com/nicoespeon/gitgraph.js
 * ========================================================================
 * Copyright (c) 2013 <NAME> (@nicoespeon) ٩(^‿^)۶
 * Copyright (c) 2013 <NAME> (@fabien0102) ✌(✰‿✰)✌
 *
 * GitGraph.js may be freely distributed under the MIT Licence
 * ======================================================================== */

/**
 * GitGraph
 *
 * @constructor
 *
 * @param {Object} options - GitGraph options
 * @param {String} [options.elementId = 'gitGraph'] - Id of <canvas> container
 * @param {Template} [options.template] - Template, default template if nothing here
 * @param {String} [options.author = '<NAME> <<EMAIL>>'] - Default author for commits
 *
 * @this GitGraph
 **/
function GitGraph(options) {
  // Options
  options = (typeof options === 'object') ?
    options : {};
  this.elementId = (typeof options.elementId === 'string') ?
    options.elementId : "gitGraph";
  this.author = (typeof options.author === 'string') ?
    options.author : '<NAME> <<EMAIL>>';
  
  // Template gestion
  if (typeof options.template === 'string') options.template =  new Template().get(options.template);
  this.template = (options.template instanceof Template) ?
    options.template : new Template();

  // Canvas init
  this.canvas = document.getElementById(this.elementId);
  this.context = this.canvas.getContext('2d');

  // Navigations vars
  this.HEAD = null;
  this.branchs = [];

  // Utilities
  this.columnMax = 0; // nb of column for message position
  this.commitOffsetX = 0;
  this.commitOffsetY = 0;

  // Error: no render()
  this.context.fillStyle = 'red';
  this.context.font = 'bold 15pt Calibri';
  this.context.fillText('Error: No render() at the end', 150, 100);
}

/**
 * Create new branch
 *
 * @param {(String | Object)} options - Branch name | Options of Branch
 * @see Branch
 * @this GitGraph
 **/
GitGraph.prototype.branch = function (options) {
  // Options
  if (typeof (options) == 'string') {
    var name = options;
    options = {};
    options.name = name;
  }

  options = (typeof options === 'object') ? options : {};
  options.parent = this;
  options.parentBranch = options.parentBranch || this.HEAD;

  // Calcul origin of branch
  if (options.parentBranch instanceof Branch) {
    options.originX = options.parentBranch.commits[options.parentBranch.commits.length - 1].x - this.template.commit.spacingX - options.parentBranch.offsetX;
    options.originY = options.parentBranch.commits[options.parentBranch.commits.length - 1].y - this.template.commit.spacingY - options.parentBranch.offsetY;
  }

  // Add branch
  var branch = new Branch(options);
  this.branchs.push(branch);

  // Return
  return branch;
};

/**
 * Commit on HEAD
 *
 * @param {Object} options - Options of commit
 * @return {GitGraph} this - Return the main object so we can chain
 * @see Commit
 * @this GitGraph
 **/
GitGraph.prototype.commit = function (options) {
  this.HEAD.commit(options);
  
  // Return the main object so we can chain
  return this;
};

/**
 * Render the canvas
 *
 * @this GitGraph
 **/
GitGraph.prototype.render = function () {
  // Resize canvas
  this.canvas.height = this.branchs[0].updateSize().height || this.branchs[this.branchs.length - 1].offsetY + this.template.commit.dot.size * 3;
  this.canvas.width = this.branchs[0].updateSize().width || 1000;

  // Clear All
  this.context.clearRect(0, 0, this.canvas.width, this.canvas.height);

  // Add some margin
  this.context.translate(this.template.commit.dot.size * 2, this.template.commit.dot.size * 2);

  // Translate for inverse orientation
  if (this.template.commit.spacingY > 0)
    this.context.translate(0, this.canvas.height - this.template.commit.dot.size * 3);
{'fraction_non_alphanumeric': 0.19820406038521604, 'fraction_numerical': 0.011972930765226444, 'mean_word_length': 3.618389423076923, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 23, 'https://': 2, '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': '4762540', 'n_tokens_mistral': 2407, 'n_tokens_neox': 2292, 'n_words': 558}