Incrementing the size of nodes in Cytoscape.js by a specific value

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-12 03:43:57

问题


I am using following json content for specifying the size of each node:

"data": {
 "id": "Name",
 "name": "NameID",
 "faveColor": "#86B342",
 "size": 120
}

Once the graph is generated, I wish to increment the size of all nodes by a particular value (which comes from user input).

Given the fact that

'data(size)' + value

isn't a legit operation, can anyone suggest an apt way to achieve it?

Thanks


回答1:


You are trying to add a int with string which won't seem to work. Instead try to get the property value and then add the input value to it.

You can edit the data value by passing a second argument to nodes().data('element', 'value')

Your code would look something like this:

cy.nodes().forEach(function(node){
  node.data('size', parseInt(node.data('size')) + 10); 
  console.log(node.data('size'))
});


来源:https://stackoverflow.com/questions/41995471/incrementing-the-size-of-nodes-in-cytoscape-js-by-a-specific-value

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!