<commit_before>/* -*- mode: espresso; espresso-indent-level: 2; indent-tabs-mode: nil -*- */
/* vim: set softtabstop=2 shiftwidth=2 tabstop=2 expandtab: */

/** Namespace where Node instances are created and edited. */
var SkeletonElements = new function()
{
  var active_skeleton_color = "rgb(255,255,0)";
  var inactive_skeleton_color = "rgb(255,0,255)";
  var inactive_skeleton_color_above = "rgb(0,0,255)";
  var inactive_skeleton_color_below = "rgb(255,0,0)";
  var root_node_color = "rgb(255, 0, 0)";

  var TYPE_NODE = "treenode";
  var TYPE_CONNECTORNODE = "location"; // TODO update the name in the PHP files

  var CATCH_RADIUS = 8;

  /** Constructor for Node instances. */
  this.Node = function(
    id, // unique id for the node from the database
    paper, // the raphael paper this node is drawn to
    parent, // the parent node
    r, // the radius
    x, // the x coordinate in pixel coordinates
    y, // y coordinates
    z, // z coordinates
    zdiff, // the different from the current slices
    skeleton_id,
    is_root_node) // the id of the skeleton this node is an element of
  {
    this.id = id;
    this.type = TYPE_NODE;
    this.paper = paper;
    this.parent = parent;
    this.children = {};
    this.connectors = {};
    this.r = r < 0 ? 3 : r;
    this.x = x;
    this.y = y;
    this.z = z;
    this.zdiff = zdiff;
    this.skeleton_id = skeleton_id;
    this.isroot = is_root_node;
    this.fillcolor = inactive_skeleton_color;
    this.c = null; // The Raphael circle for drawing
    this.mc = null; // The Raphael circle for mouse actions (it's a bit larger)
    this.line = is_root_node ? null : paper.path(); // The Raphael line element that represents an edge between nodes

    // The member functions:
    this.setXY = setXY;
    this.drawEdges = nodeDrawEdges;
    this.drawLineToParent = nodeDrawLineToParent;
    this.draw = nodeDraw;
    this.deleteall = nodeDeleteAll;
    this.deletenode = nodeDelete;
    this.setColor = setColor;
    this.colorFromZDiff = nodeColorFromZDiff;
    this.createCircle = createCircle;

    // Init block
    // 1. Add this node to the parent's children if it exists
    if (parent) this.children[id] = this;
  };

  /** Trigger the redrawing of the lines with parent, children and connectors.
   * Here, 'this' is the node, given that it is called in the context of the node only.
   */
  var nodeDrawEdges = function(toChildren) {
    var i;
    if (toChildren) {
      for (i in this.children) {
        if (this.children.hasOwnProperty(i)) {
          this.children[i].drawLineToParent();
        }
      }
    }

    for (i in this.connectors) {
      if (this.children.hasOwnProperty(i)) {
        // should update the connector paths
        this.connectors[i].drawEdges();
      }
    }
    if (this.parent !== null) {
      this.drawLineToParent();
    }
  };

  /** Update the local x,y coordinates of the node
   * Update them for the raphael objects as well.
   * Redraw the edges as well.
   * Here 'this' refers to the node.
   */
  var setXY = function(xnew, ynew)
  {
    this.x = xnew;
    this.y = ynew;
    if (this.c) {<commit_msg>nodeDrawEdges: properly find the ID in the children and not in connectors! Also extracted children and connectors vars at the top, and renamed i to ID.<commit_after>/* -*- mode: espresso; espresso-indent-level: 2; indent-tabs-mode: nil -*- */
/* vim: set softtabstop=2 shiftwidth=2 tabstop=2 expandtab: */

/** Namespace where Node instances are created and edited. */
var SkeletonElements = new function()
{
  var active_skeleton_color = "rgb(255,255,0)";
  var inactive_skeleton_color = "rgb(255,0,255)";
  var inactive_skeleton_color_above = "rgb(0,0,255)";
  var inactive_skeleton_color_below = "rgb(255,0,0)";
  var root_node_color = "rgb(255, 0, 0)";

  var TYPE_NODE = "treenode";
  var TYPE_CONNECTORNODE = "location"; // TODO update the name in the PHP files

  var CATCH_RADIUS = 8;

  /** Constructor for Node instances. */
  this.Node = function(
    id, // unique id for the node from the database
    paper, // the raphael paper this node is drawn to
    parent, // the parent node
    r, // the radius
    x, // the x coordinate in pixel coordinates
    y, // y coordinates
    z, // z coordinates
    zdiff, // the different from the current slices
    skeleton_id,
    is_root_node) // the id of the skeleton this node is an element of
  {
    this.id = id;
    this.type = TYPE_NODE;
    this.paper = paper;
    this.parent = parent;
    this.children = {};
    this.connectors = {};
    this.r = r < 0 ? 3 : r;
    this.x = x;
    this.y = y;
    this.z = z;
    this.zdiff = zdiff;
    this.skeleton_id = skeleton_id;
    this.isroot = is_root_node;
    this.fillcolor = inactive_skeleton_color;
    this.c = null; // The Raphael circle for drawing
    this.mc = null; // The Raphael circle for mouse actions (it's a bit larger)
    this.line = is_root_node ? null : paper.path(); // The Raphael line element that represents an edge between nodes

    // The member functions:
    this.setXY = setXY;
    this.drawEdges = nodeDrawEdges;
    this.drawLineToParent = nodeDrawLineToParent;
    this.draw = nodeDraw;
    this.deleteall = nodeDeleteAll;
    this.deletenode = nodeDelete;
    this.setColor = setColor;
    this.colorFromZDiff = nodeColorFromZDiff;
    this.createCircle = createCircle;

    // Init block
    // 1. Add this node to the parent's children if it exists
    if (parent) this.children[id] = this;
  };

  /** Trigger the redrawing of the lines with parent, children and connectors.
   * Here, 'this' is the node, given that it is called in the context of the node only.
   */
  var nodeDrawEdges = function(toChildren) {
    var ID,
        children = this.children,
        connectors = this.connectors;
    if (toChildren) {
      for (ID in children) {
        if (children.hasOwnProperty(ID)) {
          children[ID].drawLineToParent();
        }
      }
    }

    for (ID in connectors) {
      if (connectors.hasOwnProperty(ID)) {
        connectors[ID].drawEdges();
      }
    }
    if (this.parent !== null) {
      this.drawLineToParent();
    }
  };

  /** Update the local x,y coordinates of the node
   * Update them for the raphael objects as well.
   * Redraw the edges as well.
   * Here 'this' refers to the node.
   */
  var setXY = function(xnew, ynew)
  {
    this.x = xnew;
    this.y = ynew;
    if (this.c) {
{'fraction_non_alphanumeric': 0.1111111111111111, 'fraction_numerical': 0.011548064918851436, 'mean_word_length': 2.664379645511721, 'pattern_counts': {'":': 0, '<': 5, '<?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': '6416400', 'n_tokens_mistral': 2152, 'n_tokens_neox': 2059, 'n_words': 660}