arc_tp.js 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /**
  2. *
  3. * 圆弧连线
  4. *
  5. * @author: along
  6. * @copyright: bpd729@163.com , 2015
  7. */
  8. define(function(require, exports, module) {
  9. var kity = require('../core/kity');
  10. var connect = require('../core/connect');
  11. var connectMarker = new kity.Marker().pipe(function () {
  12. var r = 7;
  13. var dot = new kity.Circle(r - 1);
  14. this.addShape(dot);
  15. this.setRef(r - 1, 0).setViewBox(-r, -r, r + r, r + r).setWidth(r).setHeight(r);
  16. this.dot = dot;
  17. this.node.setAttribute('markerUnits', 'userSpaceOnUse');
  18. });
  19. /**
  20. * 天盘图连线除了连接当前节点和前一个节点外, 还需要渲染当前节点和后一个节点的连接, 防止样式上的断线
  21. * 这是天盘图与其余的模板不同的地方
  22. */
  23. connect.register('arc_tp', function (node, parent, connection, width, color) {
  24. var end_box = node.getLayoutBox(),
  25. start_box = parent.getLayoutBox();
  26. var index = node.getIndex();
  27. var nextNode = parent.getChildren()[index + 1];
  28. if (node.getIndex() > 0) {
  29. start_box = parent.getChildren()[index - 1].getLayoutBox();
  30. }
  31. var start, end, vector;
  32. var abs = Math.abs;
  33. var pathData = [];
  34. var side = end_box.x > start_box.x ? 'right' : 'left';
  35. node.getMinder().getPaper().addResource(connectMarker);
  36. start = new kity.Point(start_box.cx, start_box.cy);
  37. end = new kity.Point(end_box.cx, end_box.cy);
  38. var jl = Math.sqrt(Math.pow((start.x - end.x), 2) + Math.pow((start.y - end.y), 2)); //两圆中心点距离
  39. jl = node.getIndex() == 0 ? jl * 0.4 : jl;
  40. vector = kity.Vector.fromPoints(start, end);
  41. pathData.push('M', start);
  42. pathData.push('A', jl, jl, 0, 0, 1, end);
  43. connection.setMarker(connectMarker);
  44. connectMarker.dot.fill(color);
  45. connection.setPathData(pathData);
  46. // 设置下一个的节点的连接线
  47. if (nextNode && nextNode.getConnection()) {
  48. var nextConnection = nextNode.getConnection();
  49. var next_end_box = nextNode.getLayoutBox();
  50. var next_end = new kity.Point(next_end_box.cx, next_end_box.cy);
  51. var jl2 = Math.sqrt(Math.pow((end.x - next_end.x), 2) + Math.pow((end.y - next_end.y), 2)); //两圆中心点距离
  52. pathData = [];
  53. pathData.push('M', end);
  54. pathData.push('A', jl2, jl2, 0, 0, 1, next_end);
  55. nextConnection.setMarker(connectMarker);
  56. connectMarker.dot.fill(color);
  57. nextConnection.setPathData(pathData);
  58. }
  59. });
  60. });