Refresh Graph

I am making some changes to node template dynamically . how to refresh the graph .

The literal answer to your question is to call Diagram.rebuildParts, but that is a very blunt hammer.

What are you actually trying to accomplish? Perhaps there is another way to achieve what you want.

For example, it is possible to data bind GraphObject properties not just to Part.data properties, but to shared Model.modelData properties. This functionality is supported in 1.7, but actually exists unsupported in 1.6, so you can try it even without going to the alpha version of 1.7. We should be going to 1.7 beta soon.

And if you want to make structural changes to the visual tree (which you cannot do using data binding), you can use multiple templates. http://gojs.net/latest/intro/templateMaps.html

I have tried with Diagram.rebuildParts , still it is not refreshing the graph.

My requirement is :: I have buttons inside the nodes ,I want to show/hide button based on some condition (for that i am adding showFlag which will return true or false based on my condition)
> var nodeTemplate =
> goJ(go.Node, “Vertical”,
> {
> zOrder:100
> },
> goJ(go.Panel, “Auto”,
> { name: “BODY”},
> goJ(go.Shape, “RoundedRectangle”,
> { fill: “transparent” , stroke: “#67D5E0”, width:200, height:54},
> goJ(“Button”,new go.Binding(“location”, “loc”),{margin:1,alignment: new go.Spot(0, 1),cursor: “pointer”},
> { visible:showFlag},
> goJ(go.Picture,{source: “test.png”}),{
>
> }
> )
> )
> );
scope.roGraph = goJ(go.Diagram, element[0],{
linkTemplate: linkTemplate,
nodeTemplate: nodeTemplate,
“animationManager.isEnabled”:false
});

OK, so is your purpose for example wanting to show buttons on all of the nodes, which had all been hidden originally?

Is the basic change that you have performed just setting showFlag to true, and now you are trying to figure out how to make all of the buttons appear? If so, you need to realize that setting the showFlag variable does not modify the node template at all.

When you created the node template the showFlag expression evaluated to false, so the value of GraphObject.visible was set to false. Setting the showFlag variable has no effect on any existing GraphObjects, including those in your node template. So calling Diagram.rebuildParts should have no effect.

Instead, I suggest that you try moving that flag from being a JavaScript variable to being a property on the Model.modelData object. And add this binding to your Button:

         new go.Binding("visible", "showFlag").ofModel()

Then when you want to toggle the flag, call:

    var m = myDiagram.model;
    m.startTransaction();
    m.setDataProperty(m.modelData, "showFlag", !m.modelData.showFlag);
    m.commitTransaction("Toggled Button visibility");