arrows.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import util from './util'
  2. function normal (parent, id, edge, type) {
  3. const marker = parent.append('marker')
  4. .attr('id', id)
  5. .attr('viewBox', '0 0 10 10')
  6. .attr('refX', 9)
  7. .attr('refY', 5)
  8. .attr('markerUnits', 'strokeWidth')
  9. .attr('markerWidth', 8)
  10. .attr('markerHeight', 6)
  11. .attr('orient', 'auto')
  12. const path = marker.append('path')
  13. .attr('d', 'M 0 0 L 10 5 L 0 10 z')
  14. .style('stroke-width', 1)
  15. .style('stroke-dasharray', '1,0')
  16. util.applyStyle(path, edge[type + 'Style'])
  17. if (edge[type + 'Class']) {
  18. path.attr('class', edge[type + 'Class'])
  19. }
  20. }
  21. function vee (parent, id, edge, type) {
  22. const marker = parent.append('marker')
  23. .attr('id', id)
  24. .attr('viewBox', '0 0 10 10')
  25. .attr('refX', 9)
  26. .attr('refY', 5)
  27. .attr('markerUnits', 'strokeWidth')
  28. .attr('markerWidth', 8)
  29. .attr('markerHeight', 6)
  30. .attr('orient', 'auto')
  31. const path = marker.append('path')
  32. .attr('d', 'M 0 0 L 10 5 L 0 10 L 4 5 z')
  33. .style('stroke-width', 1)
  34. .style('stroke-dasharray', '1,0')
  35. util.applyStyle(path, edge[type + 'Style'])
  36. if (edge[type + 'Class']) {
  37. path.attr('class', edge[type + 'Class'])
  38. }
  39. }
  40. function undirected (parent, id, edge, type) {
  41. const marker = parent.append('marker')
  42. .attr('id', id)
  43. .attr('viewBox', '0 0 10 10')
  44. .attr('refX', 9)
  45. .attr('refY', 5)
  46. .attr('markerUnits', 'strokeWidth')
  47. .attr('markerWidth', 8)
  48. .attr('markerHeight', 6)
  49. .attr('orient', 'auto')
  50. const path = marker.append('path')
  51. .attr('d', 'M 0 5 L 10 5')
  52. .style('stroke-width', 1)
  53. .style('stroke-dasharray', '1,0')
  54. util.applyStyle(path, edge[type + 'Style'])
  55. if (edge[type + 'Class']) {
  56. path.attr('class', edge[type + 'Class'])
  57. }
  58. }
  59. export default {
  60. normal,
  61. vee,
  62. undirected,
  63. default: normal
  64. }