DiamondResize.js 4.8 KB

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