circle.js 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. import { __assign, __extends } from "tslib";
  2. import { each } from '@antv/util';
  3. import GridBase from './base';
  4. function distance(x1, y1, x2, y2) {
  5. var dx = x2 - x1;
  6. var dy = y2 - y1;
  7. return Math.sqrt(dx * dx + dy * dy);
  8. }
  9. var Circle = /** @class */ (function (_super) {
  10. __extends(Circle, _super);
  11. function Circle() {
  12. return _super !== null && _super.apply(this, arguments) || this;
  13. }
  14. Circle.prototype.getDefaultCfg = function () {
  15. var cfg = _super.prototype.getDefaultCfg.call(this);
  16. return __assign(__assign({}, cfg), { type: 'circle',
  17. /**
  18. * 中心点
  19. * @type {object}
  20. */
  21. center: null,
  22. /**
  23. * 栅格线是否封闭
  24. * @type {true}
  25. */
  26. closed: true });
  27. };
  28. Circle.prototype.getGridPath = function (points, reversed) {
  29. var lineType = this.getLineType();
  30. var closed = this.get('closed');
  31. var path = [];
  32. if (points.length) {
  33. // 防止出错
  34. if (lineType === 'circle') {
  35. var center = this.get('center');
  36. var firstPoint = points[0];
  37. var radius_1 = distance(center.x, center.y, firstPoint.x, firstPoint.y);
  38. var sweepFlag_1 = reversed ? 0 : 1; // 顺时针还是逆时针
  39. if (closed) {
  40. // 封闭时,绘制整个圆
  41. path.push(['M', center.x, center.y - radius_1]);
  42. path.push(['A', radius_1, radius_1, 0, 0, sweepFlag_1, center.x, center.y + radius_1]);
  43. path.push(['A', radius_1, radius_1, 0, 0, sweepFlag_1, center.x, center.y - radius_1]);
  44. path.push(['Z']);
  45. }
  46. else {
  47. each(points, function (point, index) {
  48. if (index === 0) {
  49. path.push(['M', point.x, point.y]);
  50. }
  51. else {
  52. path.push(['A', radius_1, radius_1, 0, 0, sweepFlag_1, point.x, point.y]);
  53. }
  54. });
  55. }
  56. }
  57. else {
  58. each(points, function (point, index) {
  59. if (index === 0) {
  60. path.push(['M', point.x, point.y]);
  61. }
  62. else {
  63. path.push(['L', point.x, point.y]);
  64. }
  65. });
  66. if (closed) {
  67. path.push(['Z']);
  68. }
  69. }
  70. }
  71. return path;
  72. };
  73. return Circle;
  74. }(GridBase));
  75. export default Circle;
  76. //# sourceMappingURL=circle.js.map