Empirical
|
#include <layout.h>
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 | |
JSONDataset * | data |
Pointer to the data - must be in hierarchical JSON format. More... | |
D3::LinkGenerator * | make_line |
Function used to make the lines for the edges in the tree. More... | |
Protected Attributes | |
int | id |
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:
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:
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.
|
inline |
Constructor - handles creating a default DiagonalGenerator and links the specified dataset up to this object's data pointer.
|
inline |
Default constructor - if you use this you need connect a dataset with SetDataset.
|
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.
|
inlineinherited |
|
inlineinherited |
|
inline |
Change this TreeLayout's data to [dataset].
|
inline |
Set the width of the tree area to [w] and the height to [h].
JSONDataset* D3::TreeLayout< NODE_TYPE >::data |
Pointer to the data - must be in hierarchical JSON format.
|
protectedinherited |
D3::LinkGenerator* D3::TreeLayout< NODE_TYPE >::make_line |
Function used to make the lines for the edges in the tree.