TnT is a javascript library built on top of TnT Tree and TnT Board to visualise trees and track-based annotations. There are several components that need to be set up in this visualisation: the tree, the board where the annotation is displayed and a track function that creates tracks for each leaf in the tree. All the methods available in TnT Tree and TnT Board are available plus some specific to TnT to synchronise the tree with the board.
In the snippet above, a tree, a board and a function to create tracks based on tree leaves are defined, configured and attached to a new TnT visualisation. This visualisation is then called using a div element as its container.
# .tnt ()
Creates a new TnT Visualisation. It can be configured via several methods described below.
# tnt.tree (<tnt.tree>)
Sets the tree (ie the tnt.tree) to the TnT visualisation. If called without arguments, retrieves the current tree.
# tnt.board (<tnt.board>)
Sets the annotation board (ie the tnt.board) to the TnT visualisation. If called without arguments, retrieves the current board.
# tnt.track (<callback>)
Sets a callback to create new tracks based on tree leaves. The callback receives a tnt.tree.node and must return a tnt.track. This callback is used by tnt to create the tracks in the board. It is called when the visualisation is started and every time it is updated (using the tnt.update method). The tracks are re-created dynamically if a new callback is set after the visualisation has started. If called without arguments returns the current callback.
# tnt.update ()
Dynamically updates the tree and the board of the visualisation. If the leaves are re-ordered, collapsed, etc, their associated tracks are updated accordingly
# tnt.top (<tnt.board.track>)
Sets the top track to be displayed in the board. This track will not be part of the tracks being linked to the tree leaves. Typically this can be an axis, but can be configured as required.
# tnt.bottom (<tnt.board.track>)
Sets the bottom track to be displayed in the board. This track will not be part of the tracks being linked to the tree leaves. Typically this can be an axis, but can be configured as required.
# tnt.key (<string | callback>)
Specifies the key to be used when linking tree nodes and tracks. By default, the nodes and the tracks are linked by internal IDs transparent to the user. If some kind of object constancy (node constancy) is required, it is possible to define a different way to link leaves and tracks. This new key can be defined either using a field name in the data or a callback that would be called on each leaf when creating or updating tracks. This callback is called with the leaf node (ie the tnt.tree.node) as its argument.