本地logicflow依赖包
This commit is contained in:
1 parent
8ff82208ad
commit
30f225df00
290 files changed
+18624
-16276
No files matched your search
@@ -0,0 +1,110 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.isNodeInSegement = exports.corssPointInSegement = exports.isInSegment = void 0;
|
||||
// 这个里面的函数有些在core中已经存在,为了解耦关系,没有引用
|
||||
var SegmentDirection;
|
||||
(function (SegmentDirection) {
|
||||
SegmentDirection["HORIZONTAL"] = "horizontal";
|
||||
SegmentDirection["VERTICAL"] = "vertical";
|
||||
})(SegmentDirection || (SegmentDirection = {}));
|
||||
/* 判断一个点是否在线段中
|
||||
入参点:point, 线段起终点,start,end,
|
||||
返回值: 在线段中true,否则false
|
||||
*/
|
||||
exports.isInSegment = function (point, start, end) {
|
||||
var x = point.x, y = point.y;
|
||||
return (x - start.x) * (x - end.x) <= 0
|
||||
&& (y - start.y) * (y - end.y) <= 0;
|
||||
};
|
||||
/* 获取节点bbox */
|
||||
var getNodeBBox = function (node) {
|
||||
var x = node.x, y = node.y, width = node.width, height = node.height;
|
||||
var bBox = {
|
||||
minX: x - width / 2,
|
||||
minY: y - height / 2,
|
||||
maxX: x + width / 2,
|
||||
maxY: y + height / 2,
|
||||
x: x,
|
||||
y: y,
|
||||
width: width,
|
||||
height: height,
|
||||
centerX: x,
|
||||
centerY: y,
|
||||
};
|
||||
return bBox;
|
||||
};
|
||||
/* 判断线段的方向 */
|
||||
var segmentDirection = function (start, end) {
|
||||
var direction;
|
||||
if (start.x === end.x) {
|
||||
direction = SegmentDirection.VERTICAL;
|
||||
}
|
||||
else if (start.y === end.y) {
|
||||
direction = SegmentDirection.HORIZONTAL;
|
||||
}
|
||||
return direction;
|
||||
};
|
||||
// 节点是够在线段内,求出节点与线段的交点
|
||||
exports.corssPointInSegement = function (node, start, end) {
|
||||
var bBox = getNodeBBox(node);
|
||||
var direction = segmentDirection(start, end);
|
||||
var maxX = Math.max(start.x, end.x);
|
||||
var minX = Math.min(start.x, end.x);
|
||||
var maxY = Math.max(start.y, end.y);
|
||||
var minY = Math.min(start.y, end.y);
|
||||
var x = node.x, y = node.y, width = node.width, height = node.height;
|
||||
if (direction === SegmentDirection.HORIZONTAL) {
|
||||
// 同一水平线
|
||||
if (start.y === y && maxX >= bBox.maxX && minX <= bBox.minX) {
|
||||
return {
|
||||
startCrossPoint: {
|
||||
x: start.x > end.x ? x + (width / 2) : x - (width / 2),
|
||||
y: y,
|
||||
},
|
||||
endCrossPoint: {
|
||||
x: start.x > end.x ? x - (width / 2) : x + (width / 2),
|
||||
y: y,
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
else if (direction === SegmentDirection.VERTICAL) {
|
||||
// 同一垂直线
|
||||
if (start.x === node.x && maxY >= bBox.maxY && minY <= bBox.minY) {
|
||||
return {
|
||||
startCrossPoint: {
|
||||
x: x,
|
||||
y: start.y > end.y ? y + (height / 2) : y - (height / 2),
|
||||
},
|
||||
endCrossPoint: {
|
||||
x: x,
|
||||
y: start.y > end.y ? y - (height / 2) : y + (height / 2),
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
};
|
||||
// 节点是否在线段内
|
||||
// eslint-disable-next-line max-len
|
||||
exports.isNodeInSegement = function (node, polyline) {
|
||||
var x = node.x, y = node.y;
|
||||
var pointsList = polyline.pointsList;
|
||||
for (var i = 0; i < pointsList.length - 1; i++) {
|
||||
if (exports.isInSegment({ x: x, y: y }, pointsList[i], pointsList[i + 1])) {
|
||||
var bBoxCross = exports.corssPointInSegement(node, pointsList[i], pointsList[i + 1]);
|
||||
if (bBoxCross) {
|
||||
return {
|
||||
crossIndex: i + 1,
|
||||
crossPoints: bBoxCross,
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
return {
|
||||
crossIndex: -1,
|
||||
crossPoints: {
|
||||
startCrossPoint: { x: 0, y: 0 },
|
||||
endCrossPoint: { x: 0, y: 0 },
|
||||
},
|
||||
};
|
||||
};
|
||||
@@ -0,0 +1,89 @@
|
||||
"use strict";
|
||||
var __read = (this && this.__read) || function (o, n) {
|
||||
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
||||
if (!m) return o;
|
||||
var i = m.call(o), r, ar = [], e;
|
||||
try {
|
||||
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
||||
}
|
||||
catch (error) { e = { error: error }; }
|
||||
finally {
|
||||
try {
|
||||
if (r && !r.done && (m = i["return"])) m.call(i);
|
||||
}
|
||||
finally { if (e) throw e.error; }
|
||||
}
|
||||
return ar;
|
||||
};
|
||||
var __spread = (this && this.__spread) || function () {
|
||||
for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i]));
|
||||
return ar;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.InsertNodeInPolyline = void 0;
|
||||
var edge_1 = require("./edge");
|
||||
var InsertNodeInPolyline = /** @class */ (function () {
|
||||
function InsertNodeInPolyline(_a) {
|
||||
var lf = _a.lf;
|
||||
this._lf = lf;
|
||||
this.dndAdd = true;
|
||||
this.dropAdd = true;
|
||||
this.eventHandler();
|
||||
}
|
||||
InsertNodeInPolyline.prototype.eventHandler = function () {
|
||||
var _this = this;
|
||||
// 监听事件
|
||||
if (this.dndAdd) {
|
||||
this._lf.on('node:dnd-add', function (_a) {
|
||||
var data = _a.data;
|
||||
_this.insetNode(data);
|
||||
});
|
||||
}
|
||||
if (this.dropAdd) {
|
||||
this._lf.on('node:drop', function (_a) {
|
||||
var data = _a.data;
|
||||
var edges = _this._lf.graphModel.edges;
|
||||
var id = data.id;
|
||||
var pureNode = true;
|
||||
for (var i = 0; i < edges.length; i++) {
|
||||
if (edges[i].sourceNodeId === id || edges[i].targetNodeId === id) {
|
||||
pureNode = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (pureNode) {
|
||||
_this.insetNode(data);
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
InsertNodeInPolyline.prototype.insetNode = function (nodeData) {
|
||||
var edges = this._lf.graphModel.edges;
|
||||
var nodeModel = this._lf.getNodeModelById(nodeData.id);
|
||||
for (var i = 0; i < edges.length; i++) {
|
||||
// eslint-disable-next-line max-len
|
||||
var _a = edge_1.isNodeInSegement(nodeModel, edges[i]), crossIndex = _a.crossIndex, crossPoints = _a.crossPoints;
|
||||
if (crossIndex >= 0) {
|
||||
var _b = edges[i], sourceNodeId = _b.sourceNodeId, targetNodeId = _b.targetNodeId, id = _b.id, type = _b.type, pointsList = _b.pointsList;
|
||||
this._lf.addEdge({
|
||||
type: type,
|
||||
sourceNodeId: sourceNodeId,
|
||||
targetNodeId: nodeData.id,
|
||||
pointsList: __spread(pointsList.slice(0, crossIndex), [crossPoints.startCrossPoint]),
|
||||
});
|
||||
this._lf.addEdge({
|
||||
type: type,
|
||||
sourceNodeId: nodeData.id,
|
||||
targetNodeId: targetNodeId,
|
||||
pointsList: __spread([crossPoints.endCrossPoint], pointsList.slice(crossIndex)),
|
||||
});
|
||||
this._lf.deleteEdge(id);
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
InsertNodeInPolyline.pluginName = 'insertNodeInPolyline';
|
||||
return InsertNodeInPolyline;
|
||||
}());
|
||||
exports.InsertNodeInPolyline = InsertNodeInPolyline;
|
||||
exports.default = InsertNodeInPolyline;
|
||||
Reference in new issue
Block a user