本地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,10 @@
import { h } from '@logicflow/core';
export default function Polygon({ fillOpacity, strokeWidth, strokeOpacity, fill, stroke, points, className, }: {
fillOpacity?: number;
strokeWidth?: number;
strokeOpacity?: number;
fill?: string;
stroke?: string;
points: any;
className?: string;
}): h.JSX.Element;
@@ -0,0 +1,26 @@
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);
};
import { h } from '@logicflow/core';
export default 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 (h("polygon", __assign({}, attrs)));
}
@@ -0,0 +1,17 @@
import { h, Point, Size } from '@logicflow/core';
declare type IProps = {
className?: string;
radius?: number;
stroke?: string;
strokeDasharray?: string;
} & Point & Size;
declare function Rect(props: IProps): h.JSX.Element;
declare namespace Rect {
var defaultProps: {
radius: number;
stroke: string;
strokeDasharray: string;
className: string;
};
}
export default Rect;
@@ -0,0 +1,28 @@
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);
};
import { h } from '@logicflow/core';
// TODO: 默认样式引入
export default 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 (h("rect", __assign({}, attrs)));
}
Rect.defaultProps = {
radius: 0,
stroke: '',
strokeDasharray: '',
className: '',
};
@@ -0,0 +1,58 @@
import { h, Component } from 'preact';
import { BaseNodeModel, GraphModel, LogicFlowUtil } from '@logicflow/core';
interface IProps {
index: number;
x: number;
y: number;
model: BaseNodeModel;
graphModel: GraphModel;
style?: CSSStyleDeclaration;
}
declare class Control extends Component<IProps> {
index: number;
nodeModel: BaseNodeModel;
graphModel: GraphModel;
dragHandler: LogicFlowUtil.StepDrag;
constructor(props: any);
getNodeEdges(nodeId: any): {
sourceEdges: any[];
targetEdges: any[];
};
updatePosition: ({ deltaX, deltaY }: {
deltaX: any;
deltaY: any;
}) => void;
getResize: ({ index, deltaX, deltaY, width, height, pct }: {
index: any;
deltaX: any;
deltaY: any;
width: any;
height: any;
pct?: number;
}) => {
width: any;
height: any;
};
updateRect: ({ deltaX, deltaY }: {
deltaX: any;
deltaY: any;
}) => void;
updateEllipse: ({ deltaX, deltaY }: {
deltaX: any;
deltaY: any;
}) => void;
updateDiamond: ({ deltaX, deltaY }: {
deltaX: any;
deltaY: any;
}) => void;
eventEmit: ({ beforeNode, afterNode }: {
beforeNode: any;
afterNode: any;
}) => void;
onDraging: ({ deltaX, deltaY }: {
deltaX: any;
deltaY: any;
}) => void;
render(): h.JSX.Element;
}
export default Control;
@@ -0,0 +1,330 @@
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);
};
import { h, Component } from 'preact';
import { LogicFlowUtil } from '@logicflow/core';
import Rect from '../BasicShape/Rect';
import { getDiamondReizeEdgePoint, getEllipseReizeEdgePoint, getRectReizeEdgePoint, ModelType } from './Util';
var StepDrag = 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 = getRectReizeEdgePoint(params);
item.updateStartPoint(afterPoint);
});
edges.targetEdges.forEach(function (item) {
params.point = item.endPoint;
afterPoint = 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 = getEllipseReizeEdgePoint(params);
item.updateStartPoint(afterPoint);
});
edges.targetEdges.forEach(function (item) {
params.point = item.endPoint;
afterPoint = 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 = getDiamondReizeEdgePoint(params);
item.updateStartPoint(afterPoint);
});
edges.targetEdges.forEach(function (item) {
params.point = item.endPoint;
afterPoint = 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 === ModelType.RECT_NODE || modelType === ModelType.HTML_NODE) {
_this.updateRect({ deltaX: deltaX, deltaY: deltaY });
// this.nodeModel.resize(deltaX, deltaY);
}
else if (modelType === ModelType.ELLIPSE_NODE) {
_this.updateEllipse({ deltaX: deltaX, deltaY: deltaY });
}
else if (modelType === 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 (h("g", { className: "lf-resize-control-" + index },
h(Rect, __assign({ className: "lf-node-control" }, { x: x, y: y }, style, { onMouseDown: this.dragHandler.handleMouseDown }))));
};
return Control;
}(Component));
export default Control;
@@ -0,0 +1,13 @@
import { h, Component } from 'preact';
import { BaseNodeModel, GraphModel } from '@logicflow/core';
interface IProps {
model: BaseNodeModel;
graphModel: GraphModel;
}
declare class ControlGroup extends Component<IProps> {
constructor();
getResizeControl(): h.JSX.Element[];
getGroupSolid(): h.JSX.Element;
render(): h.JSX.Element;
}
export default ControlGroup;
@@ -0,0 +1,83 @@
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);
};
import { h, Component } from 'preact';
import Control from './Control';
import Rect from '../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 (h(Control, __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 (h(Rect, __assign({ fill: "none" }, style, { x: x, y: y, width: width, height: height })));
};
ControlGroup.prototype.render = function () {
return (h("g", { className: "lf-resize-control" },
this.getGroupSolid(),
this.getResizeControl()));
};
return ControlGroup;
}(Component));
export default ControlGroup;
@@ -0,0 +1,33 @@
export declare enum ModelType {
NODE = "node",
CIRCLE_NODE = "circle-node",
POLYGON_NODE = "polygon-node",
RECT_NODE = "rect-node",
HTML_NODE = "html-node",
TEXT_NODE = "text-node",
ELLIPSE_NODE = "ellipse-node",
DIAMOND_NODE = "diamond-node",
EDGE = "edge",
LINE_EDGE = "line-edge",
POLYLINE_EDGE = "polyline-edge",
BEZIER_EDGE = "bezier-edge",
GRAPH = "graph"
}
export declare function getRectReizeEdgePoint({ point, beforeNode, afterNode }: {
point: any;
beforeNode: any;
afterNode: any;
}): {
x: any;
y: any;
};
export declare function getEllipseReizeEdgePoint({ point, beforeNode, afterNode }: {
point: any;
beforeNode: any;
afterNode: any;
}): any;
export declare function getDiamondReizeEdgePoint({ point, beforeNode, afterNode }: {
point: any;
beforeNode: any;
afterNode: any;
}): any;
@@ -0,0 +1,210 @@
export 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 || (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之后,与矩形连接边的新端点
export 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;
}
// 获取椭圆resize之后,与椭圆连接边的新端点
export 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;
}
// 获取菱形resize之后,与菱形连接边的新端点
export 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;
}
@@ -0,0 +1,28 @@
import { h, DiamondNode, DiamondNodeModel } from '@logicflow/core';
declare class DiamondResizeModel extends DiamondNodeModel {
constructor(data: any, graphModel: any);
initNodeData(data: any): void;
getOutlineStyle(): import("@logicflow/core/types/constant/DefaultTheme").OutlineTheme;
getResizeOutlineStyle(): {
stroke: string;
strokeWidth: number;
strokeDasharray: string;
};
getControlPointStyle(): {
width: number;
height: number;
fill: string;
stroke: string;
};
}
declare class DiamondResizeView extends DiamondNode {
getControlGroup(): h.JSX.Element;
getResizeShape(): h.JSX.Element;
getShape(): h.JSX.Element;
}
declare const EllipseResize: {
type: string;
view: typeof DiamondResizeView;
model: typeof DiamondResizeModel;
};
export default EllipseResize;
@@ -0,0 +1,102 @@
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);
};
import { h, DiamondNode, DiamondNodeModel } from '@logicflow/core';
import ControlGroup from '../Control/ControlGroup';
import Polygon from '../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;
}(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 (h(ControlGroup, { model: model, graphModel: graphModel }));
};
// getResizeShape绘制图形,功能等同于基础菱形的getShape功能,可以通过复写此方法,进行节点自定义
DiamondResizeView.prototype.getResizeShape = function () {
var model = this.props.model;
var points = model.points;
var style = model.getNodeStyle();
return (h("g", null,
h(Polygon, __assign({}, style, { points: points }))));
};
DiamondResizeView.prototype.getShape = function () {
var isSelected = this.props.model.isSelected;
return (h("g", null,
this.getResizeShape(),
isSelected ? this.getControlGroup() : ''));
};
return DiamondResizeView;
}(DiamondNode));
var EllipseResize = {
type: 'diamond',
view: DiamondResizeView,
model: DiamondResizeModel,
};
export default EllipseResize;
@@ -0,0 +1,28 @@
import { h, EllipseNode, EllipseNodeModel } from '@logicflow/core';
declare class EllipseResizeModel extends EllipseNodeModel {
constructor(data: any, graphModel: any);
initNodeData(data: any): void;
getOutlineStyle(): import("@logicflow/core/types/constant/DefaultTheme").OutlineTheme;
getResizeOutlineStyle(): {
stroke: string;
strokeWidth: number;
strokeDasharray: string;
};
getControlPointStyle(): {
width: number;
height: number;
fill: string;
stroke: string;
};
}
declare class EllipseResizeView extends EllipseNode {
getControlGroup(): h.JSX.Element;
getResizeShape(): h.JSX.Element;
getShape(): h.JSX.Element;
}
declare const EllipseResize: {
type: string;
view: typeof EllipseResizeView;
model: typeof EllipseResizeModel;
};
export default EllipseResize;
@@ -0,0 +1,85 @@
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 __());
};
})();
import { h, EllipseNode, EllipseNodeModel } from '@logicflow/core';
import ControlGroup from '../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;
}(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 (h(ControlGroup, { 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 (h("g", null,
this.getResizeShape(),
model.isSelected ? this.getControlGroup() : ''));
};
return EllipseResizeView;
}(EllipseNode));
var EllipseResize = {
type: 'ellipse',
view: EllipseResizeView,
model: EllipseResizeModel,
};
export default EllipseResize;
@@ -0,0 +1,28 @@
import { h, HtmlNode, HtmlNodeModel } from '@logicflow/core';
declare class HtmlResizeModel extends HtmlNodeModel {
constructor(data: any, graphModel: any);
initNodeData(data: any): void;
getOutlineStyle(): import("@logicflow/core/types/constant/DefaultTheme").OutlineTheme;
getResizeOutlineStyle(): {
stroke: string;
strokeWidth: number;
strokeDasharray: string;
};
getControlPointStyle(): {
width: number;
height: number;
fill: string;
stroke: string;
};
}
declare class HtmlResizeView extends HtmlNode {
getControlGroup(): h.JSX.Element;
getResizeShape(): h.JSX.Element;
getShape(): h.JSX.Element;
}
declare const HtmlResize: {
type: string;
view: typeof HtmlResizeView;
model: typeof HtmlResizeModel;
};
export default HtmlResize;
@@ -0,0 +1,85 @@
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 __());
};
})();
import { h, HtmlNode, HtmlNodeModel } from '@logicflow/core';
import ControlGroup from '../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;
}(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 (h(ControlGroup, { 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 (h("g", null,
this.getResizeShape(),
isSelected ? this.getControlGroup() : ''));
};
return HtmlResizeView;
}(HtmlNode));
var HtmlResize = {
type: 'html',
view: HtmlResizeView,
model: HtmlResizeModel,
};
export default HtmlResize;
@@ -0,0 +1,30 @@
import { h, RectNode, RectNodeModel } from '@logicflow/core';
declare class RectResizeModel extends RectNodeModel {
constructor(data: any, graphModel: any);
initNodeData(data: any): void;
getOutlineStyle(): import("@logicflow/core/types/constant/DefaultTheme").OutlineTheme;
getResizeOutlineStyle(): {
fill: string;
stroke: string;
strokeWidth: number;
strokeDasharray: string;
};
getControlPointStyle(): {
width: number;
height: number;
fill: string;
stroke: string;
};
resize(deltaX: any, deltaY: any): void;
}
declare class RectResizeView extends RectNode {
getControlGroup(): h.JSX.Element;
getResizeShape(): h.JSX.Element;
getShape(): h.JSX.Element;
}
declare const RectResize: {
type: string;
view: typeof RectResizeView;
model: typeof RectResizeModel;
};
export default RectResize;
@@ -0,0 +1,89 @@
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 __());
};
})();
import { h, RectNode, RectNodeModel } from '@logicflow/core';
import ControlGroup from '../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;
}(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 (h(ControlGroup, { 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 (h("g", null,
this.getResizeShape(),
isSelected ? this.getControlGroup() : ''));
};
return RectResizeView;
}(RectNode));
var RectResize = {
type: 'rect',
view: RectResizeView,
model: RectResizeModel,
};
export default RectResize;
+11
View File
@@ -0,0 +1,11 @@
import RectResize from './Node/RectResize';
import EllipseResize from './Node/EllipseResize';
import DiamondResize from './Node/DiamondResize';
import HtmlResize from './Node/HtmlResize';
declare const NodeResize: {
pluginName: string;
step: number;
install(lf: any): void;
};
export default NodeResize;
export { NodeResize, RectResize, EllipseResize, DiamondResize, HtmlResize, };
@@ -0,0 +1,33 @@
import RectResize from './Node/RectResize';
import EllipseResize from './Node/EllipseResize';
import DiamondResize from './Node/DiamondResize';
import HtmlResize from './Node/HtmlResize';
var NodeResize = {
pluginName: 'nodeResize',
// 拖动step
step: 0,
install: function (lf) {
lf.register({
type: RectResize.type,
view: RectResize.view,
model: RectResize.model,
});
lf.register({
type: EllipseResize.type,
view: EllipseResize.view,
model: EllipseResize.model,
});
lf.register({
type: DiamondResize.type,
view: DiamondResize.view,
model: DiamondResize.model,
});
lf.register({
type: HtmlResize.type,
view: HtmlResize.view,
model: HtmlResize.model,
});
},
};
export default NodeResize;
export { NodeResize, RectResize, EllipseResize, DiamondResize, HtmlResize, };