@logicflow/core 2.1.1 → 2.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build$colon$dev.log +2 -2
- package/.turbo/turbo-build.log +7 -7
- package/CHANGELOG.md +13 -0
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +1 -1
- package/es/model/EditConfigModel.d.ts +1 -1
- package/es/model/GraphModel.js +3 -2
- package/es/model/NestedTransformModel.d.ts +52 -0
- package/es/model/NestedTransformModel.js +129 -0
- package/es/model/index.d.ts +1 -0
- package/es/model/index.js +1 -0
- package/es/options.d.ts +2 -0
- package/es/view/edge/BaseEdge.js +15 -6
- package/lib/model/EditConfigModel.d.ts +1 -1
- package/lib/model/GraphModel.js +2 -1
- package/lib/model/NestedTransformModel.d.ts +52 -0
- package/lib/model/NestedTransformModel.js +132 -0
- package/lib/model/index.d.ts +1 -0
- package/lib/model/index.js +1 -0
- package/lib/options.d.ts +2 -0
- package/lib/view/edge/BaseEdge.js +15 -6
- package/package.json +1 -1
- package/src/model/GraphModel.ts +3 -1
- package/src/model/NestedTransformModel.ts +121 -0
- package/src/model/index.ts +1 -0
- package/src/options.ts +5 -0
- package/src/view/edge/BaseEdge.tsx +17 -8
- package/stats.html +1 -1
|
@@ -170,7 +170,7 @@ export declare class EditConfigModel {
|
|
|
170
170
|
multipleSelectKey: string;
|
|
171
171
|
constructor(config: Partial<IEditConfigType>);
|
|
172
172
|
updateEditConfig(config: Partial<IEditConfigType>): void;
|
|
173
|
-
computeConfig(config: Partial<IEditConfigType>): Partial<IEditConfigType> & Pick<Partial<IEditConfigType>, "textMode" | "adjustEdgeStartAndEnd" | "edgeTextDraggable" | "edgeTextEdit" | "nodeTextDraggable" | "nodeTextEdit" | "
|
|
173
|
+
computeConfig(config: Partial<IEditConfigType>): Partial<IEditConfigType> & Pick<Partial<IEditConfigType>, "textMode" | "adjustEdgeStartAndEnd" | "edgeTextDraggable" | "edgeTextEdit" | "nodeTextDraggable" | "nodeTextEdit" | "adjustEdge" | "edgeTextMode" | "nodeTextMode" | "allowRotate" | "allowResize" | "isSilentMode" | "stopScrollGraph" | "stopZoomGraph" | "stopMoveGraph" | "textEdit" | "snapGrid" | "adjustNodePosition" | "hoverOutline" | "nodeSelectedOutline" | "edgeSelectedOutline" | "adjustEdgeMiddle" | "adjustEdgeStart" | "adjustEdgeEnd" | "hideAnchors" | "autoExpand" | "textDraggable" | "multipleSelectKey" | "nodeTextMultiple" | "edgeTextMultiple" | "nodeTextVertical" | "edgeTextVertical">;
|
|
174
174
|
updateTextMode(textMode: TextMode): void;
|
|
175
175
|
getConfig(): IEditConfigType;
|
|
176
176
|
}
|
package/es/model/GraphModel.js
CHANGED
|
@@ -53,11 +53,12 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
53
53
|
};
|
|
54
54
|
import { find, forEach, map, merge, isBoolean, debounce, cloneDeep, isNil, } from 'lodash-es';
|
|
55
55
|
import { action, computed, observable } from 'mobx';
|
|
56
|
-
import { EditConfigModel,
|
|
56
|
+
import { EditConfigModel, } from '.';
|
|
57
57
|
import { DEFAULT_VISIBLE_SPACE, ELEMENT_MAX_Z_INDEX, ElementState, ElementType, EventType, ModelType, OverlapMode, TextMode, } from '../constant';
|
|
58
58
|
import { createEdgeGenerator, createUuid, formatData, getClosestPointOfPolyline, getMinIndex, getNodeAnchorPosition, getNodeBBox, getZIndex, isPointInArea, setupAnimation, setupTheme, snapToGrid, updateTheme, backgroundModeMap, gridModeMap, } from '../util';
|
|
59
59
|
import EventEmitter from '../event/eventEmitter';
|
|
60
60
|
import { Grid } from '../view/overlay';
|
|
61
|
+
import NestedTransformModel from './NestedTransformModel';
|
|
61
62
|
var GraphModel = /** @class */ (function () {
|
|
62
63
|
function GraphModel(options) {
|
|
63
64
|
var _this = this;
|
|
@@ -144,7 +145,7 @@ var GraphModel = /** @class */ (function () {
|
|
|
144
145
|
});
|
|
145
146
|
this.eventCenter = new EventEmitter();
|
|
146
147
|
this.editConfigModel = new EditConfigModel(options);
|
|
147
|
-
this.transformModel = new
|
|
148
|
+
this.transformModel = new NestedTransformModel(this.eventCenter, options);
|
|
148
149
|
this.flowId = createUuid();
|
|
149
150
|
this.idGenerator = idGenerator;
|
|
150
151
|
this.edgeGenerator = createEdgeGenerator(this, edgeGenerator);
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import LogicFlow from '../LogicFlow';
|
|
2
|
+
import { TransformModel } from './TransformModel';
|
|
3
|
+
import { Options as LFOptions } from '../options';
|
|
4
|
+
import EventEmitter from '../event/eventEmitter';
|
|
5
|
+
type PointTuple = LogicFlow.PointTuple;
|
|
6
|
+
export declare class NestedTransformModel extends TransformModel {
|
|
7
|
+
parentTransform?: TransformModel;
|
|
8
|
+
constructor(eventCenter: EventEmitter, options: LFOptions.Common);
|
|
9
|
+
/**
|
|
10
|
+
* 设置父级变换
|
|
11
|
+
* @param parentTransform 父级变换模型
|
|
12
|
+
*/
|
|
13
|
+
setParentTransform(parentTransform: TransformModel): void;
|
|
14
|
+
/**
|
|
15
|
+
* 获取累积的缩放值
|
|
16
|
+
* 计算包括所有父级的累积缩放
|
|
17
|
+
*/
|
|
18
|
+
private getCumulativeScale;
|
|
19
|
+
/**
|
|
20
|
+
* 获取累积的平移值
|
|
21
|
+
* 计算包括所有父级的累积平移
|
|
22
|
+
*/
|
|
23
|
+
private getCumulativeTranslate;
|
|
24
|
+
/**
|
|
25
|
+
* 将最外层graph上的点基于缩放转换为canvasOverlay层上的点。
|
|
26
|
+
* 重写以支持嵌套变换
|
|
27
|
+
* @param point HTML点
|
|
28
|
+
*/
|
|
29
|
+
HtmlPointToCanvasPoint(point: PointTuple): PointTuple;
|
|
30
|
+
/**
|
|
31
|
+
* 将最外层canvasOverlay层上的点基于缩放转换为graph上的点。
|
|
32
|
+
* 重写以支持嵌套变换
|
|
33
|
+
* @param point Canvas点
|
|
34
|
+
*/
|
|
35
|
+
CanvasPointToHtmlPoint(point: PointTuple): PointTuple;
|
|
36
|
+
/**
|
|
37
|
+
* 将一个在canvas上的点,向x轴方向移动directionX距离,向y轴方向移动directionY距离。
|
|
38
|
+
* 重写以支持嵌套变换
|
|
39
|
+
* @param point 点
|
|
40
|
+
* @param directionX x轴距离
|
|
41
|
+
* @param directionY y轴距离
|
|
42
|
+
*/
|
|
43
|
+
moveCanvasPointByHtml(point: PointTuple, directionX: number, directionY: number): PointTuple;
|
|
44
|
+
/**
|
|
45
|
+
* 根据缩放情况,获取缩放后的delta距离
|
|
46
|
+
* 重写以支持嵌套变换
|
|
47
|
+
* @param deltaX x轴距离变化
|
|
48
|
+
* @param deltaY y轴距离变化
|
|
49
|
+
*/
|
|
50
|
+
fixDeltaXY(deltaX: number, deltaY: number): PointTuple;
|
|
51
|
+
}
|
|
52
|
+
export default NestedTransformModel;
|
|
@@ -0,0 +1,129 @@
|
|
|
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 (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
6
|
+
return extendStatics(d, b);
|
|
7
|
+
};
|
|
8
|
+
return function (d, b) {
|
|
9
|
+
if (typeof b !== "function" && b !== null)
|
|
10
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
11
|
+
extendStatics(d, b);
|
|
12
|
+
function __() { this.constructor = d; }
|
|
13
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
14
|
+
};
|
|
15
|
+
})();
|
|
16
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
17
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
18
|
+
if (!m) return o;
|
|
19
|
+
var i = m.call(o), r, ar = [], e;
|
|
20
|
+
try {
|
|
21
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
22
|
+
}
|
|
23
|
+
catch (error) { e = { error: error }; }
|
|
24
|
+
finally {
|
|
25
|
+
try {
|
|
26
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
27
|
+
}
|
|
28
|
+
finally { if (e) throw e.error; }
|
|
29
|
+
}
|
|
30
|
+
return ar;
|
|
31
|
+
};
|
|
32
|
+
import { TransformModel } from './TransformModel';
|
|
33
|
+
var NestedTransformModel = /** @class */ (function (_super) {
|
|
34
|
+
__extends(NestedTransformModel, _super);
|
|
35
|
+
function NestedTransformModel(eventCenter, options) {
|
|
36
|
+
var _this = _super.call(this, eventCenter, options) || this;
|
|
37
|
+
_this.parentTransform = options.parentTransform;
|
|
38
|
+
return _this;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* 设置父级变换
|
|
42
|
+
* @param parentTransform 父级变换模型
|
|
43
|
+
*/
|
|
44
|
+
NestedTransformModel.prototype.setParentTransform = function (parentTransform) {
|
|
45
|
+
this.parentTransform = parentTransform;
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* 获取累积的缩放值
|
|
49
|
+
* 计算包括所有父级的累积缩放
|
|
50
|
+
*/
|
|
51
|
+
NestedTransformModel.prototype.getCumulativeScale = function () {
|
|
52
|
+
var scaleX = this.SCALE_X;
|
|
53
|
+
var scaleY = this.SCALE_Y;
|
|
54
|
+
if (this.parentTransform) {
|
|
55
|
+
if (this.parentTransform instanceof NestedTransformModel) {
|
|
56
|
+
var parentScale = this.parentTransform.getCumulativeScale();
|
|
57
|
+
scaleX *= parentScale.scaleX;
|
|
58
|
+
scaleY *= parentScale.scaleY;
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
scaleX *= this.parentTransform.SCALE_X;
|
|
62
|
+
scaleY *= this.parentTransform.SCALE_Y;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return { scaleX: scaleX, scaleY: scaleY };
|
|
66
|
+
};
|
|
67
|
+
/**
|
|
68
|
+
* 获取累积的平移值
|
|
69
|
+
* 计算包括所有父级的累积平移
|
|
70
|
+
*/
|
|
71
|
+
NestedTransformModel.prototype.getCumulativeTranslate = function () {
|
|
72
|
+
var translateX = this.TRANSLATE_X;
|
|
73
|
+
var translateY = this.TRANSLATE_Y;
|
|
74
|
+
if (this.parentTransform &&
|
|
75
|
+
this.parentTransform instanceof NestedTransformModel) {
|
|
76
|
+
var _a = this.parentTransform.getCumulativeScale(), scaleX = _a.scaleX, scaleY = _a.scaleY;
|
|
77
|
+
translateX = scaleX * translateX;
|
|
78
|
+
translateY = scaleY * translateY;
|
|
79
|
+
}
|
|
80
|
+
return { translateX: translateX, translateY: translateY };
|
|
81
|
+
};
|
|
82
|
+
/**
|
|
83
|
+
* 将最外层graph上的点基于缩放转换为canvasOverlay层上的点。
|
|
84
|
+
* 重写以支持嵌套变换
|
|
85
|
+
* @param point HTML点
|
|
86
|
+
*/
|
|
87
|
+
NestedTransformModel.prototype.HtmlPointToCanvasPoint = function (point) {
|
|
88
|
+
var _a = __read(point, 2), x = _a[0], y = _a[1];
|
|
89
|
+
var _b = this.getCumulativeScale(), scaleX = _b.scaleX, scaleY = _b.scaleY;
|
|
90
|
+
var _c = this.getCumulativeTranslate(), translateX = _c.translateX, translateY = _c.translateY;
|
|
91
|
+
return [(x - translateX) / scaleX, (y - translateY) / scaleY];
|
|
92
|
+
};
|
|
93
|
+
/**
|
|
94
|
+
* 将最外层canvasOverlay层上的点基于缩放转换为graph上的点。
|
|
95
|
+
* 重写以支持嵌套变换
|
|
96
|
+
* @param point Canvas点
|
|
97
|
+
*/
|
|
98
|
+
NestedTransformModel.prototype.CanvasPointToHtmlPoint = function (point) {
|
|
99
|
+
var _a = __read(point, 2), x = _a[0], y = _a[1];
|
|
100
|
+
var _b = this.getCumulativeScale(), scaleX = _b.scaleX, scaleY = _b.scaleY;
|
|
101
|
+
var _c = this.getCumulativeTranslate(), translateX = _c.translateX, translateY = _c.translateY;
|
|
102
|
+
return [x * scaleX + translateX, y * scaleY + translateY];
|
|
103
|
+
};
|
|
104
|
+
/**
|
|
105
|
+
* 将一个在canvas上的点,向x轴方向移动directionX距离,向y轴方向移动directionY距离。
|
|
106
|
+
* 重写以支持嵌套变换
|
|
107
|
+
* @param point 点
|
|
108
|
+
* @param directionX x轴距离
|
|
109
|
+
* @param directionY y轴距离
|
|
110
|
+
*/
|
|
111
|
+
NestedTransformModel.prototype.moveCanvasPointByHtml = function (point, directionX, directionY) {
|
|
112
|
+
var _a = __read(point, 2), x = _a[0], y = _a[1];
|
|
113
|
+
var _b = this.getCumulativeScale(), scaleX = _b.scaleX, scaleY = _b.scaleY;
|
|
114
|
+
return [x + directionX / scaleX, y + directionY / scaleY];
|
|
115
|
+
};
|
|
116
|
+
/**
|
|
117
|
+
* 根据缩放情况,获取缩放后的delta距离
|
|
118
|
+
* 重写以支持嵌套变换
|
|
119
|
+
* @param deltaX x轴距离变化
|
|
120
|
+
* @param deltaY y轴距离变化
|
|
121
|
+
*/
|
|
122
|
+
NestedTransformModel.prototype.fixDeltaXY = function (deltaX, deltaY) {
|
|
123
|
+
var _a = this.getCumulativeScale(), scaleX = _a.scaleX, scaleY = _a.scaleY;
|
|
124
|
+
return [deltaX / scaleX, deltaY / scaleY];
|
|
125
|
+
};
|
|
126
|
+
return NestedTransformModel;
|
|
127
|
+
}(TransformModel));
|
|
128
|
+
export { NestedTransformModel };
|
|
129
|
+
export default NestedTransformModel;
|
package/es/model/index.d.ts
CHANGED
package/es/model/index.js
CHANGED
package/es/options.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { TransformModel } from './model';
|
|
1
2
|
import { createElement as h } from 'preact/compat';
|
|
2
3
|
import LogicFlow from './LogicFlow';
|
|
3
4
|
import { KeyboardDef } from './keyboard';
|
|
@@ -68,6 +69,7 @@ export declare namespace Options {
|
|
|
68
69
|
edgeGenerator?: EdgeGeneratorType;
|
|
69
70
|
customTrajectory?: (props: CustomAnchorLineProps) => h.JSX.Element;
|
|
70
71
|
themeMode?: 'radius' | 'dark' | 'colorful';
|
|
72
|
+
parentTransform?: TransformModel;
|
|
71
73
|
[key: string]: unknown;
|
|
72
74
|
}
|
|
73
75
|
interface ManualBooleans {
|
package/es/view/edge/BaseEdge.js
CHANGED
|
@@ -282,12 +282,21 @@ var BaseEdge = /** @class */ (function (_super) {
|
|
|
282
282
|
var _a = model.getArrowStyle(), _b = _a.refY, refY = _b === void 0 ? 0 : _b, _c = _a.refX, refX = _c === void 0 ? 2 : _c;
|
|
283
283
|
var _d = __read(this.getLastTwoPoints(), 2), start = _d[0], end = _d[1];
|
|
284
284
|
var theta = 'auto';
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
285
|
+
// 防止无效点和零长度向量以避免 NaN 方向
|
|
286
|
+
if (start && end) {
|
|
287
|
+
var dx = end.x - start.x;
|
|
288
|
+
var dy = end.y - start.y;
|
|
289
|
+
// 仅在有实际方向时才计算
|
|
290
|
+
if (dx !== 0 || dy !== 0) {
|
|
291
|
+
var computed = degrees(getThetaOfVector({
|
|
292
|
+
x: dx,
|
|
293
|
+
y: dy,
|
|
294
|
+
z: 0,
|
|
295
|
+
}));
|
|
296
|
+
if (Number.isFinite(computed) && !Number.isNaN(computed)) {
|
|
297
|
+
theta = computed;
|
|
298
|
+
}
|
|
299
|
+
}
|
|
291
300
|
}
|
|
292
301
|
return (_jsx("g", { children: _jsxs("defs", { children: [_jsx("marker", { id: "marker-start-".concat(id), refX: -refX, refY: refY, overflow: "visible", orient: "auto", markerUnits: "userSpaceOnUse", children: this.getStartArrow() }), _jsx("marker", { id: "marker-end-".concat(id), refX: refX, refY: refY, overflow: "visible", orient: theta, markerUnits: "userSpaceOnUse", children: this.getEndArrow() })] }) }));
|
|
293
302
|
};
|
|
@@ -170,7 +170,7 @@ export declare class EditConfigModel {
|
|
|
170
170
|
multipleSelectKey: string;
|
|
171
171
|
constructor(config: Partial<IEditConfigType>);
|
|
172
172
|
updateEditConfig(config: Partial<IEditConfigType>): void;
|
|
173
|
-
computeConfig(config: Partial<IEditConfigType>): Partial<IEditConfigType> & Pick<Partial<IEditConfigType>, "textMode" | "adjustEdgeStartAndEnd" | "edgeTextDraggable" | "edgeTextEdit" | "nodeTextDraggable" | "nodeTextEdit" | "
|
|
173
|
+
computeConfig(config: Partial<IEditConfigType>): Partial<IEditConfigType> & Pick<Partial<IEditConfigType>, "textMode" | "adjustEdgeStartAndEnd" | "edgeTextDraggable" | "edgeTextEdit" | "nodeTextDraggable" | "nodeTextEdit" | "adjustEdge" | "edgeTextMode" | "nodeTextMode" | "allowRotate" | "allowResize" | "isSilentMode" | "stopScrollGraph" | "stopZoomGraph" | "stopMoveGraph" | "textEdit" | "snapGrid" | "adjustNodePosition" | "hoverOutline" | "nodeSelectedOutline" | "edgeSelectedOutline" | "adjustEdgeMiddle" | "adjustEdgeStart" | "adjustEdgeEnd" | "hideAnchors" | "autoExpand" | "textDraggable" | "multipleSelectKey" | "nodeTextMultiple" | "edgeTextMultiple" | "nodeTextVertical" | "edgeTextVertical">;
|
|
174
174
|
updateTextMode(textMode: TextMode): void;
|
|
175
175
|
getConfig(): IEditConfigType;
|
|
176
176
|
}
|
package/lib/model/GraphModel.js
CHANGED
|
@@ -64,6 +64,7 @@ var constant_1 = require("../constant");
|
|
|
64
64
|
var util_1 = require("../util");
|
|
65
65
|
var eventEmitter_1 = __importDefault(require("../event/eventEmitter"));
|
|
66
66
|
var overlay_1 = require("../view/overlay");
|
|
67
|
+
var NestedTransformModel_1 = __importDefault(require("./NestedTransformModel"));
|
|
67
68
|
var GraphModel = /** @class */ (function () {
|
|
68
69
|
function GraphModel(options) {
|
|
69
70
|
var _this = this;
|
|
@@ -150,7 +151,7 @@ var GraphModel = /** @class */ (function () {
|
|
|
150
151
|
});
|
|
151
152
|
this.eventCenter = new eventEmitter_1.default();
|
|
152
153
|
this.editConfigModel = new _1.EditConfigModel(options);
|
|
153
|
-
this.transformModel = new
|
|
154
|
+
this.transformModel = new NestedTransformModel_1.default(this.eventCenter, options);
|
|
154
155
|
this.flowId = (0, util_1.createUuid)();
|
|
155
156
|
this.idGenerator = idGenerator;
|
|
156
157
|
this.edgeGenerator = (0, util_1.createEdgeGenerator)(this, edgeGenerator);
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import LogicFlow from '../LogicFlow';
|
|
2
|
+
import { TransformModel } from './TransformModel';
|
|
3
|
+
import { Options as LFOptions } from '../options';
|
|
4
|
+
import EventEmitter from '../event/eventEmitter';
|
|
5
|
+
type PointTuple = LogicFlow.PointTuple;
|
|
6
|
+
export declare class NestedTransformModel extends TransformModel {
|
|
7
|
+
parentTransform?: TransformModel;
|
|
8
|
+
constructor(eventCenter: EventEmitter, options: LFOptions.Common);
|
|
9
|
+
/**
|
|
10
|
+
* 设置父级变换
|
|
11
|
+
* @param parentTransform 父级变换模型
|
|
12
|
+
*/
|
|
13
|
+
setParentTransform(parentTransform: TransformModel): void;
|
|
14
|
+
/**
|
|
15
|
+
* 获取累积的缩放值
|
|
16
|
+
* 计算包括所有父级的累积缩放
|
|
17
|
+
*/
|
|
18
|
+
private getCumulativeScale;
|
|
19
|
+
/**
|
|
20
|
+
* 获取累积的平移值
|
|
21
|
+
* 计算包括所有父级的累积平移
|
|
22
|
+
*/
|
|
23
|
+
private getCumulativeTranslate;
|
|
24
|
+
/**
|
|
25
|
+
* 将最外层graph上的点基于缩放转换为canvasOverlay层上的点。
|
|
26
|
+
* 重写以支持嵌套变换
|
|
27
|
+
* @param point HTML点
|
|
28
|
+
*/
|
|
29
|
+
HtmlPointToCanvasPoint(point: PointTuple): PointTuple;
|
|
30
|
+
/**
|
|
31
|
+
* 将最外层canvasOverlay层上的点基于缩放转换为graph上的点。
|
|
32
|
+
* 重写以支持嵌套变换
|
|
33
|
+
* @param point Canvas点
|
|
34
|
+
*/
|
|
35
|
+
CanvasPointToHtmlPoint(point: PointTuple): PointTuple;
|
|
36
|
+
/**
|
|
37
|
+
* 将一个在canvas上的点,向x轴方向移动directionX距离,向y轴方向移动directionY距离。
|
|
38
|
+
* 重写以支持嵌套变换
|
|
39
|
+
* @param point 点
|
|
40
|
+
* @param directionX x轴距离
|
|
41
|
+
* @param directionY y轴距离
|
|
42
|
+
*/
|
|
43
|
+
moveCanvasPointByHtml(point: PointTuple, directionX: number, directionY: number): PointTuple;
|
|
44
|
+
/**
|
|
45
|
+
* 根据缩放情况,获取缩放后的delta距离
|
|
46
|
+
* 重写以支持嵌套变换
|
|
47
|
+
* @param deltaX x轴距离变化
|
|
48
|
+
* @param deltaY y轴距离变化
|
|
49
|
+
*/
|
|
50
|
+
fixDeltaXY(deltaX: number, deltaY: number): PointTuple;
|
|
51
|
+
}
|
|
52
|
+
export default NestedTransformModel;
|
|
@@ -0,0 +1,132 @@
|
|
|
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 (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
if (typeof b !== "function" && b !== null)
|
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
+
extendStatics(d, b);
|
|
13
|
+
function __() { this.constructor = d; }
|
|
14
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
+
};
|
|
16
|
+
})();
|
|
17
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
18
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
19
|
+
if (!m) return o;
|
|
20
|
+
var i = m.call(o), r, ar = [], e;
|
|
21
|
+
try {
|
|
22
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
23
|
+
}
|
|
24
|
+
catch (error) { e = { error: error }; }
|
|
25
|
+
finally {
|
|
26
|
+
try {
|
|
27
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
28
|
+
}
|
|
29
|
+
finally { if (e) throw e.error; }
|
|
30
|
+
}
|
|
31
|
+
return ar;
|
|
32
|
+
};
|
|
33
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
34
|
+
exports.NestedTransformModel = void 0;
|
|
35
|
+
var TransformModel_1 = require("./TransformModel");
|
|
36
|
+
var NestedTransformModel = /** @class */ (function (_super) {
|
|
37
|
+
__extends(NestedTransformModel, _super);
|
|
38
|
+
function NestedTransformModel(eventCenter, options) {
|
|
39
|
+
var _this = _super.call(this, eventCenter, options) || this;
|
|
40
|
+
_this.parentTransform = options.parentTransform;
|
|
41
|
+
return _this;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* 设置父级变换
|
|
45
|
+
* @param parentTransform 父级变换模型
|
|
46
|
+
*/
|
|
47
|
+
NestedTransformModel.prototype.setParentTransform = function (parentTransform) {
|
|
48
|
+
this.parentTransform = parentTransform;
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* 获取累积的缩放值
|
|
52
|
+
* 计算包括所有父级的累积缩放
|
|
53
|
+
*/
|
|
54
|
+
NestedTransformModel.prototype.getCumulativeScale = function () {
|
|
55
|
+
var scaleX = this.SCALE_X;
|
|
56
|
+
var scaleY = this.SCALE_Y;
|
|
57
|
+
if (this.parentTransform) {
|
|
58
|
+
if (this.parentTransform instanceof NestedTransformModel) {
|
|
59
|
+
var parentScale = this.parentTransform.getCumulativeScale();
|
|
60
|
+
scaleX *= parentScale.scaleX;
|
|
61
|
+
scaleY *= parentScale.scaleY;
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
scaleX *= this.parentTransform.SCALE_X;
|
|
65
|
+
scaleY *= this.parentTransform.SCALE_Y;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return { scaleX: scaleX, scaleY: scaleY };
|
|
69
|
+
};
|
|
70
|
+
/**
|
|
71
|
+
* 获取累积的平移值
|
|
72
|
+
* 计算包括所有父级的累积平移
|
|
73
|
+
*/
|
|
74
|
+
NestedTransformModel.prototype.getCumulativeTranslate = function () {
|
|
75
|
+
var translateX = this.TRANSLATE_X;
|
|
76
|
+
var translateY = this.TRANSLATE_Y;
|
|
77
|
+
if (this.parentTransform &&
|
|
78
|
+
this.parentTransform instanceof NestedTransformModel) {
|
|
79
|
+
var _a = this.parentTransform.getCumulativeScale(), scaleX = _a.scaleX, scaleY = _a.scaleY;
|
|
80
|
+
translateX = scaleX * translateX;
|
|
81
|
+
translateY = scaleY * translateY;
|
|
82
|
+
}
|
|
83
|
+
return { translateX: translateX, translateY: translateY };
|
|
84
|
+
};
|
|
85
|
+
/**
|
|
86
|
+
* 将最外层graph上的点基于缩放转换为canvasOverlay层上的点。
|
|
87
|
+
* 重写以支持嵌套变换
|
|
88
|
+
* @param point HTML点
|
|
89
|
+
*/
|
|
90
|
+
NestedTransformModel.prototype.HtmlPointToCanvasPoint = function (point) {
|
|
91
|
+
var _a = __read(point, 2), x = _a[0], y = _a[1];
|
|
92
|
+
var _b = this.getCumulativeScale(), scaleX = _b.scaleX, scaleY = _b.scaleY;
|
|
93
|
+
var _c = this.getCumulativeTranslate(), translateX = _c.translateX, translateY = _c.translateY;
|
|
94
|
+
return [(x - translateX) / scaleX, (y - translateY) / scaleY];
|
|
95
|
+
};
|
|
96
|
+
/**
|
|
97
|
+
* 将最外层canvasOverlay层上的点基于缩放转换为graph上的点。
|
|
98
|
+
* 重写以支持嵌套变换
|
|
99
|
+
* @param point Canvas点
|
|
100
|
+
*/
|
|
101
|
+
NestedTransformModel.prototype.CanvasPointToHtmlPoint = function (point) {
|
|
102
|
+
var _a = __read(point, 2), x = _a[0], y = _a[1];
|
|
103
|
+
var _b = this.getCumulativeScale(), scaleX = _b.scaleX, scaleY = _b.scaleY;
|
|
104
|
+
var _c = this.getCumulativeTranslate(), translateX = _c.translateX, translateY = _c.translateY;
|
|
105
|
+
return [x * scaleX + translateX, y * scaleY + translateY];
|
|
106
|
+
};
|
|
107
|
+
/**
|
|
108
|
+
* 将一个在canvas上的点,向x轴方向移动directionX距离,向y轴方向移动directionY距离。
|
|
109
|
+
* 重写以支持嵌套变换
|
|
110
|
+
* @param point 点
|
|
111
|
+
* @param directionX x轴距离
|
|
112
|
+
* @param directionY y轴距离
|
|
113
|
+
*/
|
|
114
|
+
NestedTransformModel.prototype.moveCanvasPointByHtml = function (point, directionX, directionY) {
|
|
115
|
+
var _a = __read(point, 2), x = _a[0], y = _a[1];
|
|
116
|
+
var _b = this.getCumulativeScale(), scaleX = _b.scaleX, scaleY = _b.scaleY;
|
|
117
|
+
return [x + directionX / scaleX, y + directionY / scaleY];
|
|
118
|
+
};
|
|
119
|
+
/**
|
|
120
|
+
* 根据缩放情况,获取缩放后的delta距离
|
|
121
|
+
* 重写以支持嵌套变换
|
|
122
|
+
* @param deltaX x轴距离变化
|
|
123
|
+
* @param deltaY y轴距离变化
|
|
124
|
+
*/
|
|
125
|
+
NestedTransformModel.prototype.fixDeltaXY = function (deltaX, deltaY) {
|
|
126
|
+
var _a = this.getCumulativeScale(), scaleX = _a.scaleX, scaleY = _a.scaleY;
|
|
127
|
+
return [deltaX / scaleX, deltaY / scaleY];
|
|
128
|
+
};
|
|
129
|
+
return NestedTransformModel;
|
|
130
|
+
}(TransformModel_1.TransformModel));
|
|
131
|
+
exports.NestedTransformModel = NestedTransformModel;
|
|
132
|
+
exports.default = NestedTransformModel;
|
package/lib/model/index.d.ts
CHANGED
package/lib/model/index.js
CHANGED
|
@@ -19,5 +19,6 @@ __exportStar(require("./node"), exports);
|
|
|
19
19
|
__exportStar(require("./BaseModel"), exports);
|
|
20
20
|
__exportStar(require("./EditConfigModel"), exports);
|
|
21
21
|
__exportStar(require("./GraphModel"), exports);
|
|
22
|
+
__exportStar(require("./NestedTransformModel"), exports);
|
|
22
23
|
__exportStar(require("./SnaplineModel"), exports);
|
|
23
24
|
__exportStar(require("./TransformModel"), exports);
|
package/lib/options.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { TransformModel } from './model';
|
|
1
2
|
import { createElement as h } from 'preact/compat';
|
|
2
3
|
import LogicFlow from './LogicFlow';
|
|
3
4
|
import { KeyboardDef } from './keyboard';
|
|
@@ -68,6 +69,7 @@ export declare namespace Options {
|
|
|
68
69
|
edgeGenerator?: EdgeGeneratorType;
|
|
69
70
|
customTrajectory?: (props: CustomAnchorLineProps) => h.JSX.Element;
|
|
70
71
|
themeMode?: 'radius' | 'dark' | 'colorful';
|
|
72
|
+
parentTransform?: TransformModel;
|
|
71
73
|
[key: string]: unknown;
|
|
72
74
|
}
|
|
73
75
|
interface ManualBooleans {
|
|
@@ -308,12 +308,21 @@ var BaseEdge = /** @class */ (function (_super) {
|
|
|
308
308
|
var _a = model.getArrowStyle(), _b = _a.refY, refY = _b === void 0 ? 0 : _b, _c = _a.refX, refX = _c === void 0 ? 2 : _c;
|
|
309
309
|
var _d = __read(this.getLastTwoPoints(), 2), start = _d[0], end = _d[1];
|
|
310
310
|
var theta = 'auto';
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
311
|
+
// 防止无效点和零长度向量以避免 NaN 方向
|
|
312
|
+
if (start && end) {
|
|
313
|
+
var dx = end.x - start.x;
|
|
314
|
+
var dy = end.y - start.y;
|
|
315
|
+
// 仅在有实际方向时才计算
|
|
316
|
+
if (dx !== 0 || dy !== 0) {
|
|
317
|
+
var computed = (0, util_1.degrees)((0, util_1.getThetaOfVector)({
|
|
318
|
+
x: dx,
|
|
319
|
+
y: dy,
|
|
320
|
+
z: 0,
|
|
321
|
+
}));
|
|
322
|
+
if (Number.isFinite(computed) && !Number.isNaN(computed)) {
|
|
323
|
+
theta = computed;
|
|
324
|
+
}
|
|
325
|
+
}
|
|
317
326
|
}
|
|
318
327
|
return ((0, jsx_runtime_1.jsx)("g", { children: (0, jsx_runtime_1.jsxs)("defs", { children: [(0, jsx_runtime_1.jsx)("marker", { id: "marker-start-".concat(id), refX: -refX, refY: refY, overflow: "visible", orient: "auto", markerUnits: "userSpaceOnUse", children: this.getStartArrow() }), (0, jsx_runtime_1.jsx)("marker", { id: "marker-end-".concat(id), refX: refX, refY: refY, overflow: "visible", orient: theta, markerUnits: "userSpaceOnUse", children: this.getEndArrow() })] }) }));
|
|
319
328
|
};
|
package/package.json
CHANGED
package/src/model/GraphModel.ts
CHANGED
|
@@ -48,6 +48,8 @@ import {
|
|
|
48
48
|
} from '../util'
|
|
49
49
|
import EventEmitter from '../event/eventEmitter'
|
|
50
50
|
import { Grid } from '../view/overlay'
|
|
51
|
+
import NestedTransformModel from './NestedTransformModel'
|
|
52
|
+
|
|
51
53
|
import Position = LogicFlow.Position
|
|
52
54
|
import PointTuple = LogicFlow.PointTuple
|
|
53
55
|
import GraphData = LogicFlow.GraphData
|
|
@@ -207,7 +209,7 @@ export class GraphModel {
|
|
|
207
209
|
|
|
208
210
|
this.eventCenter = new EventEmitter()
|
|
209
211
|
this.editConfigModel = new EditConfigModel(options)
|
|
210
|
-
this.transformModel = new
|
|
212
|
+
this.transformModel = new NestedTransformModel(this.eventCenter, options)
|
|
211
213
|
|
|
212
214
|
this.flowId = createUuid()
|
|
213
215
|
this.idGenerator = idGenerator
|