RectResize.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. "use strict";
  2. var __extends = (this && this.__extends) || (function () {
  3. var extendStatics = function (d, b) {
  4. extendStatics = Object.setPrototypeOf ||
  5. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  6. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  7. return extendStatics(d, b);
  8. };
  9. return function (d, b) {
  10. extendStatics(d, b);
  11. function __() { this.constructor = d; }
  12. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  13. };
  14. })();
  15. Object.defineProperty(exports, "__esModule", { value: true });
  16. var core_1 = require("@logicflow/core");
  17. var ControlGroup_1 = require("../Control/ControlGroup");
  18. var RectResizeModel = /** @class */ (function (_super) {
  19. __extends(RectResizeModel, _super);
  20. function RectResizeModel(data, graphModel) {
  21. var _this = _super.call(this, data, graphModel) || this;
  22. var nodeSize = _this.properties.nodeSize;
  23. if (nodeSize) {
  24. _this.width = nodeSize.width;
  25. _this.height = nodeSize.height;
  26. }
  27. return _this;
  28. }
  29. RectResizeModel.prototype.initNodeData = function (data) {
  30. _super.prototype.initNodeData.call(this, data);
  31. this.minWidth = 30;
  32. this.minHeight = 30;
  33. this.maxWidth = 2000;
  34. this.maxHeight = 2000;
  35. };
  36. RectResizeModel.prototype.getOutlineStyle = function () {
  37. var style = _super.prototype.getOutlineStyle.call(this);
  38. var isSilentMode = this.graphModel.editConfigModel.isSilentMode;
  39. if (isSilentMode)
  40. return style;
  41. style.stroke = 'none';
  42. if (style.hover) {
  43. style.hover.stroke = 'none';
  44. }
  45. return style;
  46. };
  47. RectResizeModel.prototype.getResizeOutlineStyle = function () {
  48. return {
  49. fill: 'none',
  50. stroke: 'transparent',
  51. strokeWidth: 1,
  52. strokeDasharray: '3,3',
  53. };
  54. };
  55. RectResizeModel.prototype.getControlPointStyle = function () {
  56. return {
  57. width: 7,
  58. height: 7,
  59. fill: '#FFFFFF',
  60. stroke: '#000000',
  61. };
  62. };
  63. RectResizeModel.prototype.resize = function (deltaX, deltaY) {
  64. console.log(deltaX, deltaY);
  65. };
  66. // 该方法需要在重设宽高和最大、最小限制后被调用,不建议在 initNodeData() 方法中使用
  67. RectResizeModel.prototype.enableProportionResize = function (turnOn) {
  68. if (turnOn === void 0) { turnOn = true; }
  69. if (turnOn) {
  70. var ResizePCT = { widthPCT: 100, hightPCT: 100 };
  71. var ResizeBasis = { basisWidth: this.width, basisHeight: this.height };
  72. var ScaleLimit = {
  73. maxScaleLimit: Math.min((this.maxWidth / this.width) * 100, (this.maxHeight / this.height) * 100),
  74. minScaleLimit: Math.max((this.minWidth / this.width) * 100, (this.minHeight / this.height) * 100),
  75. };
  76. this.PCTResizeInfo = { ResizePCT: ResizePCT, ResizeBasis: ResizeBasis, ScaleLimit: ScaleLimit };
  77. }
  78. else {
  79. delete this.PCTResizeInfo;
  80. }
  81. };
  82. return RectResizeModel;
  83. }(core_1.RectNodeModel));
  84. var RectResizeView = /** @class */ (function (_super) {
  85. __extends(RectResizeView, _super);
  86. function RectResizeView() {
  87. return _super !== null && _super.apply(this, arguments) || this;
  88. }
  89. RectResizeView.prototype.getControlGroup = function () {
  90. var _a = this.props, model = _a.model, graphModel = _a.graphModel;
  91. return (core_1.h(ControlGroup_1.default, { model: model, graphModel: graphModel }));
  92. };
  93. // getResizeShape绘制图形,功能等同于基础矩形的getShape功能,可以通过复写此方法,进行节点自定义
  94. RectResizeView.prototype.getResizeShape = function () {
  95. return _super.prototype.getShape.call(this);
  96. };
  97. RectResizeView.prototype.getShape = function () {
  98. var _a = this.props, isSelected = _a.model.isSelected, isSilentMode = _a.graphModel.editConfigModel.isSilentMode;
  99. return (core_1.h("g", null,
  100. this.getResizeShape(),
  101. isSelected && !isSilentMode ? this.getControlGroup() : ''));
  102. };
  103. return RectResizeView;
  104. }(core_1.RectNode));
  105. var RectResize = {
  106. type: 'rect',
  107. view: RectResizeView,
  108. model: RectResizeModel,
  109. };
  110. exports.default = RectResize;