UNPKG

5.1 kBJavaScriptView Raw
1/*
2* Copyright (C) 1998-2021 by Northwoods Software Corporation. All Rights Reserved.
3*/
4var __extends = (this && this.__extends) || (function () {
5 var extendStatics = function (d, b) {
6 extendStatics = Object.setPrototypeOf ||
7 ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
8 function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
9 return extendStatics(d, b);
10 };
11 return function (d, b) {
12 extendStatics(d, b);
13 function __() { this.constructor = d; }
14 d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15 };
16})();
17(function (factory) {
18 if (typeof module === "object" && typeof module.exports === "object") {
19 var v = factory(require, exports);
20 if (v !== undefined) module.exports = v;
21 }
22 else if (typeof define === "function" && define.amd) {
23 define(["require", "exports", "../release/go.js"], factory);
24 }
25})(function (require, exports) {
26 "use strict";
27 Object.defineProperty(exports, "__esModule", { value: true });
28 exports.ParallelRouteLink = void 0;
29 /*
30 * This is an extension and not part of the main GoJS library.
31 * Note that the API for this class may change with any version, even point releases.
32 * If you intend to use an extension in production, you should copy the code to your own source directory.
33 * Extensions can be found in the GoJS kit under the extensions or extensionsTS folders.
34 * See the Extensions intro page (https://gojs.net/latest/intro/extensions.html) for more information.
35 */
36 var go = require("../release/go.js");
37 /**
38 * This custom {@link Link} class customizes its route to go parallel to other links connecting the same ports,
39 * if the link is not orthogonal and is not Bezier curved.
40 *
41 * If you want to experiment with this extension, try the <a href="../../extensionsJSM/ParallelRoute.html">Parallel Route Links</a> sample.
42 * @category Part Extension
43 */
44 var ParallelRouteLink = /** @class */ (function (_super) {
45 __extends(ParallelRouteLink, _super);
46 function ParallelRouteLink() {
47 return _super !== null && _super.apply(this, arguments) || this;
48 }
49 /**
50 * Constructs the link's route by modifying {@link #points}.
51 * @return {boolean} true if it computed a route of points
52 */
53 ParallelRouteLink.prototype.computePoints = function () {
54 var result = _super.prototype.computePoints.call(this);
55 if (!this.isOrthogonal && this.curve !== go.Link.Bezier && this.hasCurviness()) {
56 var curv = this.computeCurviness();
57 if (curv !== 0) {
58 var num = this.pointsCount;
59 var pidx = 0;
60 var qidx = num - 1;
61 if (num >= 4) {
62 pidx++;
63 qidx--;
64 }
65 var frompt = this.getPoint(pidx);
66 var topt = this.getPoint(qidx);
67 var dx = topt.x - frompt.x;
68 var dy = topt.y - frompt.y;
69 var mx = frompt.x + dx * 1 / 8;
70 var my = frompt.y + dy * 1 / 8;
71 var px = mx;
72 var py = my;
73 if (-0.01 < dy && dy < 0.01) {
74 if (dx > 0)
75 py -= curv;
76 else
77 py += curv;
78 }
79 else {
80 var slope = -dx / dy;
81 var e = Math.sqrt(curv * curv / (slope * slope + 1));
82 if (curv < 0)
83 e = -e;
84 px = (dy < 0 ? -1 : 1) * e + mx;
85 py = slope * (px - mx) + my;
86 }
87 mx = frompt.x + dx * 7 / 8;
88 my = frompt.y + dy * 7 / 8;
89 var qx = mx;
90 var qy = my;
91 if (-0.01 < dy && dy < 0.01) {
92 if (dx > 0)
93 qy -= curv;
94 else
95 qy += curv;
96 }
97 else {
98 var slope = -dx / dy;
99 var e = Math.sqrt(curv * curv / (slope * slope + 1));
100 if (curv < 0)
101 e = -e;
102 qx = (dy < 0 ? -1 : 1) * e + mx;
103 qy = slope * (qx - mx) + my;
104 }
105 this.insertPointAt(pidx + 1, px, py);
106 this.insertPointAt(qidx + 1, qx, qy);
107 }
108 }
109 return result;
110 };
111 return ParallelRouteLink;
112 }(go.Link));
113 exports.ParallelRouteLink = ParallelRouteLink;
114});