Tito Nobre
Tito Nobre

Reputation: 1402

Force positions of some nodes with CoSE Bilkent layout

I'm working with compound graphs. I know the positions (e.g.: geographic coordinates) of the parent nodes and I want to layout the children nodes in order to minimize the intersection of the edges. The final position of the children does not matter, provided that they are close to each other.

The CoSE Bilkent algorithm with Cytoscape.js gives me the right kind of layout but I would like to set the positions of the parent nodes and lock them in place.

What I've done:

  1. Started with this example but with less nodes;
  2. Set the position for each group:
    1. Only the parent;
    2. Same coordinates for parent and its children;
  3. Adjusted some options of the layout;
  4. Tried the attribute locked with no luck

The best I got is this.

So far, the relative positions of the groups is correct but if I add a new group g5 I got this.

The desired result would be something like this:

I'm open to use another library if needed.

Upvotes: 4

Views: 2438

Answers (1)

maxkfranz
maxkfranz

Reputation: 12250

(1) A parent's position and dimensions are implied by the positions and dimensions of its children.

(2) You can run a layout on a subset of the graph (e.g. children only): http://js.cytoscape.org/#collection/layout

(3) Avoiding edges from overlapping each other in a layout in a performant way is an active, unsolved research problem. Additionally, some graphs just aren't planar.

Try using (2) to run a layout on the subgraph of each parent's descendants:

var topLvlParents = cy.nodes().orphans(':parent');

topLvlParents.forEach(function( parent ){
  var descendants = parent.descendants();
  var edges = nodes.edgesWith( nodes );

  descendants.union( edges ).layout( someLayoutOptions );
});

You can use cose-bilkent as the subgraph layout and adjust the positions to your desired bounding box on layoutstop (and this would be easier with boundingBox natively supported in cose-bilkent). Or you could use cose -- which isn't as sophisticated as cose-bilkent but allows for direct boundingBox placement today.

If your compound parent-child hierarchy is only one level, then you could try using any of the noncompound layouts on the children with boundingBox as well.

My understanding is that CoSE Bilkent is the most state of the art algorithm for compound node layout. It's from a university lab that specialises in graph theory, layouts, etc.

Upvotes: 4

Related Questions