outside.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.outside = exports.inferOutsideCircularStyle = exports.angleOf = exports.radiusOf = exports.linePoints = void 0;
  4. const utils_1 = require("../../../shape/utils");
  5. const coordinate_1 = require("../../../utils/coordinate");
  6. const default_1 = require("./default");
  7. function linePoints(center, angle, radius, radius1, offsetX) {
  8. const [x0, y0] = (0, default_1.pointOfArc)(center, angle, radius);
  9. const [x1, y1] = (0, default_1.pointOfArc)(center, angle, radius1);
  10. const sign = Math.sin(angle) > 0 ? 1 : -1;
  11. return [
  12. [x0, y0],
  13. [x1, y1],
  14. [x1 + sign * offsetX, y1],
  15. ];
  16. }
  17. exports.linePoints = linePoints;
  18. function radiusOf(points, value, coordinate) {
  19. const arcObject = (0, utils_1.getArcObject)(coordinate, points, [value.y, value.y1]);
  20. const { innerRadius, outerRadius } = arcObject;
  21. return innerRadius + (outerRadius - innerRadius);
  22. }
  23. exports.radiusOf = radiusOf;
  24. function angleOf(points, value, coordinate) {
  25. const arcObject = (0, utils_1.getArcObject)(coordinate, points, [value.y, value.y1]);
  26. const { startAngle, endAngle } = arcObject;
  27. return (startAngle + endAngle) / 2;
  28. }
  29. exports.angleOf = angleOf;
  30. function inferOutsideCircularStyle(position, points, value, coordinate) {
  31. const { autoRotate, rotateToAlignArc, offset = 0, connector = true, connectorLength = offset, connectorLength2 = 0, connectorDistance = 0, } = value;
  32. const center = coordinate.getCenter();
  33. const angle = angleOf(points, value, coordinate);
  34. const sign = Math.sin(angle) > 0 ? 1 : -1;
  35. const rotate = (0, default_1.inferRotation)(angle, autoRotate, rotateToAlignArc);
  36. const textStyle = {
  37. textAlign: sign > 0 || (0, coordinate_1.isRadial)(coordinate) ? 'start' : 'end',
  38. textBaseline: 'middle',
  39. rotate,
  40. };
  41. const radius = radiusOf(points, value, coordinate);
  42. const radius1 = radius + (connector ? connectorLength : offset);
  43. const [[x0, y0], [x1, y1], [x2, y2]] = linePoints(center, angle, radius, radius1, connector ? connectorLength2 : 0);
  44. const dx = connector ? +connectorDistance * sign : 0;
  45. const x = x2 + dx;
  46. const y = y2;
  47. const connectorStyle = {
  48. connector,
  49. connectorPoints: [
  50. [x1 - x, y1 - y],
  51. [x2 - x, y2 - y],
  52. ],
  53. };
  54. return Object.assign(Object.assign({ x0,
  55. y0, x: x2 + dx, y: y2 }, textStyle), connectorStyle);
  56. }
  57. exports.inferOutsideCircularStyle = inferOutsideCircularStyle;
  58. function outside(position, points, value, coordinate) {
  59. const { bounds } = value;
  60. // When bounds.length = 1
  61. // For series mark, such as line and area.
  62. // The bounds for text is defined with only one point.
  63. // Use this point as the label position.
  64. if (bounds.length === 1) {
  65. return (0, default_1.inferIdentityStyle)(position, points, value, coordinate);
  66. }
  67. const inferDefaultStyle = (0, coordinate_1.isRadial)(coordinate)
  68. ? default_1.inferRadialStyle
  69. : (0, coordinate_1.isCircular)(coordinate)
  70. ? inferOutsideCircularStyle
  71. : default_1.inferNonCircularStyle;
  72. return inferDefaultStyle(position, points, value, coordinate);
  73. }
  74. exports.outside = outside;
  75. //# sourceMappingURL=outside.js.map