oneside.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import { NumberExt } from '@antv/x6-common';
  2. /**
  3. * Routes the edge always to/from a certain side
  4. */
  5. export const oneSide = function (vertices, options, edgeView) {
  6. const side = options.side || 'bottom';
  7. const padding = NumberExt.normalizeSides(options.padding || 40);
  8. const sourceBBox = edgeView.sourceBBox;
  9. const targetBBox = edgeView.targetBBox;
  10. const sourcePoint = sourceBBox.getCenter();
  11. const targetPoint = targetBBox.getCenter();
  12. let coord;
  13. let dim;
  14. let factor;
  15. switch (side) {
  16. case 'top':
  17. factor = -1;
  18. coord = 'y';
  19. dim = 'height';
  20. break;
  21. case 'left':
  22. factor = -1;
  23. coord = 'x';
  24. dim = 'width';
  25. break;
  26. case 'right':
  27. factor = 1;
  28. coord = 'x';
  29. dim = 'width';
  30. break;
  31. case 'bottom':
  32. default:
  33. factor = 1;
  34. coord = 'y';
  35. dim = 'height';
  36. break;
  37. }
  38. // Move the points from the center of the element to outside of it.
  39. sourcePoint[coord] += factor * (sourceBBox[dim] / 2 + padding[side]);
  40. targetPoint[coord] += factor * (targetBBox[dim] / 2 + padding[side]);
  41. // Make edge orthogonal (at least the first and last vertex).
  42. if (factor * (sourcePoint[coord] - targetPoint[coord]) > 0) {
  43. targetPoint[coord] = sourcePoint[coord];
  44. }
  45. else {
  46. sourcePoint[coord] = targetPoint[coord];
  47. }
  48. return [sourcePoint.toJSON(), ...vertices, targetPoint.toJSON()];
  49. };
  50. //# sourceMappingURL=oneside.js.map