Controls
Controls are small buttons displayed on the tree that let users quickly perform actions.
Controls are managed through the controlsUI API, which provides two main methods:
show(config)— Displays controls on the tree.onControlClick(callback)— Handles control click events.
Displaying Controls
Use the show() method to define which controls should appear and how they should behave.
familyTree.controlsUI.show({
zoom_in: { title: 'zoom in' },
zoom_out: { title: 'zoom out' }
});
Simple Code demo:
You can have the below properties:
title(string) – Tooltip text shown on hover.anchor(FamilyTree2.anchor) – Position of the control (e.g., left or right side of the tree).isOn(boolean) – Optional. Indicates toggle state (useful for switch-like controls).
Built-in Controls
Some controls may be predefined (such as zoom controls), but you can also create fully custom controls.
zoom_inzoom_outfit
Creating a Custom Control
To create a custom control:
- Define it inside
controlsUI.show() - Handle its click event in
onControlClick()
familyTree.controlsUI.show({
my_control: {
title: 'Toggle something',
anchor: FamilyTree2.anchor.left,
isOn: true
}
});
familyTree.controlsUI.onControlClick(function(args){
if (args.key === 'my_control'){
console.log('Custom control clicked');
}
});
Positioning Controls
Controls can be anchored to different sides of the tree interface:
OrgChart.anchor.bottomOrgChart.anchor.bottom_leftOrgChart.anchor.bottom_rightOrgChart.anchor.leftOrgChart.anchor.left_bottomOrgChart.anchor.left_topOrgChart.anchor.rightOrgChart.anchor.right_bottomOrgChart.anchor.right_topOrgChart.anchor.topOrgChart.anchor.top_leftOrgChart.anchor.top_right
You can group multiple controls on the same anchor side.
Code demo: