Empirical
Public Member Functions | Protected Attributes | List of all members
D3::Selection Class Reference

#include <selection.h>

Inheritance diagram for D3::Selection:
D3::SelectionOrTransition< Selection > D3::D3_Base

Public Member Functions

Selection Append (std::string name)
 Append DOM element(s) of the type specified by [name] to this selection. More...
 
Selection Insert (std::string name, std::string before=NULL)
 
Transition MakeTransition (std::string name="")
 
Transition MakeTransition (Transition &t)
 
SelectionInterrupt (std::string name="")
 Interrupt the transition with the name [name] on the current selection. More...
 
SelectionMove (int x, int y)
 
SelectionRotate (int degrees)
 
SelectionOrder ()
 Change the order of elements in the document to match their order in this selection. More...
 
SelectionRaise ()
 
SelectionLower ()
 
SelectionOn (std::string type, std::string listener="null", bool capture=false)
 
SelectionSort (std::string comparator="ascending")
 
void AddToolTip (ToolTip &tip)
 Add the ToolTip [tip] to the current selection. More...
 
Selection Select (std::string selector) const
 
Selection SelectAll (std::string selector) const
 
SelectionCall (std::string function)
 
Selection Filter (std::string selector) const
 
SelectionEach (std::string function)
 
void Remove ()
 
Selection Merge (Selection &other)
 
int GetID () const
 
void Log () const
 
Constructors

You may prefer to use the Select or SelectAll functions for improved code clarity/consistency with d3.js

 Selection ()
 Default constructor - constructs empty selection. More...
 
 Selection (int id)
 
 Selection (const Selection &s)
 
 Selection (std::string selector, bool all=false)
 
 ~Selection ()
 Destructor. More...
 
Binding Data

This group of functions allows you to bind data to the current selection and deal with new data you have just bound (the enter selection) and data that was previously bound to to the selection but is not present in the set of data that was most recently bound (the exit selection)

The process of binding data to a selection is called a "join" in d3-speak. For more in-depth explanation, see this article.

Selection Data (Dataset &values, std::string key="")
 
Dataset GetData () const
 
Selection EnterAppend (std::string type)
 
Selection EnterInsert (std::string name, std::string before=NULL)
 
Selection Enter ()
 
void ExitRemove ()
 Selection must have an exit selection (i.e. have just had data bound to it). More...
 
Selection Exit ()
 
Setters

There are three main types of values you might want to change about a selection: attributes (use SetAttr), styles (use SetStyle), and properties (use SetProperty). The distinction between these types is rooted in how they are represented in web languages (Javascript, CSS, and HTML) and would ideally be abstracted in this wrapper but can't be.

Additional traits you can set include text and html.

Advanced note: In D3.js, the same functions are used to set and get values (depending on whether an argument is passed). Because C++ needs to have clearly defined return types we need separate getters for each return type.

SelectionSetAttr (std::string name, std::string value)
 
SelectionSetStyle (std::string name, std::string value, bool priority=false)
 
SelectionSetText (std::string text)
 
SelectionSetProperty (std::string name, std::string value)
 
SelectionSetHtml (std::string value)
 
SelectionSetClassed (std::string classname, bool value)
 
Getters

There are three main types of values you might want to access about a selection: attributes (use GetAttr), styles (use GetStyle), and properties (use GetProperty). The distinction between these types is rooted in how they are represented in web languages (Javascript, CSS, and HTML) and would ideally be abstracted in this wrapper but can't be.

Additional traits you can set include text and html.

Advanced note: In D3.js, the same functions are used to set and get values (depending on whether an argument is passed). Because C++ needs to have clearly defined return types (and because different macros are required to return different types from Javascript), we need separate getters for each return type.

std::string GetAttrString (std::string name) const
 Get the value of this object's [name] attribute when it's a string. More...
 
int GetAttrInt (std::string name) const
 Get the value of this object's [name] attribute when it's an int. More...
 
double GetAttrDouble (std::string name) const
 Get the value of this object's [name] attribute when it's a double. More...
 
std::string GetStyleString (std::string name) const
 Get the value of this object's [name] style when it's a string. More...
 
int GetStyleInt (std::string name) const
 Get the value of this object's [name] style when it's an int. More...
 
double GetStyleDouble (std::string name) const
 Get the value of this object's [name] style when it's a double. More...
 
std::string GetText () const
 Get this object's text. More...
 
std::string GetHtml ()
 
std::string GetPropertyString (std::string name)
 
int GetPropertyInt (std::string name)
 
double GetPropertyDouble (std::string name)
 
bool Empty () const
 Returns true if there are no elements in this selection (or all elements are null) More...
 
int Size () const
 Returns number of elements in this selection. More...
 

Protected Attributes

int id
 

Detailed Description

Selections are the primary way that d3 allows you to operate on DOM elements (i.e. objects on your webpage). A selection is effectively an array of DOM elements that you can act on at the same time and bind a collection of data to.

For a deep dive into how selections work in d3, see this article.

Constructor & Destructor Documentation

D3::Selection::Selection ( )
inline

Default constructor - constructs empty selection.

D3::Selection::Selection ( int  id)
inline

Create Selection object with a specific id.

Advanced note: This is useful when creating a Selection object to point to a selection

D3::Selection::Selection ( const Selection s)
inline
D3::Selection::Selection ( std::string  selector,
bool  all = false 
)
inline

This is the Selection constructor you usually want to use. It takes a string saying what to select and a bool saying whether to select all elements matching that string [true] or just the first [false]

D3::Selection::~Selection ( )
inline

Destructor.

Member Function Documentation

void D3::Selection::AddToolTip ( ToolTip tip)
inline

Add the ToolTip [tip] to the current selection.

Selection D3::Selection::Append ( std::string  name)
inline

Append DOM element(s) of the type specified by [name] to this selection.

Selection & D3::SelectionOrTransition< Selection >::Call ( std::string  function)
inlineinherited

Call the given function once on the entire selection/transition. [function] can either be a C++ function or a string with the name of a Javascript function in the d3, emp, or current window namespace. To get around the problem of passing selections into C++, this function assumes that the function you are passing expects a single argument: an int, representing the id of the selection to be operated on (which you can then convert to a selection object with D3::Selection(i)).

Selection D3::Selection::Data ( Dataset values,
std::string  key = "" 
)
inline

Bind data to selection. Accepts any contiguous container (such as an array or vector) or a D3::Dataset object (which stores the data Javascript). Optionally also accepts a key function to run on each element to determine which elements are equivalent (if no key is provided, elements are expected to be in the same order each time you bind data to this selection). This function can either be a string with the name of a function in Javascript, or it can be a C++ function pointer, std::function object, or lambda.

Selection & D3::SelectionOrTransition< Selection >::Each ( std::string  function)
inlineinherited

Call the given function on each element of the selection/transition. [function] can either be a C++ function or a string with the name of a Javascript function in the d3, emp, or current window namespace.

bool D3::SelectionOrTransition< Selection >::Empty ( ) const
inlineinherited

Returns true if there are no elements in this selection (or all elements are null)

Selection D3::Selection::Enter ( )
inline

Sometimes you want to perform multiple operations on the enter selection. If so, you can use the Enter() method to get the enter selection, rather than using one of the convenience functions like EnterAppend().

Returns a selection object pointing at this selection's enter selection.

Selection D3::Selection::EnterAppend ( std::string  type)
inline

This function appends the specified type of nodes to this selection's enter selection, which merges the enter selection with the update selection.

Selection must have an enter selection (i.e. have just had data bound to it).

Selection D3::Selection::EnterInsert ( std::string  name,
std::string  before = NULL 
)
inline

Insert elements of type [name] into current enter selection

For more information, see the D3 documention on insert

Selection D3::Selection::Exit ( )
inline

Usually the only thing you want to do with the exit selection is remove its contents, in which case you should use the ExitRemove method. However, advanced users may want to operate on the exit selection, which is why this method is provided.

Returns a selection object pointing at this selection's exit selection.

void D3::Selection::ExitRemove ( )
inline

Selection must have an exit selection (i.e. have just had data bound to it).

Pretty much the only thing you ever want to do with the exit() selection is remove all of the nodes in it. This function does just that.

Selection D3::SelectionOrTransition< Selection >::Filter ( std::string  selector) const
inlineinherited

Returns a new selection/transition, representing the current selection/transition filtered by [selector]. [selector] can be a C++ function that returns a bool, a string representing a function in either the d3, emp, or window namespaces that returns a bool, or a string containing a selector to filter by.

For more information see the D3 documentation

double D3::SelectionOrTransition< Selection >::GetAttrDouble ( std::string  name) const
inlineinherited

Get the value of this object's [name] attribute when it's a double.

int D3::SelectionOrTransition< Selection >::GetAttrInt ( std::string  name) const
inlineinherited

Get the value of this object's [name] attribute when it's an int.

std::string D3::SelectionOrTransition< Selection >::GetAttrString ( std::string  name) const
inlineinherited

Get the value of this object's [name] attribute when it's a string.

Dataset D3::Selection::GetData ( ) const
inline
std::string D3::SelectionOrTransition< Selection >::GetHtml ( )
inlineinherited

Get this object's html

Advanced note: This is implemented differently for selection vs transitions. As such, calling it on a SelectionOrTransition object directly is not supported.

int D3::D3_Base::GetID ( ) const
inlineinherited
double D3::SelectionOrTransition< Selection >::GetPropertyDouble ( std::string  name)
inlineinherited

Get the value of this object's [name] property when it's a double

Advanced note: This is implemented differently for selection vs transitions. As such, calling it on a SelectionOrTransition object directly is not supported.

int D3::SelectionOrTransition< Selection >::GetPropertyInt ( std::string  name)
inlineinherited

Get the value of this object's [name] property when it's an int

Advanced note: This is implemented differently for selection vs transitions. As such, calling it on a SelectionOrTransition object directly is not supported.

std::string D3::SelectionOrTransition< Selection >::GetPropertyString ( std::string  name)
inlineinherited

Get the value of this object's [name] property when its a string

Advanced note: This is implemented differently for selection vs transitions. As such, calling it on a SelectionOrTransition object directly is not supported.

double D3::SelectionOrTransition< Selection >::GetStyleDouble ( std::string  name) const
inlineinherited

Get the value of this object's [name] style when it's a double.

int D3::SelectionOrTransition< Selection >::GetStyleInt ( std::string  name) const
inlineinherited

Get the value of this object's [name] style when it's an int.

std::string D3::SelectionOrTransition< Selection >::GetStyleString ( std::string  name) const
inlineinherited

Get the value of this object's [name] style when it's a string.

std::string D3::SelectionOrTransition< Selection >::GetText ( ) const
inlineinherited

Get this object's text.

Selection D3::Selection::Insert ( std::string  name,
std::string  before = NULL 
)
inline

Insert DOM element of type "name" into the current selection before the element selected by the element specified by the [before] string

For more information, see the D3 documention on insert

Selection& D3::Selection::Interrupt ( std::string  name = "")
inline

Interrupt the transition with the name [name] on the current selection.

void D3::D3_Base::Log ( ) const
inlineinherited
Selection& D3::Selection::Lower ( )
inline
Transition D3::Selection::MakeTransition ( std::string  name = "")
inline

Create a transition from the current selection. If a [name] is specified the transition will be given that name

Transition D3::Selection::MakeTransition ( Transition t)
inline
Selection D3::SelectionOrTransition< Selection >::Merge ( Selection other)
inlineinherited
Selection& D3::Selection::Move ( int  x,
int  y 
)
inline

Move the elements in this selection by [x] in the x direction and [y] in the y direction. Note for advanced users: this method is just a shortcut for setting the "transform" attribute to "translate(x, y)", because doing that is a pain in C++ (even more so than in Javascript)

Selection& D3::Selection::On ( std::string  type,
std::string  listener = "null",
bool  capture = false 
)
inline

Listen for an event of type [type] and call [listener] when it happens [listener] can be a string containing the name of a Javascript function, or a C++ function

The third paramter for the listener function is the id of a selection containing the relevant DOM object.

To remove an event listener, call On with that type and "null" as the listener (default)

Advanced note: the optional capture flag invokes Javascript's useCapture option

Selection& D3::Selection::Order ( )
inline

Change the order of elements in the document to match their order in this selection.

Selection& D3::Selection::Raise ( )
inline
void D3::SelectionOrTransition< Selection >::Remove ( )
inlineinherited

Remove the elements in this selection/transition from the document For transitions, this happens at the end of the transition.

Selection& D3::Selection::Rotate ( int  degrees)
inline

Rotate the elements in this selection by [degrees]. Note for advanced users: this method is just a shortcut for setting the "transform" attribute to "rotate(degrees)", because doing that is a pain in C++ (even more so than in Javascript)

Selection D3::SelectionOrTransition< Selection >::Select ( std::string  selector) const
inlineinherited

Create a new selection/transition containing the first element matching the [selector] string that are within this current selection/transition

Selection D3::SelectionOrTransition< Selection >::SelectAll ( std::string  selector) const
inlineinherited

Create a new selection/transition containing all elements matching the [selector] string that are within this current selection/transition

Selection & D3::SelectionOrTransition< Selection >::SetAttr ( std::string  name,
std::string  value 
)
inlineinherited

Assigns [value] to the selection's [name] attribute. Value can be any primitive type, a string, a function object, or a lambda. If a string is passed, it can be a normal string, or the name of a function in d3, emp (such as one created with JSWrap), or the local window. If it is a function name, that function will be run, receiving bound data, if any, as input

Selection & D3::SelectionOrTransition< Selection >::SetClassed ( std::string  classname,
bool  value 
)
inlineinherited

Change whether or not element in this selection have the [classname] class. Example: Add the data-point class with selection.SetClassed("data-point", true); Advanced note: This is implemented differently for selection vs transitions. As such, calling it on a SelectionOrTransition object directly is not supported.

Selection & D3::SelectionOrTransition< Selection >::SetHtml ( std::string  value)
inlineinherited

Sets this selection's inner html to the specified string, or the string returned by running the specified function on the element's bound data

Advanced note: This is implemented differently for selection vs transitions. As such, calling it on a SelectionOrTransition object directly is not supported.

Selection & D3::SelectionOrTransition< Selection >::SetProperty ( std::string  name,
std::string  value 
)
inlineinherited

Sets special properties of DOM elements (e.g. "checked" for checkboxes) Value can be a number, function, string, or string naming a Javascript function See the d3 documentation for more information.

Advanced note: This is implemented differently for selection vs transitions. As such, calling it on a SelectionOrTransition object directly is not supported.

Selection & D3::SelectionOrTransition< Selection >::SetStyle ( std::string  name,
std::string  value,
bool  priority = false 
)
inlineinherited

Sets the selection's [name] style to [value]. This is the same idea as SetAttr, except for CSS styles. Value can be any primitive type, a string, a function object, or a lambda. If a string is passed, it can be a normal string, or the name of a function in d3, emp (such as one created with JSWrap), or the local window. If it is a function name, that function will be run, receiving bound data, if any, as input

There is a third optional argument, a boolean indicating whether you want to give this setting priority.

Selection & D3::SelectionOrTransition< Selection >::SetText ( std::string  text)
inlineinherited

Sets this selection's text to the specified string, or the string returned by running the specified function on the element's bound data

int D3::SelectionOrTransition< Selection >::Size ( ) const
inlineinherited

Returns number of elements in this selection.

Selection& D3::Selection::Sort ( std::string  comparator = "ascending")
inline

Sort the selection by the given comparator function. The function can be a C++ function or a stirng indicating a function in the d3 namespace, the emp namespace (as results from JSWrapping C++ functions), or the window namespace. These three options are checked sequentially in that order, so a C++ function with the same name as d3 built-in will not override the built-in. Similarly, a function declared directly in the window will be overriden by a JSWrapped function with the same name.

Member Data Documentation

int D3::D3_Base::id
protectedinherited

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