<commit_before>import constant from "./constant";

export default function(x, y) {
  var strength = constant(0.1),
      nodes,
      strengths,
      xz,
      yz;

  if (x == null) x = constant(0);
  if (y == null) y = constant(0);

  function force(alpha) {
    for (var i = 0, n = nodes.length, node, k; i < n; ++i) {
      node = nodes[i];
      k = strengths[i] * alpha;
      node.vx += (xz[i] - node.x) * k;
      node.vy += (yz[i] - node.y) * k;
    }
  }

  function initialize() {
    if (!nodes) return;
    var i, n = nodes.length;
    strengths = new Array(n);
    xz = new Array(n);
    yz = new Array(n);
    for (i = 0; i < n; ++i) {
      strengths[i] = +strength(nodes[i], i, nodes);
      xz[i] = +x(nodes[i], i, nodes);
      yz[i] = +y(nodes[i], i, nodes);
    }
  }<commit_msg>Fix position initialization.<commit_after>import constant from "./constant";

export default function(x, y) {
  var strength = constant(0.1),
      nodes,
      strengths,
      xz,
      yz;

  if (typeof x !== "function") x = constant(x == null ? 0 : +x);
  if (typeof y !== "function") y = constant(y == null ? 0 : +y);

  function force(alpha) {
    for (var i = 0, n = nodes.length, node, k; i < n; ++i) {
      node = nodes[i];
      k = strengths[i] * alpha;
      node.vx += (xz[i] - node.x) * k;
      node.vy += (yz[i] - node.y) * k;
    }
  }

  function initialize() {
    if (!nodes) return;
    var i, n = nodes.length;
    strengths = new Array(n);
    xz = new Array(n);
    yz = new Array(n);
    for (i = 0; i < n; ++i) {
      strengths[i] = +strength(nodes[i], i, nodes);
      xz[i] = +x(nodes[i], i, nodes);
      yz[i] = +y(nodes[i], i, nodes);
    }
  }
{'fraction_non_alphanumeric': 0.1937984496124031, 'fraction_numerical': 0.007155635062611807, 'mean_word_length': 2.21455938697318, 'pattern_counts': {'":': 0, '<': 7, '<?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': '7171886', 'n_tokens_mistral': 665, 'n_tokens_neox': 643, 'n_words': 184}