最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Set different shapes for different nodes in cytoscape.js - Stack Overflow

programmeradmin6浏览0评论

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?

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?

Share Improve this question edited May 31, 2016 at 18:45 Erik Kaplun 38.2k15 gold badges102 silver badges113 bronze badges asked Mar 27, 2016 at 23:36 TejusTejus 1111 silver badge5 bronze badges 0
Add a ment  | 

2 Answers 2

Reset to default 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'
    }
  }
]

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

node[type = 'foo'] {
  background-color: red;
  shape: star;
  /* ... */
}
发布评论

评论列表(0)

  1. 暂无评论