EllipseResize.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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, EllipseNode, EllipseNodeModel } from '@logicflow/core';
  15. import ControlGroup from '../Control/ControlGroup';
  16. var EllipseResizeModel = /** @class */ (function (_super) {
  17. __extends(EllipseResizeModel, _super);
  18. function EllipseResizeModel(data, graphModel) {
  19. var _this = _super.call(this, data, graphModel) || this;
  20. var nodeSize = _this.properties.nodeSize;
  21. if (nodeSize) {
  22. _this.rx = nodeSize.rx;
  23. _this.ry = nodeSize.ry;
  24. }
  25. return _this;
  26. }
  27. EllipseResizeModel.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. EllipseResizeModel.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. EllipseResizeModel.prototype.getResizeOutlineStyle = function () {
  46. return {
  47. stroke: '#000000',
  48. strokeWidth: 1,
  49. strokeDasharray: '3,3',
  50. };
  51. };
  52. EllipseResizeModel.prototype.getControlPointStyle = function () {
  53. return {
  54. width: 7,
  55. height: 7,
  56. fill: '#FFFFFF',
  57. stroke: '#000000',
  58. };
  59. };
  60. // 该方法需要在重设宽高和最大、最小限制后被调用,不建议在 initNodeData() 方法中使用
  61. EllipseResizeModel.prototype.enableProportionResize = function (turnOn) {
  62. if (turnOn === void 0) { turnOn = true; }
  63. if (turnOn) {
  64. var ResizePCT = { widthPCT: 100, hightPCT: 100 };
  65. var ResizeBasis = { basisWidth: this.rx, basisHeight: this.ry };
  66. var ScaleLimit = {
  67. maxScaleLimit: Math.min((this.maxWidth / (this.rx * 2)) * 100, (this.maxHeight / (this.ry * 2)) * 100),
  68. minScaleLimit: Math.max((this.minWidth / (this.rx * 2)) * 100, (this.minHeight / (this.ry * 2)) * 100),
  69. };
  70. this.PCTResizeInfo = { ResizePCT: ResizePCT, ResizeBasis: ResizeBasis, ScaleLimit: ScaleLimit };
  71. }
  72. else {
  73. delete this.PCTResizeInfo;
  74. }
  75. };
  76. return EllipseResizeModel;
  77. }(EllipseNodeModel));
  78. var EllipseResizeView = /** @class */ (function (_super) {
  79. __extends(EllipseResizeView, _super);
  80. function EllipseResizeView() {
  81. return _super !== null && _super.apply(this, arguments) || this;
  82. }
  83. EllipseResizeView.prototype.getControlGroup = function () {
  84. var _a = this.props, model = _a.model, graphModel = _a.graphModel;
  85. return (h(ControlGroup, { model: model, graphModel: graphModel }));
  86. };
  87. // getResizeShape绘制图形,功能等同于基础椭圆的getShape功能,可以通过复写此方法,进行节点自定义
  88. EllipseResizeView.prototype.getResizeShape = function () {
  89. return _super.prototype.getShape.call(this);
  90. };
  91. EllipseResizeView.prototype.getShape = function () {
  92. var _a = this.props, model = _a.model, isSilentMode = _a.graphModel.editConfigModel.isSilentMode;
  93. return (h("g", null,
  94. this.getResizeShape(),
  95. model.isSelected && !isSilentMode ? this.getControlGroup() : ''));
  96. };
  97. return EllipseResizeView;
  98. }(EllipseNode));
  99. var EllipseResize = {
  100. type: 'ellipse',
  101. view: EllipseResizeView,
  102. model: EllipseResizeModel,
  103. };
  104. export default EllipseResize;