BarLink.js 1.66 KB
Newer Older
1
/* eslint-disable */
涂茜's avatar
涂茜 committed
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
import * as go from './go';

export default class BarLink extends go.Link {
  constructor() {
    super(...arguments);
    go.Link.call(this);
  }
  getLinkPoint(node, port, spot, from, ortho, othernode, otherport) {
    if (node.category === 'HBar') {
      window.οncοntextmenu = function (event) {
        var e = event || window.event;
        document.getElementById('Menu').style.left = e.clientX + 'px';
        document.getElementById('Menu').style.top = e.clientY + 'px';
        document.getElementById('Menu').style.display = 'block';
        return false;
      };
      var op = go.Link.prototype.getLinkPoint.call(
        this,
        othernode,
        otherport,
        this.computeSpot(!from),
        !from,
        ortho,
        node,
        port,
      );
      var r = port.getDocumentBounds();
      // 横向合管
      var r = port.getDocumentBounds();
      var angle = node.angle;
      var spare = (angle / 90) % 2;
      if (!spare) {
        var y = op.y > r.centerY ? r.bottom : r.top;
        if (op.x < r.left) return new go.Point(r.left, y);
        if (op.x > r.right) return new go.Point(r.right, y);
        return new go.Point(op.x, y);
      }
      // 纵向合管
      var x = op.x > r.centerX ? r.right : r.left;
      if (op.y < r.top) return new go.Point(x, r.top);
      if (op.y > r.bottom) return new go.Point(x, r.bottom);
      // return new go.Point(x, op.y - r.width / 2 + 3);
      return new go.Point(x, op.y);
    } else {
      return go.Link.prototype.getLinkPoint.call(
        this,
        node,
        port,
        spot,
        from,
        ortho,
        othernode,
        otherport,
      );
    }
  }
}