Set different shapes for different nodes in cytoscape.js
Asked Answered
S

2

10

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?

Slapbang answered 27/3, 2016 at 23:36 Comment(0)
F
12

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'
    }
  }
]
Finbur answered 30/11, 2016 at 7:2 Comment(0)
R
3

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

node[type = 'foo'] {
  background-color: red;
  shape: star;
  /* ... */
}
Rapallo answered 28/3, 2016 at 15:9 Comment(1)
are custom shapes possible?Oldenburg

© 2022 - 2024 — McMap. All rights reserved.