<commit_before>/**
 * @file Memory chart rendering.
 */

'use strict';
var d3array = require('d3-array');
var d3axis = require('d3-axis');
var d3format = require('d3-format');
var d3shape = require('d3-shape');
var d3select = require('d3-selection');
var d3scale = require('d3-scale');

/**
 * Represents memory chart.
 * @constructor
 * @param {Object} parent - Parent element for memory chart.
 * @param {Object} data - Data for memory chart rendering.
 */
function MemoryChart(parent, data) {
  this.MARGIN_LEFT = 40;
  this.MARGIN_RIGHT = 5;
  this.MARGIN_TOP = 15;
  this.MARGIN_BOTTOM  = 30;
  this.PAD_SIZE = 10;
  this.MIN_RANGE_C = 0.98;
  this.MAX_RANGE_C = 1.02;
  this.MOUSE_X_OFFSET = 10;
  this.TICKS_NUMBER = 10;
  this.FOCUS_RADIUS = 5;
  this.DOT_RADIUS = 3;
  this.TOOLTIP_OFFSET = 35;
  this.SCALE_FACTOR = 3;
  this.MAX_ZOOM_POINTS = 20;
  this.HELP_MESSAGE = (
    '<p>&#8226 Click to zoom highlighted region</p>'+
    '<p>&#8226 Double click to restore original scale</p>');

  this.data_ = data;
  this.parent_ = parent;

  // Memory view div size should be specified in CSS to render
  // SVG graph correctly.
  this.memoryView_ = this.parent_.append('div')
    .attr('class', 'memory-info-container');
  this.objectsTable_ = this.memoryView_.append('div')
    .attr('class', 'memory-table-wrapper') // To display overflow correctly.
    .append('div')
    .attr('class', 'memory-objects-table');
  this.memoryUsageGraph_ = this.memoryView_.append('div')
    .attr('class', 'memory-usage-graph');

  this.TABLE_WIDTH = this.objectsTable_.node().scrollWidth;
  this.HEIGHT = this.memoryUsageGraph_.node().scrollHeight - this.PAD_SIZE;
  this.WIDTH = this.memoryUsageGraph_.node().scrollWidth - this.PAD_SIZE;
  this.GRAPH_HEIGHT = this.HEIGHT - (this.MARGIN_TOP + this.MARGIN_BOTTOM);
  this.GRAPH_WIDTH = this.TABLE_WIDTH + this.WIDTH - (
      this.MARGIN_LEFT + this.MARGIN_RIGHT);
  this.AXIS_TEXT_X = this.GRAPH_WIDTH - this.TABLE_WIDTH;
  this.AXIS_TEXT_Y = 12;
  this.AXIS_TEXT_Y_OFFSET = 30;
  this.LEGEND_X = this.GRAPH_WIDTH - 350;
  this.LEGEND_Y = 100;

  this.xScale_ = d3scale.scaleLinear()
    .domain(d3array.extent(this.data_.codeEvents, function(d) { return d[0]; }))
    .range([0, this.GRAPH_WIDTH]);

  this.xAxis_ = d3axis.axisBottom()
    .scale(this.xScale_)
    .ticks(this.TICKS_NUMBER)
    .tickFormat(d3format.format(',.0f'));

  // Since axis.ticks(n) is only a recommendation, set tick values
  // explicitly when their number is low.
  if (this.data_.codeEvents.length < this.TICKS_NUMBER) {
    var tickValues = Array.apply(null, Array(this.data_.codeEvents.length)).map(
      function (_, i) { return i + 1; });
    this.xAxis_.tickValues(tickValues);
  } else {
    this.xAxis_.ticks(this.TICKS_NUMBER);
  }

  this.yRange_ = d3array.extent(
      this.data_.codeEvents, function(d) { return d[2]; });
  this.yScale_ = d3scale.scaleLinear()<commit_msg>Refactor ticks assignment.<commit_after>/**
 * @file Memory chart rendering.
 */

'use strict';
var d3array = require('d3-array');
var d3axis = require('d3-axis');
var d3format = require('d3-format');
var d3shape = require('d3-shape');
var d3select = require('d3-selection');
var d3scale = require('d3-scale');

/**
 * Represents memory chart.
 * @constructor
 * @param {Object} parent - Parent element for memory chart.
 * @param {Object} data - Data for memory chart rendering.
 */
function MemoryChart(parent, data) {
  this.MARGIN_LEFT = 40;
  this.MARGIN_RIGHT = 5;
  this.MARGIN_TOP = 15;
  this.MARGIN_BOTTOM  = 30;
  this.PAD_SIZE = 10;
  this.MIN_RANGE_C = 0.98;
  this.MAX_RANGE_C = 1.02;
  this.MOUSE_X_OFFSET = 10;
  this.TICKS_NUMBER = 10;
  this.FOCUS_RADIUS = 5;
  this.DOT_RADIUS = 3;
  this.TOOLTIP_OFFSET = 35;
  this.SCALE_FACTOR = 3;
  this.MAX_ZOOM_POINTS = 20;
  this.HELP_MESSAGE = (
    '<p>&#8226 Click to zoom highlighted region</p>'+
    '<p>&#8226 Double click to restore original scale</p>');

  this.data_ = data;
  this.parent_ = parent;

  // Memory view div size should be specified in CSS to render
  // SVG graph correctly.
  this.memoryView_ = this.parent_.append('div')
    .attr('class', 'memory-info-container');
  this.objectsTable_ = this.memoryView_.append('div')
    .attr('class', 'memory-table-wrapper') // To display overflow correctly.
    .append('div')
    .attr('class', 'memory-objects-table');
  this.memoryUsageGraph_ = this.memoryView_.append('div')
    .attr('class', 'memory-usage-graph');

  this.TABLE_WIDTH = this.objectsTable_.node().scrollWidth;
  this.HEIGHT = this.memoryUsageGraph_.node().scrollHeight - this.PAD_SIZE;
  this.WIDTH = this.memoryUsageGraph_.node().scrollWidth - this.PAD_SIZE;
  this.GRAPH_HEIGHT = this.HEIGHT - (this.MARGIN_TOP + this.MARGIN_BOTTOM);
  this.GRAPH_WIDTH = this.TABLE_WIDTH + this.WIDTH - (
      this.MARGIN_LEFT + this.MARGIN_RIGHT);
  this.AXIS_TEXT_X = this.GRAPH_WIDTH - this.TABLE_WIDTH;
  this.AXIS_TEXT_Y = 12;
  this.AXIS_TEXT_Y_OFFSET = 30;
  this.LEGEND_X = this.GRAPH_WIDTH - 350;
  this.LEGEND_Y = 100;

  this.xScale_ = d3scale.scaleLinear()
    .domain(d3array.extent(this.data_.codeEvents, function(d) { return d[0]; }))
    .range([0, this.GRAPH_WIDTH]);

  this.xAxis_ = d3axis.axisBottom()
    .scale(this.xScale_)
    .ticks(this.TICKS_NUMBER)
    .tickFormat(d3format.format(',.0f'));

  // Set tick values explicitly when number of events is low.
  if (this.data_.codeEvents.length < this.TICKS_NUMBER) {
    var tickValues = [];
    for (var i = 0; i < this.data_.codeEvents.length; i++) {
      tickValues.push(i);
    }
    this.xAxis_.tickValues(tickValues);
  } else {
    this.xAxis_.ticks(this.TICKS_NUMBER);
  }

  this.yRange_ = d3array.extent(
      this.data_.codeEvents, function(d) { return d[2]; });
  this.yScale_ = d3scale.scaleLinear()
{'fraction_non_alphanumeric': 0.1482442483999308, 'fraction_numerical': 0.023179380729977512, 'mean_word_length': 3.723856209150327, 'pattern_counts': {'":': 0, '<': 14, '<?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': '3198009', 'n_tokens_mistral': 2223, 'n_tokens_neox': 2103, 'n_words': 411}