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.
javascript
familyTree.controlsUI.show({
zoom_in: { title: 'zoom in' },
zoom_out: { title: 'zoom out' }
});You can have the below properties:
title(string) - Tooltip text shown on hover.anchor(FamilyTree2.anchor) - Position of the control, such as the 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().
javascript
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:
FamilyTree2.anchor.bottomFamilyTree2.anchor.bottom_leftFamilyTree2.anchor.bottom_rightFamilyTree2.anchor.leftFamilyTree2.anchor.left_bottomFamilyTree2.anchor.left_topFamilyTree2.anchor.rightFamilyTree2.anchor.right_bottomFamilyTree2.anchor.right_topFamilyTree2.anchor.topFamilyTree2.anchor.top_leftFamilyTree2.anchor.top_right
You can group multiple controls on the same anchor side.