Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cytoscape.js style node based on content

I would like to color my root node a different color than the rest of the nodes on the screen, I have already done some pre-work to identify the value of the root node and have it readily available in a variable. However, in trying to style the graph nothing happens and its been difficult to debug through this.

example:

nodes: [{id = 1}, {id=2}]

var startingNode = 1; //root node

$('#cy').cytoscape({
                style: [
                    {
                        selector: 'node',
                        css: {
                            'content': 'data(id)',
                            'background-color': 'red',
                            'color': 'black',
                            'border-width': '1px',
                            'border-color': 'black'
                        }
                    },
                    {
                        selector: "node[content = 'startingNode']", 
                        css: {
                            'content': 'data(id)',
                            'background-color': 'purple',
                            'color': 'black',
                            'border-width': '1px',
                            'border-color': 'black'

                        }
                    }]

// more info for cytoscape rendering omitted

});

Any input would be helpful!

Thanks, Paul G.

like image 555
Paul Giganti Avatar asked Sep 26 '14 19:09

Paul Giganti


People also ask

What is Cytoscape JS?

Cytoscape.js is an open-source graph theory (a.k.a. network) library written in JS. You can use Cytoscape.js for graph analysis and visualisation. Cytoscape.js allows you to easily display and manipulate rich, interactive graphs.

What is style in Cytoscape?

Style in Cytoscape.js follows CSS conventions as closely as possible. In most cases, a property has the same name and behaviour as its corresponding CSS namesake. However, the properties in CSS are not sufficient to specify the style of some parts of the graph.

Can Cytoscape export to JSON?

From version 3.1.0 on, Cytoscape can also export Cytoscape.js compatible JSON file. Since Cytoscape.js is an independent JavaScript library, and there are some differences between Cytoscape and Cytoscape.js, not all properties are mapped to JSON.

How to get started with Cytoscape?

Getting started 1 Including Cytoscape.js. If you are using a simple HTML environment (without a build system), then source Cytoscape.js in a <script> tag or import it as an ES6 module, e.g.: 2 Initialisation. An instance of Cytoscape.js corresponds to a graph. ... 3 Specifying basic options 4 Next steps. ...


1 Answers

Unless, content is in the node's data, that won't work. If you have the ID of a node (e.g. foo), you can use #foo or [id = 'foo'] as the selector.

like image 128
maxkfranz Avatar answered Sep 28 '22 19:09

maxkfranz