line.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536
  1. import { __assign, __extends } from "tslib";
  2. import { getTextPoint } from '../util/util';
  3. import CrosshairBase from './base';
  4. var LineCrosshair = /** @class */ (function (_super) {
  5. __extends(LineCrosshair, _super);
  6. function LineCrosshair() {
  7. return _super !== null && _super.apply(this, arguments) || this;
  8. }
  9. LineCrosshair.prototype.getDefaultCfg = function () {
  10. var cfg = _super.prototype.getDefaultCfg.call(this);
  11. return __assign(__assign({}, cfg), { type: 'line', locationType: 'region', start: null, end: null });
  12. };
  13. // 直线的文本需要同直线垂直
  14. LineCrosshair.prototype.getRotateAngle = function () {
  15. var _a = this.getLocation(), start = _a.start, end = _a.end;
  16. var position = this.get('text').position;
  17. var angle = Math.atan2(end.y - start.y, end.x - start.x);
  18. var tangentAngle = position === 'start' ? angle - Math.PI / 2 : angle + Math.PI / 2;
  19. return tangentAngle;
  20. };
  21. LineCrosshair.prototype.getTextPoint = function () {
  22. var _a = this.getLocation(), start = _a.start, end = _a.end;
  23. var _b = this.get('text'), position = _b.position, offset = _b.offset;
  24. return getTextPoint(start, end, position, offset);
  25. };
  26. LineCrosshair.prototype.getLinePath = function () {
  27. var _a = this.getLocation(), start = _a.start, end = _a.end;
  28. return [
  29. ['M', start.x, start.y],
  30. ['L', end.x, end.y],
  31. ];
  32. };
  33. return LineCrosshair;
  34. }(CrosshairBase));
  35. export default LineCrosshair;
  36. //# sourceMappingURL=line.js.map