123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- <!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>
|