mirror of
https://gitee.com/antv/g6.git
synced 2024-12-03 20:28:36 +08:00
55 lines
1.0 KiB
HTML
55 lines
1.0 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": [
|
|
{
|
|
"shape": "customNode",
|
|
"id": "node1"
|
|
}
|
|
],
|
|
};
|
|
|
|
G6.registerNode('customNode', {
|
|
draw(item){
|
|
const group = item.getGraphicGroup();
|
|
group.addShape('text', {
|
|
attrs: {
|
|
x: 100,
|
|
y: 100,
|
|
fill: '#333',
|
|
text: '我是一个自定义节点,\n有下面那个方形和我自己组成'
|
|
}
|
|
});
|
|
return group.addShape('rect', {
|
|
attrs: {
|
|
x: 100,
|
|
y: 100,
|
|
width: 100,
|
|
height: 100,
|
|
stroke: 'red'
|
|
}
|
|
});
|
|
}
|
|
});
|
|
|
|
const graph = new G6.Graph({
|
|
container: 'mountNode', // 容器ID
|
|
fitView: 'cc',
|
|
height: window.innerHeight
|
|
});
|
|
graph.read(data);
|
|
|
|
</script>
|
|
</body>
|
|
</html>
|