JgraphX How can you make an edge connect a vertex to another edge (instead of another vertex)?

I want to able to use an edge to connect a vertex and another edge (which is connecting two other vertices). I want to change the code accordingly so that I will be able to do this connection from the user interface (just like you do for two vertices).

To illustrate what I am after: I want to get the green square from the tip of the arrow to turn blue (just like the one at its bottom), suggesting that a connection was established.

Screenshot of JgraphX situation

I have checked the documentation and the code related to the creation of connections and valid terminals, but I could not implement the behaviour I need, which is the ability to set an edge as a valid terminal/a valid target in a connection. Any help would be greatly appreciated.

I am not sure if this is where I should look (mxGraph.java class) when trying to make an edge a valid target/source.

public boolean isValidSource(Object cell)
{
    return (cell == null && allowDanglingEdges)
                    || (cell != null 
                           && (!model.isEdge(cell) || isConnectableEdges()) && isCellConnectable(cell));

}

UPDATE: I was able to connect two edges in code, using the insertEdge method of the graph. However, I still struggle with achieving this behaviour in the user interface.

Answers


I suspect a solution to your question either requires that we break fundamental rules of graph theory (and jgraphx) or that you adjust your goal. It would help if you could explain your rationale for needing this behavior, and if any alternatives would be acceptable to you.

In math, a single edge can only ever connect two vertices together (or connect a vertex to itself). You cannot connect an edge to a vertex using an edge, and jgraphx appears to obey this design.

If you're more concerned with the flow of your graph and not its mathematical representation, you could add a new vertex at the desired location where your edges intersect, then connect the appropriate edges to the appropriate vertexes. I suspect this is what you are looking for, or at least your best alternative.

If you absolutely require the behavior you describe, it may be possible if you redefine your terms and apply some serious abstraction (and a lot of coding). You may need to manually implement a new object in jgraphx which can behave as both a vertex and and edge, and define the relationships between all of these components, etc, etc. I would discourage this, and jgraphx does not seem to offer an alternative.

If you can help it, don't change graph theory to work with your design. Change your design to work with graph theory. Good luck.


You could try a workaround: Lets say you have vertex u, v and t and an edge connecting (u,v).

  • Delete the edge (u,v)
  • add invisible vertex (x)
  • add edge u -> x
  • add edge x -> v
  • add edge t -> x

Take into account, that you'll have to remove the decorator from the edge (u,x) and maybe (t,x).


Need Your Help

Apache Server Won't start (Bitnami Redmine Stack - 2.0-3-1)

authentication tortoisesvn redmine bitnami

I have been trying to get my head around to make things work with Redmine and I have downloaded TortoiseSVN 1.7.7 (Build 22907 - 64 Bit (Subversion 1.7.5)).

EmberJS: global class functions depend on a session variable, using Ember-Simple-Auth. Best Practice?

security ember.js user-profile ember-simple-auth

I had a question regarding best practice when it comes to building a global utility class in EmberJS when the class will exhibit user-specific behavior.