util.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.getPointAtEdge = exports.resolve = void 0;
  4. const x6_common_1 = require("@antv/x6-common");
  5. const x6_geometry_1 = require("@antv/x6-geometry");
  6. // eslint-disable-next-line
  7. function resolve(fn) {
  8. return function (view, magnet, ref, options) {
  9. if (ref instanceof Element) {
  10. const refView = this.graph.findViewByElem(ref);
  11. let refPoint;
  12. if (refView) {
  13. if (refView.isEdgeElement(ref)) {
  14. const distance = options.fixedAt != null ? options.fixedAt : '50%';
  15. refPoint = getPointAtEdge(refView, distance);
  16. }
  17. else {
  18. refPoint = refView.getBBoxOfElement(ref).getCenter();
  19. }
  20. }
  21. else {
  22. refPoint = new x6_geometry_1.Point();
  23. }
  24. return fn.call(this, view, magnet, refPoint, options);
  25. }
  26. return fn.apply(this, arguments); // eslint-disable-line
  27. };
  28. }
  29. exports.resolve = resolve;
  30. function getPointAtEdge(edgeView, value) {
  31. const isPercentage = x6_common_1.NumberExt.isPercentage(value);
  32. const num = typeof value === 'string' ? parseFloat(value) : value;
  33. if (isPercentage) {
  34. return edgeView.getPointAtRatio(num / 100);
  35. }
  36. return edgeView.getPointAtLength(num);
  37. }
  38. exports.getPointAtEdge = getPointAtEdge;
  39. //# sourceMappingURL=util.js.map