connection.js 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.atConnectionRatio = exports.atConnectionLength = exports.atConnectionRatioIgnoreGradient = exports.atConnectionRatioKeepGradient = exports.atConnectionLengthIgnoreGradient = exports.atConnectionLengthKeepGradient = exports.connection = void 0;
  4. const isEdgeView = (val, { view }) => {
  5. return view.cell.isEdge();
  6. };
  7. exports.connection = {
  8. qualify: isEdgeView,
  9. set(val, args) {
  10. var _a, _b, _c, _d;
  11. const view = args.view;
  12. const reverse = (val.reverse || false);
  13. const stubs = (val.stubs || 0);
  14. let d;
  15. if (Number.isFinite(stubs) && stubs !== 0) {
  16. if (!reverse) {
  17. let offset;
  18. if (stubs < 0) {
  19. const len = view.getConnectionLength() || 0;
  20. offset = (len + stubs) / 2;
  21. }
  22. else {
  23. offset = stubs;
  24. }
  25. const path = view.getConnection();
  26. if (path) {
  27. const sourceParts = path.divideAtLength(offset);
  28. const targetParts = path.divideAtLength(-offset);
  29. if (sourceParts && targetParts) {
  30. d = `${sourceParts[0].serialize()} ${targetParts[1].serialize()}`;
  31. }
  32. }
  33. }
  34. else {
  35. let offset;
  36. let length;
  37. const len = view.getConnectionLength() || 0;
  38. if (stubs < 0) {
  39. offset = (len + stubs) / 2;
  40. length = -stubs;
  41. }
  42. else {
  43. offset = stubs;
  44. length = len - stubs * 2;
  45. }
  46. const path = view.getConnection();
  47. d = (_d = (_c = (_b = (_a = path === null || path === void 0 ? void 0 : path.divideAtLength(offset)) === null || _a === void 0 ? void 0 : _a[1]) === null || _b === void 0 ? void 0 : _b.divideAtLength(length)) === null || _c === void 0 ? void 0 : _c[0]) === null || _d === void 0 ? void 0 : _d.serialize();
  48. }
  49. }
  50. return { d: d || view.getConnectionPathData() };
  51. },
  52. };
  53. exports.atConnectionLengthKeepGradient = {
  54. qualify: isEdgeView,
  55. set: atConnectionWrapper('getTangentAtLength', { rotate: true }),
  56. };
  57. exports.atConnectionLengthIgnoreGradient = {
  58. qualify: isEdgeView,
  59. set: atConnectionWrapper('getTangentAtLength', { rotate: false }),
  60. };
  61. exports.atConnectionRatioKeepGradient = {
  62. qualify: isEdgeView,
  63. set: atConnectionWrapper('getTangentAtRatio', { rotate: true }),
  64. };
  65. exports.atConnectionRatioIgnoreGradient = {
  66. qualify: isEdgeView,
  67. set: atConnectionWrapper('getTangentAtRatio', { rotate: false }),
  68. };
  69. // aliases
  70. // -------
  71. exports.atConnectionLength = exports.atConnectionLengthKeepGradient;
  72. exports.atConnectionRatio = exports.atConnectionRatioKeepGradient;
  73. // utils
  74. // -----
  75. function atConnectionWrapper(method, options) {
  76. const zeroVector = { x: 1, y: 0 };
  77. return (value, args) => {
  78. let p;
  79. let angle;
  80. const view = args.view;
  81. const tangent = view[method](Number(value));
  82. if (tangent) {
  83. angle = options.rotate ? tangent.vector().vectorAngle(zeroVector) : 0;
  84. p = tangent.start;
  85. }
  86. else {
  87. p = view.path.start;
  88. angle = 0;
  89. }
  90. if (angle === 0) {
  91. return { transform: `translate(${p.x},${p.y}')` };
  92. }
  93. return {
  94. transform: `translate(${p.x},${p.y}') rotate(${angle})`,
  95. };
  96. };
  97. }
  98. //# sourceMappingURL=connection.js.map