RectResize.js 4.3 KB

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