0%

jsPlumb 笔记

jsPlumb todo

  • save position
  • add delete edit node|line
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
nodes.push({
blockId: $elem.attr('id'),
nodetype: $elem.attr('data-nodetype'),
positionX: parseInt($elem.css("left"), 10),
positionY: parseInt($elem.css("top"), 10)
});

$.each(jsPlumb.getConnections(), function (idx, connection) {
connections.push({
connectionId: connection.id,
pageSourceId: connection.sourceId,
pageTargetId: connection.targetId
});
});

flow.plumbIns.getConnections()
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
Anchor : "BottomCenter",//端点的定位点的位置声明(锚点):left,top,bottom等
Anchors : [ null, null ],//多个锚点的位置声明
ConnectionsDetachable : true,//连接是否可以使用鼠标默认分离
ConnectionOverlays : [],//附加到每个连接的默认重叠
Connector : "Bezier",//要使用的默认连接器的类型:折线,流程等
Container : null,//设置父级的元素,一个容器
DoNotThrowErrors : false,//如果请求不存在的Anchor,Endpoint或Connector,是否会抛出
DragOptions : { },//用于配置拖拽元素的参数
DropOptions : { },//用于配置元素的drop行为的参数
Endpoint : "Dot",//端点(锚点)的样式声明(Dot)
Endpoints : [ null, null ],//多个端点的样式声明(Dot)
EndpointOverlays : [ ],//端点的重叠
EndpointStyle : { fill : "#456" },//端点的css样式声明
EndpointStyles : [ null, null ],//同上
EndpointHoverStyle : null,//鼠标经过样式
EndpointHoverStyles : [ null, null ],//同上
HoverPaintStyle : null,//鼠标经过线的样式
LabelStyle : { color : "black" },//标签的默认样式。
LogEnabled : false,//是否打开jsPlumb的内部日志记录
Overlays : [ ],//重叠
MaxConnections : 1,//最大连接数
PaintStyle : { lineWidth : 8, stroke : "#456" },//连线样式
ReattachConnections : false,//是否重新连接使用鼠标分离的线
RenderMode : "svg",//默认渲染模式
Scope : "jsPlumb_DefaultScope"//范围,标识

如果是全局则可以使用jsPlumb.importDefaults({···}),
也可以在实例化时,重新定义jsPlumb.getInstance({···}),

via https://www.cnblogs.com/leomyili/p/6346526.html

关原之战.01

https://www.bilibili.com/video/BV1Y44y1b7bu/?spm_id_from=333.788.video.desc.click

d3

1
import * as d3 from "d3";
  • source 源
  • target 目标

anchor 锚点

right left top bottom TopRight BottomRight center … [x,y,dx,dy]

endpoint 端点

Dot Rectangle Blank Image

connector 连线

  • Bezier
  • Flowchart
  • StateMachine
  • Straight

overlays

Arrow - 箭头
Label - 标签
PlainArrow - 平头箭头
Diamond - 菱形
Diamond(钻石):钻石箭头
Custom - 自定义

1
overlays: [ [‘Arrow’, { width: 8, length: 8, location: 1 }] ]

例子

1
2
3
4
5
6
7
8
9
10
11
12
13
res.transitions.forEach((k) => {
jsPlumb.connect({
source: div.querySelector('[data-id="' + k.from + '"]'),
target: div.querySelector('[data-id="' + k.to + '"]'),
// endpoint: 'Dot', //端点的形状 Dot(默认圆点)、Rectangle(矩形)、Blank(空)
// endpoints: ["Dot", "Blank"],
// options:{
// radius: 5
// }
connector:'Flowchart',
// anchors: ['Right', 'Left'],
});
});
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
jsPlumb.importDefaults({
DragOptions: { cursor: "pointer", zIndex: 2000 },
PaintStyle: {
stroke: "#666" ,
strokeWidth: 2,
outlineStroke:'transparent', // transparent
outlineWidth:10
},
HoverPaintStyle: {
stroke: '#b0b2b5',
// strokeWidth: 2
}, // 鼠标滑过线的样式=
// Endpoint: "Rectangle",
// Anchors: ["TopCenter"],
//控制是否有箭头
ConnectionOverlays1111: [
["Arrow", { location: 1 }],
[
"Label",
{
location: 0.1,
id: "label",
cssClass: "aLabel",
},
],
],
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
jsPlumb.ready(function () {
jsPlumb.importDefaults({
ConnectionsDetachable: false,
});

jsPlumb.connect({
source: "item_left",
target: "item_right",
// endpoint: 'Dot',
endpoints: ["Dot", "Blank"],
// options:{
// radius: 5
// }
});

jsPlumb.draggable("item_left");
});
1
2
3
4
5
6
jsPlumb.batch(function() {
// import here
for (var i = 0, j = connections.length; i < j; i++) {
jsPlumb.connect(connections[i]);
}
});
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
< template>
< h3>jsplumb使用
< div id="container">
< div class="col1">
< div v-for="item in list1" :key="item.nodeId" :id="item.nodeId" name="joint">{{ item.name }}
< /div>
< div class="col2">
< div v-for="item in list2" :key="item.nodeId" :id="item.nodeId" name="data">{{ item.name }}
< /div>
< /div>
< /template>
< script lang="ts" setup>
import {ref, reactive,onMounted} from 'vue'
import jsPlumb from 'jsplumb'
//jsplumb使用
let $jsPlumb = jsPlumb.jsPlumb;
let jsPlumb_instance = null; // 缓存实例化的jsplumb对象
//模型轴
const list1 = reactive([
{name: "name1", nodeId: "name1", axis: '', type:''},
{name: "name2", nodeId: "name2", axis: '', type:''},
{name: "name3", nodeId: "name3", axis: '', type:''},
{name: "name4", nodeId: "name4", axis: '', type:''},
{name: "name5", nodeId: "name5", axis: '', type:''},
{name: "name6", nodeId: "name6", axis: '', type:''}
]);
//接口数据点
const list2 = reactive([
{name: '数据1', nodeId: 'data1'},
{name: '数据2', nodeId: 'data2'},
{name: '数据3', nodeId: 'data3'},
{name: '数据4', nodeId: 'data4'},
{name: '数据5', nodeId: 'data5'},
{name: '数据6', nodeId: 'data6'}
]);

onMounted(()=>{
showPlumb();
})

const showPlumb = ()=> {
jsPlumb_instance = $jsPlumb.getInstance({
Container: 'container', // 选择器id
EndpointStyle: {radius: 0.11, fill: '#fff'}, // 端点样式
PaintStyle: {stroke: '#000', strokeWidth: 2}, // 绘画样式,默认8px线宽 #456
HoverPaintStyle: {stroke: '#1E90FF'}, // 默认悬停样式 默认为null
ConnectionOverlays: [ // 此处可以设置所有箭头的样式,因为我们要改变连接线的样式,故单独配置
['Arrow', { // 设置参数可以参考中文文档
location: 1,
length: 10,
paintStyle: {
stroke: '#000',
fill: '#000'
}
}]
],
Connector: ['Straight'], // 要使用的默认连接器的类型:直线,折线,曲线等
DrapOptions: {cursor: 'crosshair', zIndex: 2000}
},)

console.log(jsPlumb_instance)

jsPlumb_instance.batch(() => {

for (let i = 0; i < list1.length; i++) {
initLeaf(list1[i].nodeId, 'joint')
}
for (let i = 0; i < list2.length; i++) {
initLeaf(list2[i].nodeId, 'data')
}
})

const joint = document.getElementsByName('joint')
const data = document.getElementsByName('data')

jsPlumb_instance.setSourceEnabled(joint, true)
jsPlumb_instance.setTargetEnabled(data, true)
jsPlumb_instance.setDraggable(joint, false) // 是否支持拖拽
jsPlumb_instance.setDraggable(data, false) // 是否支持拖拽

jsPlumb_instance.bind('click', (conn, originalEvent) => {
jsPlumb_instance.deleteConnection(conn)
})

}

// 初始化具体节点
const initLeaf = (id, type)=> {
const ins = jsPlumb_instance;
const elem = document.getElementById(id)
if (type == 'joint') {
ins.makeSource(elem, {
anchor: [1, 0.5, 0, 0], // 左 上 右 下
allowLoopback: false,
maxConnections: 1
})
} else {
ins.makeTarget(elem, {
anchor: [0, 0.5, 0, 0],
allowLoopback: false,
maxConnections: 1
})
}
}

< /script>
1
2
3
4
5
jsPlumb.setSuspendDrawing(true);

jsPlumb.setSuspendDrawing(false,true);

jsPlumb.batch(fn,[doNotRepaintAfterwards]);

jsPlumb自带了默认的参数,AutoDefault。其实与[“Top”,”Right”,”Bottom”,”Left”]相同。

Bezier:它有一个配置项,curviness(弯曲度),默认为150.这定义了Bezier的控制点与锚点的距离
Straight:在两个端点之间绘制一条直线,支持两个配置参数:stub,默认为0。gap,默认为0
Flowchart:由一系列垂直或水平段组成的连接。支持四个参数,stub,默认为30;alwaysRespectStubs,默认为false;gap,默认为0;midpoint,默认为0.5;cornerRadius,默认为0;
StateMachine:状态器,支持在同一元素上开始和结束的连接,支持的参数有:margin,默认为5;curviness,默认为10;proximityLimit,默认为80;