customArrow.js
2.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/*
* @Date: 2025-03-12 15:30:18
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2025-03-12 16:19:06
* @FilePath: /logic-flow2/src/views/edge/customArrow.js
* @Description: 文件描述
*/
import { PolylineEdge, PolylineEdgeModel, h } from '@logicflow/core';
class CustomEdgeModel extends PolylineEdgeModel {
// customTextPosition = true;
initEdgeData(data) {
super.initEdgeData(data);
this.customTextPosition = true;
this.adjustEdgeMiddle = true; // 允许调整边中间的点
}
setAttributes() {
this.isAnimation = true;
}
// setHovered(isHovered) {
// super.setHovered(isHovered);
// this.isAnimation = isHovered;
// }
getEdgeAnimationStyle() {
const style = super.getEdgeAnimationStyle();
style.strokeDasharray = "5 5";
style.strokeDashoffset = "100%";
style.animationDuration = "10s";
return style;
}
}
class CustomArrow extends PolylineEdge {
getAdjustPointShape(x, y) {
return h("g", {}, [
h("image", {
x: x - 9,
y: y - 9,
width: 18,
height: 18,
cursor: "move",
href:
"data:image/svg+xml;base64,PCFET0NUWVBFIHN2ZyBQVUJMSUMgIi0vL1czQy8vRFREIFNWRyAxLjEvL0VOIiAiaHR0cDovL3d3dy53My5vcmcvR3JhcGhpY3MvU1ZHLzEuMS9EVEQvc3ZnMTEuZHRkIj48c3ZnIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIHdpZHRoPSIyMnB4IiBoZWlnaHQ9IjIycHgiIHZlcnNpb249IjEuMSI+PGNpcmNsZSBjeD0iMTEiIGN5PSIxMSIgcj0iNyIgc3Ryb2tlPSIjZmZmIiBmaWxsPSIjMjliNmYyIi8+PGNpcmNsZSBjeD0iMTEiIGN5PSIxMSIgcj0iMyIgc3Ryb2tlPSIjZmZmIiBmaWxsPSJ0cmFuc3BhcmVudCIvPjwvc3ZnPg=="
})
]);
}
getEndArrow() {
const { model } = this.props;
const {
properties: { arrowType },
} = model;
const { stroke, strokeWidth } = model.getArrowStyle();
const pathAttr = {
stroke,
strokeWidth,
};
if (arrowType === 'empty') {
// 空心箭头
return h('path', {
...pathAttr,
fill: '#FFF',
d: 'M 0 0 -20 -5 -30 0 -20 5 z',
});
} else if (arrowType === 'half') {
// 半箭头
return h('path', {
...pathAttr,
d: 'M 0 0 -10 5',
});
}
return h('path', {
...pathAttr,
d: 'M 0 0 -10 -5 -10 5 z',
});
}
}
export default {
type: 'custom-arrow',
model: CustomEdgeModel,
view: CustomArrow,
};