jsplumb连接线有箭头
时间: 2023-07-22 17:26:23 浏览: 87
是的,jsPlumb连接线可以设置箭头。你可以使用`connectorOverlays`选项来设置箭头,具体可以参考jsPlumb官方文档中的示例。下面是一个示例代码片段:
```
jsPlumb.connect({
source:"element1",
target:"element2",
connector:["Flowchart", {cornerRadius:5}],
endpoint:"Blank",
paintStyle:{lineWidth:2, strokeStyle:"#f76258", outlineWidth:3, outlineColor:"transparent"},
connectorOverlays:[ ["Arrow", { width:15, length:15, location:1 }] ]
});
```
在上面的示例中,`connectorOverlays`选项设置了箭头,箭头的样式可以通过`width`和`length`属性进行调整,`location`属性指定箭头的位置。
相关问题
jsplumb创建垂直线
以下是使用jsplumb创建垂直线的示例代码:
```javascript
jsPlumb.ready(function() {
// 创建一个jsPlumb实例
var instance = jsPlumb.getInstance();
// 设置连接线的默认样式
var connectorPaintStyle = {
lineWidth: 2,
strokeStyle: "#61B7CF",
joinstyle: "round",
outlineColor: "white",
outlineWidth: 2
};
// 设置连接点的默认样式
var endpointStyle = {
endpoint: "Dot",
paintStyle: {
strokeStyle: "#7AB02C",
fillStyle: "transparent",
radius: 7,
lineWidth: 2
},
isSource: true,
connector: ["Flowchart", { stub: [40, 60], gap: 10, cornerRadius: 5, alwaysRespectStubs: true }],
connectorStyle: connectorPaintStyle,
hoverPaintStyle: endpointHoverStyle,
connectorHoverStyle: connectorHoverStyle, dragOptions: {},
overlays: [
["Label", {
location: [0.5, 1.5],
label: "Drag",
cssClass: "endpointSourceLabel",
visible:false
}]
]
};
// 设置连接点的悬停样式
var endpointHoverStyle = {
endpoint: "Dot",
paintStyle: { fillStyle: "#7AB02C" },
hoverPaintStyle: { fillStyle: "#216477" },
isSource: true,
connectorHoverStyle: connectorHoverStyle,
dragOptions: {},
overlays: [
["Label", {
location: [0.5, 1.5],
label: "Drag",
cssClass: "endpointSourceLabel",
visible:false
}]
]
};
// 设置连接线的悬停样式
var connectorHoverStyle = {
lineWidth: 4,
strokeStyle: "#216477",
outlineWidth: 2,
outlineColor: "white"
};
// 创建连接点
var sourceEndpoint = instance.addEndpoint("source", {
anchor: "BottomCenter"
}, endpointStyle);
var targetEndpoint = instance.addEndpoint("target", {
anchor: "TopCenter"
}, endpointStyle);
// 创建连接线
var connection = instance.connect({
source: sourceEndpoint,
target: targetEndpoint,
paintStyle: connectorPaintStyle,
hoverPaintStyle: connectorHoverStyle,
overlays: [
["Arrow", {
location: 1,
visible: true,
width: 11,
length: 11,
id: "ARROW",
events: {
click: function() { alert("you clicked on the arrow overlay")}
}
}],
["Label", {
location: 0.1,
id: "label",
cssClass: "aLabel",
events:{
tap:function() { alert("hey"); }
}
}]
],
detachable: false
});
// 创建垂直线
var verticalLine = instance.connect({
source: [sourceEndpoint.getAnchor(), [sourceEndpoint.getAnchor()[0], targetEndpoint.getAnchor()[1]]],
target: [targetEndpoint.getAnchor(), [sourceEndpoint.getAnchor()[0], targetEndpoint.getAnchor()[1]]],
paintStyle: connectorPaintStyle,
detachable: false
});
});
```
在上面的代码中,我们首先创建了一个jsPlumb实例,然后设置了连接线和连接点的默认样式。接着,我们创建了两个连接点,一个位于源元素的底部中心,另一个位于目标元素的顶部中心。然后,我们使用`instance.connect()`方法创建了一条连接线,并设置了箭头和标签。最后,我们使用`instance.connect()`方法创建了一条垂直线,该线的起点和终点分别为源元素和目标元素的中心点,但是终点的x坐标与起点相同,y坐标与目标元素的中心点相同,从而实现了垂直线的效果。
jsplumb connect函数
`jsPlumb.connect` 函数用于在两个元素之间创建连接线。该函数的语法如下:
```js
jsPlumb.connect({
source: "sourceElementId",
target: "targetElementId",
[options]
});
```
其中,`source` 和 `target` 是必需的参数,分别指定连接线的起始元素和目标元素的 ID。`options` 是可选的参数对象,用于指定连接线的样式、箭头、标签等属性。
以下是一些常用的 `options` 属性:
- `endpoint`: 连接线的端点,可以是一个数组(起始端点和终止端点),也可以是一个对象(同时指定起始和终止端点)。
- `anchors`: 连接线的锚点,可以是一个数组(起始锚点和终止锚点),也可以是一个对象(同时指定起始和终止锚点)。
- `connector`: 连接线的类型,可以是 `"Bezier"`、`"Flowchart"`、`"StateMachine"` 等。
- `paintStyle`: 连接线的样式,可以指定颜色、线宽、虚线等属性。
- `overlays`: 连接线的覆盖物,可以是箭头、标签等等。
除了以上属性外,还有许多其他属性可以用于进一步定制连接线的样式和行为。具体可以参考官方文档:http://jsplumb.github.io/jsplumb/connectors.html。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)