util.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.getTargetAnchor = exports.getSourceAnchor = exports.getTargetBBox = exports.getSourceBBox = exports.getPaddingBox = exports.getPointBBox = void 0;
  4. const x6_common_1 = require("@antv/x6-common");
  5. const x6_geometry_1 = require("@antv/x6-geometry");
  6. function getPointBBox(p) {
  7. return new x6_geometry_1.Rectangle(p.x, p.y, 0, 0);
  8. }
  9. exports.getPointBBox = getPointBBox;
  10. function getPaddingBox(options = {}) {
  11. const sides = x6_common_1.NumberExt.normalizeSides(options.padding || 20);
  12. return {
  13. x: -sides.left,
  14. y: -sides.top,
  15. width: sides.left + sides.right,
  16. height: sides.top + sides.bottom,
  17. };
  18. }
  19. exports.getPaddingBox = getPaddingBox;
  20. function getSourceBBox(view, options = {}) {
  21. return view.sourceBBox.clone().moveAndExpand(getPaddingBox(options));
  22. }
  23. exports.getSourceBBox = getSourceBBox;
  24. function getTargetBBox(view, options = {}) {
  25. return view.targetBBox.clone().moveAndExpand(getPaddingBox(options));
  26. }
  27. exports.getTargetBBox = getTargetBBox;
  28. function getSourceAnchor(view, options = {}) {
  29. if (view.sourceAnchor) {
  30. return view.sourceAnchor;
  31. }
  32. const bbox = getSourceBBox(view, options);
  33. return bbox.getCenter();
  34. }
  35. exports.getSourceAnchor = getSourceAnchor;
  36. function getTargetAnchor(view, options = {}) {
  37. if (view.targetAnchor) {
  38. return view.targetAnchor;
  39. }
  40. const bbox = getTargetBBox(view, options);
  41. return bbox.getCenter();
  42. }
  43. exports.getTargetAnchor = getTargetAnchor;
  44. //# sourceMappingURL=util.js.map