G6 图表示例
源码
x
 
1
<!DOCTYPE html>
2
<html>
3
  <head>
4
    <meta charset="utf-8">
5
    <title>自定义箭头</title>
6
    <script src="https://a.alipayobjects.com/jquery/jquery/1.11.1/jquery.js"></script>
7
    <script src="https://gw.alipayobjects.com/os/antv/assets/g6/1.2.8/g6.min.js"></script>
8
  </head>
9
  <body>
10
    <div id="c1"></div>
11
    <script type="text/javascript">
12
      var Util = G6.Util;
13
      G6.registEdge('bezierQuadratic', {
14
        afterDraw: function(cfg, group, keyShape) {
15
          var points = cfg.points;
16
          var start = points[0];
17
          var end = points[points.length - 1];
18
          var center = keyShape.getPoint(0.5);
19
          var lineWidth = keyShape.attr('lineWidth');
20
          if(lineWidth < 5){
21
            lineWidth = 5;
22
          }
23
          // 关于自身坐标系构造一个形,作为箭头
24
          var arrow = group.addShape('polyline', {
25
            attrs:{
26
              points: [
27
                [-lineWidth/4, lineWidth/2],
28
                [lineWidth/4, 0],
29
                [-lineWidth/4, -lineWidth/2]
30
              ],
31
              stroke: '#333'
32
            },
33
            class: 'arrow'
34
          });
35
          Util.arrowTo(arrow, center.x, center.y, center.x, center.y, end.x, end.y);
36
        }
37
      });
38
      var data = {
39
        "source": {
40
          "nodes": [
41
            {
42
              "shape": "rect",
43
              "label": "文本",
44
              "x": 550,
45
              "y": 260,
46
              "id": "af11b7bc"
47
            },
48
            {
49
              "shape": "rect",
50
              "label": "文本",
51
              "x": 780,
52
              "y": 260,
53
              "id": "313ed868"
54
            }
55
          ],
56
          "edges": [
57
            {
58
              "source": "af11b7bc",
59
              "target": "313ed868",
60
              "id": "bd2bc602"
61
            },
62
            {
63
              "source": "313ed868",
64
              "target": "af11b7bc",
65
              "id": "1be6dc9f",
66
              "size": 2,
67
              "targetAnchor": 2,
68
              "sourceAnchor": 2
69
            },
70
            {
71
              "source": "af11b7bc",
72
              "target": "313ed868",
73
              "id": "3d463cd1",
74
              "targetAnchor": 0,
75
              "sourceAnchor": 0
76
            },
77
            {
78
              "source": "313ed868",
79
              "target": "af11b7bc",
80
              "id": "ba7e057c",
81
              "size": 6
82
            }
83
          ]
84
        }
85
      };
86
      var net = new G6.Net({
87
        id: 'c1',           // 容器ID
88
        width: 500,         // 画布宽
89
        height: 500,        // 画布高
90
        fitView: 'cc',      // 图居中自适应
91
        mode: 'none',       // 模式
92
        grid: {
93
          forceAlign: true, // 是否支持网格对齐
94
          cell: 10          // 网格大小
95
        }
96
      });
97
      net.read(data);
98
      net.edge().shape('bezierQuadratic');
99
      net.render();
100
    </script>
101
  </body>
102
</html>
103

自定义箭头