@logicflow/core 2.1.2 → 2.1.4
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 +16 -0
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +1 -1
- package/es/LogicFlow.d.ts +2 -1
- package/es/LogicFlow.js +4 -1
- package/es/constant/index.d.ts +3 -1
- package/es/constant/index.js +2 -0
- package/es/model/GraphModel.d.ts +9 -1
- package/es/model/GraphModel.js +34 -8
- package/es/model/edge/BaseEdgeModel.d.ts +2 -1
- package/es/model/edge/BaseEdgeModel.js +29 -5
- package/es/model/node/BaseNodeModel.d.ts +2 -1
- package/es/model/node/BaseNodeModel.js +29 -5
- package/es/view/edge/BaseEdge.js +15 -6
- package/es/view/node/BaseNode.js +13 -2
- package/lib/LogicFlow.d.ts +2 -1
- package/lib/LogicFlow.js +3 -0
- package/lib/constant/index.d.ts +3 -1
- package/lib/constant/index.js +2 -0
- package/lib/model/GraphModel.d.ts +9 -1
- package/lib/model/GraphModel.js +34 -8
- package/lib/model/edge/BaseEdgeModel.d.ts +2 -1
- package/lib/model/edge/BaseEdgeModel.js +29 -5
- package/lib/model/node/BaseNodeModel.d.ts +2 -1
- package/lib/model/node/BaseNodeModel.js +29 -5
- package/lib/view/edge/BaseEdge.js +15 -6
- package/lib/view/node/BaseNode.js +13 -2
- package/package.json +1 -1
- package/src/LogicFlow.tsx +9 -1
- package/src/constant/index.ts +2 -0
- package/src/model/GraphModel.ts +36 -11
- package/src/model/edge/BaseEdgeModel.ts +32 -5
- package/src/model/node/BaseNodeModel.ts +30 -5
- package/src/view/edge/BaseEdge.tsx +17 -8
- package/src/view/node/BaseNode.tsx +13 -3
- package/stats.html +1 -1
|
@@ -76,6 +76,7 @@ var BaseEdgeModel = /** @class */ (function () {
|
|
|
76
76
|
* setAttributes除了初始化调用外,还会在properties发生变化后调用。
|
|
77
77
|
*/
|
|
78
78
|
BaseEdgeModel.prototype.initEdgeData = function (data) {
|
|
79
|
+
var _this = this;
|
|
79
80
|
if (!data.properties) {
|
|
80
81
|
data.properties = {};
|
|
81
82
|
}
|
|
@@ -91,10 +92,8 @@ var BaseEdgeModel = /** @class */ (function () {
|
|
|
91
92
|
var adjustEdgeStartAndEnd = this.graphModel.editConfigModel.adjustEdgeStartAndEnd;
|
|
92
93
|
this.isShowAdjustPoint = adjustEdgeStartAndEnd;
|
|
93
94
|
(0, lodash_es_1.assign)(this, (0, util_1.pickEdgeConfig)(data));
|
|
94
|
-
var
|
|
95
|
-
|
|
96
|
-
this.zIndex = data.zIndex || (0, util_1.getZIndex)();
|
|
97
|
-
}
|
|
95
|
+
var _a = this.graphModel, overlapMode = _a.overlapMode, eventCenter = _a.eventCenter;
|
|
96
|
+
this.updateZIndexByOverlap(overlapMode, data.zIndex || (0, util_1.getZIndex)());
|
|
98
97
|
// 设置边的 anchors,也就是边的两个端点
|
|
99
98
|
// 端点依赖于 edgeData 的 sourceNode 和 targetNode
|
|
100
99
|
this.setAnchors();
|
|
@@ -102,6 +101,10 @@ var BaseEdgeModel = /** @class */ (function () {
|
|
|
102
101
|
this.initPoints();
|
|
103
102
|
// 文本位置依赖于边上的所有拐点
|
|
104
103
|
this.formatText(data);
|
|
104
|
+
eventCenter.on('overlap:change', function (data) {
|
|
105
|
+
var newMode = data.overlapMode;
|
|
106
|
+
_this.updateZIndexByOverlap(newMode, _this.zIndex || (0, util_1.getZIndex)());
|
|
107
|
+
});
|
|
105
108
|
};
|
|
106
109
|
/**
|
|
107
110
|
* 设置model属性
|
|
@@ -325,7 +328,9 @@ var BaseEdgeModel = /** @class */ (function () {
|
|
|
325
328
|
startPoint: (0, lodash_es_1.assign)({}, this.startPoint),
|
|
326
329
|
endPoint: (0, lodash_es_1.assign)({}, this.endPoint),
|
|
327
330
|
};
|
|
328
|
-
|
|
331
|
+
// 因为默认模式和边在上模式下,对节点的zIndex要求不高(因为渲染的时候会按照模式对所有元素进行排序)
|
|
332
|
+
// 所以只在递增模式和静态模式下设置zIndex
|
|
333
|
+
if ([constant_1.OverlapMode.INCREASE, constant_1.OverlapMode.STATIC].includes(this.graphModel.overlapMode)) {
|
|
329
334
|
data.zIndex = this.zIndex;
|
|
330
335
|
}
|
|
331
336
|
var _a = this.text, x = _a.x, y = _a.y, value = _a.value;
|
|
@@ -589,6 +594,22 @@ var BaseEdgeModel = /** @class */ (function () {
|
|
|
589
594
|
this.updateStartPoint({ x: startPoint.x, y: startPoint.y });
|
|
590
595
|
this.updateEndPoint({ x: endPoint.x, y: endPoint.y });
|
|
591
596
|
};
|
|
597
|
+
// 堆叠模式变化时,更新zIndex
|
|
598
|
+
BaseEdgeModel.prototype.updateZIndexByOverlap = function (overlapMode, defaultZIndex) {
|
|
599
|
+
switch (overlapMode) {
|
|
600
|
+
case constant_1.OverlapMode.DEFAULT:
|
|
601
|
+
this.zIndex = 0;
|
|
602
|
+
break;
|
|
603
|
+
case constant_1.OverlapMode.EDGE_TOP:
|
|
604
|
+
this.zIndex = 1;
|
|
605
|
+
break;
|
|
606
|
+
case constant_1.OverlapMode.INCREASE:
|
|
607
|
+
this.zIndex = defaultZIndex;
|
|
608
|
+
break;
|
|
609
|
+
default:
|
|
610
|
+
break;
|
|
611
|
+
}
|
|
612
|
+
};
|
|
592
613
|
BaseEdgeModel.BaseType = constant_1.ElementType.EDGE;
|
|
593
614
|
__decorate([
|
|
594
615
|
mobx_1.observable
|
|
@@ -758,6 +779,9 @@ var BaseEdgeModel = /** @class */ (function () {
|
|
|
758
779
|
__decorate([
|
|
759
780
|
mobx_1.action
|
|
760
781
|
], BaseEdgeModel.prototype, "updateAfterAdjustStartAndEnd", null);
|
|
782
|
+
__decorate([
|
|
783
|
+
mobx_1.action
|
|
784
|
+
], BaseEdgeModel.prototype, "updateZIndexByOverlap", null);
|
|
761
785
|
return BaseEdgeModel;
|
|
762
786
|
}());
|
|
763
787
|
exports.BaseEdgeModel = BaseEdgeModel;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { GraphModel, Model } from '..';
|
|
2
2
|
import LogicFlow from '../../LogicFlow';
|
|
3
|
-
import { ElementState, ElementType, ModelType, TextMode } from '../../constant';
|
|
3
|
+
import { ElementState, ElementType, ModelType, OverlapMode, TextMode } from '../../constant';
|
|
4
4
|
import { ResizeControl } from '../../view/Control';
|
|
5
5
|
import AnchorConfig = Model.AnchorConfig;
|
|
6
6
|
import GraphElements = LogicFlow.GraphElements;
|
|
@@ -288,6 +288,7 @@ export declare class BaseNodeModel<P extends PropertiesType = PropertiesType> im
|
|
|
288
288
|
updateStyles(styles: Record<string, any>): void;
|
|
289
289
|
setZIndex(zIndex?: number): void;
|
|
290
290
|
updateAttributes(attributes: any): void;
|
|
291
|
+
updateZIndexByOverlap(overlapMode: OverlapMode, defaultZIndex: any): void;
|
|
291
292
|
}
|
|
292
293
|
export declare namespace BaseNodeModel {
|
|
293
294
|
type PointTuple = [number, number];
|
|
@@ -175,6 +175,7 @@ var BaseNodeModel = /** @class */ (function () {
|
|
|
175
175
|
* setAttributes 除了初始化调用外,还会在 properties 发生变化了调用。
|
|
176
176
|
*/
|
|
177
177
|
BaseNodeModel.prototype.initNodeData = function (data) {
|
|
178
|
+
var _this = this;
|
|
178
179
|
if (!data.properties) {
|
|
179
180
|
data.properties = {};
|
|
180
181
|
}
|
|
@@ -189,10 +190,12 @@ var BaseNodeModel = /** @class */ (function () {
|
|
|
189
190
|
// 在下面又将 NodeConfig 中的数据赋值给了 this,应该会触发 setAttributes,确认是否符合预期
|
|
190
191
|
// TODO: 确认 constructor 中赋值 properties 是否必要,此处将 NodeConfig 中所有属性赋值给 this,包括 rotate、rotatable,resizable 等
|
|
191
192
|
(0, lodash_es_1.assign)(this, (0, util_1.pickNodeConfig)(data));
|
|
192
|
-
var
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
193
|
+
var _a = this.graphModel, overlapMode = _a.overlapMode, eventCenter = _a.eventCenter;
|
|
194
|
+
this.updateZIndexByOverlap(overlapMode, data.zIndex || (0, util_1.getZIndex)());
|
|
195
|
+
eventCenter.on('overlap:change', function (data) {
|
|
196
|
+
var newMode = data.overlapMode;
|
|
197
|
+
_this.updateZIndexByOverlap(newMode, _this.zIndex || (0, util_1.getZIndex)());
|
|
198
|
+
});
|
|
196
199
|
};
|
|
197
200
|
/**
|
|
198
201
|
* 设置model属性,每次properties发生变化会触发
|
|
@@ -305,7 +308,9 @@ var BaseNodeModel = /** @class */ (function () {
|
|
|
305
308
|
if (this.rotate) {
|
|
306
309
|
data.rotate = this.rotate;
|
|
307
310
|
}
|
|
308
|
-
|
|
311
|
+
// 因为默认模式和节点在上模式下,对边的zIndex要求不高(因为渲染的时候会按照模式对所有元素进行排序)
|
|
312
|
+
// 所以只在递增模式和静态模式下设置zIndex
|
|
313
|
+
if ([constant_1.OverlapMode.INCREASE, constant_1.OverlapMode.STATIC].includes(this.graphModel.overlapMode)) {
|
|
309
314
|
data.zIndex = this.zIndex;
|
|
310
315
|
}
|
|
311
316
|
if (value) {
|
|
@@ -794,6 +799,22 @@ var BaseNodeModel = /** @class */ (function () {
|
|
|
794
799
|
BaseNodeModel.prototype.updateAttributes = function (attributes) {
|
|
795
800
|
(0, lodash_es_1.assign)(this, attributes);
|
|
796
801
|
};
|
|
802
|
+
// 堆叠模式变化时,更新zIndex
|
|
803
|
+
BaseNodeModel.prototype.updateZIndexByOverlap = function (overlapMode, defaultZIndex) {
|
|
804
|
+
switch (overlapMode) {
|
|
805
|
+
case constant_1.OverlapMode.DEFAULT:
|
|
806
|
+
this.zIndex = 1;
|
|
807
|
+
break;
|
|
808
|
+
case constant_1.OverlapMode.EDGE_TOP:
|
|
809
|
+
this.zIndex = 0;
|
|
810
|
+
break;
|
|
811
|
+
case constant_1.OverlapMode.INCREASE:
|
|
812
|
+
this.zIndex = defaultZIndex;
|
|
813
|
+
break;
|
|
814
|
+
default:
|
|
815
|
+
break;
|
|
816
|
+
}
|
|
817
|
+
};
|
|
797
818
|
BaseNodeModel.BaseType = constant_1.ElementType.NODE;
|
|
798
819
|
__decorate([
|
|
799
820
|
mobx_1.observable
|
|
@@ -948,6 +969,9 @@ var BaseNodeModel = /** @class */ (function () {
|
|
|
948
969
|
__decorate([
|
|
949
970
|
mobx_1.action
|
|
950
971
|
], BaseNodeModel.prototype, "updateAttributes", null);
|
|
972
|
+
__decorate([
|
|
973
|
+
mobx_1.action
|
|
974
|
+
], BaseNodeModel.prototype, "updateZIndexByOverlap", null);
|
|
951
975
|
return BaseNodeModel;
|
|
952
976
|
}());
|
|
953
977
|
exports.BaseNodeModel = BaseNodeModel;
|
|
@@ -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
|
};
|
|
@@ -177,11 +177,19 @@ var BaseNode = /** @class */ (function (_super) {
|
|
|
177
177
|
// 节点拖拽进画布之后,不触发click事件相关emit
|
|
178
178
|
// 点拖拽进画布没有触发mousedown事件,没有startTime,用这个值做区分
|
|
179
179
|
var isDragging = _this.mouseUpDrag === false;
|
|
180
|
+
var curTime = new Date().getTime();
|
|
180
181
|
if (!_this.startTime)
|
|
181
182
|
return;
|
|
183
|
+
var timeInterval = curTime - _this.startTime;
|
|
182
184
|
var _a = _this.props, model = _a.model, graphModel = _a.graphModel;
|
|
183
|
-
|
|
184
|
-
|
|
185
|
+
// 这里会有一种极端情况:当网格大小是1或者关闭网格吸附时,用触摸板点击节点会触发拖拽事件导致节点无法选中
|
|
186
|
+
// 当触摸板点击节点时,为了防止误触发拖拽导致节点无法选中,允许在非拖拽状态且时间间隔小于100ms时触发点击事件
|
|
187
|
+
if (!isDragging && timeInterval > 100)
|
|
188
|
+
return;
|
|
189
|
+
if (!isDragging) {
|
|
190
|
+
_this.onDragEnd();
|
|
191
|
+
_this.handleMouseUp();
|
|
192
|
+
}
|
|
185
193
|
// 节点数据,多为事件对象数据抛出
|
|
186
194
|
var nodeData = model.getData();
|
|
187
195
|
var position = graphModel.getPointByClient({
|
|
@@ -272,6 +280,9 @@ var BaseNode = /** @class */ (function (_super) {
|
|
|
272
280
|
});
|
|
273
281
|
};
|
|
274
282
|
_this.handleBlur = function () {
|
|
283
|
+
// 当节点通过自定义锚点实现节点删除时,这里props会变成undefined,需兼容一下
|
|
284
|
+
if (!_this.props)
|
|
285
|
+
return;
|
|
275
286
|
var _a = _this.props, model = _a.model, graphModel = _a.graphModel;
|
|
276
287
|
graphModel.eventCenter.emit(constant_1.EventType.NODE_BLUR, {
|
|
277
288
|
data: model.getData(),
|
package/package.json
CHANGED
package/src/LogicFlow.tsx
CHANGED
|
@@ -26,7 +26,12 @@ import Tool from './tool'
|
|
|
26
26
|
import History from './history'
|
|
27
27
|
import Keyboard, { initDefaultShortcut } from './keyboard'
|
|
28
28
|
import { EventCallback, CallbackArgs, EventArgs } from './event/eventEmitter'
|
|
29
|
-
import {
|
|
29
|
+
import {
|
|
30
|
+
ElementType,
|
|
31
|
+
EventType,
|
|
32
|
+
OverlapMode,
|
|
33
|
+
SegmentDirection,
|
|
34
|
+
} from './constant'
|
|
30
35
|
import { Grid } from './view/overlay'
|
|
31
36
|
|
|
32
37
|
import Extension = LogicFlow.Extension
|
|
@@ -1088,6 +1093,9 @@ export class LogicFlow {
|
|
|
1088
1093
|
this.render({})
|
|
1089
1094
|
}
|
|
1090
1095
|
|
|
1096
|
+
setOverlapMode(mode: OverlapMode) {
|
|
1097
|
+
this.graphModel.setOverlapMode(mode)
|
|
1098
|
+
}
|
|
1091
1099
|
/*********************************************************
|
|
1092
1100
|
* LogicFlow Render方法
|
|
1093
1101
|
********************************************************/
|
package/src/constant/index.ts
CHANGED
package/src/model/GraphModel.ts
CHANGED
|
@@ -181,6 +181,7 @@ export class GraphModel {
|
|
|
181
181
|
this.animation = setupAnimation(animation)
|
|
182
182
|
this.overlapMode = options.overlapMode || OverlapMode.DEFAULT
|
|
183
183
|
|
|
184
|
+
this.isMiniMap = options.isMiniMap || false
|
|
184
185
|
this.width = options.width ?? this.rootEl.getBoundingClientRect().width
|
|
185
186
|
this.isContainerWidth = isNil(options.width)
|
|
186
187
|
this.height = options.height ?? this.rootEl.getBoundingClientRect().height
|
|
@@ -249,9 +250,11 @@ export class GraphModel {
|
|
|
249
250
|
* todo: 性能优化
|
|
250
251
|
*/
|
|
251
252
|
@computed get sortElements() {
|
|
252
|
-
const
|
|
253
|
-
(a, b) => a.zIndex - b.zIndex
|
|
254
|
-
|
|
253
|
+
const sortElement = (list) => {
|
|
254
|
+
return [...list].sort((a, b) => a.zIndex - b.zIndex)
|
|
255
|
+
}
|
|
256
|
+
// 默认情况下节点与边按照 zIndex 排序
|
|
257
|
+
const elements = sortElement([...this.nodes, ...this.edges])
|
|
255
258
|
|
|
256
259
|
// 只显示可见区域的节点和边
|
|
257
260
|
const visibleElements: (BaseNodeModel | BaseEdgeModel)[] = []
|
|
@@ -717,6 +720,22 @@ export class GraphModel {
|
|
|
717
720
|
}
|
|
718
721
|
}
|
|
719
722
|
|
|
723
|
+
/**
|
|
724
|
+
* 内部保留方法,请勿直接使用
|
|
725
|
+
*/
|
|
726
|
+
|
|
727
|
+
/**
|
|
728
|
+
* 设置重叠模式
|
|
729
|
+
* @param mode 重叠模式
|
|
730
|
+
*/
|
|
731
|
+
@action
|
|
732
|
+
setOverlapMode(mode: OverlapMode) {
|
|
733
|
+
this.overlapMode = mode
|
|
734
|
+
this.eventCenter.emit('overlap:change', {
|
|
735
|
+
overlapMode: mode,
|
|
736
|
+
})
|
|
737
|
+
}
|
|
738
|
+
|
|
720
739
|
/**
|
|
721
740
|
* 更新元素的文本模式
|
|
722
741
|
* @param mode
|
|
@@ -767,14 +786,19 @@ export class GraphModel {
|
|
|
767
786
|
toFront(id: string) {
|
|
768
787
|
const element = this.nodesMap[id]?.model || this.edgesMap[id]?.model
|
|
769
788
|
if (element) {
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
this.topElement = element
|
|
789
|
+
// 静态模式toFront不做处理
|
|
790
|
+
if (this.overlapMode === OverlapMode.STATIC) {
|
|
791
|
+
return
|
|
774
792
|
}
|
|
793
|
+
// 递增模式下,将需指定元素zIndex设置为当前最大zIndex + 1
|
|
775
794
|
if (this.overlapMode === OverlapMode.INCREASE) {
|
|
776
795
|
this.setElementZIndex(id, 'top')
|
|
796
|
+
return
|
|
777
797
|
}
|
|
798
|
+
// 默认模式(节点在上)和边在上模式下,将原置顶元素重新恢复原有层级,将需指定元素zIndex设置为最大zIndex
|
|
799
|
+
this.topElement?.setZIndex()
|
|
800
|
+
element.setZIndex(ELEMENT_MAX_Z_INDEX)
|
|
801
|
+
this.topElement = element
|
|
778
802
|
}
|
|
779
803
|
}
|
|
780
804
|
|
|
@@ -1229,7 +1253,9 @@ export class GraphModel {
|
|
|
1229
1253
|
/**
|
|
1230
1254
|
* 如果堆叠模式为默认模式,则将置顶元素重新恢复原有层级
|
|
1231
1255
|
*/
|
|
1232
|
-
if (
|
|
1256
|
+
if (
|
|
1257
|
+
[OverlapMode.DEFAULT, OverlapMode.EDGE_TOP].includes(this.overlapMode)
|
|
1258
|
+
) {
|
|
1233
1259
|
this.topElement?.setZIndex()
|
|
1234
1260
|
}
|
|
1235
1261
|
}
|
|
@@ -1584,7 +1610,7 @@ export class GraphModel {
|
|
|
1584
1610
|
}
|
|
1585
1611
|
|
|
1586
1612
|
/**
|
|
1587
|
-
*
|
|
1613
|
+
* 获取图形区域虚拟矩形的尺寸和中心坐标
|
|
1588
1614
|
* @returns
|
|
1589
1615
|
*/
|
|
1590
1616
|
getVirtualRectSize(): GraphModel.VirtualRectProps {
|
|
@@ -1611,7 +1637,7 @@ export class GraphModel {
|
|
|
1611
1637
|
const virtualRectWidth = maxX - minX || 0
|
|
1612
1638
|
const virtualRectHeight = maxY - minY || 0
|
|
1613
1639
|
|
|
1614
|
-
//
|
|
1640
|
+
// 获取虚拟矩形的中心坐标
|
|
1615
1641
|
const virtualRectCenterPositionX = minX + virtualRectWidth / 2
|
|
1616
1642
|
const virtualRectCenterPositionY = minY + virtualRectHeight / 2
|
|
1617
1643
|
|
|
@@ -1717,7 +1743,6 @@ export class GraphModel {
|
|
|
1717
1743
|
@action setPartial(partial: boolean): void {
|
|
1718
1744
|
this.partial = partial
|
|
1719
1745
|
}
|
|
1720
|
-
|
|
1721
1746
|
/** 销毁当前实例 */
|
|
1722
1747
|
destroy() {
|
|
1723
1748
|
try {
|
|
@@ -144,10 +144,8 @@ export class BaseEdgeModel<P extends PropertiesType = PropertiesType>
|
|
|
144
144
|
} = this.graphModel
|
|
145
145
|
this.isShowAdjustPoint = adjustEdgeStartAndEnd
|
|
146
146
|
assign(this, pickEdgeConfig(data))
|
|
147
|
-
const { overlapMode } = this.graphModel
|
|
148
|
-
|
|
149
|
-
this.zIndex = data.zIndex || getZIndex()
|
|
150
|
-
}
|
|
147
|
+
const { overlapMode, eventCenter } = this.graphModel
|
|
148
|
+
this.updateZIndexByOverlap(overlapMode, data.zIndex || getZIndex())
|
|
151
149
|
// 设置边的 anchors,也就是边的两个端点
|
|
152
150
|
// 端点依赖于 edgeData 的 sourceNode 和 targetNode
|
|
153
151
|
this.setAnchors()
|
|
@@ -155,6 +153,11 @@ export class BaseEdgeModel<P extends PropertiesType = PropertiesType>
|
|
|
155
153
|
this.initPoints()
|
|
156
154
|
// 文本位置依赖于边上的所有拐点
|
|
157
155
|
this.formatText(data)
|
|
156
|
+
|
|
157
|
+
eventCenter.on('overlap:change', (data) => {
|
|
158
|
+
const { overlapMode: newMode } = data
|
|
159
|
+
this.updateZIndexByOverlap(newMode, this.zIndex || getZIndex())
|
|
160
|
+
})
|
|
158
161
|
}
|
|
159
162
|
|
|
160
163
|
/**
|
|
@@ -397,7 +400,13 @@ export class BaseEdgeModel<P extends PropertiesType = PropertiesType>
|
|
|
397
400
|
startPoint: assign({}, this.startPoint),
|
|
398
401
|
endPoint: assign({}, this.endPoint),
|
|
399
402
|
}
|
|
400
|
-
|
|
403
|
+
// 因为默认模式和边在上模式下,对节点的zIndex要求不高(因为渲染的时候会按照模式对所有元素进行排序)
|
|
404
|
+
// 所以只在递增模式和静态模式下设置zIndex
|
|
405
|
+
if (
|
|
406
|
+
[OverlapMode.INCREASE, OverlapMode.STATIC].includes(
|
|
407
|
+
this.graphModel.overlapMode,
|
|
408
|
+
)
|
|
409
|
+
) {
|
|
401
410
|
data.zIndex = this.zIndex
|
|
402
411
|
}
|
|
403
412
|
const { x, y, value } = this.text
|
|
@@ -745,6 +754,24 @@ export class BaseEdgeModel<P extends PropertiesType = PropertiesType>
|
|
|
745
754
|
this.updateStartPoint({ x: startPoint.x, y: startPoint.y })
|
|
746
755
|
this.updateEndPoint({ x: endPoint.x, y: endPoint.y })
|
|
747
756
|
}
|
|
757
|
+
|
|
758
|
+
// 堆叠模式变化时,更新zIndex
|
|
759
|
+
@action
|
|
760
|
+
updateZIndexByOverlap(overlapMode: OverlapMode, defaultZIndex) {
|
|
761
|
+
switch (overlapMode) {
|
|
762
|
+
case OverlapMode.DEFAULT:
|
|
763
|
+
this.zIndex = 0
|
|
764
|
+
break
|
|
765
|
+
case OverlapMode.EDGE_TOP:
|
|
766
|
+
this.zIndex = 1
|
|
767
|
+
break
|
|
768
|
+
case OverlapMode.INCREASE:
|
|
769
|
+
this.zIndex = defaultZIndex
|
|
770
|
+
break
|
|
771
|
+
default:
|
|
772
|
+
break
|
|
773
|
+
}
|
|
774
|
+
}
|
|
748
775
|
}
|
|
749
776
|
|
|
750
777
|
export default BaseEdgeModel
|
|
@@ -206,10 +206,12 @@ export class BaseNodeModel<P extends PropertiesType = PropertiesType>
|
|
|
206
206
|
// TODO: 确认 constructor 中赋值 properties 是否必要,此处将 NodeConfig 中所有属性赋值给 this,包括 rotate、rotatable,resizable 等
|
|
207
207
|
assign(this, pickNodeConfig(data))
|
|
208
208
|
|
|
209
|
-
const { overlapMode } = this.graphModel
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
209
|
+
const { overlapMode, eventCenter } = this.graphModel
|
|
210
|
+
this.updateZIndexByOverlap(overlapMode, data.zIndex || getZIndex())
|
|
211
|
+
eventCenter.on('overlap:change', (data) => {
|
|
212
|
+
const { overlapMode: newMode } = data
|
|
213
|
+
this.updateZIndexByOverlap(newMode, this.zIndex || getZIndex())
|
|
214
|
+
})
|
|
213
215
|
}
|
|
214
216
|
|
|
215
217
|
/**
|
|
@@ -339,7 +341,13 @@ export class BaseNodeModel<P extends PropertiesType = PropertiesType>
|
|
|
339
341
|
if (this.rotate) {
|
|
340
342
|
data.rotate = this.rotate
|
|
341
343
|
}
|
|
342
|
-
|
|
344
|
+
// 因为默认模式和节点在上模式下,对边的zIndex要求不高(因为渲染的时候会按照模式对所有元素进行排序)
|
|
345
|
+
// 所以只在递增模式和静态模式下设置zIndex
|
|
346
|
+
if (
|
|
347
|
+
[OverlapMode.INCREASE, OverlapMode.STATIC].includes(
|
|
348
|
+
this.graphModel.overlapMode,
|
|
349
|
+
)
|
|
350
|
+
) {
|
|
343
351
|
data.zIndex = this.zIndex
|
|
344
352
|
}
|
|
345
353
|
if (value) {
|
|
@@ -914,6 +922,23 @@ export class BaseNodeModel<P extends PropertiesType = PropertiesType>
|
|
|
914
922
|
@action updateAttributes(attributes: any) {
|
|
915
923
|
assign(this, attributes)
|
|
916
924
|
}
|
|
925
|
+
// 堆叠模式变化时,更新zIndex
|
|
926
|
+
@action
|
|
927
|
+
updateZIndexByOverlap(overlapMode: OverlapMode, defaultZIndex) {
|
|
928
|
+
switch (overlapMode) {
|
|
929
|
+
case OverlapMode.DEFAULT:
|
|
930
|
+
this.zIndex = 1
|
|
931
|
+
break
|
|
932
|
+
case OverlapMode.EDGE_TOP:
|
|
933
|
+
this.zIndex = 0
|
|
934
|
+
break
|
|
935
|
+
case OverlapMode.INCREASE:
|
|
936
|
+
this.zIndex = defaultZIndex
|
|
937
|
+
break
|
|
938
|
+
default:
|
|
939
|
+
break
|
|
940
|
+
}
|
|
941
|
+
}
|
|
917
942
|
}
|
|
918
943
|
|
|
919
944
|
export namespace BaseNodeModel {
|
|
@@ -124,14 +124,23 @@ export abstract class BaseEdge<P extends IProps> extends Component<
|
|
|
124
124
|
const { refY = 0, refX = 2 } = model.getArrowStyle()
|
|
125
125
|
const [start, end] = this.getLastTwoPoints()
|
|
126
126
|
let theta: string | number = 'auto'
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
127
|
+
// 防止无效点和零长度向量以避免 NaN 方向
|
|
128
|
+
if (start && end) {
|
|
129
|
+
const dx = end.x - start.x
|
|
130
|
+
const dy = end.y - start.y
|
|
131
|
+
// 仅在有实际方向时才计算
|
|
132
|
+
if (dx !== 0 || dy !== 0) {
|
|
133
|
+
const computed = degrees(
|
|
134
|
+
getThetaOfVector({
|
|
135
|
+
x: dx,
|
|
136
|
+
y: dy,
|
|
137
|
+
z: 0,
|
|
138
|
+
}),
|
|
139
|
+
)
|
|
140
|
+
if (Number.isFinite(computed) && !Number.isNaN(computed)) {
|
|
141
|
+
theta = computed
|
|
142
|
+
}
|
|
143
|
+
}
|
|
135
144
|
}
|
|
136
145
|
return (
|
|
137
146
|
<g>
|
|
@@ -88,9 +88,9 @@ export abstract class BaseNode<P extends IProps = IProps> extends Component<
|
|
|
88
88
|
}
|
|
89
89
|
}
|
|
90
90
|
|
|
91
|
-
componentDidMount() {}
|
|
91
|
+
componentDidMount() { }
|
|
92
92
|
|
|
93
|
-
componentDidUpdate() {}
|
|
93
|
+
componentDidUpdate() { }
|
|
94
94
|
|
|
95
95
|
abstract getShape(): h.JSX.Element | null
|
|
96
96
|
|
|
@@ -336,9 +336,17 @@ export abstract class BaseNode<P extends IProps = IProps> extends Component<
|
|
|
336
336
|
// 节点拖拽进画布之后,不触发click事件相关emit
|
|
337
337
|
// 点拖拽进画布没有触发mousedown事件,没有startTime,用这个值做区分
|
|
338
338
|
const isDragging = this.mouseUpDrag === false
|
|
339
|
+
const curTime = new Date().getTime()
|
|
339
340
|
if (!this.startTime) return
|
|
341
|
+
const timeInterval = curTime - this.startTime
|
|
340
342
|
const { model, graphModel } = this.props
|
|
341
|
-
|
|
343
|
+
// 这里会有一种极端情况:当网格大小是1或者关闭网格吸附时,用触摸板点击节点会触发拖拽事件导致节点无法选中
|
|
344
|
+
// 当触摸板点击节点时,为了防止误触发拖拽导致节点无法选中,允许在非拖拽状态且时间间隔小于100ms时触发点击事件
|
|
345
|
+
if (!isDragging && timeInterval > 100) return
|
|
346
|
+
if (!isDragging) {
|
|
347
|
+
this.onDragEnd()
|
|
348
|
+
this.handleMouseUp()
|
|
349
|
+
}
|
|
342
350
|
// 节点数据,多为事件对象数据抛出
|
|
343
351
|
const nodeData = model.getData()
|
|
344
352
|
const position = graphModel.getPointByClient({
|
|
@@ -440,6 +448,8 @@ export abstract class BaseNode<P extends IProps = IProps> extends Component<
|
|
|
440
448
|
}
|
|
441
449
|
|
|
442
450
|
handleBlur = () => {
|
|
451
|
+
// 当节点通过自定义锚点实现节点删除时,这里props会变成undefined,需兼容一下
|
|
452
|
+
if (!this.props) return
|
|
443
453
|
const { model, graphModel } = this.props
|
|
444
454
|
graphModel.eventCenter.emit(EventType.NODE_BLUR, {
|
|
445
455
|
data: model.getData(),
|