Open Alexithemia opened 2 years ago
You should write a recursive function and find the collapsed node. Collapsed nodes are removed from cytoscape.js but they stay in the memory. You should investigate collapsedChildren
properties
So I am able to just insert a cytoscape node object into the collapsedChildren
collection?
Have you considered making an object map for nodes that are removed when clustered to get quick simple access to important datapoints? I know there are ways to get these objects currently, but it's not very performant to do repeatedly, and it seems like it would be simple and quick to update the references to these objects when they get clustered. Something like this
collapsedDataMap = { collapsedNodeId1: { existingAncestor: nearestExistingAncestorNodeObject, parent: directParentNodeObject, node: nodeObjectInsideCollapsedChildren }, ... }
I could also create and update a map like this on my application side if the afterCollapse
event provides what data becomes collapsed
@Alexithemia
Did you find an approach that allows you too add collapsedChildren nodes? I am in a similar situation, needing to add collapsedChildren and edges to the collapsedChildren.
@jacksonneal I'm still working on it but I think I found a method that should work.
You can create a map to locate the nodes even after they are removed due to collapsing. The node objects that are there in the graph before collapsing are the same objects inside of the collapsedChildren collection of collapsed nodes. So make a map to reference all the node objects before they become collapsed and then you can add the nodes to their respective parent's collapsedChildren
collection.
Currently you will need to add the node to the graph, use node.move({parent: parent.id()});
then const removedNode = node.remove()
and finally parent.data('collapsedChildren').merge(removedNode)
I'm currently trying to figure out a way to make a clone of a node to use as a base to copy, edit, and and merge it into the collection without having to add it to the cytoscape graph first.
@Alexithemia I think if you are going to add NEW elements to collapsed children, you should add them to Cytoscape.js. Otherwise, there is no similar thing to a node "constructor" or "creator" function.
Secondly, I see that API has getCollapsedChildrenRecursively
and getAllCollapsedChildrenRecursively
functions. So the recursive function is already in the API, you don't need to write another.
@canbax I'm not really creating a function to get all the children, I am simply adding the node objects to a node map I have created for other uses as they are added to the graph, before they are collapsed. This object is the same after it is removed and collapsed under other nodes.
That way I can easily access them by going nodeMap[id].graphNode
to get a singular element I need to edit or interact with, without having to run a recursive function to get a list, then find it in the list.
Ok. Still you can use getCollapsedChildrenRecursively
and/or getAllCollapsedChildrenRecursively
methods to achieve this easily.
I am finding it difficult to add new data to an already collapsed workspace, specifically when I am adding nodes that should be collapsed under nodes that have already been collapsed.
Expanding the whole graph and then collapsing again after loading is probably the easiest thing to do, but seems a little overkill and requires a lot of processing and load time.
I also attempted programmatically finding which nodes to expand, then collapse those nodes again afterwards, but that runs even slower.
Is there a simple way I am missing? Could we possibly just generate a cytoscape node object and attach it under the correct parent's 'collapsedChildren' datapoint?