I’m currently evaluating GoJS for a client and have been following the samples to create a doubleTreeLayout, which is working exactly as we need it to.
I’ve also been able to create another node to include additional text, but I can’t for the life of me work out how to link that to the root of the doubleTreeLayout.
Here’s the relevant part of my code (which is based heavily on the sample)
doubleTreeLayout: function (diagram) {
// Within this function override the definition of '$' from jQuery:
var $ = go.GraphObject.make; // for conciseness in defining templates
diagram.startTransaction("Double Tree Layout");
// split the nodes and links into two Sets, depending on direction
var leftParts = new go.Set(go.Part);
var rightParts = new go.Set(go.Part);
bowtie.separatePartsByLayout(diagram, leftParts, rightParts);
// but the ROOT node will be in both collections
// create and perform two TreeLayouts, one in each direction,
// without moving the ROOT node, on the different subsets of nodes and links
var layout1 =
$(go.TreeLayout,
{
angle: 180,
arrangement: go.TreeLayout.ArrangementFixedRoots,
setsPortSpot: false
});
var layout2 =
$(go.TreeLayout,
{
angle: 0,
arrangement: go.TreeLayout.ArrangementFixedRoots,
setsPortSpot: false
});
layout1.doLayout(leftParts);
layout2.doLayout(rightParts);
var leftPoint = parseInt(((diagram.findNodeForKey("Root").actualBounds.width - 145) /2));
var scenarioDisplay = $(go.Node, "Auto",
{
position: new go.Point(leftPoint, -100)
},
$(go.Shape, "RoundedRectangle", {
fill: "yellow"
}),
$(go.TextBlock, scenario, {
margin: 5,
width: 150,
wrap: go.TextBlock.WrapFit, textAlign: "center"
})
);
diagram.add(scenarioDisplay);
diagram.commitTransaction("Double Tree Layout");
},
It looks like I should be able to link these two things together, but I have no idea how to add an ID (key?) to the scenarioDisplay so that I can then join the two components together - all the link examples seem to assume that you’re using a template and wanting to link two ‘identical’ things together.
Any assistance much appreciated.