Empirical
Public Member Functions | Public Attributes | Protected Attributes | List of all members
D3::TreeLayout< NODE_TYPE > Class Template Reference

#include <layout.h>

Inheritance diagram for D3::TreeLayout< NODE_TYPE >:
D3::Layout D3::D3_Base

Public Member Functions

 TreeLayout (JSONDataset *dataset)
 
 TreeLayout ()
 Default constructor - if you use this you need connect a dataset with SetDataset. More...
 
void SetDataset (JSONDataset *dataset)
 Change this TreeLayout's data to [dataset]. More...
 
emp::array< Selection, 4 > GenerateNodesAndLinks (Selection svg)
 
void SetSize (int w, int h)
 Set the width of the tree area to [w] and the height to [h]. More...
 
int GetID () const
 
void Log () const
 

Public Attributes

JSONDatasetdata
 Pointer to the data - must be in hierarchical JSON format. More...
 
D3::LinkGeneratormake_line
 Function used to make the lines for the edges in the tree. More...
 

Protected Attributes

int id
 

Detailed Description

template<typename NODE_TYPE = JSONTreeNode>
class D3::TreeLayout< NODE_TYPE >

A TreeLayout can be used to visualize hierarchical data as a tree (a series of edges connecting parent and child nodes).

Since hierarchical data is much more pleasant to store in JSON format than anything C++ can offer, the TreeLayout expects your data to be stored in a D3::JSONDataset. Each node is expected to have, at a minimum, the following values:

Parameters
name- a name that uniquely identifies a single node
parent- the name of this node's parent (each node is expected to have exactly one parent, unless it is the root, in which case the parent should be "null")
children- an array containing all of the node's children (yes, the nesting gets intense).

Calculating the tree layout will automatically create three additional values for each node:

Parameters
x- the x coordinate of the node
y- the y coordinate
depth- the depth of the node in the tree

You can include any additional parameters that you want to use to store data. The dataset is expected to be an array containing one element: the root node object, which in turn has the other nodes nested inside it. You must provide a dataset to the TreeLayout constructor.

A TreeLayout must be templated off of a type that describes all of the values that a node contains (or at least the ones you care about using from C++, as well as x and y). This allows nodes to be passed back up to C++ without C++ throwing a fit about types. If you don't need access to any data other than name, parent, x, y, and depth from C++, you can use the default, JSONTreeNode.

If you need access to additional data, you can build structs to template TreeLayouts off with Empirical Introspective Tuple Structs (see JSONTreeNode as an example). Don't be scared by the complicated sounding name - you just need to list the names and types of values you care about.

Constructor & Destructor Documentation

template<typename NODE_TYPE = JSONTreeNode>
D3::TreeLayout< NODE_TYPE >::TreeLayout ( JSONDataset dataset)
inline

Constructor - handles creating a default DiagonalGenerator and links the specified dataset up to this object's data pointer.

template<typename NODE_TYPE = JSONTreeNode>
D3::TreeLayout< NODE_TYPE >::TreeLayout ( )
inline

Default constructor - if you use this you need connect a dataset with SetDataset.

Member Function Documentation

template<typename NODE_TYPE = JSONTreeNode>
emp::array<Selection, 4> D3::TreeLayout< NODE_TYPE >::GenerateNodesAndLinks ( Selection  svg)
inline

This function does the heavy lifting of visualizing your data. It generates nodes and links between them based on this object's dataset. [svg] must be a selection containing a single svg element on which to draw the the visualization.

In case you want to further customize the tree, this method returns an array of selections, containing: the enter selection for nodes (i.e. a selection containing all nodes that were just added to the tree), the exit selection for nodes (i.e. a selection containing any nodes that are currently drawn but are no longer in the dataset), the enter selection for links, and the exit selection for links.

int D3::D3_Base::GetID ( ) const
inlineinherited
void D3::D3_Base::Log ( ) const
inlineinherited
template<typename NODE_TYPE = JSONTreeNode>
void D3::TreeLayout< NODE_TYPE >::SetDataset ( JSONDataset dataset)
inline

Change this TreeLayout's data to [dataset].

template<typename NODE_TYPE = JSONTreeNode>
void D3::TreeLayout< NODE_TYPE >::SetSize ( int  w,
int  h 
)
inline

Set the width of the tree area to [w] and the height to [h].

Member Data Documentation

template<typename NODE_TYPE = JSONTreeNode>
JSONDataset* D3::TreeLayout< NODE_TYPE >::data

Pointer to the data - must be in hierarchical JSON format.

int D3::D3_Base::id
protectedinherited
template<typename NODE_TYPE = JSONTreeNode>
D3::LinkGenerator* D3::TreeLayout< NODE_TYPE >::make_line

Function used to make the lines for the edges in the tree.


The documentation for this class was generated from the following file: