Rasmus
Rasmus

Reputation: 178

Is there a way to show connections from compound nodes to the children in Cytoscape.js

I am exploring the potential of Cytoscape.js, and would like to know if it is possible to visualize connections from compound nodes (parents) to children within this node.

In the example below I would like to show the connection between the parent node 'b' and the children 'a' and 'c', but so far I am unsuccessful.

Minimal working example is given below below, and editable here: http://jsbin.com/lelinaduko/3/edit

    elements: {
        nodes: [
          { data: { id: 'a', parent: 'b' } },
          { data: { id: 'c', parent: 'b' } },
          { data: { id: 'd' } },
          { data: { id: 'e' } },
          { data: { id: 'f', parent: 'e' } },
          { data: { id: 'b' } }
        ],
        edges: [
          { data: { id: 'bd', source: 'b', target: 'd' } },
          { data: { id: 'eb', source: 'e', target: 'b' } },
          { data: { id: 'ca', source: 'c', target: 'a' } },
          { data: { id: 'ab', source: 'a', target: 'b' } },
          { data: { id: 'bc', source: 'b', target: 'c' } }

        ]
      },

<!DOCTYPE html>
<!--
Created using JS Bin
http://jsbin.com

Copyright (c) 2015 by anonymous (http://jsbin.com/lelinaduko/3/edit)

Released under the MIT license: http://jsbin.mit-license.org
-->
<meta name="robots" content="noindex">
<html>
<head>
<link href="style.css" rel="stylesheet" />
<meta charset=utf-8 />
<title>Cytoscape.js initialisation</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script src="http://cytoscape.github.io/cytoscape.js/api/cytoscape.js-latest/cytoscape.min.js"></script>
<script src="code.js"></script>
<style id="jsbin-css">
body { 
  font: 14px helvetica neue, helvetica, arial, sans-serif;
}

#cy {
  height: 100%;
  width: 100%;
  position: absolute;
  left: 0;
  top: 0;
}

#info {
  color: #c88;
  font-size: 1em;
  position: absolute;
  z-index: -1;
  left: 1em;
  top: 1em;
}
</style>
</head>
<body>
<div id="cy"></div>
<script id="jsbin-javascript">
$(function(){ // on dom ready

var cy = cytoscape({
  container: $('#cy')[0],
  
  style: cytoscape.stylesheet()
    .selector('node')
      .css({
        'content': 'data(id)',
        'text-valign': 'center',
        'text-halign': 'center',
        'color': 'black'
      })
      .selector('$node > node')
      .css({
        'content': 'data(id)',
        'text-valign': 'top',
        'text-halign': 'center',
        'color': 'blue'
      })
    .selector('edge')
      .css({
'target-arrow-shape': 'triangle',
        'target-arrow-color': 'black',
        'source-arrow-color': 'black',
        'line-color': 'red',
        'line-style': 'dashed',
        'text-valign': 'top',
        'text-halign': 'center',
        'content': 'data(id)'
      })
    .selector(':selected')
      .css({
        'background-color': '',
        'line-color': 'black',
        'target-arrow-color': 'black',
        'source-arrow-color': 'black'
      }),
  
  elements: {
    nodes: [
      { data: { id: 'a', parent: 'b' } },
      { data: { id: 'c', parent: 'b' } },
      { data: { id: 'd' } },
      { data: { id: 'e' } },
      { data: { id: 'f', parent: 'e' } },
      { data: { id: 'b' } }
    ],
    edges: [
      { data: { id: 'bd', source: 'b', target: 'd' } },
      { data: { id: 'eb', source: 'e', target: 'b' } },
      { data: { id: 'ca', source: 'c', target: 'a' } },
      { data: { id: 'ab', source: 'a', target: 'b' } },
      { data: { id: 'bc', source: 'b', target: 'c' } }
      
    ]
  },
    
  layout: {
    name: 'breadthfirst',
    directed: false,
    avoidOverlap: true,
    padding: 5
  }
});

}); // on dom ready
</script>
</body>
</html>

Upvotes: 2

Views: 387

Answers (1)

maxkfranz
maxkfranz

Reputation: 12242

It seems you found a bug:

https://github.com/cytoscape/cytoscape.js/issues/866

Use haystack edges instead if you want to work around the issue until a new release -- as those edges are unaffected.

Upvotes: 1

Related Questions