admin管理员组文章数量:1357646
I have a requirement to hide or unhide some nodes and edges depending on some data. I can achieve it by traversing through visjs's data but that will trigger stabilization everytime one hides or unhides (this overwrite existing data).
I found this example which adds, updates and removes a node by directly changing nodes
value by using add
, update
& remove
functions. This dynamically does these operations without stabilizing, but when I try the same thing in AngularJS I encounter the following error
org_nodes.update is not a function
Snippet taken from source of this example
function addNode() {
var newId = (Math.random() * 1e7).toString(32);
nodes.add({id:newId, label:"I'm new!"});
nodeIds.push(newId);
}
function changeNode1() {
var newColor = '#' + Math.floor((Math.random() * 255 * 255 * 255)).toString(16);
nodes.update([{id:1, color:{background:newColor}}]);
}
function removeRandomNode() {
var randomNodeId = nodeIds[Math.floor(Math.random() * nodeIds.length)];
nodes.remove({id:randomNodeId});
var index = nodeIds.indexOf(randomNodeId);
nodeIds.splice(index,1);
}
Check out my plunker which demonstrates this. What is it that I am missing here? Note - I am using angular-visjs
I have a requirement to hide or unhide some nodes and edges depending on some data. I can achieve it by traversing through visjs's data but that will trigger stabilization everytime one hides or unhides (this overwrite existing data).
I found this example which adds, updates and removes a node by directly changing nodes
value by using add
, update
& remove
functions. This dynamically does these operations without stabilizing, but when I try the same thing in AngularJS I encounter the following error
org_nodes.update is not a function
Snippet taken from source of this example
function addNode() {
var newId = (Math.random() * 1e7).toString(32);
nodes.add({id:newId, label:"I'm new!"});
nodeIds.push(newId);
}
function changeNode1() {
var newColor = '#' + Math.floor((Math.random() * 255 * 255 * 255)).toString(16);
nodes.update([{id:1, color:{background:newColor}}]);
}
function removeRandomNode() {
var randomNodeId = nodeIds[Math.floor(Math.random() * nodeIds.length)];
nodes.remove({id:randomNodeId});
var index = nodeIds.indexOf(randomNodeId);
nodeIds.splice(index,1);
}
Check out my plunker which demonstrates this. What is it that I am missing here? Note - I am using angular-visjs
Share Improve this question edited Dec 15, 2015 at 19:52 rene 42.5k78 gold badges121 silver badges165 bronze badges asked Jul 2, 2015 at 11:16 user801116user8011162 Answers
Reset to default 3 +100You appear to be slightly off when calling update
. Referring to that example, the update
function requires an argument passed that is a new vis.DataSet
. You are instead supplying a simple array. We can approach this a couple of ways, but let's make the change when declaring $scope.data
as such
$scope.data = {
nodes: new vis.DataSet(org_nodes),
edges: edges
};
Now that we have done this, within $scope.agentClicked
lets modify our call to reference our vis.DataSet
object
$scope.agentClicked = function() {
$scope.data.nodes.update([ ... ]);
}
Plunker Link - updated demo
Seems not to work anymore in 2022. I worked around this by using updateClusterNode
:
for (const node of this.data.nodes) {
thiswork.updateClusteredNode(node.id, node);
}
Maybe there is a better way to force an update of nodes data. Let me know ;-) .
本文标签: javascriptHow to update a node or edge property of visjs using angularjsStack Overflow
版权声明:本文标题:javascript - How to update a node or edge property of visjs using angularjs? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743995098a2572844.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论