<commit_before>/// <reference path="../../../bower_components/polymer-ts/polymer-ts.d.ts"/>

class Orientation {
  position: Coords;
  direction: string;
}

class Relation {
  entity1: Orientation;
  entity2: Orientation;
  connection: any;
  constructor() {
    this.entity1 = new Orientation();
    this.entity2 = new Orientation();
  }
  getSide(side: string) {
    this[side]
  }
}

class TablePort {
  constructor(
    public connectionId: number,
    public side: string,
    public position: Coords,
    public remoteTableY: number,
    public selfConnection: boolean = false) {
  }
}

class Sides {
  constructor(
    public left: TablePort[] = [],
    public right: TablePort[] = [],
    public down: TablePort[] = []) {
  }
  indexOf(connectionId: number, direction: string) {
    var side = this[direction];
    for (var index in side) {
      if (side[index].connectionId == connectionId) {
        return index;
      }
    }
  }
  pop(connectionId: number, direction: string) {
    var index;
    index = this.indexOf(connectionId, direction)
    var port = this[direction][index];
    this[direction].splice(index, 1);
    return port;
  }
}

// Store ports on sides of table
class TableSides {
  geometry: any = {};
  sides: Sides;
  sideAlign(direction: string) {
    var sideConnections = this.sides[direction];
    var start = new Coords(this.geometry.x, this.geometry.y);
    if (direction == "right") {
      start = start.moveToDir("right", this.geometry.width)
    }
    if (direction == "down") {
      start = start.moveToDir("down", this.geometry.height);
    }

    var conNum = Object.keys(sideConnections).length;
    var moveDir;
    var interval;
    var index = 1;
    if (direction == "left" || direction == "right") {
      sideConnections = sideConnections.sort(function(a, b) {
        var difz = a.remoteTableY - b.remoteTableY;
        if (difz != 0) {
          return difz;
        }
        return a.connectionId - b.connectionId;
      })
      moveDir = "down";
      interval = this.geometry.height / (conNum + 1);
    } else {
      moveDir = "right";
      interval = this.geometry.width / (conNum + 1);
    }
    //regular connections entity1
    for (var connectionId in sideConnections) {
      var conSide: TablePort = sideConnections[connectionId];
      if (conSide.selfConnection) {
        continue;
      }
      conSide.position = start.moveToDir(moveDir, (index) * interval);
      index += 1;
    }
    //self connections after
    for (var connectionId in sideConnections) {
      var conSide: TablePort = sideConnections[connectionId];
      if (!conSide.selfConnection) {
        continue;
      }
      conSide.position = start.moveToDir(moveDir, (index) * interval);
      index += 1;
    }
  }

  //change geometry of table - compute all sides
  updateGeometry(geometry: any) {
    this.geometry = geometry;
    for (var side in this.sides) {
      this.sideAlign(side);
    }
  }
}

function computeDirections(geometry1, geometry2) {
  var directions = { entity1: "right", entity2: "right" };
  var leftX1 = geometry1.x;
  var rightX1 = leftX1 + geometry1.width;
  var leftX2 = geometry2.x;
  var rightX2 = leftX2 + geometry2.width;
  if (rightX1 + 70 < leftX2) {
    directions.entity2 = "left";
  } else if (leftX1 > rightX2 + 70) {
    directions.entity1 = "left";
  }
  return directions;
}

@component('connections-view')
class ConnectionsView extends polymer.Base {
  @property({ type: Object, notify: true })
  model: any;

  relations: any;

  relationsLocked: boolean = false;

  tableSides: TableSides[];

  ready() {
    this.relations = [];
  }

  @observe("model.*")
  modelChanged(change) {
    var pathParts = change.path.split(".");

    if (pathParts.length == 1 || pathParts[1] == "connections") {
      var connections = this.model.connections;
      for (var connId in connections) {
        if (!this.relations[connId]) {
          var connection = connections[connId];
          this.relationUpdate(connId);
          this.entityUpdate(connection.entity1);
          this.entityUpdate(connection.entity2);
        }
      }
    } else if (pathParts[1] == "entities" && pathParts[3] == "geometry") {
      var connectionId = pathParts[2].substr(1);
      this.entityUpdate(connectionId);
    }
  }


  relationUpdate(relationId) {
    var rel = new Relation();
    rel.connection = this.model.connections[relationId];

    rel.entity1 = new Orientation()
    rel.entity1.position = new Coords();
    rel.entity1.direction = "right";

    rel.entity2 = new Orientation()
    rel.entity2.position = new Coords();<commit_msg>Connections-view table delete<commit_after>/// <reference path="../../../bower_components/polymer-ts/polymer-ts.d.ts"/>

class Orientation {
  position: Coords;
  direction: string;
}

class Relation {
  entity1: Orientation;
  entity2: Orientation;
  connection: any;
  constructor() {
    this.entity1 = new Orientation();
    this.entity2 = new Orientation();
  }
  getSide(side: string) {
    this[side]
  }
}

class TablePort {
  constructor(
    public connectionId: number,
    public side: string,
    public position: Coords,
    public remoteTableY: number,
    public selfConnection: boolean = false) {
  }
}

class Sides {
  constructor(
    public left: TablePort[] = [],
    public right: TablePort[] = [],
    public down: TablePort[] = []) {
  }
  indexOf(connectionId: number, direction: string) {
    var side = this[direction];
    for (var index in side) {
      if (side[index].connectionId == connectionId) {
        return index;
      }
    }
  }
  pop(connectionId: number, direction: string) {
    var index;
    index = this.indexOf(connectionId, direction)
    var port = this[direction][index];
    this[direction].splice(index, 1);
    return port;
  }
}

// Store ports on sides of table
class TableSides {
  geometry: any = {};
  sides: Sides;
  sideAlign(direction: string) {
    var sideConnections = this.sides[direction];
    var start = new Coords(this.geometry.x, this.geometry.y);
    if (direction == "right") {
      start = start.moveToDir("right", this.geometry.width)
    }
    if (direction == "down") {
      start = start.moveToDir("down", this.geometry.height);
    }

    var conNum = Object.keys(sideConnections).length;
    var moveDir;
    var interval;
    var index = 1;
    if (direction == "left" || direction == "right") {
      sideConnections = sideConnections.sort(function(a, b) {
        var difz = a.remoteTableY - b.remoteTableY;
        if (difz != 0) {
          return difz;
        }
        return a.connectionId - b.connectionId;
      })
      moveDir = "down";
      interval = this.geometry.height / (conNum + 1);
    } else {
      moveDir = "right";
      interval = this.geometry.width / (conNum + 1);
    }
    //regular connections entity1
    for (var connectionId in sideConnections) {
      var conSide: TablePort = sideConnections[connectionId];
      if (conSide.selfConnection) {
        continue;
      }
      conSide.position = start.moveToDir(moveDir, (index) * interval);
      index += 1;
    }
    //self connections after
    for (var connectionId in sideConnections) {
      var conSide: TablePort = sideConnections[connectionId];
      if (!conSide.selfConnection) {
        continue;
      }
      conSide.position = start.moveToDir(moveDir, (index) * interval);
      index += 1;
    }
  }

  //change geometry of table - compute all sides
  updateGeometry(geometry: any) {
    this.geometry = geometry;
    for (var side in this.sides) {
      this.sideAlign(side);
    }
  }
}

function computeDirections(geometry1, geometry2) {
  var directions = { entity1: "right", entity2: "right" };
  var leftX1 = geometry1.x;
  var rightX1 = leftX1 + geometry1.width;
  var leftX2 = geometry2.x;
  var rightX2 = leftX2 + geometry2.width;
  if (rightX1 + 70 < leftX2) {
    directions.entity2 = "left";
  } else if (leftX1 > rightX2 + 70) {
    directions.entity1 = "left";
  }
  return directions;
}

@component('connections-view')
class ConnectionsView extends polymer.Base {
  @property({ type: Object, notify: true })
  model: any;

  relations: any;

  relationsLocked: boolean = false;

  tableSides: TableSides[];

  ready() {
    this.relations = [];
  }

  @observe("model.*")
  modelChanged(change) {
    console.log(change)
    var pathParts = change.path.split(".");

    if (pathParts.length == 1 ||
      (pathParts[1] == "connections" && pathParts[2] == "splices")) {
      var connections = this.model.connections;
      this.relations = [];
      this.tableSides = [];
      for (var connId in connections) {
        if (!this.relations[connId]) {
          var connection = connections[connId];
          this.relationUpdate(connId);
          this.entityUpdate(connection.entity1);
          this.entityUpdate(connection.entity2);
        }
      }
    } else if (pathParts[1] == "entities" && pathParts[3] == "geometry") {
      var connectionId = pathParts[2].substr(1);
      this.entityUpdate(connectionId);
    }
    else {
    }
  }


  relationUpdate(relationId) {
    var rel = new Relation();
    rel.connection = this.model.connections[relationId];

    rel.entity1 = new Orientation()
    rel.entity1.position = new Coords();
    rel.entity1.direction = "right";

    rel.entity2 = new Orientation()
    rel.entity2.position = new Coords();
{'fraction_non_alphanumeric': 0.13176721836625735, 'fraction_numerical': 0.010571276027762947, 'mean_word_length': 2.796513984596676, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '2552499', 'n_tokens_mistral': 2980, 'n_tokens_neox': 2904, 'n_words': 693}