bezier.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /**
  2. * @fileOverview
  3. *
  4. * 提供折线相连的方法
  5. *
  6. * @author: techird
  7. * @copyright: Baidu FEX, 2014
  8. */
  9. define(function(require, exports, module) {
  10. var kity = require('../core/kity');
  11. var connect = require('../core/connect');
  12. connect.register('bezier', function(node, parent, connection) {
  13. // 连线起点和终点
  14. var po = parent.getLayoutVertexOut(),
  15. pi = node.getLayoutVertexIn();
  16. // 连线矢量和方向
  17. var v = parent.getLayoutVectorOut().normalize();
  18. var r = Math.round;
  19. var abs = Math.abs;
  20. var pathData = [];
  21. pathData.push('M', r(po.x), r(po.y));
  22. if (abs(v.x) > abs(v.y)) {
  23. // x - direction
  24. var hx = (pi.x + po.x) / 2;
  25. pathData.push('C', hx, po.y, hx, pi.y, pi.x, pi.y);
  26. } else {
  27. // y - direction
  28. var hy = (pi.y + po.y) / 2;
  29. pathData.push('C', po.x, hy, pi.x, hy, pi.x, pi.y);
  30. }
  31. connection.setMarker(null);
  32. connection.setPathData(pathData);
  33. });
  34. });