-
Notifications
You must be signed in to change notification settings - Fork 857
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
Re-use div/paper to show another graph #1442
Comments
Here're are 3 options.
Adding an official API for this is doable. I don't think the performance is a real issue here, since we do not expect anyone to swap papers multiple times per second. From the visual perspective you won't see a difference in any of the approaches above. It makes the garbage collector more busy though (case no. 1). However, I do see a value in this proposal. You can keep the same reference to the paper across your application. No need to update it when the paper changes (case no 1.). The owner of a cell is questionable (in case no 2.). When an element is added to a graph, the reference to the graph is added to the cell i.e. property Note that adding the graph reference can be skipped by passing graph1.addCells([cell1, cell2], { dry: true });
// assert: graph.getCells()[0].graph === undefined It's open to discussion which option is better (if any or both). paper.changeModel(graph2);
// case no.3
paper.model.fromGraph(graph2);
// makes sure it overrides the cell owner and copies all the graph attributes (not only `cells`) My question is what exactly do you do with the graphs, which are not connected to the paper. Just trying to better understand the use-case. graph1.fromJSON(json1);
graph2.fromJSON(json2);
// what actions are performed here with graph1 and graph2 before:
paperGraph.changeModel(graph1); If none actions are performed, this would be an equivalent code: paperGraph.model.fromJSON(json1); |
Wow, thanks for your extensive answer! I went with case no. 1 for the time being and it works, but still feels like quite a lot of overhead (especially the DOM manipulation). My use case is as follows: I have different graphs that are not related to each other, having different element objects etc. but all from the same cellNamespace. I only want to show one graph at a time at the same place in the UI, and the papers for all graphs would have the same options (e.g. for I also have been considering the |
This issue is stale because it has been open 60 days with no activity. Please remove stale label or comment or this will be closed in 14 days. |
For my application, I want to have a div that can be associated to and show different graphs one after another. Simply re-using the same
div
when constructing a newPaper
object produces unexpected effects e.g. while dragging elements. Is there any method to properly "shutdown" a paper object before creating a new one on the very same div? I guess easiest might then even be to callpaper.remove()
and create a new div every time I want to switch to a different graph?I think somehow changing the paper's associated graph (
model
) could be more performant, as it wouldn't require that much DOM manipulation. Is there a way to changepaper.model
after constructing the paper?The text was updated successfully, but these errors were encountered: