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

#include <selection.h>

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

Public Member Functions

 SelectionOrTransition ()
 
 SelectionOrTransition (int id)
 
 SelectionOrTransition (const SelectionOrTransition< DERIVED > &s)
 
DERIVED Select (std::string selector) const
 
DERIVED SelectAll (std::string selector) const
 
DERIVED & Call (std::string function)
 
DERIVED Filter (std::string selector) const
 
DERIVED & Each (std::string function)
 
void Remove ()
 
DERIVED Merge (DERIVED &other)
 
int GetID () const
 
void Log () const
 
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.

DERIVED & SetAttr (std::string name, std::string value)
 
DERIVED & SetStyle (std::string name, std::string value, bool priority=false)
 
DERIVED & SetText (std::string text)
 
DERIVED & SetProperty (std::string name, std::string value)
 
DERIVED & SetHtml (std::string value)
 
DERIVED & SetClassed (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

template<typename DERIVED>
class D3::SelectionOrTransition< DERIVED >

You probably never want to instantiate this class. Its sole purpose is to hold code for methods that are common to selections and transitions.

Developer note: It's also handy if you want to allow a function to accept either a selection or transition. This is a good idea any time you are only using methods that are applicable to either, and the person calling the function may want to animate its results.

Constructor & Destructor Documentation

template<typename DERIVED>
D3::SelectionOrTransition< DERIVED >::SelectionOrTransition ( )
inline
template<typename DERIVED>
D3::SelectionOrTransition< DERIVED >::SelectionOrTransition ( int  id)
inline
template<typename DERIVED>
D3::SelectionOrTransition< DERIVED >::SelectionOrTransition ( const SelectionOrTransition< DERIVED > &  s)
inline

Member Function Documentation

template<typename DERIVED>
DERIVED& D3::SelectionOrTransition< DERIVED >::Call ( std::string  function)
inline

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)).

template<typename DERIVED>
DERIVED& D3::SelectionOrTransition< DERIVED >::Each ( std::string  function)
inline

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.

template<typename DERIVED>
bool D3::SelectionOrTransition< DERIVED >::Empty ( ) const
inline

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

template<typename DERIVED>
DERIVED D3::SelectionOrTransition< DERIVED >::Filter ( std::string  selector) const
inline

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

template<typename DERIVED>
double D3::SelectionOrTransition< DERIVED >::GetAttrDouble ( std::string  name) const
inline

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

template<typename DERIVED>
int D3::SelectionOrTransition< DERIVED >::GetAttrInt ( std::string  name) const
inline

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

template<typename DERIVED>
std::string D3::SelectionOrTransition< DERIVED >::GetAttrString ( std::string  name) const
inline

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

template<typename DERIVED>
std::string D3::SelectionOrTransition< DERIVED >::GetHtml ( )
inline

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
template<typename DERIVED>
double D3::SelectionOrTransition< DERIVED >::GetPropertyDouble ( std::string  name)
inline

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.

template<typename DERIVED>
int D3::SelectionOrTransition< DERIVED >::GetPropertyInt ( std::string  name)
inline

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.

template<typename DERIVED>
std::string D3::SelectionOrTransition< DERIVED >::GetPropertyString ( std::string  name)
inline

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.

template<typename DERIVED>
double D3::SelectionOrTransition< DERIVED >::GetStyleDouble ( std::string  name) const
inline

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

template<typename DERIVED>
int D3::SelectionOrTransition< DERIVED >::GetStyleInt ( std::string  name) const
inline

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

template<typename DERIVED>
std::string D3::SelectionOrTransition< DERIVED >::GetStyleString ( std::string  name) const
inline

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

template<typename DERIVED>
std::string D3::SelectionOrTransition< DERIVED >::GetText ( ) const
inline

Get this object's text.

void D3::D3_Base::Log ( ) const
inlineinherited
template<typename DERIVED>
DERIVED D3::SelectionOrTransition< DERIVED >::Merge ( DERIVED &  other)
inline
template<typename DERIVED>
void D3::SelectionOrTransition< DERIVED >::Remove ( )
inline

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

template<typename DERIVED>
DERIVED D3::SelectionOrTransition< DERIVED >::Select ( std::string  selector) const
inline

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

template<typename DERIVED>
DERIVED D3::SelectionOrTransition< DERIVED >::SelectAll ( std::string  selector) const
inline

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

template<typename DERIVED>
DERIVED& D3::SelectionOrTransition< DERIVED >::SetAttr ( std::string  name,
std::string  value 
)
inline

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

template<typename DERIVED>
DERIVED& D3::SelectionOrTransition< DERIVED >::SetClassed ( std::string  classname,
bool  value 
)
inline

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.

template<typename DERIVED>
DERIVED& D3::SelectionOrTransition< DERIVED >::SetHtml ( std::string  value)
inline

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.

template<typename DERIVED>
DERIVED& D3::SelectionOrTransition< DERIVED >::SetProperty ( std::string  name,
std::string  value 
)
inline

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.

template<typename DERIVED>
DERIVED& D3::SelectionOrTransition< DERIVED >::SetStyle ( std::string  name,
std::string  value,
bool  priority = false 
)
inline

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.

template<typename DERIVED>
DERIVED& D3::SelectionOrTransition< DERIVED >::SetText ( std::string  text)
inline

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

template<typename DERIVED>
int D3::SelectionOrTransition< DERIVED >::Size ( ) const
inline

Returns number of elements in this selection.

Member Data Documentation

int D3::D3_Base::id
protectedinherited

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