9

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?

Erik Kaplun
  • 37,128
  • 15
  • 99
  • 111
Tejus
  • 101
  • 1
  • 4

2 Answers2

11

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'
    }
  }
]
viv
  • 111
  • 1
  • 3
3

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

node[type = 'foo'] {
  background-color: red;
  shape: star;
  /* ... */
}
Erik Kaplun
  • 37,128
  • 15
  • 99
  • 111
maxkfranz
  • 11,896
  • 1
  • 27
  • 36