You can make a decision tree by adding a ShapeConnector
to the root object of the document and set the ShapeConnectorType method to DecisionTree.
{
var myDocument=new VS.Document();
var rootShape=myDocument.GetTheShape();
var myConnector=rootShape.AddShapeConnector(VS.ShapeConnectorTypes.DecisionTree);
myConnector.AddShape();
myConnector.AddShape();
var vsJSON = myDocument.toJSON(); //turn the VisualScript object constructed using the API into a JSON string
vsCompleteCallback(vsJSON); //pass the JSON string into the callback to trigger the creation of a document.
}
More than two children added to the decision tree will create a multiple-way split:
{
var myDocument=new VS.Document();
var rootShape=myDocument.GetTheShape();
var myConnector=rootShape.AddShapeConnector(VS.ShapeConnectorTypes.DecisionTree);
myConnector.AddShape();
myConnector.AddShape();
myConnector.AddShape();
var vsJSON = myDocument.toJSON(); //turn the VisualScript object constructed using the API into a JSON string
vsCompleteCallback(vsJSON); //pass the JSON string into the callback to trigger the creation of a document.
}
By default, decision trees will grow from left to right. This is the default "Direction"="Right" setting. You can change
this to any of the three other directions "Up","Down","Left".
{
var myDocument=new VS.Document();
var rootShape=myDocument.GetTheShape();
var myConnector=rootShape.AddShapeConnector(VS.ShapeConnectorTypes.DecisionTree);
myConnector.SetDirection(VS.Directions.Down);
myConnector.AddShape();
myConnector.AddShape();
myConnector.AddShape();
var vsJSON = myDocument.toJSON(); //turn the VisualScript object constructed using the API into a JSON string
vsCompleteCallback(vsJSON); //pass the JSON string into the callback to trigger the creation of a document.
}
Adding ShapeConnectors to the child shapes recursively creates a deeper tree:
{
var myDocument=new VS.Document();
var rootShape=myDocument.GetTheShape();
var myConnector=rootShape.AddShapeConnector(VS.ShapeConnectorTypes.DecisionTree);
myConnector.SetDirection(VS.Directions.Down);
var myConnectorShape1=myConnector.AddShape();
var myConnectorShape2=myConnector.AddShape();
var myConnectorShape3=myConnector.AddShape();
var myChildConnector1=myConnectorShape1.AddShapeConnector();
myChildConnector1.AddShape();
myChildConnector1.AddShape();
var myChildConnector2=myConnectorShape2.AddShapeConnector();
myChildConnector2.AddShape();
myChildConnector2.AddShape();
var myChildConnector3=myConnectorShape3.AddShapeConnector();
myChildConnector3.AddShape();
myChildConnector3.AddShape();
var vsJSON = myDocument.toJSON(); //turn the VisualScript object constructed using the API into a JSON string
vsCompleteCallback(vsJSON); //pass the JSON string into the callback to trigger the creation of a document.
}
Like other trees, you can use "Collapse" as a property of a ShapeConnector to collapse a branch.
By default, the first two shapes in a Decision Tree ShapeConnector have the labels "Yes" and "No" on the lines that connect them to their parent. Additonal shapes have the label "Label".
You can control the text that appears on the line going into a shape by using the LineLabel property of the Shape.
{
var myDocument=new VS.Document();
var rootShape=myDocument.GetTheShape();
var myConnector=rootShape.AddShapeConnector(VS.ShapeConnectorTypes.DecisionTree);
var myChildShape1=myConnector.AddShape();
myChildShape1.SetLineLabel("<25");
var myChildShape2=myConnector.AddShape();
myChildShape1.SetLineLabel("25-75");
var myChildShape3=myConnector.AddShape();
myChildShape1.SetLineLabel(">75");
var vsJSON = myDocument.toJSON(); //turn the VisualScript object constructed using the API into a JSON string
vsCompleteCallback(vsJSON); //pass the JSON string into the callback to trigger the creation of a document.
}
Like regular trees, you should only use one ShapeConnector per shape in a Decision Tree.