<commit_before>var _ = require('underscore');
var cdb = require('cartodb.js');
var formatter = require('../../formatter');
var HistogramTitleView = require('./histogram-title-view');
var HistogramChartView = require('./chart');
var placeholder = require('./placeholder.tpl');
var template = require('./content.tpl');
var DropdownView = require('../dropdown/widget-dropdown-view');
var AnimateValues = require('../animate-values.js');
var animationTemplate = require('./animation-template.tpl');

/**
 * Widget content view for a histogram
 */
module.exports = cdb.core.View.extend({
  className: 'CDB-Widget-body',

  defaults: {
    chartHeight: 48 + 20 + 4
  },

  events: {
    'click .js-clear': '_clear',
    'click .js-zoom': '_zoom'
  },

  initialize: function () {
    this._dataviewModel = this.model.dataviewModel;
    this.filter = this._dataviewModel.filter;
    this.lockedByUser = false;
    this._initBinds();
  },

  _initViews: function () {
    var titleView = new HistogramTitleView({
      widgetModel: this.model,
      dataviewModel: this._dataviewModel
    });

    this.$('.js-title').html(titleView.render().el);
    this.addView(titleView);

    var dropdown = new DropdownView({
      target: this.$('.js-actions'),
      container: this.$('.js-header')
    });

    dropdown.bind('click', function (action) {
      if (action === 'toggle') {
        this.model.set('collapsed', !this.model.get('collapsed'));
      }
    }, this);

    this.addView(dropdown);

    this._renderMiniChart();
    this._renderMainChart();
  },

  _initBinds: function () {
    this._dataviewModel.once('change:data', this._onFirstLoad, this);
    this.model.bind('change:collapsed', this.render, this);
  },

  _onFirstLoad: function () {
    this.render();
    this._storeBounds();

    this._dataviewModel.bind('change:data', this._onHistogramDataChanged, this);
    this.add_related_model(this._dataviewModel);
    this._dataviewModel.fetch();
  },

  _storeBounds: function () {
    var data = this._dataviewModel.getData();
    if (data && data.length > 0) {
      this.start = data[0].start;
      this.end = data[data.length - 1].end;
    }
  },

  _isZoomed: function () {
    return this.model.get('zoomed');
  },

  _onHistogramDataChanged: function () {
    // When the histogram is zoomed, we don't need to rely
    // on the change url to update the histogram
    // TODO the widget should not know about the URL… could this state be got from the dataview model somehow?
    if (this._dataviewModel.changed.url && this._isZoomed()) {
      return;
    }

    // if the action was initiated by the user
    // don't replace the stored data
    if (this.lockedByUser) {<commit_msg>Removed unnecesary storeBounds method<commit_after>var _ = require('underscore');
var cdb = require('cartodb.js');
var formatter = require('../../formatter');
var HistogramTitleView = require('./histogram-title-view');
var HistogramChartView = require('./chart');
var placeholder = require('./placeholder.tpl');
var template = require('./content.tpl');
var DropdownView = require('../dropdown/widget-dropdown-view');
var AnimateValues = require('../animate-values.js');
var animationTemplate = require('./animation-template.tpl');

/**
 * Widget content view for a histogram
 */
module.exports = cdb.core.View.extend({
  className: 'CDB-Widget-body',

  defaults: {
    chartHeight: 48 + 20 + 4
  },

  events: {
    'click .js-clear': '_clear',
    'click .js-zoom': '_zoom'
  },

  initialize: function () {
    this._dataviewModel = this.model.dataviewModel;
    this.filter = this._dataviewModel.filter;
    this.lockedByUser = false;
    this._initBinds();
  },

  _initViews: function () {
    var titleView = new HistogramTitleView({
      widgetModel: this.model,
      dataviewModel: this._dataviewModel
    });

    this.$('.js-title').html(titleView.render().el);
    this.addView(titleView);

    var dropdown = new DropdownView({
      target: this.$('.js-actions'),
      container: this.$('.js-header')
    });

    dropdown.bind('click', function (action) {
      if (action === 'toggle') {
        this.model.set('collapsed', !this.model.get('collapsed'));
      }
    }, this);

    this.addView(dropdown);

    this._renderMiniChart();
    this._renderMainChart();
  },

  _initBinds: function () {
    this._dataviewModel.once('change:data', this._onFirstLoad, this);
    this.model.bind('change:collapsed', this.render, this);
  },

  _onFirstLoad: function () {
    this.render();

    this._dataviewModel.bind('change:data', this._onHistogramDataChanged, this);
    this.add_related_model(this._dataviewModel);
    this._dataviewModel.fetch();
  },

  _isZoomed: function () {
    return this.model.get('zoomed');
  },

  _onHistogramDataChanged: function () {
    // When the histogram is zoomed, we don't need to rely
    // on the change url to update the histogram
    // TODO the widget should not know about the URL… could this state be got from the dataview model somehow?
    if (this._dataviewModel.changed.url && this._isZoomed()) {
      return;
    }

    // if the action was initiated by the user
    // don't replace the stored data
    if (this.lockedByUser) {
{'fraction_non_alphanumeric': 0.15461538461538463, 'fraction_numerical': 0.0025, 'mean_word_length': 3.3019023986765923, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, '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': '4136752', 'n_tokens_mistral': 1645, 'n_tokens_neox': 1588, 'n_words': 358}