arc.js 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import { __assign, __extends } from "tslib";
  2. import GroupComponent from '../abstract/group-component';
  3. import { getCirclePoint } from '../util/util';
  4. var ArcAnnotation = /** @class */ (function (_super) {
  5. __extends(ArcAnnotation, _super);
  6. function ArcAnnotation() {
  7. return _super !== null && _super.apply(this, arguments) || this;
  8. }
  9. /**
  10. * @protected
  11. * 默认的配置项
  12. * @returns {object} 默认的配置项
  13. */
  14. ArcAnnotation.prototype.getDefaultCfg = function () {
  15. var cfg = _super.prototype.getDefaultCfg.call(this);
  16. return __assign(__assign({}, cfg), { name: 'annotation', type: 'arc', locationType: 'circle', center: null, radius: 100, startAngle: -Math.PI / 2, endAngle: (Math.PI * 3) / 2, style: {
  17. stroke: '#999',
  18. lineWidth: 1,
  19. } });
  20. };
  21. ArcAnnotation.prototype.renderInner = function (group) {
  22. this.renderArc(group);
  23. };
  24. ArcAnnotation.prototype.getArcPath = function () {
  25. var _a = this.getLocation(), center = _a.center, radius = _a.radius, startAngle = _a.startAngle, endAngle = _a.endAngle;
  26. var startPoint = getCirclePoint(center, radius, startAngle);
  27. var endPoint = getCirclePoint(center, radius, endAngle);
  28. var largeFlag = endAngle - startAngle > Math.PI ? 1 : 0;
  29. var path = [['M', startPoint.x, startPoint.y]];
  30. if (endAngle - startAngle === Math.PI * 2) {
  31. // 整个圆是分割成两个圆
  32. var middlePoint = getCirclePoint(center, radius, startAngle + Math.PI);
  33. path.push(['A', radius, radius, 0, largeFlag, 1, middlePoint.x, middlePoint.y]);
  34. path.push(['A', radius, radius, 0, largeFlag, 1, endPoint.x, endPoint.y]);
  35. }
  36. else {
  37. path.push(['A', radius, radius, 0, largeFlag, 1, endPoint.x, endPoint.y]);
  38. }
  39. return path;
  40. };
  41. // 绘制 arc
  42. ArcAnnotation.prototype.renderArc = function (group) {
  43. // 也可以 通过 get('center') 类似的方式逐个获取
  44. var path = this.getArcPath();
  45. var style = this.get('style');
  46. this.addShape(group, {
  47. type: 'path',
  48. id: this.getElementId('arc'),
  49. name: 'annotation-arc',
  50. attrs: __assign({ path: path }, style),
  51. });
  52. };
  53. return ArcAnnotation;
  54. }(GroupComponent));
  55. export default ArcAnnotation;
  56. //# sourceMappingURL=arc.js.map