<commit_before>import Transform from '../Transform';
import {error} from '../util/Errors';
import {array, inherits, isFunction} from 'vega-util';
import {map} from 'd3-collection';
import {
  forceSimulation, forceCenter, forceCollide,
  forceManyBody, forceLink, forceX, forceY
} from 'd3-force';

var FORCE_MAP = map()
  .set('center', forceCenter)
  .set('collide', forceCollide)
  .set('nbody', forceManyBody)
  .set('link', forceLink)
  .set('x', forceX)
  .set('y', forceY);

var FORCES = 'forces',
    PARAMS = ['alpha', 'alphaMin', 'alphaTarget', 'drag', 'forces'],
    CONFIG = ['static', 'iterations'],
    FIELDS = ['x', 'y', 'vx', 'vy'];

/**
 * Force simulation layout.
 * @constructor
 * @param {object} params - The parameters for this operator.
 * @param {Array<object>} params.forces - The forces to apply.
 */
export default function Force(params) {
  Transform.call(this, null, params);
}

var prototype = inherits(Force, Transform);

prototype.transform = function(_, pulse) {
  var sim = this.value,
      change = pulse.changed(pulse.ADD_REM),
      params = _.modified(PARAMS),
      iters = _.iterations || 300;

  // configure simulation
  if (!sim) {
    this.value = sim = simulation(pulse.source, _);
    sim.on('tick', rerun(pulse.dataflow, this));
    if (!_.static) change = true, sim.tick(); // ensure we run on init
    pulse.modifies('index');
  } else {
    if (change) pulse.modifies('index'), sim.nodes(pulse.source);
    if (params) setup(sim, _);
  }

  // fix / unfix nodes as needed
  if (_.modified('fixed')) {
    sim.unfixAll();
    array(_.fixed).forEach(function(t) { sim.fix(t); });
  }

  // run simulation
  if (params || change || pulse.changed() || _.modified(CONFIG)) {
    sim.alpha(Math.max(sim.alpha(), _.alpha || 1))
       .alphaDecay(1 - Math.pow(sim.alphaMin(), 1 / iters));<commit_msg>Update Force to d3-force 1.0 API.<commit_after>import Transform from '../Transform';
import {error} from '../util/Errors';
import {array, inherits, isFunction} from 'vega-util';
import {map} from 'd3-collection';
import {
  forceSimulation, forceCenter, forceCollide,
  forceManyBody, forceLink, forceX, forceY
} from 'd3-force';

var FORCE_MAP = map()
  .set('center', forceCenter)
  .set('collide', forceCollide)
  .set('nbody', forceManyBody)
  .set('link', forceLink)
  .set('x', forceX)
  .set('y', forceY);

var FORCES = 'forces',
    PARAMS = ['alpha', 'alphaMin', 'alphaTarget', 'velocityDecay', 'drag', 'forces'],
    CONFIG = ['static', 'iterations'],
    FIELDS = ['x', 'y', 'vx', 'vy', 'fx', 'fy'];

/**
 * Force simulation layout.
 * @constructor
 * @param {object} params - The parameters for this operator.
 * @param {Array<object>} params.forces - The forces to apply.
 */
export default function Force(params) {
  Transform.call(this, null, params);
}

var prototype = inherits(Force, Transform);

prototype.transform = function(_, pulse) {
  var sim = this.value,
      change = pulse.changed(pulse.ADD_REM),
      params = _.modified(PARAMS),
      iters = _.iterations || 300;

  // configure simulation
  if (!sim) {
    this.value = sim = simulation(pulse.source, _);
    sim.on('tick', rerun(pulse.dataflow, this));
    if (!_.static) change = true, sim.tick(); // ensure we run on init
    pulse.modifies('index');
  } else {
    if (change) pulse.modifies('index'), sim.nodes(pulse.source);
    if (params) setup(sim, _);
  }

  // fix / unfix nodes as needed
  if (_.modified('fixed')) {
    sim.nodes().forEach(function(t) { t.fx = null; t.fy = null; });
    array(_.fixed).forEach(function(t) { t.fx = t.x; t.fy = t.y; });
  }

  // run simulation
  if (params || change || pulse.changed() || _.modified(CONFIG)) {
    sim.alpha(Math.max(sim.alpha(), _.alpha || 1))
       .alphaDecay(1 - Math.pow(sim.alphaMin(), 1 / iters));
{'fraction_non_alphanumeric': 0.18294287970518558, 'fraction_numerical': 0.005001316135825217, 'mean_word_length': 3.628501827040195, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '4583743', 'n_tokens_mistral': 1304, 'n_tokens_neox': 1255, 'n_words': 326}