<commit_before>var createClass = require('./../utilities/createClass');
var AttrValidators = require('./../utilities/attrValidators');
var Lang = require('./../utilities/lang');
var Graph = require('./graph');
var Parse = require('./../parse/parse');
var ParseError = require('./../parse/parseError');
var AutoLayout = require('./../layout/dummyLayout');

var GCLEditorModel = createClass({

  attrs: {

    text: {
      value: '',
      validator: Lang.isString,
      setter: function(val) {
        var parseResult = Parse(val);

        // Set the graph model if the parser made a new one.
        var newGraphModel = parseResult.model;
        if (newGraphModel !== null) {
          this._set('graph', newGraphModel);
        }

        this._set('errors', parseResult.gclErrors);

        return val;
      }
    },

    errors: {
      value: [],
      validator: AttrValidators.isArrayOf(ParseError)
    },

    graph: {
      value: new Graph({vertices: [], edges: []}),
      setter: function(val) {
        AutoLayout(val);
        this.get('graph').removeBubbleTarget(this);
        val.addBubbleTarget(this);
        return val;
      }
    }
  }
});

module.exports = GCLEditorModel;<commit_msg>Added auto layout step after move, pin, and unpin.<commit_after>var createClass = require('./../utilities/createClass');
var AttrValidators = require('./../utilities/attrValidators');
var Lang = require('./../utilities/lang');
var Graph = require('./graph');
var parse = require('./../parse/parse');
var ParseError = require('./../parse/parseError');
var autoLayout = require('./../layout/forceDirectedLayout');

var GCLEditorModel = createClass({

  constructor: function() {

    /**
     * Stop listening to layout changes made to the graph.
     */
    this._detachManualLayoutListeners = function() {
      if (this._positionChangedEventHandle) {
        this._positionChangedEventHandle.detach();
      }
      if (this._isPinnedChangedEventHandle) {
        this._isPinnedChangedEventHandle.detach();
      }
    }.bind(this);

    /**
     * Start listening to layout changes made to the graph, and perform
     * automatic layout each time there is one.
     */
    this._attachManualLayoutListeners = function(graph) {
      // TODO Pass in the moved element to _doAutomaticLayout. Also pass in whether the event was a pin, unpin, or move.
      this._positionChangedEventHandle = this.get('graph').after('positionChange', this._doAutomaticLayout);
      this._isPinnedChangedEventHandle = this.get('graph').after('isPinnedChange', this._doAutomaticLayout);
    }.bind(this);

    /**
     * Stop listening to the graph, then do the auto layout on it, then start
     * listening again.
     */
    this._doAutomaticLayout = function() {
      // TODO Perform the layout starting with the moved element.

      // Detach the change listeners in preparation for automatic layout.
      this._detachManualLayoutListeners();

      // Do the automatic layout.
      autoLayout(this.get('graph'));

      // Attach new listeners.
      this._attachManualLayoutListeners(this.get('graph'));

    }.bind(this);
  },

  attrs: {

    text: {
      value: '',
      validator: Lang.isString,
      setter: function(val) {
        var parseResult = parse(val);

        // Set the graph model if the parser made a new one.
        var newGraphModel = parseResult.model;
        if (newGraphModel !== null) {
          this._set('graph', newGraphModel);
          this._doAutomaticLayout();
        }

        this._set('errors', parseResult.gclErrors);

        return val;
      }
    },

    errors: {
      value: [],
      validator: AttrValidators.isArrayOf(ParseError)
    },

    graph: {
      value: new Graph({vertices: [], edges: []}),
      setter: function(val) {
        this.get('graph').removeBubbleTarget(this);
        val.addBubbleTarget(this);
        return val;
      }
    }
  }
});

module.exports = GCLEditorModel;
{'fraction_non_alphanumeric': 0.13743356112376615, 'fraction_numerical': 0.0, 'mean_word_length': 2.6390423572744015, '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': '5771854', 'n_tokens_mistral': 1127, 'n_tokens_neox': 1106, 'n_words': 271}