handler.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.Handler = exports.DEFAULT_HANDLER_STYLE = void 0;
  4. var tslib_1 = require("tslib");
  5. var group_component_1 = require("../abstract/group-component");
  6. exports.DEFAULT_HANDLER_STYLE = {
  7. fill: '#F7F7F7',
  8. stroke: '#BFBFBF',
  9. radius: 2,
  10. opacity: 1,
  11. cursor: 'ew-resize',
  12. // 高亮的颜色
  13. highLightFill: '#FFF',
  14. };
  15. var Handler = /** @class */ (function (_super) {
  16. tslib_1.__extends(Handler, _super);
  17. function Handler() {
  18. return _super !== null && _super.apply(this, arguments) || this;
  19. }
  20. Handler.prototype.getDefaultCfg = function () {
  21. var cfg = _super.prototype.getDefaultCfg.call(this);
  22. return tslib_1.__assign(tslib_1.__assign({}, cfg), { name: 'handler', x: 0, y: 0, width: 10, height: 24, style: exports.DEFAULT_HANDLER_STYLE });
  23. };
  24. Handler.prototype.renderInner = function (group) {
  25. var _a = this.cfg, width = _a.width, height = _a.height, style = _a.style;
  26. var fill = style.fill, stroke = style.stroke, radius = style.radius, opacity = style.opacity, cursor = style.cursor;
  27. // 按钮框框
  28. this.addShape(group, {
  29. type: 'rect',
  30. id: this.getElementId('background'),
  31. attrs: {
  32. x: 0,
  33. y: 0,
  34. width: width,
  35. height: height,
  36. fill: fill,
  37. stroke: stroke,
  38. radius: radius,
  39. opacity: opacity,
  40. cursor: cursor,
  41. },
  42. });
  43. // 两根竖线
  44. var x1 = (1 / 3) * width;
  45. var x2 = (2 / 3) * width;
  46. var y1 = (1 / 4) * height;
  47. var y2 = (3 / 4) * height;
  48. this.addShape(group, {
  49. id: this.getElementId('line-left'),
  50. type: 'line',
  51. attrs: {
  52. x1: x1,
  53. y1: y1,
  54. x2: x1,
  55. y2: y2,
  56. stroke: stroke,
  57. cursor: cursor,
  58. },
  59. });
  60. this.addShape(group, {
  61. id: this.getElementId('line-right'),
  62. type: 'line',
  63. attrs: {
  64. x1: x2,
  65. y1: y1,
  66. x2: x2,
  67. y2: y2,
  68. stroke: stroke,
  69. cursor: cursor,
  70. },
  71. });
  72. };
  73. Handler.prototype.applyOffset = function () {
  74. this.moveElementTo(this.get('group'), {
  75. x: this.get('x'),
  76. y: this.get('y'),
  77. });
  78. };
  79. Handler.prototype.initEvent = function () {
  80. this.bindEvents();
  81. };
  82. Handler.prototype.bindEvents = function () {
  83. var _this = this;
  84. this.get('group').on('mouseenter', function () {
  85. var highLightFill = _this.get('style').highLightFill;
  86. _this.getElementByLocalId('background').attr('fill', highLightFill);
  87. _this.draw();
  88. });
  89. this.get('group').on('mouseleave', function () {
  90. var fill = _this.get('style').fill;
  91. _this.getElementByLocalId('background').attr('fill', fill);
  92. _this.draw();
  93. });
  94. };
  95. Handler.prototype.draw = function () {
  96. var canvas = this.get('container').get('canvas');
  97. if (canvas) {
  98. canvas.draw();
  99. }
  100. };
  101. return Handler;
  102. }(group_component_1.default));
  103. exports.Handler = Handler;
  104. exports.default = Handler;
  105. //# sourceMappingURL=handler.js.map