MXGraph adding edges

白昼怎懂夜的黑 提交于 2019-12-13 18:19:36

问题


In MXGraph, edges can be added using graph.addEdge() but this requires passing 2 vertices as arguments. I want to create an edge which can be randomly placed on the graph, without the need to the vertices, just like in draw.io or graph editor. After googling, mxCell can be used for the same but I am not able to understand the usage. Please Help.


回答1:


Whenever you use mxCells, you need to set TerminalPoints for each of the sides if you are using it as an Edge. After Adding and setting it as an edge you need to insert it into the cells array which has been done by the fireEvent function.

  var cell = new mxCell('your text', new mxGeometry(0, 0, 50, 50), 'curved=1;endArrow=classic;html=1;');
  cell.geometry.setTerminalPoint(new mxPoint(50, 150), true);
  cell.geometry.setTerminalPoint(new mxPoint(150, 50), false);

  cell.geometry.relative = true;
  cell.edge = true;

  cell = graph.addCell(cell);
  graph.fireEvent(new mxEventObject('cellsInserted', 'cells', [cell]));


来源:https://stackoverflow.com/questions/49839882/mxgraph-adding-edges

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!