经验首页 前端设计 程序设计 Java相关 移动开发 数据库/运维 软件/图像 大数据/云计算 其他经验
当前位置:技术经验 » JS/JS库/框架 » JavaScript » 查看文章
使用jsplumb的一些笔记
来源:cnblogs  作者:改个名字吧  时间:2018/11/23 10:10:14  对本文有异议

 欢迎就是需要使用jsplumb跟正在使用jsplumb的一起讨论 欢迎私聊

1.关于jsplumb的connection的一些事件

####connection拖动的事件

  1. instance.bind('connectionDragStop', function(conn) {});

 ####连接废弃

  1. instance.bind('connectionAborted', (conn, originalEvent) => {})

####在落下来某一个点之前

  1. instance.bind('beforeDrop', (conn) => {})

####

  1. instance.bind('beforeDrag', (conn) => {})

####

  1. instance.bind('connectionDrag', (conn) => {})

####

  1. instance.bind('beforeDetach', (conn) => {})

 ####想要拿到连线的点击事件啊,hover事件啊,都可以通过bind来实现

  1. instance.bind('click', function(c) {})

 

等等这些事件吧~~~~~

2.就是关于连接线的一些样式问题

  1.你可以在一个页面上实现多种连接的样式,这个都是可以实现的

  2.有关于线是实线啊,虚线啊这些也都是可以实现的 虚线的话dashstyle可以来实现,应该是跟css差不多的

 

恩。。。。。

放一些废弃代码

  1. initConnect(instance) {
  2. var that = this;
  3. instance.batch(function() {
  4. for (const point of that.$store.state.nodes) {
  5. that.initNode(instance, point.node_id)
  6. if (point.child_nodes.length > 0 || point.parent_node == 'root') {
  7. instance.addEndpoint(point.node_id, {
  8. uuid: `${point.node_id}-bottom`,
  9. anchor: 'Bottom',
  10. maxConnections: -1,
  11. // connectorStyle: { stroke: '#2FB39C', strokeWidth: 2 },
  12. // connectorHoverStyle: {
  13. // strokeWidth: 3,
  14. // stroke: "yellow",
  15. // },
  16. deleteEndpointsOnEmpty: true,
  17. dragOptions: {},
  18. }, {
  19. isSource: true,
  20. isTarget: true,
  21. });
  22. }
  23. if (point.parent_node !== 'root') {
  24. instance.addEndpoint(point.node_id, {
  25. uuid: `${point.node_id}-top`,
  26. anchor: 'Top',
  27. maxConnections: -1,
  28. deleteEndpointsOnEmpty: true,
  29. }, {
  30. isSource: true,
  31. isTarget: true,
  32. });
  33. }
  34. if (point.jump_nodes.length > 0) {
  35. point.jump_nodes.forEach((item, index) => {
  36. instance.connect({
  37. source: point.node_id,
  38. target: item,
  39. paintStyle: {
  40. stroke: "#E72F1F",
  41. strokeWidth: 2.5,
  42. dashstyle: "4 2",
  43. },
  44. maxConnections: -1,
  45. anchor: 'Right',
  46. overlays: [
  47. ["Arrow",
  48. {
  49. width: 9,
  50. length: 8,
  51. location: 1,
  52. events: {
  53. click: function() {
  54. // alert('click')
  55. }
  56. }
  57. }
  58. ],
  59. ["Custom", {
  60. create: function(component) {
  61. return $('<img src=' + shears + '>');
  62. },
  63. location: -50,
  64. events: {
  65. click: function(e) {
  66. that.deleteConfirmFun(instance, e.component)
  67. },
  68. }
  69. }]
  70. ]
  71. });
  72. })
  73. }
  74. }
  75. // init transition
  76. for (const i of that.$store.state.lines) {
  77. const uuid = [`${i[0]}-bottom`, `${i[1]}-top`];
  78. instance.connect({
  79. uuids: uuid,
  80. });
  81. }
  82. })
  83. var sourceEndpoint=this.jsPlumbInstance.getEndpoint(`A1-bottom`);
  84. console.log('sourceEndpoint',sourceEndpoint)
  85. },
  1. addConnect(point) {
  2. var parent=this.findParentNode(point.node_id);
  3. // console.log('parentNode',parentNode)
  4. this.jsPlumbInstance.addEndpoint(point.node_id, {
  5. uuid: `${point.node_id}-bottom`,
  6. anchor: 'Bottom',
  7. maxConnections: -1,
  8. deleteEndpointsOnEmpty: true,
  9. dragOptions: {},
  10. }, {
  11. isSource: true,
  12. isTarget: true,
  13. });
  14. this.jsPlumbInstance.addEndpoint(point.node_id, {
  15. uuid: `${point.node_id}-top`,
  16. anchor: 'Top',
  17. maxConnections: -1,
  18. deleteEndpointsOnEmpty: true,
  19. }, {
  20. isSource: true,
  21. isTarget: true,
  22. });
  23. var sourceEndpoint=this.jsPlumbInstance.getEndpoint(`${parent.node_id}-bottom`);
  24. var targetEndpoint=this.jsPlumbInstance.getEndpoint(`${point.node_id}-top`);
  25. const uuid = [`${parent.node_id}-bottom`, `${point.node_id}-top`];
  26. this.jsPlumbInstance.connect({
  27. source:sourceEndpoint,
  28. target:targetEndpoint
  29. })
  30. this.jsPlumbInstance.repaintEverything({clearEdits:false})
  31. },
  1. deleteEndpoint() {
  2. console.log('123')
  3. // jsPlumb.detach(conn);
  4. // 删除他与子元素的连接
  5. console.log(this.jsPlumbInstance)
  6. // this.jsPlumbInstance.remove(this.nodes[0].node_id);
  7. // this.jsPlumbInstance.empty(this.nodes[0].node_id);
  8.  
  9. var a = this.jsPlumbInstance.getEndpoint(`${this.nodes[0].node_id}-bottom`)
  10. console.log('a', a)
  11. this.jsPlumbInstance.deleteEndpoint(a)
  12. },

 

 恩。。。还有一个问题

就是如果你连线的元素发生了位置的转移,如果你是通过端点去连接的

然后我想说 是确实需要重绘的

如果你元素的位置发生了改变

有什么想说的 欢迎来指教 

 

 

 友情链接:直通硅谷  点职佳  北美留学生论坛

本站QQ群:前端 618073944 | Java 606181507 | Python 626812652 | C/C++ 612253063 | 微信 634508462 | 苹果 692586424 | C#/.net 182808419 | PHP 305140648 | 运维 608723728

W3xue 的所有内容仅供测试,对任何法律问题及风险不承担任何责任。通过使用本站内容随之而来的风险与本站无关。
关于我们  |  意见建议  |  捐助我们  |  报错有奖  |  广告合作、友情链接(目前9元/月)请联系QQ:27243702 沸活量
皖ICP备17017327号-2 皖公网安备34020702000426号