BarLink.js 3.27 KB
Newer Older
涂茜's avatar
涂茜 committed
1 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 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
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,
      );
    }
  }
}

// function BarLink() {
//     go.Link.call(this);
// }
// go.Diagram.inherit(BarLink, go.Link);

// BarLink.prototype.getLinkPoint = function(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);
//     }
// };