Diagram reverts to default values when a part is added

when i add new part to diagram use “diagram.add(new Part)” , diagram reset , ex: when i edit nodes location , after add part, all nodes back to (0,0) location .

Could you please describe what you are doing in more detail so that we can understand the situation?

initDiagrm when page loaded , then add part use addPartToDiagram function,
initDiagrm create tree at TopCenter as you see ,
when i change nodes locations using (drop and drag) and try to add part , all nodes back to TopCenter location , like first time .

If you look at nearly all of our samples, Nodes and Links are created by adding data objects to a Model and then assigning the model to the Diagram.model property. I suggest that you do the same. Don’t call Diagram.add unless you really know why.

Have you read Get Started with GoJS and the first few pages of GoJS Introduction -- Northwoods Software ?

how can i add TextBlock after create digram

Add a node data Object to the model by calling Model.addNodeData. You can find examples of this in the samples.

How can I change the width of all nodes using code, after create it

The width of each node? That is normally set in the node template. Although you could set it programmatically on each node.

all nodes , so i have to change node template ever time i want to change nodes width, or make iterator to change for each one??

Normally one never modifies a template.

Yes, you could do:

myDiagram.commit(d => d.nodes.each(n => n.width = 123))

Or if there is a Binding on the width in the template, you could modify the model data instead. For example, just to modify one node:

myDiagram.model.commit(m => m.set(m.nodeDataArray[12], "width", 123))

when i try it , nodes back to (0,0) location after each edit.


Maybe you want to set Layout.isOngoing to false.

thank you guys, all worked well

problem with link , how to save last status ??
ezgif.com-gif-maker (1)

What property is changing there?

all nodes width

I’m unable to reproduce that behavior. Can you provide us a simple reproducible example?

If you increase the layerSpacing and nodeSpacing of your TreeLayout, does that help? What about setting Link.adjusting to go.Link.End in your link template?