Keeping expansion state while switching templates


I am trying to figure out how to preserve tree expansion state while switching templates via a zoom action. The the code I have is:

cmp.orgChartCanvas = new go.Diagram(“orgchart-canvas-container”);

cmp.orgChartCanvas.addDiagramListener( ‘ViewportBoundsChanged’, function () {
cmp.orgChartCanvas.startTransaction(“viewport bounds”);
if (cmp.orgChartCanvas.scale < 0.9) {
cmp.orgChartCanvas.nodeTemplate = minimalTemplateNode;
cmp.orgChartCanvas.linkTemplate = minimalTemplateLink;
} else {
cmp.orgChartCanvas.nodeTemplate = standardTemplateNode;
cmp.orgChartCanvas.linkTemplate = standardTemplateLink;
cmp.orgChartCanvas.commitTransaction(“viewport bounds”);
} );

standardTemplateNode and minimalTemplate node do not have the isTreeExpanded explicitly set to a value, so the standardTemplateNode when used, shows the tree in its expanded state. When I collapse a few nodes and zoom in, pushing the diagram scale below 0.9, the minimalTemplateNode is used, but the tree is ‘re-expanded’ again. Is there a way I can preserve the state of the tree while switching templates?

Thanks in advance.

I have not had the time to test this, but I think you should have a TwoWay Binding of Node.isTreeExpanded in your templates to a data property.