line.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.LineCrosshair = void 0;
  4. var tslib_1 = require("tslib");
  5. var util_1 = require("../../util");
  6. var base_1 = require("./base");
  7. var constant_1 = require("./constant");
  8. var LineCrosshair = /** @class */ (function (_super) {
  9. tslib_1.__extends(LineCrosshair, _super);
  10. function LineCrosshair(options) {
  11. return _super.call(this, (0, util_1.deepAssign)({}, LineCrosshair.defaultOptions, options)) || this;
  12. }
  13. Object.defineProperty(LineCrosshair.prototype, "crosshairPath", {
  14. get: function () {
  15. var _a = this.attributes, _b = tslib_1.__read(_a.startPos, 2), sx = _b[0], sy = _b[1], _c = tslib_1.__read(_a.endPos, 2), ex = _c[0], ey = _c[1];
  16. var path = [['M', 0, 0], ['L', ex - sx, ey - sy], ['Z']];
  17. return path;
  18. },
  19. enumerable: false,
  20. configurable: true
  21. });
  22. Object.defineProperty(LineCrosshair.prototype, "localPointer", {
  23. /**
  24. * 获得 pointer 的相对坐标
  25. */
  26. get: function () {
  27. if (!this.pointer)
  28. return this.attributes.startPos;
  29. var _a = tslib_1.__read(this.getPosition(), 2), bx = _a[0], by = _a[1];
  30. var _b = tslib_1.__read(this.pointer, 2), x = _b[0], y = _b[1];
  31. return [x - bx, y - by];
  32. },
  33. enumerable: false,
  34. configurable: true
  35. });
  36. Object.defineProperty(LineCrosshair.prototype, "isVertical", {
  37. get: function () {
  38. var _a = this.attributes, _b = tslib_1.__read(_a.startPos, 2), x1 = _b[0], y1 = _b[1], _c = tslib_1.__read(_a.endPos, 2), x2 = _c[0], y2 = _c[1];
  39. return x1 === x2 && y1 !== y2;
  40. },
  41. enumerable: false,
  42. configurable: true
  43. });
  44. Object.defineProperty(LineCrosshair.prototype, "tagShapeSpace", {
  45. get: function () {
  46. var _a = (0, util_1.getShapeSpace)(this.tagShape), width = _a.width, height = _a.height;
  47. return { width: width, height: height };
  48. },
  49. enumerable: false,
  50. configurable: true
  51. });
  52. LineCrosshair.prototype.update = function (cfg) {
  53. _super.prototype.update.call(this, cfg);
  54. };
  55. /**
  56. * 将线移动至对应位置
  57. */
  58. LineCrosshair.prototype.setPointer = function (pointer) {
  59. _super.prototype.setPointer.call(this, pointer);
  60. this.adjustPosition();
  61. };
  62. LineCrosshair.prototype.setText = function (text) {
  63. this.tagShape.update({ text: text });
  64. this.adjustTag();
  65. };
  66. LineCrosshair.prototype.adjustLayout = function () {
  67. this.adjustPosition();
  68. this.adjustTag();
  69. };
  70. /**
  71. * 调整this位置
  72. */
  73. LineCrosshair.prototype.adjustPosition = function () {
  74. var _a = tslib_1.__read(this.localPointer, 2), lx = _a[0], ly = _a[1];
  75. var _b = tslib_1.__read(this.attributes.startPos, 2), sx = _b[0], sy = _b[1];
  76. var targetPos = this.getOrientVal([sx, ly], [lx, sy]);
  77. this.shapesGroup.setLocalPosition(targetPos);
  78. };
  79. /**
  80. * 调整tag位置
  81. */
  82. LineCrosshair.prototype.adjustTag = function () {
  83. var _a = this.attributes, tagText = _a.tagText, tagPosition = _a.tagPosition, _b = tslib_1.__read(_a.startPos, 2), x1 = _b[0], y1 = _b[1], _c = tslib_1.__read(_a.endPos, 2), x2 = _c[0], y2 = _c[1];
  84. if (!tagText || tagText === '') {
  85. (0, util_1.hide)(this.tagShape);
  86. return;
  87. }
  88. (0, util_1.show)(this.tagShape);
  89. var _d = this.tagShapeSpace, width = _d.width, height = _d.height;
  90. // 偏移量
  91. var _e = tslib_1.__read(this.getOrientVal({
  92. start: [-width / 2, height / 2],
  93. end: [x2 - x1 + width / 2, height / 2],
  94. }, {
  95. start: [0, 0],
  96. end: [0, y2 - y1 + height],
  97. })[tagPosition], 2), xOffset = _e[0], yOffset = _e[1];
  98. this.tagShape.setLocalPosition(xOffset, yOffset);
  99. };
  100. LineCrosshair.prototype.getOrientVal = function (v1, v2) {
  101. return this.isVertical ? v2 : v1;
  102. };
  103. LineCrosshair.tag = 'line-crosshair';
  104. LineCrosshair.defaultOptions = {
  105. style: constant_1.LINE_CROSSHAIR_DEFAULT_STYLE,
  106. };
  107. return LineCrosshair;
  108. }(base_1.CrosshairBase));
  109. exports.LineCrosshair = LineCrosshair;
  110. //# sourceMappingURL=line.js.map