circle.js 2.8 KB

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