surround.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. "use strict";
  2. var __rest = (this && this.__rest) || function (s, e) {
  3. var t = {};
  4. for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
  5. t[p] = s[p];
  6. if (s != null && typeof Object.getOwnPropertySymbols === "function")
  7. for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
  8. if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
  9. t[p[i]] = s[p[i]];
  10. }
  11. return t;
  12. };
  13. Object.defineProperty(exports, "__esModule", { value: true });
  14. exports.surround = void 0;
  15. const coordinate_1 = require("../../../utils/coordinate");
  16. const vector_1 = require("../../../utils/vector");
  17. const default_1 = require("./default");
  18. const outside_1 = require("./outside");
  19. /**
  20. * Surround label transform is used to make labels surround circular.
  21. */
  22. function surround(position, points, value, coordinate) {
  23. if (!(0, coordinate_1.isCircular)(coordinate))
  24. return {};
  25. const { connectorLength, connectorLength2, connectorDistance } = value;
  26. const style = __rest((0, outside_1.inferOutsideCircularStyle)('outside', points, value, coordinate), []);
  27. const { x0, y0 } = style;
  28. const center = coordinate.getCenter();
  29. const radius = (0, coordinate_1.getRadius)(coordinate);
  30. const radius1 = radius + connectorLength;
  31. const angle = (0, vector_1.angleWithQuadrant)([x0 - center[0], y0 - center[1]]);
  32. const sign = Math.sin(angle) > 0 ? 1 : -1;
  33. const [newX, newY] = (0, default_1.pointOfArc)(center, angle, radius1);
  34. style.x = newX + (connectorLength2 + connectorDistance) * sign;
  35. style.y = newY;
  36. return style;
  37. }
  38. exports.surround = surround;
  39. //# sourceMappingURL=surround.js.map