Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding new data to collapsed workspace #136

Open
Alexithemia opened this issue Apr 19, 2022 · 7 comments
Open

Adding new data to collapsed workspace #136

Alexithemia opened this issue Apr 19, 2022 · 7 comments
Assignees

Comments

@Alexithemia
Copy link

Alexithemia commented Apr 19, 2022

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?

@canbax
Copy link
Member

canbax commented Apr 19, 2022

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

@Alexithemia
Copy link
Author

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

@jacksonneal
Copy link

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

@Alexithemia
Copy link
Author

Alexithemia commented Apr 26, 2022

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

@canbax
Copy link
Member

canbax commented Apr 27, 2022

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

@Alexithemia
Copy link
Author

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

@canbax
Copy link
Member

canbax commented Apr 28, 2022

Ok. Still you can use getCollapsedChildrenRecursively and/or getAllCollapsedChildrenRecursively methods to achieve this easily.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants