base.js 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import { __assign, __extends, __read } from "tslib";
  2. import { GUI } from '../../core';
  3. import { select, subStyleProps } from '../../util';
  4. import { Tag } from '../tag';
  5. import { CROSSHAIR_BASE_DEFAULT_STYLE } from './constant';
  6. var CrosshairBase = /** @class */ (function (_super) {
  7. __extends(CrosshairBase, _super);
  8. function CrosshairBase(options) {
  9. // @ts-ignore
  10. return _super.call(this, options, CROSSHAIR_BASE_DEFAULT_STYLE) || this;
  11. }
  12. Object.defineProperty(CrosshairBase.prototype, "localPointer", {
  13. /**
  14. * 获得 pointer 的相对坐标
  15. */
  16. get: function () {
  17. var _a = __read(this.getPosition(), 2), bx = _a[0], by = _a[1];
  18. var _b = __read(this.pointer, 2), x = _b[0], y = _b[1];
  19. return [x - bx, y - by];
  20. },
  21. enumerable: false,
  22. configurable: true
  23. });
  24. Object.defineProperty(CrosshairBase.prototype, "tagStyle", {
  25. get: function () {
  26. var style = subStyleProps(this.attributes, 'tag');
  27. return style;
  28. },
  29. enumerable: false,
  30. configurable: true
  31. });
  32. Object.defineProperty(CrosshairBase.prototype, "crosshairStyle", {
  33. get: function () {
  34. var style = subStyleProps(this.attributes, 'line');
  35. return __assign(__assign({}, style), { path: this.crosshairPath });
  36. },
  37. enumerable: false,
  38. configurable: true
  39. });
  40. CrosshairBase.prototype.render = function (attributes, container) {
  41. var group = select(container).maybeAppendByClassName('.crosshair-group', 'g').node();
  42. this.shapesGroup = group;
  43. var tagStyle = this.tagStyle;
  44. var crosshairStyle = this.crosshairStyle;
  45. this.tagShape = select(group)
  46. .maybeAppendByClassName('crosshair-tag', function () { return new Tag({ style: tagStyle }); })
  47. .styles(tagStyle)
  48. .node();
  49. this.crosshairShape = select(group).maybeAppendByClassName('.crosshair-path', 'path').styles(crosshairStyle).node();
  50. this.adjustLayout();
  51. };
  52. /**
  53. * 设置当前指针的位置
  54. * 1. 线条类型 调整位置即可
  55. * 2. circle 和 polygon 需要重新计算 path
  56. */
  57. CrosshairBase.prototype.setPointer = function (pointer) {
  58. this.pointer = pointer;
  59. };
  60. CrosshairBase.tag = 'crosshair-base';
  61. return CrosshairBase;
  62. }(GUI));
  63. export { CrosshairBase };
  64. //# sourceMappingURL=base.js.map