DiamondResize.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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. var __assign = (this && this.__assign) || function () {
  16. __assign = Object.assign || function(t) {
  17. for (var s, i = 1, n = arguments.length; i < n; i++) {
  18. s = arguments[i];
  19. for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
  20. t[p] = s[p];
  21. }
  22. return t;
  23. };
  24. return __assign.apply(this, arguments);
  25. };
  26. Object.defineProperty(exports, "__esModule", { value: true });
  27. var core_1 = require("@logicflow/core");
  28. var ControlGroup_1 = require("../Control/ControlGroup");
  29. var Polygon_1 = require("../BasicShape/Polygon");
  30. var DiamondResizeModel = /** @class */ (function (_super) {
  31. __extends(DiamondResizeModel, _super);
  32. function DiamondResizeModel(data, graphModel) {
  33. var _this = _super.call(this, data, graphModel) || this;
  34. var nodeSize = _this.properties.nodeSize;
  35. if (nodeSize) {
  36. _this.rx = nodeSize.rx;
  37. _this.ry = nodeSize.ry;
  38. }
  39. return _this;
  40. }
  41. DiamondResizeModel.prototype.initNodeData = function (data) {
  42. _super.prototype.initNodeData.call(this, data);
  43. this.minWidth = 30;
  44. this.minHeight = 30;
  45. this.maxWidth = 2000;
  46. this.maxHeight = 2000;
  47. this.gridSize = 1;
  48. };
  49. DiamondResizeModel.prototype.getOutlineStyle = function () {
  50. var style = _super.prototype.getOutlineStyle.call(this);
  51. var isSilentMode = this.graphModel.editConfigModel.isSilentMode;
  52. if (isSilentMode)
  53. return style;
  54. style.stroke = 'none';
  55. if (style.hover) {
  56. style.hover.stroke = 'none';
  57. }
  58. return style;
  59. };
  60. DiamondResizeModel.prototype.getResizeOutlineStyle = function () {
  61. return {
  62. stroke: '#000000',
  63. strokeWidth: 1,
  64. strokeDasharray: '3,3',
  65. };
  66. };
  67. DiamondResizeModel.prototype.getControlPointStyle = function () {
  68. return {
  69. width: 7,
  70. height: 7,
  71. fill: '#FFFFFF',
  72. stroke: '#000000',
  73. };
  74. };
  75. // 该方法需要在重设宽高和最大、最小限制后被调用,不建议在 initNodeData() 方法中使用
  76. DiamondResizeModel.prototype.enableProportionResize = function (turnOn) {
  77. if (turnOn === void 0) { turnOn = true; }
  78. if (turnOn) {
  79. var ResizePCT = { widthPCT: 100, hightPCT: 100 };
  80. var ResizeBasis = { basisWidth: this.rx, basisHeight: this.ry };
  81. var ScaleLimit = {
  82. maxScaleLimit: Math.min((this.maxWidth / (this.rx * 2)) * 100, (this.maxHeight / (this.ry * 2)) * 100),
  83. minScaleLimit: Math.max((this.minWidth / (this.rx * 2)) * 100, (this.minHeight / (this.ry * 2)) * 100),
  84. };
  85. this.PCTResizeInfo = { ResizePCT: ResizePCT, ResizeBasis: ResizeBasis, ScaleLimit: ScaleLimit };
  86. }
  87. else {
  88. delete this.PCTResizeInfo;
  89. }
  90. };
  91. return DiamondResizeModel;
  92. }(core_1.DiamondNodeModel));
  93. var DiamondResizeView = /** @class */ (function (_super) {
  94. __extends(DiamondResizeView, _super);
  95. function DiamondResizeView() {
  96. return _super !== null && _super.apply(this, arguments) || this;
  97. }
  98. DiamondResizeView.prototype.getControlGroup = function () {
  99. var _a = this.props, model = _a.model, graphModel = _a.graphModel;
  100. return (core_1.h(ControlGroup_1.default, { model: model, graphModel: graphModel }));
  101. };
  102. // getResizeShape绘制图形,功能等同于基础菱形的getShape功能,可以通过复写此方法,进行节点自定义
  103. DiamondResizeView.prototype.getResizeShape = function () {
  104. var model = this.props.model;
  105. var points = model.points;
  106. var style = model.getNodeStyle();
  107. return (core_1.h("g", null,
  108. core_1.h(Polygon_1.default, __assign({}, style, { points: points }))));
  109. };
  110. DiamondResizeView.prototype.getShape = function () {
  111. var _a = this.props, isSelected = _a.model.isSelected, isSilentMode = _a.graphModel.editConfigModel.isSilentMode;
  112. return (core_1.h("g", null,
  113. this.getResizeShape(),
  114. isSelected && !isSilentMode ? this.getControlGroup() : ''));
  115. };
  116. return DiamondResizeView;
  117. }(core_1.DiamondNode));
  118. var EllipseResize = {
  119. type: 'diamond',
  120. view: DiamondResizeView,
  121. model: DiamondResizeModel,
  122. };
  123. exports.default = EllipseResize;