radial.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.radialOriented = exports.radial = void 0;
  4. const x6_geometry_1 = require("@antv/x6-geometry");
  5. const util_1 = require("./util");
  6. const radial = (portPosition, elemBBox, args) => radialLayout(portPosition.diff(elemBBox.getCenter()), false, args);
  7. exports.radial = radial;
  8. const radialOriented = (portPosition, elemBBox, args) => radialLayout(portPosition.diff(elemBBox.getCenter()), true, args);
  9. exports.radialOriented = radialOriented;
  10. function radialLayout(portCenterOffset, autoOrient, args) {
  11. const offset = args.offset != null ? args.offset : 20;
  12. const origin = new x6_geometry_1.Point(0, 0);
  13. const angle = -portCenterOffset.theta(origin);
  14. const pos = portCenterOffset
  15. .clone()
  16. .move(origin, offset)
  17. .diff(portCenterOffset)
  18. .round();
  19. let y = '.3em';
  20. let textAnchor;
  21. let orientAngle = angle;
  22. if ((angle + 90) % 180 === 0) {
  23. textAnchor = autoOrient ? 'end' : 'middle';
  24. if (!autoOrient && angle === -270) {
  25. y = '0em';
  26. }
  27. }
  28. else if (angle > -270 && angle < -90) {
  29. textAnchor = 'start';
  30. orientAngle = angle - 180;
  31. }
  32. else {
  33. textAnchor = 'end';
  34. }
  35. return (0, util_1.toResult)({
  36. position: pos.round().toJSON(),
  37. angle: autoOrient ? orientAngle : 0,
  38. attrs: {
  39. '.': {
  40. y,
  41. 'text-anchor': textAnchor,
  42. },
  43. },
  44. }, args);
  45. }
  46. //# sourceMappingURL=radial.js.map