<commit_before>
cdb.admin.Visualization = cdb.core.Model.extend({

  defaults: {
    bindMap: true
  },

  urlRoot: '/api/v1/viz',

  INHERIT_TABLE_ATTRIBUTES: [
    'name', 'privacy'
  ],

  initialize: function() {
    this.map = new cdb.admin.Map();

    if (this.get('bindMap')) this._bindMap();
    this.on(_(this.INHERIT_TABLE_ATTRIBUTES).map(function(t) { return 'change:' + t }).join(' '),  this._changeAttributes, this);
  },

  _bindMap: function() {

    this.on('change:map_id', this._fetchMap, this);

    this.map.bind('change:id', function() {
      this.set('map_id', this.map.id);
    }, this);

    this.map.set('id', this.get('map_id'));

  },

  viewUrl: function() {
    return "/viz/" + this.id + "/";
  },

  /**
   *  Is this model a true visualization?
   */
  isVisualization: function() {
    return this.get('type') === "derived";
  },

  /**
   * change current visualization by new one without
   * creating a new instance
   */
  changeTo: function(new_vis, callbacks) {
    this.set(new_vis.attributes, { silent: true });
    
    var func_success = function() {
      this.map.layers.unbind('reset', func_success);
      this.map.layers.unbind('error', func_error);
      callbacks && callbacks.success && callbacks.success(this);
    };

    var func_error = function() {
      this.map.layers.unbind('reset', func_success);
      this.map.layers.unbind('error', func_error);
      callbacks && callbacks.error && callbacks.error();
    }

    this.map.layers.bind('reset', func_success, this);
    this.map.layers.bind('error', func_error, this)
    this.set({ map_id: new_vis.map.id });
  },

  /**<commit_msg>changed changeToVis function in vis model<commit_after>
cdb.admin.Visualization = cdb.core.Model.extend({

  defaults: {
    bindMap: true
  },

  urlRoot: '/api/v1/viz',

  INHERIT_TABLE_ATTRIBUTES: [
    'name', 'privacy'
  ],

  initialize: function() {
    this.map = new cdb.admin.Map();

    if (this.get('bindMap')) this._bindMap();
    this.on(_(this.INHERIT_TABLE_ATTRIBUTES).map(function(t) { return 'change:' + t }).join(' '),  this._changeAttributes, this);
  },

  _bindMap: function() {

    this.on('change:map_id', this._fetchMap, this);

    this.map.bind('change:id', function() {
      this.set('map_id', this.map.id);
    }, this);

    this.map.set('id', this.get('map_id'));

  },

  viewUrl: function() {
    return "/viz/" + this.id + "/";
  },

  /**
   *  Is this model a true visualization?
   */
  isVisualization: function() {
    return this.get('type') === "derived";
  },

  /**
   *  Change current visualization by new one without
   *  creating a new instance.
   *
   *  When turn table visualization to derived visualization,
   *  it needs to wait until reset layers. If not, adding a new
   *  layer after create the new visualization won't work...
   *
   */
  changeTo: function(new_vis, callbacks) {
    this.set(new_vis.attributes, { silent: true });
    
    var success = function() {
      this.map.layers.unbind('reset', success);
      this.map.layers.unbind('error', error);
      callbacks && callbacks.success && callbacks.success(this);
    };

    var error = function() {
      this.map.layers.unbind('reset', success);
      this.map.layers.unbind('error', error);
      callbacks && callbacks.error && callbacks.error();
    }

    this.map.layers.bind('reset', success, this);
    this.map.layers.bind('error', error, this)
    this.set({ map_id: new_vis.map.id });
  },

  /**
{'fraction_non_alphanumeric': 0.17270114942528736, 'fraction_numerical': 0.0005747126436781609, 'mean_word_length': 3.0149942329873127, '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': '6192153', 'n_tokens_mistral': 1205, 'n_tokens_neox': 1163, 'n_words': 232}