g6/demos/custom-anchor.html

78 lines
1.2 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>自定义-锚点</title>
</head>
<body>
<div id="mountNode"></div>
<script src="../build/g6.js"></script>
<script>
const data = {
nodes: [{
id: 'node1',
x: 250,
y: 250
},{
id: 'node2',
x: 250,
y: 100
},{
id: 'node3',
x: 50,
y: 400
},{
id: 'node5',
x: 450,
y: 400
}],
edges: [{
id: 'edge1',
target: 'node2',
source: 'node1'
},{
id: 'edge2',
target: 'node3',
source: 'node1'
},{
id: 'edge4',
target: 'node5',
source: 'node1'
}]
};
// 设置右边中点为连接锚点
G6.registerNode('node2', {
anchor: [
// 右边中点
[1, 0.5]
]
});
// 设置相交盒模型为矩形
G6.registerNode('node3', {
anchor: {
intersectBox: 'rect'
}
});
const graph = new G6.Graph({
container: 'mountNode', // 容器ID
fitView: 'cc',
height: window.innerHeight
});
graph.node({
label(model) {
return model.id;
},
shape(model) {
return model.id;
}
})
graph.read(data);
</script>
</body>
</html>