surround.js 1.5 KB

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