I am currently working on a project that requires allowing users to rearrange a graph and automatically readjust the edges when vertices are moved. However, I have been facing difficulties in implementing this feature smoothly.
Here is what I have accomplished so far:
Graph with oddly adjusted edges:
My goal is to achieve this:
Graph with neatly adjusted edges:
The XML code for the second diagram is as follows:
<mxGraphModel dx="774" dy="824" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="850" pageHeight="1100">
<root>
...
Unfortunately, translating this into TS code has been challenging for me :-(
Since I am using Angular with TypeScript, creating a Plunker example to assist may be complex. However, I have a component that initializes the graph like this:
declare var require: any;
const mx = require('mxgraph')({
mxImageBasePath: 'assets/mxgraph/images',
mxBasePath: 'assets/mxgraph',
});
const container = document.getElementById('graphContainer');
this.graph = new mx.mxGraph(container);
...
As I continue to work on it, the result resembles the first picture above (Graph with oddly adjusted edges).
If you can help me achieve the desired output shown in the second image (Graph with neatly adjusted edges), please let me know.
Edit 1: Despite attempting to apply the same style present in the XML file to my code, the edges do not rearrange as expected. Here is an example of what I have tried:
graph.insertEdge(
parent,
`${getId()}`,
'',
source,
target,
'edgeStyle=orthogonalEdgeStyle;...'
);
This resulted in: https://i.sstatic.net/BoXFd.png
Edit 2:
While my code did not yield the desired outcome, a similar implementation on this CodePen worked properly: CodePen Example
At this point, I suspect that the layout class being invoked may be altering the edge styles and causing the issue. Is there a layout class available that preserves the edge styles?