handler.js 3.2 KB

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