EllipseResize.js 4.3 KB

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