The Tree Explorer API

Contents

  1. Contents
  2. Overview
  3. The TNode interface
  4. The TExpl interface

Overview

The tree explorer API encompasses the TExpl and TNode interfaces. The library provides TExpl implementations, which are instantiated by the library user to display a tree explorer widget on the page. The TNode interface is implemented by node objects provided by the library user, which describe the data the tree displays.

The tree explorer displays navigable visualizations of trees, which are directed acyclic graphs with a single root. A tree is defined by a root node, provided by the library user, which may have child nodes, which may in turn have children, etc. The root node provided by the caller must be a JavaScript object implementing the TNode interface. Nodes have short textual labels and may also have attributes associated with them that affect the visualization in various ways.

Arbitrarily large, even infinite, trees may be navigated, but only part of the tree is visible at any given instant. The widget creates UI elements called panels for each node in the visible part of the tree. The user of the widget navigates by hovering over, clicking, or otherwise activating the panels. As the user navigates the widget, the TExpl implementation will create further panels as necessary, calling the TNode interface methods to learn about the shape of the graph and the relevant attributes of the nodes.

As the user navigates the tree or activates panels, the widget generates events which may be handled by providing callback functions. Event handler callbacks may be provided on node objects to handle things like mouse clicks, or on the tree explorer object to handle events generated by a user's navigation of the tree.

Trees may be visualized in any number of ways, and various visualizations are available as plugins. Visualizations may expose any number of options (colors, sizes, speeds, etc) for the library user to adjust.

The TNode interface

Each TNode object provided by the caller must implement getLabel() and must either implement getChildren() or set isLeaf to true.

TNode.getLabel()
Must return a string which will label the panel representing this node.
TNode.isLeaf
Boolean, must be true if this node object represents a leaf node. If isLeaf is true, getChildren() will never be called. Note that a leaf node is not necessarily the same as a node with zero children. For example, in a filesystem browser, leaf nodes might represent files, while an empty directory would be a non-leaf node with zero children. Leaf nodes may be visualized differently from other nodes.
TNode.getChildren()
Must return an array of zero or more objects which implement the TNode interface and which are children of this TNode. The implementation will typically call getChildren() once per node and cache the results.

The following properties and methods will be added by the implementation to each TNode as the tree is constructed.

TNode.children
array of zero or more TNodes, or undefined for leaf nodes
TNode.parent
the TNode parent
TNode.refresh()
Invalidates this node's panel and all its descendants. If the user's navigation of the tree touches a node on which refresh() has been called, getLabel() and getChildren() will be called again just as on a node that had not previously been navigated.

The TExpl interface

Instantiating TExpl

Each visualization implements the TExpl interface. Each visualization provides a constructor which requires two arguments: a visualization options object which specifies any options appropriate to the visualization, and an object implementing the TNode interface representing the root node of the tree. The options object may be empty, in which case default values will be used.

To change between visualizations, only the name of the constructor (and possibly any options) need be changed. Every visualization supports the same TNode node object interface.

Examples:

var options = { /* ... options specific to the ElasticRow visualization ... */ }
var tree = new ElasticRowTree(options, root);
var tree2 = new RadialTree({}, root); /* use an empty options object for the defaults */

See the visualization documentation [which doesn't yet exist] for the options supported by each visualization.

TExpl callbacks

After instantiating the tree explorer object, the user may provide callback functions (event handlers) which will be called as the widget is navigated.

TExpl.onhoverpathchange()
The hover path is the path from the root of the tree to the node corresponding to the panel under the mouse pointer. This event handler is called every time the hover path changes.

TExpl methods and properties

Visualizations must provide the methods and properties shown below, and may provide additional methods.

TExpl.show()
When initially created, the explorer widget is not visible. After setting any desired callbacks the library user must call show() to display the widget.
TExpl.hide()
Causes the widget to be hidden or removed from the page. As long as the object remains in scope it can be shown again by calling show().
TExpl.hoverPath
The path from the root to the currently hovered panel, if any, as an array of node objects.