Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set different shapes for different nodes in cytoscape.js

I have the following fields as my nodes data:

nodes {
    data: {id: "something",     type: "human"}
    data: {id: "somethingElse", type: "mouse"}
}

Is there any way to set the shapes of the nodes based on the type in data?

like image 842
Tejus Avatar asked Mar 27 '16 23:03

Tejus


Video Answer


2 Answers

You can structure the cytoscape style element and selectors, like in the code snippet below:

style: [
  {
    selector: 'node[type="human"]',
    style: {
      'shape': 'triangle',
      'background-color': 'red'
    }
  },
  {
    selector: 'node[type="mouse"]',
    style: {
      'shape': 'square',
      'background-color': 'blue'
    }
  }
]
like image 103
viv Avatar answered Sep 22 '22 14:09

viv


Use a stylesheet with appropriate selectors, e.g.:

node[type = 'foo'] {
  background-color: red;
  shape: star;
  /* ... */
}
like image 41
maxkfranz Avatar answered Sep 23 '22 14:09

maxkfranz