Circular Hierarchy in Cytoscape js?

Is it possible to obtain a circular hierarchy in Cytoscape js?

The breadthfirst layout gives a generic hierarchy layout, if somehow nodes could be arranged in a circrular hierarchy (with roots being in the center...), please do let me know the way out.

Thanks

Upvotes: 1

Views: 781

Answers (1)

Joseph
Joseph

Reputation: 11

Have you tried the concentric options for the breadth-first layout? By default breadth-first gives a pyramid-like layout but you can specify a circular layout.

For example:

var cy = cytoscape({
  container: document.getElementById('cy'),
  elements: {
      nodes: [
        { data: { id: 'a' } },
        { data: { id: 'b' } },
        { data: { id: 'c' } },
        { data: { id: 'd' } },
        { data: { id: 'e' } }
      ], 

      edges: [
        { data: { id: 'ae', weight: 1, source: 'a', target: 'e' } },
        { data: { id: 'ab', weight: 3, source: 'a', target: 'b' } },
        { data: { id: 'be', weight: 4, source: 'b', target: 'e' } },
        { data: { id: 'bc', weight: 5, source: 'b', target: 'c' } },
        { data: { id: 'ce', weight: 6, source: 'c', target: 'e' } },
        { data: { id: 'cd', weight: 2, source: 'c', target: 'd' } },
        { data: { id: 'de', weight: 7, source: 'd', target: 'e' } }
      ]
  },
  layout: {
    name: 'breadthfirst',
    circle: true,
    root: 'a',
  },
});

See https://jsfiddle.net/josephst18/kznos1x9/2/ for the rest of my code.

Upvotes: 1

Related Questions