将Cytoscape.js中的节点大小增加特定值 [英] Incrementing the size of nodes in Cytoscape.js by a specific value

查看:679
本文介绍了将Cytoscape.js中的节点大小增加特定值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下json内容指定每个节点的大小:

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).

鉴于

'data(size)' + value

不是合法的操作,有人可以建议一种合适的方法来实现它吗?

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

谢谢

推荐答案

您正在尝试使用字符串添加int这似乎不起作用。而是尝试获取属性值,然后将输入值添加到其中。

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.

您可以通过向 nodes()。data('element','value')

您的代码应如下所示:

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

这篇关于将Cytoscape.js中的节点大小增加特定值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆