本地logicflow依赖包

This commit is contained in:
Jam committed 2022-11-28 14:31:03 +08:00
1 parent 8ff82208ad
commit 30f225df00
290 files changed
+18624 -16276

No files matched your search

@@ -0,0 +1,29 @@
"use strict";
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
Object.defineProperty(exports, "__esModule", { value: true });
var core_1 = require("@logicflow/core");
function Polygon(_a) {
var _b = _a.fillOpacity, fillOpacity = _b === void 0 ? 1 : _b, _c = _a.strokeWidth, strokeWidth = _c === void 0 ? 1 : _c, _d = _a.strokeOpacity, strokeOpacity = _d === void 0 ? 1 : _d, _e = _a.fill, fill = _e === void 0 ? 'transparent' : _e, _f = _a.stroke, stroke = _f === void 0 ? '#000' : _f, points = _a.points, _g = _a.className, className = _g === void 0 ? 'lf-basic-shape' : _g;
var attrs = {
fill: fill,
fillOpacity: fillOpacity,
strokeWidth: strokeWidth,
stroke: stroke,
strokeOpacity: strokeOpacity,
points: '',
className: className,
};
attrs.points = points.map(function (point) { return point.join(','); }).join(' ');
return (core_1.h("polygon", __assign({}, attrs)));
}
exports.default = Polygon;
@@ -0,0 +1,31 @@
"use strict";
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
Object.defineProperty(exports, "__esModule", { value: true });
var core_1 = require("@logicflow/core");
// TODO: 默认样式引入
function Rect(props) {
var x = props.x, y = props.y, width = props.width, height = props.height, radius = props.radius, className = props.className;
var leftTopX = x - width / 2;
var leftTopY = y - height / 2;
var attrs = __assign(__assign({
// default
width: 10, height: 10, cx: 0, cy: 0, rx: radius || 0, ry: radius || 0, fill: 'transparent', fillOpacity: 1, strokeWidth: '1px', stroke: '#000', strokeOpacity: 1, className: "lf-basic-shape " + className }, props), { x: leftTopX, y: leftTopY });
return (core_1.h("rect", __assign({}, attrs)));
}
exports.default = Rect;
Rect.defaultProps = {
radius: 0,
stroke: '',
strokeDasharray: '',
className: '',
};
@@ -0,0 +1,332 @@
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
Object.defineProperty(exports, "__esModule", { value: true });
var preact_1 = require("preact");
var core_1 = require("@logicflow/core");
var Rect_1 = require("../BasicShape/Rect");
var Util_1 = require("./Util");
var StepDrag = core_1.LogicFlowUtil.StepDrag;
var Control = /** @class */ (function (_super) {
__extends(Control, _super);
function Control(props) {
var _this = _super.call(this) || this;
// 更新中心点位置,更新文案位置
_this.updatePosition = function (_a) {
var deltaX = _a.deltaX, deltaY = _a.deltaY;
var _b = _this.nodeModel, x = _b.x, y = _b.y;
_this.nodeModel.x = x + deltaX / 2;
_this.nodeModel.y = y + deltaY / 2;
_this.nodeModel.moveText(deltaX / 2, deltaY / 2);
};
// 计算control拖动后,节点的宽高
_this.getResize = function (_a) {
var index = _a.index, deltaX = _a.deltaX, deltaY = _a.deltaY, width = _a.width, height = _a.height, _b = _a.pct, pct = _b === void 0 ? 1 : _b;
var resize = { width: width, height: height };
switch (index) {
case 0:
resize.width = width - deltaX * pct;
resize.height = height - deltaY * pct;
break;
case 1:
resize.width = width + deltaX * pct;
resize.height = height - deltaY * pct;
break;
case 2:
resize.width = width + deltaX;
resize.height = height + deltaY * pct;
break;
case 3:
resize.width = width - deltaX * pct;
resize.height = height + deltaY * pct;
break;
default:
break;
}
return resize;
};
// 矩形更新
_this.updateRect = function (_a) {
var deltaX = _a.deltaX, deltaY = _a.deltaY;
var _b = _this.nodeModel, id = _b.id, x = _b.x, y = _b.y, width = _b.width, height = _b.height, radius = _b.radius;
// 更新中心点位置,更新文案位置
var index = _this.index;
var size = _this.getResize({
index: index,
deltaX: deltaX,
deltaY: deltaY,
width: width,
height: height,
pct: 1,
});
// 限制放大缩小的最大最小范围
var _c = _this.nodeModel, minWidth = _c.minWidth, minHeight = _c.minHeight, maxWidth = _c.maxWidth, maxHeight = _c.maxHeight;
if (size.width < minWidth
|| size.width > maxWidth
|| size.height < minHeight
|| size.height > maxHeight) {
// 为了避免放到和缩小位置和鼠标不一致的问题
_this.dragHandler.cancelDrag();
return;
}
_this.updatePosition({ deltaX: deltaX, deltaY: deltaY });
// 更新宽高
_this.nodeModel.width = size.width;
_this.nodeModel.height = size.height;
_this.nodeModel.setProperties({
nodeSize: {
width: size.width,
height: size.height,
},
});
var edges = _this.getNodeEdges(id);
var beforeNode = {
x: x,
y: y,
width: width,
height: height,
radius: radius,
};
var afterNode = {
x: _this.nodeModel.x,
y: _this.nodeModel.y,
width: _this.nodeModel.width,
height: _this.nodeModel.height,
radius: radius,
};
var params = {
point: '',
beforeNode: beforeNode,
afterNode: afterNode,
};
// 更新边
var afterPoint;
edges.sourceEdges.forEach(function (item) {
params.point = item.startPoint;
afterPoint = Util_1.getRectReizeEdgePoint(params);
item.updateStartPoint(afterPoint);
});
edges.targetEdges.forEach(function (item) {
params.point = item.endPoint;
afterPoint = Util_1.getRectReizeEdgePoint(params);
item.updateEndPoint(afterPoint);
});
_this.eventEmit({ beforeNode: beforeNode, afterNode: afterNode });
};
// 椭圆更新
_this.updateEllipse = function (_a) {
var deltaX = _a.deltaX, deltaY = _a.deltaY;
var _b = _this.nodeModel, id = _b.id, rx = _b.rx, ry = _b.ry, x = _b.x, y = _b.y;
var index = _this.index;
var width = rx;
var height = ry;
var size = _this.getResize({
index: index,
deltaX: deltaX,
deltaY: deltaY,
width: width,
height: height,
pct: 1 / 2,
});
// 限制放大缩小的最大最小范围
var _c = _this.nodeModel, minWidth = _c.minWidth, minHeight = _c.minHeight, maxWidth = _c.maxWidth, maxHeight = _c.maxHeight;
if (size.width < (minWidth / 2)
|| size.width > (maxWidth / 2)
|| size.height < (minHeight / 2)
|| size.height > (maxHeight / 2)) {
_this.dragHandler.cancelDrag();
return;
}
// 更新中心点位置,更新文案位置
_this.updatePosition({ deltaX: deltaX, deltaY: deltaY });
// 更新rx ry,宽高为计算属性自动更新
// @ts-ignore
_this.nodeModel.rx = _this.nodeModel.rx + deltaX / 2;
// @ts-ignore
_this.nodeModel.ry = _this.nodeModel.ry + deltaY / 2;
_this.nodeModel.setProperties({
nodeSize: {
rx: size.width,
ry: size.height,
},
});
var edges = _this.getNodeEdges(id);
var beforeNode = { x: x, y: y };
var afterNode = {
rx: size.width,
ry: size.height,
x: _this.nodeModel.x,
y: _this.nodeModel.y,
};
var params = {
point: {},
beforeNode: beforeNode,
afterNode: afterNode,
};
// 更新边
var afterPoint;
edges.sourceEdges.forEach(function (item) {
params.point = item.startPoint;
afterPoint = Util_1.getEllipseReizeEdgePoint(params);
item.updateStartPoint(afterPoint);
});
edges.targetEdges.forEach(function (item) {
params.point = item.endPoint;
afterPoint = Util_1.getEllipseReizeEdgePoint(params);
item.updateEndPoint(afterPoint);
});
_this.eventEmit({ beforeNode: __assign(__assign({}, beforeNode), { rx: rx, ry: ry }), afterNode: afterNode });
};
// 菱形更新
_this.updateDiamond = function (_a) {
var deltaX = _a.deltaX, deltaY = _a.deltaY;
var _b = _this.nodeModel, id = _b.id, rx = _b.rx, ry = _b.ry, x = _b.x, y = _b.y;
var index = _this.index;
var width = rx;
var height = ry;
var size = _this.getResize({
index: index,
deltaX: deltaX,
deltaY: deltaY,
width: width,
height: height,
pct: 1 / 2,
});
// 限制放大缩小的最大最小范围
var _c = _this.nodeModel, minWidth = _c.minWidth, minHeight = _c.minHeight, maxWidth = _c.maxWidth, maxHeight = _c.maxHeight;
if (size.width < (minWidth / 2)
|| size.width > (maxWidth / 2)
|| size.height < (minHeight / 2)
|| size.height > (maxHeight / 2)) {
_this.dragHandler.cancelDrag();
return;
}
// 更新中心点位置,更新文案位置
_this.updatePosition({ deltaX: deltaX, deltaY: deltaY });
// 更新rx ry,宽高为计算属性自动更新
// @ts-ignore
_this.nodeModel.rx = _this.nodeModel.rx + deltaX / 2;
// @ts-ignore
_this.nodeModel.ry = _this.nodeModel.ry + deltaY / 2;
_this.nodeModel.setProperties({
nodeSize: {
rx: size.width,
ry: size.height,
},
});
var beforeNode = { x: x, y: y, rx: rx, ry: ry };
var afterNode = {
rx: size.width,
ry: size.height,
x: _this.nodeModel.x,
y: _this.nodeModel.y,
};
var params = {
point: {},
beforeNode: beforeNode,
afterNode: afterNode,
};
// 更新边
var afterPoint;
var edges = _this.getNodeEdges(id);
edges.sourceEdges.forEach(function (item) {
params.point = item.startPoint;
afterPoint = Util_1.getDiamondReizeEdgePoint(params);
item.updateStartPoint(afterPoint);
});
edges.targetEdges.forEach(function (item) {
params.point = item.endPoint;
afterPoint = Util_1.getDiamondReizeEdgePoint(params);
item.updateEndPoint(afterPoint);
});
_this.eventEmit({ beforeNode: beforeNode, afterNode: afterNode });
};
_this.eventEmit = function (_a) {
var beforeNode = _a.beforeNode, afterNode = _a.afterNode;
var _b = _this.nodeModel, id = _b.id, modelType = _b.modelType, type = _b.type;
var oldNodeSize = __assign({ id: id, modelType: modelType, type: type }, beforeNode);
var newNodeSize = __assign({ id: id, modelType: modelType, type: type }, afterNode);
_this.graphModel.eventCenter.emit('node:resize', { oldNodeSize: oldNodeSize, newNodeSize: newNodeSize });
};
_this.onDraging = function (_a) {
var deltaX = _a.deltaX, deltaY = _a.deltaY;
var modelType = _this.nodeModel.modelType;
// html和矩形的计算方式是一样的,共用一个方法
if (modelType === Util_1.ModelType.RECT_NODE || modelType === Util_1.ModelType.HTML_NODE) {
_this.updateRect({ deltaX: deltaX, deltaY: deltaY });
// this.nodeModel.resize(deltaX, deltaY);
}
else if (modelType === Util_1.ModelType.ELLIPSE_NODE) {
_this.updateEllipse({ deltaX: deltaX, deltaY: deltaY });
}
else if (modelType === Util_1.ModelType.DIAMOND_NODE) {
_this.updateDiamond({ deltaX: deltaX, deltaY: deltaY });
}
};
_this.index = props.index;
_this.nodeModel = props.model;
_this.graphModel = props.graphModel;
var gridSize = _this.graphModel.gridSize;
// 为保证对齐线功能正常使用,step默认是网格grid的两倍,
// 没有网格设置,默认为2,保证坐标是整数
var step = 2;
if (gridSize > 1) {
step = 2 * gridSize;
}
if (_this.nodeModel.gridSize) {
step = 2 * _this.nodeModel.gridSize;
}
_this.state = {};
_this.dragHandler = new StepDrag({
onDraging: _this.onDraging,
step: step,
});
return _this;
}
Control.prototype.getNodeEdges = function (nodeId) {
var graphModel = this.graphModel;
var edges = graphModel.edges;
var sourceEdges = [];
var targetEdges = [];
for (var i = 0; i < edges.length; i++) {
var edgeModel = edges[i];
if (edgeModel.sourceNodeId === nodeId) {
sourceEdges.push(edgeModel);
}
else if (edges[i].targetNodeId === nodeId) {
targetEdges.push(edgeModel);
}
}
return { sourceEdges: sourceEdges, targetEdges: targetEdges };
};
Control.prototype.render = function () {
var _a = this.props, x = _a.x, y = _a.y, index = _a.index, model = _a.model;
var style = model.getControlPointStyle();
return (preact_1.h("g", { className: "lf-resize-control-" + index },
preact_1.h(Rect_1.default, __assign({ className: "lf-node-control" }, { x: x, y: y }, style, { onMouseDown: this.dragHandler.handleMouseDown }))));
};
return Control;
}(preact_1.Component));
exports.default = Control;
@@ -0,0 +1,85 @@
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
Object.defineProperty(exports, "__esModule", { value: true });
var preact_1 = require("preact");
var Control_1 = require("./Control");
var Rect_1 = require("../BasicShape/Rect");
var ControlGroup = /** @class */ (function (_super) {
__extends(ControlGroup, _super);
function ControlGroup() {
var _this = _super.call(this) || this;
_this.state = {};
return _this;
}
ControlGroup.prototype.getResizeControl = function () {
var _a = this.props, model = _a.model, graphModel = _a.graphModel;
var x = model.x, y = model.y, width = model.width, height = model.height;
var box = {
minX: x - width / 2,
minY: y - height / 2,
maxX: x + width / 2,
maxY: y + height / 2,
};
var minX = box.minX, minY = box.minY, maxX = box.maxX, maxY = box.maxY;
var controlList = [
// 左上角
{
x: minX,
y: minY,
},
// 右上角
{
x: maxX,
y: minY,
},
// 右下角
{
x: maxX,
y: maxY,
},
// 左下角
{
x: minX,
y: maxY,
},
];
return controlList.map(function (control, index) { return (preact_1.h(Control_1.default, __assign({ index: index }, control, { model: model, graphModel: graphModel }))); });
};
// 一般节点被选中了会有outline, 先不用这个
ControlGroup.prototype.getGroupSolid = function () {
var model = this.props.model;
var x = model.x, y = model.y, width = model.width, height = model.height;
var style = model.getResizeOutlineStyle();
return (preact_1.h(Rect_1.default, __assign({ fill: "none" }, style, { x: x, y: y, width: width, height: height })));
};
ControlGroup.prototype.render = function () {
return (preact_1.h("g", { className: "lf-resize-control" },
this.getGroupSolid(),
this.getResizeControl()));
};
return ControlGroup;
}(preact_1.Component));
exports.default = ControlGroup;
@@ -0,0 +1,216 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getDiamondReizeEdgePoint = exports.getEllipseReizeEdgePoint = exports.getRectReizeEdgePoint = exports.ModelType = void 0;
var ModelType;
(function (ModelType) {
ModelType["NODE"] = "node";
ModelType["CIRCLE_NODE"] = "circle-node";
ModelType["POLYGON_NODE"] = "polygon-node";
ModelType["RECT_NODE"] = "rect-node";
ModelType["HTML_NODE"] = "html-node";
ModelType["TEXT_NODE"] = "text-node";
ModelType["ELLIPSE_NODE"] = "ellipse-node";
ModelType["DIAMOND_NODE"] = "diamond-node";
ModelType["EDGE"] = "edge";
ModelType["LINE_EDGE"] = "line-edge";
ModelType["POLYLINE_EDGE"] = "polyline-edge";
ModelType["BEZIER_EDGE"] = "bezier-edge";
ModelType["GRAPH"] = "graph";
})(ModelType = exports.ModelType || (exports.ModelType = {}));
// 计算节点的box四角数据
function getNodeBox(node) {
var x = node.x, y = node.y, width = node.width, height = node.height;
return {
minX: x - width / 2,
minY: y - height / 2,
maxX: x + width / 2,
maxY: y + height / 2,
};
}
// 计算矩形radius设置后,四个圆角的圆心
function getRidusCenter(node) {
var nodeBox = getNodeBox(node);
var radius = node.radius;
var minX = nodeBox.minX, minY = nodeBox.minY, maxX = nodeBox.maxX, maxY = nodeBox.maxY;
return [
{
x: minX + radius,
y: minY + radius,
},
{
x: maxX - radius,
y: minY + radius,
},
{
x: maxX - radius,
y: maxY - radius,
},
{
x: minX + radius,
y: maxY - radius,
},
];
}
// 获取矩形resize之后,与矩形连接边的新端点
function getRectReizeEdgePoint(_a) {
var point = _a.point, beforeNode = _a.beforeNode, afterNode = _a.afterNode;
var x = point.x, y = point.y;
var afterPoint = {
x: x, y: y,
};
var radius = beforeNode.radius;
var beforeNodeBox = getNodeBox(beforeNode);
var afterNodeBox = getNodeBox(afterNode);
if (x === beforeNodeBox.minX) {
// 左边
afterPoint.x = afterNodeBox.minX;
var pct = (y - beforeNode.y) / (beforeNode.height / 2 - radius);
if (pct) {
afterPoint.y = afterNode.y + (afterNode.height / 2 - radius) * pct;
}
else {
afterPoint.y = afterNode.y;
}
}
else if (x === beforeNodeBox.maxX) {
// 右边
afterPoint.x = afterNodeBox.maxX;
var pct = (y - beforeNode.y) / (beforeNode.height / 2 - radius);
if (pct) {
afterPoint.y = afterNode.y + (afterNode.height / 2 - radius) * pct;
}
else {
afterPoint.y = afterNode.y;
}
}
else if (y === beforeNodeBox.minY) {
// 上边
afterPoint.y = afterNodeBox.minY;
var pct = (x - beforeNode.x) / (beforeNode.width / 2 - radius);
if (pct) {
afterPoint.x = afterNode.x + (afterNode.width / 2 - radius) * pct;
}
else {
afterPoint.x = afterNode.x;
}
}
else if (y === beforeNodeBox.maxY) {
// 下边
afterPoint.y = afterNodeBox.maxY;
var pct = (x - beforeNode.x) / (beforeNode.width / 2 - radius);
if (pct) {
afterPoint.x = afterNode.x + (afterNode.width / 2 - radius) * pct;
}
else {
afterPoint.x = afterNode.x;
}
}
else {
// 在圆角部分
var beeforCoc = getRidusCenter(beforeNode);
var afterCoc = getRidusCenter(afterNode);
var nodeBox = getNodeBox(beforeNode);
var minX = nodeBox.minX, minY = nodeBox.minY, maxX = nodeBox.maxX, maxY = nodeBox.maxY;
var index = -1;
if (x - minX < radius && y - minY < radius) {
// 左上角
index = 0;
}
else if (maxX - x < radius && y - minY < radius) {
// 右上角
index = 1;
}
else if (maxX - x < radius && maxY - y < radius) {
// 右下角
index = 2;
}
else if (x - minX < radius && minY - y < radius) {
// 左下角
index = 3;
}
if (index > -1) {
// 根据夹角角度计算位置
var angle = Math.atan2((y - beeforCoc[index].y), (x - beeforCoc[index].x));
afterPoint.x = afterCoc[index].x + radius * Math.cos(angle);
afterPoint.y = afterCoc[index].y + radius * Math.sin(angle);
}
}
return afterPoint;
}
exports.getRectReizeEdgePoint = getRectReizeEdgePoint;
// 获取椭圆resize之后,与椭圆连接边的新端点
function getEllipseReizeEdgePoint(_a) {
var point = _a.point, beforeNode = _a.beforeNode, afterNode = _a.afterNode;
var rx = afterNode.rx, ry = afterNode.ry;
var afterPoint = point;
// 将椭圆中心当做中心点(0,0),放大缩小前点与X周夹角
var tan = (point.y - beforeNode.y) / (point.x - beforeNode.x);
// 方便与公式对照,将rx命名为a,ry命名为b
var a = rx;
var b = ry;
var x;
var y;
// 将椭圆中心当做中心点(0,0),计算放大缩小后,同一夹角下,点相对位置
if (tan >= Infinity) {
// θ = PI / 2
x = 0;
y = b;
}
else if (tan <= -Infinity) {
// θ = 3 * PI / 2
x = 0;
y = -b;
}
else if (point.x - beforeNode.x > 0) {
// 0 < θ = PI / 2 或者 3 * PI / 2 < θ = 2 * PI
// 一四象限
x = (a * b) / (Math.sqrt((b * b) + a * a * tan * tan));
y = (a * b * tan) / (Math.sqrt((b * b) + a * a * tan * tan));
}
else {
// PI / 2 < θ 3 * PI / 2
// 二三象限
x = -(a * b) / (Math.sqrt((b * b) + a * a * tan * tan));
y = -(a * b * tan) / (Math.sqrt((b * b) + a * a * tan * tan));
}
afterPoint = { x: x + afterNode.x, y: y + afterNode.y };
return afterPoint;
}
exports.getEllipseReizeEdgePoint = getEllipseReizeEdgePoint;
// 获取菱形resize之后,与菱形连接边的新端点
function getDiamondReizeEdgePoint(_a) {
var point = _a.point, beforeNode = _a.beforeNode, afterNode = _a.afterNode;
var afterPoint = point;
var x;
var y;
var px = point.x - beforeNode.x;
var py = point.y - beforeNode.y;
var rxBefore = beforeNode.rx;
var ryBefore = beforeNode.ry;
// eslint-disable-next-line max-len
var pct = Math.sqrt((rxBefore - Math.abs(px)) * (rxBefore - Math.abs(px)) + py * py) / Math.sqrt(rxBefore * rxBefore + ryBefore * ryBefore);
var rxAfter = afterNode.rx;
var ryAfter = afterNode.ry;
// eslint-disable-next-line max-len
var a = Math.sqrt((rxAfter * rxAfter + ryAfter * ryAfter) * pct * pct * ((rxAfter * rxAfter) / (rxAfter * rxAfter + ryAfter * ryAfter)));
var b = a * (ryAfter / rxAfter);
if (px >= 0) {
// eslint-disable-next-line max-len
x = rxAfter - a;
}
else {
x = a - rxAfter;
}
if (py > 0) {
y = b;
}
else {
y = -b;
}
afterPoint = {
x: x + afterNode.x,
y: y + afterNode.y,
};
return afterPoint;
}
exports.getDiamondReizeEdgePoint = getDiamondReizeEdgePoint;
@@ -0,0 +1,104 @@
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
Object.defineProperty(exports, "__esModule", { value: true });
var core_1 = require("@logicflow/core");
var ControlGroup_1 = require("../Control/ControlGroup");
var Polygon_1 = require("../BasicShape/Polygon");
var DiamondResizeModel = /** @class */ (function (_super) {
__extends(DiamondResizeModel, _super);
function DiamondResizeModel(data, graphModel) {
var _this = _super.call(this, data, graphModel) || this;
var nodeSize = _this.properties.nodeSize;
if (nodeSize) {
_this.rx = nodeSize.rx;
_this.ry = nodeSize.ry;
}
return _this;
}
DiamondResizeModel.prototype.initNodeData = function (data) {
_super.prototype.initNodeData.call(this, data);
this.minWidth = 30;
this.minHeight = 30;
this.maxWidth = 2000;
this.maxHeight = 2000;
this.gridSize = 1;
};
DiamondResizeModel.prototype.getOutlineStyle = function () {
var style = _super.prototype.getOutlineStyle.call(this);
style.stroke = 'none';
if (style.hover) {
style.hover.stroke = 'none';
}
return style;
};
DiamondResizeModel.prototype.getResizeOutlineStyle = function () {
return {
stroke: '#000000',
strokeWidth: 1,
strokeDasharray: '3,3',
};
};
DiamondResizeModel.prototype.getControlPointStyle = function () {
return {
width: 7,
height: 7,
fill: '#FFFFFF',
stroke: '#000000',
};
};
return DiamondResizeModel;
}(core_1.DiamondNodeModel));
var DiamondResizeView = /** @class */ (function (_super) {
__extends(DiamondResizeView, _super);
function DiamondResizeView() {
return _super !== null && _super.apply(this, arguments) || this;
}
DiamondResizeView.prototype.getControlGroup = function () {
var _a = this.props, model = _a.model, graphModel = _a.graphModel;
return (core_1.h(ControlGroup_1.default, { model: model, graphModel: graphModel }));
};
// getResizeShape绘制图形,功能等同于基础菱形的getShape功能,可以通过复写此方法,进行节点自定义
DiamondResizeView.prototype.getResizeShape = function () {
var model = this.props.model;
var points = model.points;
var style = model.getNodeStyle();
return (core_1.h("g", null,
core_1.h(Polygon_1.default, __assign({}, style, { points: points }))));
};
DiamondResizeView.prototype.getShape = function () {
var isSelected = this.props.model.isSelected;
return (core_1.h("g", null,
this.getResizeShape(),
isSelected ? this.getControlGroup() : ''));
};
return DiamondResizeView;
}(core_1.DiamondNode));
var EllipseResize = {
type: 'diamond',
view: DiamondResizeView,
model: DiamondResizeModel,
};
exports.default = EllipseResize;
@@ -0,0 +1,87 @@
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
var core_1 = require("@logicflow/core");
var ControlGroup_1 = require("../Control/ControlGroup");
var EllipseResizeModel = /** @class */ (function (_super) {
__extends(EllipseResizeModel, _super);
function EllipseResizeModel(data, graphModel) {
var _this = _super.call(this, data, graphModel) || this;
var nodeSize = _this.properties.nodeSize;
if (nodeSize) {
_this.rx = nodeSize.rx;
_this.ry = nodeSize.ry;
}
return _this;
}
EllipseResizeModel.prototype.initNodeData = function (data) {
_super.prototype.initNodeData.call(this, data);
this.minWidth = 30;
this.minHeight = 30;
this.maxWidth = 2000;
this.maxHeight = 2000;
};
EllipseResizeModel.prototype.getOutlineStyle = function () {
var style = _super.prototype.getOutlineStyle.call(this);
style.stroke = 'none';
if (style.hover) {
style.hover.stroke = 'none';
}
return style;
};
EllipseResizeModel.prototype.getResizeOutlineStyle = function () {
return {
stroke: '#000000',
strokeWidth: 1,
strokeDasharray: '3,3',
};
};
EllipseResizeModel.prototype.getControlPointStyle = function () {
return {
width: 7,
height: 7,
fill: '#FFFFFF',
stroke: '#000000',
};
};
return EllipseResizeModel;
}(core_1.EllipseNodeModel));
var EllipseResizeView = /** @class */ (function (_super) {
__extends(EllipseResizeView, _super);
function EllipseResizeView() {
return _super !== null && _super.apply(this, arguments) || this;
}
EllipseResizeView.prototype.getControlGroup = function () {
var _a = this.props, model = _a.model, graphModel = _a.graphModel;
return (core_1.h(ControlGroup_1.default, { model: model, graphModel: graphModel }));
};
// getResizeShape绘制图形,功能等同于基础椭圆的getShape功能,可以通过复写此方法,进行节点自定义
EllipseResizeView.prototype.getResizeShape = function () {
return _super.prototype.getShape.call(this);
};
EllipseResizeView.prototype.getShape = function () {
var model = this.props.model;
return (core_1.h("g", null,
this.getResizeShape(),
model.isSelected ? this.getControlGroup() : ''));
};
return EllipseResizeView;
}(core_1.EllipseNode));
var EllipseResize = {
type: 'ellipse',
view: EllipseResizeView,
model: EllipseResizeModel,
};
exports.default = EllipseResize;
@@ -0,0 +1,87 @@
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
var core_1 = require("@logicflow/core");
var ControlGroup_1 = require("../Control/ControlGroup");
var HtmlResizeModel = /** @class */ (function (_super) {
__extends(HtmlResizeModel, _super);
function HtmlResizeModel(data, graphModel) {
var _this = _super.call(this, data, graphModel) || this;
var nodeSize = _this.properties.nodeSize;
if (nodeSize) {
_this.width = nodeSize.width;
_this.height = nodeSize.height;
}
return _this;
}
HtmlResizeModel.prototype.initNodeData = function (data) {
_super.prototype.initNodeData.call(this, data);
this.minWidth = 30;
this.minHeight = 30;
this.maxWidth = 2000;
this.maxHeight = 2000;
};
HtmlResizeModel.prototype.getOutlineStyle = function () {
var style = _super.prototype.getOutlineStyle.call(this);
style.stroke = 'none';
if (style.hover) {
style.hover.stroke = 'none';
}
return style;
};
HtmlResizeModel.prototype.getResizeOutlineStyle = function () {
return {
stroke: '#000000',
strokeWidth: 1,
strokeDasharray: '3,3',
};
};
HtmlResizeModel.prototype.getControlPointStyle = function () {
return {
width: 7,
height: 7,
fill: '#FFFFFF',
stroke: '#000000',
};
};
return HtmlResizeModel;
}(core_1.HtmlNodeModel));
var HtmlResizeView = /** @class */ (function (_super) {
__extends(HtmlResizeView, _super);
function HtmlResizeView() {
return _super !== null && _super.apply(this, arguments) || this;
}
HtmlResizeView.prototype.getControlGroup = function () {
var _a = this.props, model = _a.model, graphModel = _a.graphModel;
return (core_1.h(ControlGroup_1.default, { model: model, graphModel: graphModel }));
};
// getResizeShape绘制图形,功能等同于基础矩形的getShape功能,可以通过复写此方法,进行节点自定义
HtmlResizeView.prototype.getResizeShape = function () {
return _super.prototype.getShape.call(this);
};
HtmlResizeView.prototype.getShape = function () {
var isSelected = this.props.model.isSelected;
return (core_1.h("g", null,
this.getResizeShape(),
isSelected ? this.getControlGroup() : ''));
};
return HtmlResizeView;
}(core_1.HtmlNode));
var HtmlResize = {
type: 'html',
view: HtmlResizeView,
model: HtmlResizeModel,
};
exports.default = HtmlResize;
@@ -0,0 +1,91 @@
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
var core_1 = require("@logicflow/core");
var ControlGroup_1 = require("../Control/ControlGroup");
var RectResizeModel = /** @class */ (function (_super) {
__extends(RectResizeModel, _super);
function RectResizeModel(data, graphModel) {
var _this = _super.call(this, data, graphModel) || this;
var nodeSize = _this.properties.nodeSize;
if (nodeSize) {
_this.width = nodeSize.width;
_this.height = nodeSize.height;
}
return _this;
}
RectResizeModel.prototype.initNodeData = function (data) {
_super.prototype.initNodeData.call(this, data);
this.minWidth = 30;
this.minHeight = 30;
this.maxWidth = 2000;
this.maxHeight = 2000;
};
RectResizeModel.prototype.getOutlineStyle = function () {
var style = _super.prototype.getOutlineStyle.call(this);
style.stroke = 'none';
if (style.hover) {
style.hover.stroke = 'none';
}
return style;
};
RectResizeModel.prototype.getResizeOutlineStyle = function () {
return {
fill: 'none',
stroke: 'transparent',
strokeWidth: 1,
strokeDasharray: '3,3',
};
};
RectResizeModel.prototype.getControlPointStyle = function () {
return {
width: 7,
height: 7,
fill: '#FFFFFF',
stroke: '#000000',
};
};
RectResizeModel.prototype.resize = function (deltaX, deltaY) {
console.log(deltaX, deltaY);
};
return RectResizeModel;
}(core_1.RectNodeModel));
var RectResizeView = /** @class */ (function (_super) {
__extends(RectResizeView, _super);
function RectResizeView() {
return _super !== null && _super.apply(this, arguments) || this;
}
RectResizeView.prototype.getControlGroup = function () {
var _a = this.props, model = _a.model, graphModel = _a.graphModel;
return (core_1.h(ControlGroup_1.default, { model: model, graphModel: graphModel }));
};
// getResizeShape绘制图形,功能等同于基础矩形的getShape功能,可以通过复写此方法,进行节点自定义
RectResizeView.prototype.getResizeShape = function () {
return _super.prototype.getShape.call(this);
};
RectResizeView.prototype.getShape = function () {
var isSelected = this.props.model.isSelected;
return (core_1.h("g", null,
this.getResizeShape(),
isSelected ? this.getControlGroup() : ''));
};
return RectResizeView;
}(core_1.RectNode));
var RectResize = {
type: 'rect',
view: RectResizeView,
model: RectResizeModel,
};
exports.default = RectResize;
@@ -0,0 +1,40 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.HtmlResize = exports.DiamondResize = exports.EllipseResize = exports.RectResize = exports.NodeResize = void 0;
var RectResize_1 = require("./Node/RectResize");
exports.RectResize = RectResize_1.default;
var EllipseResize_1 = require("./Node/EllipseResize");
exports.EllipseResize = EllipseResize_1.default;
var DiamondResize_1 = require("./Node/DiamondResize");
exports.DiamondResize = DiamondResize_1.default;
var HtmlResize_1 = require("./Node/HtmlResize");
exports.HtmlResize = HtmlResize_1.default;
var NodeResize = {
pluginName: 'nodeResize',
// 拖动step
step: 0,
install: function (lf) {
lf.register({
type: RectResize_1.default.type,
view: RectResize_1.default.view,
model: RectResize_1.default.model,
});
lf.register({
type: EllipseResize_1.default.type,
view: EllipseResize_1.default.view,
model: EllipseResize_1.default.model,
});
lf.register({
type: DiamondResize_1.default.type,
view: DiamondResize_1.default.view,
model: DiamondResize_1.default.model,
});
lf.register({
type: HtmlResize_1.default.type,
view: HtmlResize_1.default.view,
model: HtmlResize_1.default.model,
});
},
};
exports.NodeResize = NodeResize;
exports.default = NodeResize;