D3 Wrapper API

Basic D3 Objects

namespace D3

Functions

int NextD3ID()
class D3_Base
#include <d3_init.h>

A base object that all D3 objects inherit from. Handles storing the object in Javascript You probably don’t want to instantiate this directly

Subclassed by D3::Axis< D3::LinearScale >, D3::Axis< X_SCALE_TYPE >, D3::Axis< Y_SCALE_TYPE >, D3::Axis< SCALE_TYPE >, D3::Category10Scale, D3::Category20bScale, D3::Category20cScale, D3::Category20Scale, D3::Dataset, D3::FormatFunction, D3::Histogram, D3::JSFunction, D3::JSObject, D3::Layout, D3::Scale, D3::SelectionOrTransition< DERIVED >, D3::SvgShapeGenerator, D3::ToolTip, D3::SelectionOrTransition< Selection >, D3::SelectionOrTransition< Transition >

Public Functions

int GetID() const
void Log() const

Protected Functions

D3_Base()

Default constructor - adds placeholder to js.objects array in Javascript.

D3_Base(int id)

Construct an object pointing to a pre-determined location in js.objects. Warning: This trusts that you know what you’re doing in choosing an id.

D3_Base(const D3_Base &other)
D3_Base &operator=(const D3_Base &other)
~D3_Base()

Protected Attributes

int id
class FormatFunction : public D3::D3_Base
#include <d3_init.h>

A callable string d3.format() string formatting function.

Public Functions

FormatFunction(std::string format = "")
std::string operator()(double d)
int GetID() const
void Log() const

Protected Attributes

int id
class JSFunction : public D3::D3_Base
#include <d3_init.h>

Wrapper for creating functions in javascript and calling them there.

Public Functions

JSFunction()
JSFunction(std::string name)
void operator()()

Only works if function has no arguments or returns.

int GetID() const
void Log() const

Protected Attributes

int id
class JSObject : public D3::D3_Base
#include <d3_init.h>

Catch-all object for storing references to things created in JS.

Public Functions

JSObject()
int GetID() const
void Log() const

Protected Attributes

int id
class ToolTip : public D3::D3_Base
#include <d3_init.h>

Create a tooltup using the d3.tip Javascript library.

Public Functions

ToolTip()

Default constructor - displays whatever data is bound on mouseover.

ToolTip(std::string func)

Cosntructor that allows you to specify a function that returns the html for the tooltip. As input, this function should take 3 parameters: the bound data, the index of this item in the selection (int), and a placeholder (int).

Example:

`D3::FormatFunction rounded = D3::FormatFunction(“.2f”);

std::function<double, int, int)> tooltip_display = [this](double d, int i, int k) {return “Data: ” + to_string(rounded(d));}

D3::ToolTip tip = D3::ToolTip(tooltip_display);

D3::Selection example_selection = D3::SelectAll(“circle”);

example_selection.SetupToolTip(tip);’

Mousing over a circle in the example selection will display “Data: ” followed by the value of d, rounded to two decimal points.

void SetHtml(std::string func)
int GetID() const
void Log() const

Protected Attributes

int id

Selections and Transitions

namespace D3

Functions

Selection Select(std::string selector)

Create a selection containing the first DOM element matching [selector] (convenience function to match D3 syntax - you can also just use the constructor)

Selection SelectAll(std::string selector)

Create a selection containing all DOM elements matching [selector] (convenience function to match D3 syntax - you can also just use the constructor)

template <typename T>
Selection ShapesFromData(T values, std::string shape)

Makes a shape of type [shape] for each element in [values] on the first svg canvas on the DOM Values can be a D3::Dataset, an array, or a vector.

template <typename T>
Selection ShapesFromData(T values, std::string shape, Selection &svg)

Makes a shape of type [shape] for each element in [values] on [svg], which must be a selection containing an SVG canvas. Values can be a D3::Dataset, an array, or a vector.

class Selection : public D3::SelectionOrTransition<Selection>
#include <selection.h>

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.

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.

Selection &SetAttr(std::string name, std::string value)

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 &SetStyle(std::string name, std::string value, bool priority = false)

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 &SetText(std::string text)

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

Selection &SetProperty(std::string name, std::string value)

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 &SetHtml(std::string value)

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 &SetClassed(std::string classname, bool value)

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.

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.

int GetAttrInt(std::string name) const

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

double GetAttrDouble(std::string name) const

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

std::string GetStyleString(std::string name) const

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

int GetStyleInt(std::string name) const

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

double GetStyleDouble(std::string name) const

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

std::string GetText() const

Get this object’s text.

std::string GetHtml()

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.

std::string GetPropertyString(std::string name)

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.

int GetPropertyInt(std::string name)

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.

double GetPropertyDouble(std::string name)

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.

bool Empty() const

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

int Size() const

Returns number of elements in this selection.

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.

Selection(int id)

Create Selection object with a specific id.

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

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

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]

~Selection()

Destructor.

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 = "")

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.

Dataset GetData() const
Selection EnterAppend(std::string type)

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 EnterInsert(std::string name, std::string before = NULL)

Insert elements of type [name] into current enter selection

For more information, see the D3 documention on insert

Selection Enter()

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.

void ExitRemove()

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 Exit()

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.

Public Functions

Selection Append(std::string name)

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

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

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

Transition MakeTransition(std::string name = "")

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

Transition MakeTransition(Transition &t)
Selection &Interrupt(std::string name = "")

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

Selection &Move(int x, int y)

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 &Rotate(int degrees)

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 &Order()

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

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

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 &Sort(std::string comparator = "ascending")

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.

void AddToolTip(ToolTip &tip)

Add the ToolTip [tip] to the current selection.

Selection Select(std::string selector) const

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

Selection SelectAll(std::string selector) const

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

Selection &Call(std::string function)

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 Filter(std::string selector) const

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

Selection &Each(std::string function)

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.

void Remove()

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

Selection Merge(Selection &other)
template <typename DERIVED>
class SelectionOrTransition : public D3::D3_Base
#include <selection.h>

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.

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)

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

DERIVED &SetStyle(std::string name, std::string value, bool priority = false)

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.

DERIVED &SetText(std::string text)

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

DERIVED &SetProperty(std::string name, std::string value)

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.

DERIVED &SetHtml(std::string value)

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.

DERIVED &SetClassed(std::string classname, bool value)

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.

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.

int GetAttrInt(std::string name) const

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

double GetAttrDouble(std::string name) const

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

std::string GetStyleString(std::string name) const

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

int GetStyleInt(std::string name) const

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

double GetStyleDouble(std::string name) const

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

std::string GetText() const

Get this object’s text.

std::string GetHtml()

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.

std::string GetPropertyString(std::string name)

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.

int GetPropertyInt(std::string name)

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.

double GetPropertyDouble(std::string name)

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.

bool Empty() const

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

int Size() const

Returns number of elements in this selection.

Public Functions

SelectionOrTransition()
SelectionOrTransition(int id)
SelectionOrTransition(const SelectionOrTransition<DERIVED> &s)
DERIVED Select(std::string selector) const

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

DERIVED SelectAll(std::string selector) const

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

DERIVED &Call(std::string function)

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

DERIVED Filter(std::string selector) const

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

DERIVED &Each(std::string function)

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.

void Remove()

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

DERIVED Merge(DERIVED &other)
class Transition : public D3::SelectionOrTransition<Transition>
#include <selection.h>

Transitions are similar to selections, but when you make a change to them (attr or style), it will be animated. For additional discussion of transitions in d3, see this article.

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.

Transition &SetAttr(std::string name, std::string value)

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

Transition &SetStyle(std::string name, std::string value, bool priority = false)

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.

Transition &SetText(std::string text)

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

Transition &SetProperty(std::string name, std::string value)

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.

Transition &SetHtml(std::string value)

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.

Transition &SetClassed(std::string classname, bool value)

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.

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.

int GetAttrInt(std::string name) const

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

double GetAttrDouble(std::string name) const

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

std::string GetStyleString(std::string name) const

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

int GetStyleInt(std::string name) const

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

double GetStyleDouble(std::string name) const

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

std::string GetText() const

Get this object’s text.

std::string GetHtml()

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.

std::string GetPropertyString(std::string name)

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.

int GetPropertyInt(std::string name)

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.

double GetPropertyDouble(std::string name)

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.

bool Empty() const

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

int Size() const

Returns number of elements in this selection.

Constructors

Usually transitions are constructed from selections by calling the selection.MakeTransition() method. In rare cases you may want to construct a new transition, though.

Transition()

Default constructor - construct empty transition.

Transition(int id)

Advanced: Construct new transition pointing to the [id]th element in js.objects.

Transition NewTransition(std::string name = "") const

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

Note: In D3.js this method is just called transition(), but in C++ that would cause a collision with the constructor

Public Functions

Transition Select(std::string selector) const

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

Transition SelectAll(std::string selector) const

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

Transition &Call(std::string function)

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

Transition Filter(std::string selector) const

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

Transition &Each(std::string function)

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.

void Remove()

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

Transition Merge(Transition &other)

Scales

Tools for scaling graph axes in D3.

Note
This file is part of Empirical, https://github.com/devosoft/Empirical
Copyright
Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md
Date
2016-2018

namespace D3

Functions

PowScale SqrtScale()
class Category10Scale : D3::D3_Base
#include <scales.h>

Public Functions

Category10Scale()
class Category20bScale : D3::D3_Base
#include <scales.h>

Public Functions

Category20bScale()
class Category20cScale : D3::D3_Base
#include <scales.h>

Public Functions

Category20cScale()

Protected Attributes

int id
class Category20Scale : D3::D3_Base
#include <scales.h>

Public Functions

Category20Scale()
class IdentityScale : public D3::Scale
#include <scales.h>

Subclassed by D3::LinearScale

Public Functions

IdentityScale()
IdentityScale(bool derived)
template <typename T>
double Invert(T y)
IdentityScale &SetTicks(int count)
IdentityScale &SetTickFormat(int count, std::string format)
template <typename T, size_t SIZE>
Scale &SetRange(emp::array<T, SIZE> values)

Set the output values corresponding to values in the domain. Output for values in between will be interpolated with a function determined by the type of the scale. Array should contain same number of elements as the one used to set the domain.

Scale &SetRange(double min, double max)
template <typename T, size_t SIZE>
Scale &SetDomain(emp::array<T, SIZE> values)

Set the input values corresponding to values in the range. Array should contain same number of elements as the one used to set the range.

Scale &SetDomain(double min, double max)
Scale Copy()

Make a copy of this scale.

double ApplyScale(double input)

Calculate the ouput for [input], based on the scale’s scaling function.

int ApplyScale(int input)
class LinearScale : public D3::IdentityScale
#include <scales.h>

Subclassed by D3::LogScale, D3::PowScale, D3::TimeScale

Public Functions

LinearScale()
LinearScale(bool derived)
template <typename T, size_t SIZE>
LinearScale &SetRangeRound(emp::array<T, SIZE> values)
LinearScale &SetRangeRound(double min, double max)
LinearScale &SetInterpolate(std::string factory)
LinearScale &Clamp(bool clamp)
LinearScale &Nice(int count = -1)
template <typename T>
double Invert(T y)
IdentityScale &SetTicks(int count)
IdentityScale &SetTickFormat(int count, std::string format)
template <typename T, size_t SIZE>
Scale &SetRange(emp::array<T, SIZE> values)

Set the output values corresponding to values in the domain. Output for values in between will be interpolated with a function determined by the type of the scale. Array should contain same number of elements as the one used to set the domain.

Scale &SetRange(double min, double max)
template <typename T, size_t SIZE>
Scale &SetDomain(emp::array<T, SIZE> values)

Set the input values corresponding to values in the range. Array should contain same number of elements as the one used to set the range.

Scale &SetDomain(double min, double max)
Scale Copy()

Make a copy of this scale.

double ApplyScale(double input)

Calculate the ouput for [input], based on the scale’s scaling function.

int ApplyScale(int input)
class LogScale : public D3::LinearScale
#include <scales.h>

Public Functions

LogScale()
LogScale(bool derived)
template <typename T, size_t SIZE>
LinearScale &SetRangeRound(emp::array<T, SIZE> values)
LinearScale &SetRangeRound(double min, double max)
LinearScale &SetInterpolate(std::string factory)
LinearScale &Clamp(bool clamp)
LinearScale &Nice(int count = -1)
template <typename T>
double Invert(T y)
IdentityScale &SetTicks(int count)
IdentityScale &SetTickFormat(int count, std::string format)
template <typename T, size_t SIZE>
Scale &SetRange(emp::array<T, SIZE> values)

Set the output values corresponding to values in the domain. Output for values in between will be interpolated with a function determined by the type of the scale. Array should contain same number of elements as the one used to set the domain.

Scale &SetRange(double min, double max)
template <typename T, size_t SIZE>
Scale &SetDomain(emp::array<T, SIZE> values)

Set the input values corresponding to values in the range. Array should contain same number of elements as the one used to set the range.

Scale &SetDomain(double min, double max)
Scale Copy()

Make a copy of this scale.

double ApplyScale(double input)

Calculate the ouput for [input], based on the scale’s scaling function.

int ApplyScale(int input)
class OrdinalScale : public D3::QuantizeScale
#include <scales.h>

Public Functions

OrdinalScale()
OrdinalScale(bool derived)
template <typename T>
double InvertExtent(T y)
template <typename T, size_t SIZE>
Scale &SetRange(emp::array<T, SIZE> values)

Set the output values corresponding to values in the domain. Output for values in between will be interpolated with a function determined by the type of the scale. Array should contain same number of elements as the one used to set the domain.

Scale &SetRange(double min, double max)
template <typename T, size_t SIZE>
Scale &SetDomain(emp::array<T, SIZE> values)

Set the input values corresponding to values in the range. Array should contain same number of elements as the one used to set the range.

Scale &SetDomain(double min, double max)
Scale Copy()

Make a copy of this scale.

double ApplyScale(double input)

Calculate the ouput for [input], based on the scale’s scaling function.

int ApplyScale(int input)
class PowScale : public D3::LinearScale
#include <scales.h>

Public Functions

PowScale()
PowScale(bool derived)
PowScale &Exponent(double ex)
template <typename T, size_t SIZE>
LinearScale &SetRangeRound(emp::array<T, SIZE> values)
LinearScale &SetRangeRound(double min, double max)
LinearScale &SetInterpolate(std::string factory)
LinearScale &Clamp(bool clamp)
LinearScale &Nice(int count = -1)
template <typename T>
double Invert(T y)
IdentityScale &SetTicks(int count)
IdentityScale &SetTickFormat(int count, std::string format)
template <typename T, size_t SIZE>
Scale &SetRange(emp::array<T, SIZE> values)

Set the output values corresponding to values in the domain. Output for values in between will be interpolated with a function determined by the type of the scale. Array should contain same number of elements as the one used to set the domain.

Scale &SetRange(double min, double max)
template <typename T, size_t SIZE>
Scale &SetDomain(emp::array<T, SIZE> values)

Set the input values corresponding to values in the range. Array should contain same number of elements as the one used to set the range.

Scale &SetDomain(double min, double max)
Scale Copy()

Make a copy of this scale.

double ApplyScale(double input)

Calculate the ouput for [input], based on the scale’s scaling function.

int ApplyScale(int input)
class QuantileScale : public D3::QuantizeScale
#include <scales.h>

Public Functions

QuantileScale()
QuantileScale(bool derived)
template <typename T>
double InvertExtent(T y)
template <typename T, size_t SIZE>
Scale &SetRange(emp::array<T, SIZE> values)

Set the output values corresponding to values in the domain. Output for values in between will be interpolated with a function determined by the type of the scale. Array should contain same number of elements as the one used to set the domain.

Scale &SetRange(double min, double max)
template <typename T, size_t SIZE>
Scale &SetDomain(emp::array<T, SIZE> values)

Set the input values corresponding to values in the range. Array should contain same number of elements as the one used to set the range.

Scale &SetDomain(double min, double max)
Scale Copy()

Make a copy of this scale.

double ApplyScale(double input)

Calculate the ouput for [input], based on the scale’s scaling function.

int ApplyScale(int input)
class QuantizeScale : public D3::Scale
#include <scales.h>

Subclassed by D3::OrdinalScale, D3::QuantileScale, D3::ThresholdScale

Public Functions

QuantizeScale()
QuantizeScale(bool derived)
template <typename T>
double InvertExtent(T y)
template <typename T, size_t SIZE>
Scale &SetRange(emp::array<T, SIZE> values)

Set the output values corresponding to values in the domain. Output for values in between will be interpolated with a function determined by the type of the scale. Array should contain same number of elements as the one used to set the domain.

Scale &SetRange(double min, double max)
template <typename T, size_t SIZE>
Scale &SetDomain(emp::array<T, SIZE> values)

Set the input values corresponding to values in the range. Array should contain same number of elements as the one used to set the range.

Scale &SetDomain(double min, double max)
Scale Copy()

Make a copy of this scale.

double ApplyScale(double input)

Calculate the ouput for [input], based on the scale’s scaling function.

int ApplyScale(int input)
class Scale : public D3::D3_Base
#include <scales.h>

Scales in D3 are functions that take input values and map them to output based on a scaling function. They are often used to map data calues to x, y coordinates in pixels describing where on the screen elements should be placed. This is a base class to inherit from - should never be made stand-alone

Subclassed by D3::IdentityScale, D3::QuantizeScale

Public Functions

Scale()
Scale(bool derived)

Decoy constructor so we don’t construct extra base scales.

template <typename T, size_t SIZE>
Scale &SetRange(emp::array<T, SIZE> values)

Set the output values corresponding to values in the domain. Output for values in between will be interpolated with a function determined by the type of the scale. Array should contain same number of elements as the one used to set the domain.

Scale &SetRange(double min, double max)
template <typename T, size_t SIZE>
Scale &SetDomain(emp::array<T, SIZE> values)

Set the input values corresponding to values in the range. Array should contain same number of elements as the one used to set the range.

Scale &SetDomain(double min, double max)
Scale Copy()

Make a copy of this scale.

double ApplyScale(double input)

Calculate the ouput for [input], based on the scale’s scaling function.

int ApplyScale(int input)

Protected Functions

Scale(int id)
class ThresholdScale : public D3::QuantizeScale
#include <scales.h>

Public Functions

ThresholdScale()
ThresholdScale(bool derived)
template <typename T>
double InvertExtent(T y)
template <typename T, size_t SIZE>
Scale &SetRange(emp::array<T, SIZE> values)

Set the output values corresponding to values in the domain. Output for values in between will be interpolated with a function determined by the type of the scale. Array should contain same number of elements as the one used to set the domain.

Scale &SetRange(double min, double max)
template <typename T, size_t SIZE>
Scale &SetDomain(emp::array<T, SIZE> values)

Set the input values corresponding to values in the range. Array should contain same number of elements as the one used to set the range.

Scale &SetDomain(double min, double max)
Scale Copy()

Make a copy of this scale.

double ApplyScale(double input)

Calculate the ouput for [input], based on the scale’s scaling function.

int ApplyScale(int input)
class TimeScale : public D3::LinearScale
#include <scales.h>

Public Functions

TimeScale()
TimeScale(bool derived)
template <typename T, size_t SIZE>
LinearScale &SetRangeRound(emp::array<T, SIZE> values)
LinearScale &SetRangeRound(double min, double max)
LinearScale &SetInterpolate(std::string factory)
LinearScale &Clamp(bool clamp)
LinearScale &Nice(int count = -1)
template <typename T>
double Invert(T y)
IdentityScale &SetTicks(int count)
IdentityScale &SetTickFormat(int count, std::string format)
template <typename T, size_t SIZE>
Scale &SetRange(emp::array<T, SIZE> values)

Set the output values corresponding to values in the domain. Output for values in between will be interpolated with a function determined by the type of the scale. Array should contain same number of elements as the one used to set the domain.

Scale &SetRange(double min, double max)
template <typename T, size_t SIZE>
Scale &SetDomain(emp::array<T, SIZE> values)

Set the input values corresponding to values in the range. Array should contain same number of elements as the one used to set the range.

Scale &SetDomain(double min, double max)
Scale Copy()

Make a copy of this scale.

double ApplyScale(double input)

Calculate the ouput for [input], based on the scale’s scaling function.

int ApplyScale(int input)

Axes

Handle drawing of axes on D3 graphts.

Note
This file is part of Empirical, https://github.com/devosoft/Empirical
Copyright
Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md
Date
2017-2018

namespace D3

Functions

template <typename SCALE_X_TYPE = D3::LinearScale, typename SCALE_Y_TYPE = D3::LinearScale>
void DrawAxes(Axis<SCALE_X_TYPE> &x_axis, Axis<SCALE_Y_TYPE> &y_axis, Selection &selection)

Helper function to draw a standard set of x and y axes Takes the desired x axis, y axis, and the selection on which to draw them

template <typename SCALE_TYPE = LinearScale>
class Axis : public D3::D3_Base
#include <axis.h>

Axis objects are in charge of drawing graphical axes onto svg canvases. An axis depicts a scale, so every axis has a scale, and is templated off of the type of that scale.

Public Functions

Axis(std::string type, std::string label = "")

Consruct an axis - this doesn’t draw anything yet, but sets up the necessary infrastructure to draw it when you call the Draw method. Optionally takes a label to label the axis with. This label will also be used to create an id for the axis, to make it easier to select it later. The id will be the same as [label], but with all whitespace removed and “_axis” appended to the end.

For example, if your label was “Per capita mortality”, you could select the axis with: D3::Select("#Percapitamortality_axis");.

Axis &Draw(Selection &selection)

Draw axis on [selection] (must contain a single SVG element) with intelligent default positioning

template <typename T>
Axis &ApplyAxis(const SelectionOrTransition<T> &selection)
Axis &SetScale(SCALE_TYPE &scale)

An axis must have a scale. By default, a scale of SCALE_TYPE will be constructed, but usually you want an axis to depict a specific scale. This method points this object’s scale member variable at [scale].

SCALE_TYPE &GetScale()

Get a reference to this object’s scale.

Axis &AdjustLabelOffset(std::string offset)

Adjust the location of the label text relative to the axis (helpful if numbers are overlapping it). Can be negative. Use “em” (e.g. “2em”) to specify distance relative to font size.

Axis &Move(int x, int y)

Draw tries to make a good guess about where to place the axis, but sometimes you want to scoot it over. This method will move the axis to the x,y location specified.

template <typename T, std::size_t SIZE>
Axis &SetTickValues(emp::array<T, SIZE> values)
Axis &SetTickSize(float size)
Axis &SetTickSizeInner(float size)
Axis &SetTickSizeOuter(float size)
Axis &SetTickPadding(int padding)
Axis &SetTicks(int count)

Set the number of ticks along the axis.

Axis &SetTickFormat(std::string format)

Set the format for displaying numbers assoiated with ticks. [format] should be a format following the rules for d3.format()

template <typename T>
Axis &Rescale(double new_min, double new_max, const D3::SelectionOrTransition<T> &svg)

Adjust scale and axis to accomodate the new range of data specified by [new_min], and [new_max]. [svg] is a Selection or Transition containing the current axis. If it’s a transition, then the rescaling will be animated.

Public Members

Selection group

There are a lot of graphical elements associated with an axis, so it’s best to group them all together into an html group element. This selection holds a pointer to the group for this axis

Private Members

SCALE_TYPE scale
std::string label
std::string dom_id = ""
std::string label_offset = ""
std::string orientation

SVG Shapes and Paths

Tools to build common SVG shapes.

Note
This file is part of Empirical, https://github.com/devosoft/Empirical
Copyright
Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md
Date
2016-2018

namespace D3
class ArcGenerator : public D3::RadialAreaGenerator
#include <svg_shapes.h>

Public Functions

ArcGenerator()
void SetCornerRadius(float radius)
void SetCornerRadius(std::string radius)
void SetPadRadius(float radius)
void SetPadRadius(std::string radius)
void SetPadAngle(float angle)
void SetPadAngle(std::string angle)
void SetInnerRadius(float radius)
void SetInnerRadius(std::string radius)
void SetOuterRadius(float radius)
void SetOuterRadius(std::string radius)
void SetStartAngle(float angle)
void SetStartAngle(std::string angle)
void SetEndAngle(float angle)
void SetEndAngle(std::string angle)
void SetRadius(float radius)
void SetRadius(std::string radius)
void SetAngle(float angle)
void SetAngle(std::string angle)
void SetCurve(std::string curve)

Set the method used to interpolate a curve between points in the line. For allowed options, see the d3 documntation

void SetTension(float tension)

If interpolation is “bundle”, “cardinal”, “cardinal-open”, or “cardinal-closed”, a tension parameter is used.

void SetDefined(std::string defined)

Set a function indicating where the line is defined (i.e. valid) Can be a C++ function or a string indicating a Javascript function

template <typename T, size_t SIZE>
std::string Generate(emp::array<emp::array<T, 2>, SIZE> &data)

Generate the string describing the path associated with [data] Assumes [data] is an array of 2-element arrays describing (x,y) coordinates and makes the line that connects them

template <typename T, std::size_t SIZE>
Selection DrawShape(emp::array<emp::array<T, 2>, SIZE> &data, Selection &s)

Draws the path associated with [data] onto the [s] selection (must contain a single SVG) element).

Selection DrawShape(Dataset data, Selection s)

DrawShape will also accept a D3::Dataset.

template <typename T, std::size_t SIZE, std::size_t SIZE2>
Selection DrawShape(emp::array<emp::array<emp::array<T, 2>, SIZE>, SIZE2> &data)

If you pass a triple-nested array, it will be treated as an array of paths.

class AreaGenerator : public D3::LineGenerator
#include <svg_shapes.h>

An area is defined by two lines, with the area in between shaded.

Public Functions

AreaGenerator()
template <typename T>
void SetX0(T x)
template <typename T>
void SetY0(T y)
void SetX0(std::string x)
void SetY0(std::string y)
template <typename T>
void SetX1(T x)
template <typename T>
void SetY1(T y)
void SetX1(std::string x)
void SetY1(std::string y)
template <typename X_SCALE_TYPE>
void AddXScale(X_SCALE_TYPE &scale)

Often, when you’re drawing cartesion lines, you want to use a scale to transform numbers from range of your data to the range of pixels on your screen. Adding an X scale will cause the x-coordinates of all points on the line to be passed through that scale function. This stacks on top of whatever the current function for accessing x is (which means scales will also stack).

template <typename Y_SCALE_TYPE>
void AddYScale(Y_SCALE_TYPE &scale)

Often, when you’re drawing cartesion lines, you want to use a scale to transform numbers from range of your data to the range of pixels on your screen. Adding a Y scale will cause the y-coordinates of all points on the line to be passed through that scale function. This stacks on top of whatever the current function for accessing y is (which means scales will also stack).

void SetX(std::string x)

If the data that you are generating lines from is anything more complicated than a sequence of pairs of numbers, representing x and y (in that order), you need to tell the line generator how it should figure out what the x coordinate of a point in the line is. The parameter you pass to SetX should be instructions for doing so. It can either be a function (as a string indicating a Javascript function or as a literal C++ function) that accepts an element of the data sequence you are generating the line from, or it can be a constant, in which case the x coordinate of every point will be that constant.

Note: This function will re-set any scales that you’ve added to the X coordinate

As an example, the default function expects data like this (array of arrays): [[0,0], [1,1], [2,2]] And has (a Javascript equivalent of) this accessor: int x(emp::array<int, 2> d) {return d[0];}

If your data instead looked like this (array of Javascript objects with x and y values): [{x:0, y:0}, {x:1, y:1}, {x:2, y:2}] You might want to use an accessor like this: int x(JSONObject d) {return d.x();} Where JSONObject is a struct designed to hold necessary data from the Javascript object: struct JSONObject { EMP_BUILD_INTROSPECTIVE_TUPLE( int, x, int, y ) };

void SetY(std::string y)

If the data that you are generating lines from is anything more complicated than a sequence of pairs of numbers, representing x and y (in that order), you need to tell the line generator how it should figure out what the y coordinate of a point in the line is. The parameter you pass to SetY should be instructions for doing so. It can either be a function (as a string indicating a Javascript function or as a literal C++ function) that accepts an element of the data sequence you are generating the line from, or it can be a constant, in which case the y coordinate of every point will be that constant.

Note: This function will re-set any scales that you’ve added to the Y coordinate

As an example, the default function expects data like this (array of arrays): [[0,0], [1,1], [2,2]] And has (a Javascript equivalent of) this accessor: int x(emp::array<int, 2> d) {return d[1];}

If your data instead looked like this (array of Javascript objects with x and y values): [{x:0, y:0}, {x:1, y:1}, {x:2, y:2}] You might want to use an accessor like this: int x(JSONObject d) {return d.y();} Where JSONObject is a struct designed to hold necessary data from the Javascript object: struct JSONObject { EMP_BUILD_INTROSPECTIVE_TUPLE( int, x, int, y ) };

void SetCurve(std::string curve)

Set the method used to interpolate a curve between points in the line. For allowed options, see the d3 documntation

void SetTension(float tension)

If interpolation is “bundle”, “cardinal”, “cardinal-open”, or “cardinal-closed”, a tension parameter is used.

void SetDefined(std::string defined)

Set a function indicating where the line is defined (i.e. valid) Can be a C++ function or a string indicating a Javascript function

template <typename T, size_t SIZE>
std::string Generate(emp::array<emp::array<T, 2>, SIZE> &data)

Generate the string describing the path associated with [data] Assumes [data] is an array of 2-element arrays describing (x,y) coordinates and makes the line that connects them

template <typename T, std::size_t SIZE>
Selection DrawShape(emp::array<emp::array<T, 2>, SIZE> &data, Selection &s)

Draws the path associated with [data] onto the [s] selection (must contain a single SVG) element).

Selection DrawShape(Dataset data, Selection s)

DrawShape will also accept a D3::Dataset.

template <typename T, std::size_t SIZE, std::size_t SIZE2>
Selection DrawShape(emp::array<emp::array<emp::array<T, 2>, SIZE>, SIZE2> &data)

If you pass a triple-nested array, it will be treated as an array of paths.

class BaseLineGenerator : public D3::SvgShapeGenerator
#include <svg_shapes.h>

Base class for generating both cartesian and radial lines You don’t normally want to instantiate this - use LineGenerator or RadialLineGenerator instead.

Subclassed by D3::LineGenerator, D3::RadialLineGenerator

Public Functions

BaseLineGenerator()
void SetCurve(std::string curve)

Set the method used to interpolate a curve between points in the line. For allowed options, see the d3 documntation

void SetTension(float tension)

If interpolation is “bundle”, “cardinal”, “cardinal-open”, or “cardinal-closed”, a tension parameter is used.

void SetDefined(std::string defined)

Set a function indicating where the line is defined (i.e. valid) Can be a C++ function or a string indicating a Javascript function

template <typename T, size_t SIZE>
std::string Generate(emp::array<emp::array<T, 2>, SIZE> &data)

Generate the string describing the path associated with [data] Assumes [data] is an array of 2-element arrays describing (x,y) coordinates and makes the line that connects them

template <typename T, std::size_t SIZE>
Selection DrawShape(emp::array<emp::array<T, 2>, SIZE> &data, Selection &s)

Draws the path associated with [data] onto the [s] selection (must contain a single SVG) element).

Selection DrawShape(Dataset data, Selection s)

DrawShape will also accept a D3::Dataset.

template <typename T, std::size_t SIZE, std::size_t SIZE2>
Selection DrawShape(emp::array<emp::array<emp::array<T, 2>, SIZE>, SIZE2> &data)

If you pass a triple-nested array, it will be treated as an array of paths.

class ChordGenerator : public D3::RadialAreaGenerator
#include <svg_shapes.h>

Public Functions

ChordGenerator()
template <typename T>
void SetSource(T source)
void SetSource(std::string source)
template <typename T>
void SetTarget(T target)
void SetTarget(std::string target)
void SetInnerRadius(float radius)
void SetInnerRadius(std::string radius)
void SetOuterRadius(float radius)
void SetOuterRadius(std::string radius)
void SetStartAngle(float angle)
void SetStartAngle(std::string angle)
void SetEndAngle(float angle)
void SetEndAngle(std::string angle)
void SetRadius(float radius)
void SetRadius(std::string radius)
void SetAngle(float angle)
void SetAngle(std::string angle)
void SetCurve(std::string curve)

Set the method used to interpolate a curve between points in the line. For allowed options, see the d3 documntation

void SetTension(float tension)

If interpolation is “bundle”, “cardinal”, “cardinal-open”, or “cardinal-closed”, a tension parameter is used.

void SetDefined(std::string defined)

Set a function indicating where the line is defined (i.e. valid) Can be a C++ function or a string indicating a Javascript function

template <typename T, size_t SIZE>
std::string Generate(emp::array<emp::array<T, 2>, SIZE> &data)

Generate the string describing the path associated with [data] Assumes [data] is an array of 2-element arrays describing (x,y) coordinates and makes the line that connects them

template <typename T, std::size_t SIZE>
Selection DrawShape(emp::array<emp::array<T, 2>, SIZE> &data, Selection &s)

Draws the path associated with [data] onto the [s] selection (must contain a single SVG) element).

Selection DrawShape(Dataset data, Selection s)

DrawShape will also accept a D3::Dataset.

template <typename T, std::size_t SIZE, std::size_t SIZE2>
Selection DrawShape(emp::array<emp::array<emp::array<T, 2>, SIZE>, SIZE2> &data)

If you pass a triple-nested array, it will be treated as an array of paths.

class LineGenerator : public D3::BaseLineGenerator
#include <svg_shapes.h>

Generator for regular old (cartesian) lines.

Subclassed by D3::AreaGenerator, D3::LinkGenerator

Public Functions

LineGenerator()
template <typename X_SCALE_TYPE>
void AddXScale(X_SCALE_TYPE &scale)

Often, when you’re drawing cartesion lines, you want to use a scale to transform numbers from range of your data to the range of pixels on your screen. Adding an X scale will cause the x-coordinates of all points on the line to be passed through that scale function. This stacks on top of whatever the current function for accessing x is (which means scales will also stack).

template <typename Y_SCALE_TYPE>
void AddYScale(Y_SCALE_TYPE &scale)

Often, when you’re drawing cartesion lines, you want to use a scale to transform numbers from range of your data to the range of pixels on your screen. Adding a Y scale will cause the y-coordinates of all points on the line to be passed through that scale function. This stacks on top of whatever the current function for accessing y is (which means scales will also stack).

void SetX(std::string x)

If the data that you are generating lines from is anything more complicated than a sequence of pairs of numbers, representing x and y (in that order), you need to tell the line generator how it should figure out what the x coordinate of a point in the line is. The parameter you pass to SetX should be instructions for doing so. It can either be a function (as a string indicating a Javascript function or as a literal C++ function) that accepts an element of the data sequence you are generating the line from, or it can be a constant, in which case the x coordinate of every point will be that constant.

Note: This function will re-set any scales that you’ve added to the X coordinate

As an example, the default function expects data like this (array of arrays): [[0,0], [1,1], [2,2]] And has (a Javascript equivalent of) this accessor: int x(emp::array<int, 2> d) {return d[0];}

If your data instead looked like this (array of Javascript objects with x and y values): [{x:0, y:0}, {x:1, y:1}, {x:2, y:2}] You might want to use an accessor like this: int x(JSONObject d) {return d.x();} Where JSONObject is a struct designed to hold necessary data from the Javascript object: struct JSONObject { EMP_BUILD_INTROSPECTIVE_TUPLE( int, x, int, y ) };

void SetY(std::string y)

If the data that you are generating lines from is anything more complicated than a sequence of pairs of numbers, representing x and y (in that order), you need to tell the line generator how it should figure out what the y coordinate of a point in the line is. The parameter you pass to SetY should be instructions for doing so. It can either be a function (as a string indicating a Javascript function or as a literal C++ function) that accepts an element of the data sequence you are generating the line from, or it can be a constant, in which case the y coordinate of every point will be that constant.

Note: This function will re-set any scales that you’ve added to the Y coordinate

As an example, the default function expects data like this (array of arrays): [[0,0], [1,1], [2,2]] And has (a Javascript equivalent of) this accessor: int x(emp::array<int, 2> d) {return d[1];}

If your data instead looked like this (array of Javascript objects with x and y values): [{x:0, y:0}, {x:1, y:1}, {x:2, y:2}] You might want to use an accessor like this: int x(JSONObject d) {return d.y();} Where JSONObject is a struct designed to hold necessary data from the Javascript object: struct JSONObject { EMP_BUILD_INTROSPECTIVE_TUPLE( int, x, int, y ) };

void SetCurve(std::string curve)

Set the method used to interpolate a curve between points in the line. For allowed options, see the d3 documntation

void SetTension(float tension)

If interpolation is “bundle”, “cardinal”, “cardinal-open”, or “cardinal-closed”, a tension parameter is used.

void SetDefined(std::string defined)

Set a function indicating where the line is defined (i.e. valid) Can be a C++ function or a string indicating a Javascript function

template <typename T, size_t SIZE>
std::string Generate(emp::array<emp::array<T, 2>, SIZE> &data)

Generate the string describing the path associated with [data] Assumes [data] is an array of 2-element arrays describing (x,y) coordinates and makes the line that connects them

template <typename T, std::size_t SIZE>
Selection DrawShape(emp::array<emp::array<T, 2>, SIZE> &data, Selection &s)

Draws the path associated with [data] onto the [s] selection (must contain a single SVG) element).

Selection DrawShape(Dataset data, Selection s)

DrawShape will also accept a D3::Dataset.

template <typename T, std::size_t SIZE, std::size_t SIZE2>
Selection DrawShape(emp::array<emp::array<emp::array<T, 2>, SIZE>, SIZE2> &data)

If you pass a triple-nested array, it will be treated as an array of paths.

class LinkGenerator : public D3::LineGenerator
#include <svg_shapes.h>

Public Functions

LinkGenerator(std::string type)
void SetSource(std::string source)
void SetTarget(std::string target)
template <typename X_SCALE_TYPE>
void AddXScale(X_SCALE_TYPE &scale)

Often, when you’re drawing cartesion lines, you want to use a scale to transform numbers from range of your data to the range of pixels on your screen. Adding an X scale will cause the x-coordinates of all points on the line to be passed through that scale function. This stacks on top of whatever the current function for accessing x is (which means scales will also stack).

template <typename Y_SCALE_TYPE>
void AddYScale(Y_SCALE_TYPE &scale)

Often, when you’re drawing cartesion lines, you want to use a scale to transform numbers from range of your data to the range of pixels on your screen. Adding a Y scale will cause the y-coordinates of all points on the line to be passed through that scale function. This stacks on top of whatever the current function for accessing y is (which means scales will also stack).

void SetX(std::string x)

If the data that you are generating lines from is anything more complicated than a sequence of pairs of numbers, representing x and y (in that order), you need to tell the line generator how it should figure out what the x coordinate of a point in the line is. The parameter you pass to SetX should be instructions for doing so. It can either be a function (as a string indicating a Javascript function or as a literal C++ function) that accepts an element of the data sequence you are generating the line from, or it can be a constant, in which case the x coordinate of every point will be that constant.

Note: This function will re-set any scales that you’ve added to the X coordinate

As an example, the default function expects data like this (array of arrays): [[0,0], [1,1], [2,2]] And has (a Javascript equivalent of) this accessor: int x(emp::array<int, 2> d) {return d[0];}

If your data instead looked like this (array of Javascript objects with x and y values): [{x:0, y:0}, {x:1, y:1}, {x:2, y:2}] You might want to use an accessor like this: int x(JSONObject d) {return d.x();} Where JSONObject is a struct designed to hold necessary data from the Javascript object: struct JSONObject { EMP_BUILD_INTROSPECTIVE_TUPLE( int, x, int, y ) };

void SetY(std::string y)

If the data that you are generating lines from is anything more complicated than a sequence of pairs of numbers, representing x and y (in that order), you need to tell the line generator how it should figure out what the y coordinate of a point in the line is. The parameter you pass to SetY should be instructions for doing so. It can either be a function (as a string indicating a Javascript function or as a literal C++ function) that accepts an element of the data sequence you are generating the line from, or it can be a constant, in which case the y coordinate of every point will be that constant.

Note: This function will re-set any scales that you’ve added to the Y coordinate

As an example, the default function expects data like this (array of arrays): [[0,0], [1,1], [2,2]] And has (a Javascript equivalent of) this accessor: int x(emp::array<int, 2> d) {return d[1];}

If your data instead looked like this (array of Javascript objects with x and y values): [{x:0, y:0}, {x:1, y:1}, {x:2, y:2}] You might want to use an accessor like this: int x(JSONObject d) {return d.y();} Where JSONObject is a struct designed to hold necessary data from the Javascript object: struct JSONObject { EMP_BUILD_INTROSPECTIVE_TUPLE( int, x, int, y ) };

void SetCurve(std::string curve)

Set the method used to interpolate a curve between points in the line. For allowed options, see the d3 documntation

void SetTension(float tension)

If interpolation is “bundle”, “cardinal”, “cardinal-open”, or “cardinal-closed”, a tension parameter is used.

void SetDefined(std::string defined)

Set a function indicating where the line is defined (i.e. valid) Can be a C++ function or a string indicating a Javascript function

template <typename T, size_t SIZE>
std::string Generate(emp::array<emp::array<T, 2>, SIZE> &data)

Generate the string describing the path associated with [data] Assumes [data] is an array of 2-element arrays describing (x,y) coordinates and makes the line that connects them

template <typename T, std::size_t SIZE>
Selection DrawShape(emp::array<emp::array<T, 2>, SIZE> &data, Selection &s)

Draws the path associated with [data] onto the [s] selection (must contain a single SVG) element).

Selection DrawShape(Dataset data, Selection s)

DrawShape will also accept a D3::Dataset.

template <typename T, std::size_t SIZE, std::size_t SIZE2>
Selection DrawShape(emp::array<emp::array<emp::array<T, 2>, SIZE>, SIZE2> &data)

If you pass a triple-nested array, it will be treated as an array of paths.

class RadialAreaGenerator : public D3::RadialLineGenerator
#include <svg_shapes.h>

Subclassed by D3::ArcGenerator, D3::ChordGenerator

Public Functions

RadialAreaGenerator()
void SetInnerRadius(float radius)
void SetInnerRadius(std::string radius)
void SetOuterRadius(float radius)
void SetOuterRadius(std::string radius)
void SetStartAngle(float angle)
void SetStartAngle(std::string angle)
void SetEndAngle(float angle)
void SetEndAngle(std::string angle)
void SetRadius(float radius)
void SetRadius(std::string radius)
void SetAngle(float angle)
void SetAngle(std::string angle)
void SetCurve(std::string curve)

Set the method used to interpolate a curve between points in the line. For allowed options, see the d3 documntation

void SetTension(float tension)

If interpolation is “bundle”, “cardinal”, “cardinal-open”, or “cardinal-closed”, a tension parameter is used.

void SetDefined(std::string defined)

Set a function indicating where the line is defined (i.e. valid) Can be a C++ function or a string indicating a Javascript function

template <typename T, size_t SIZE>
std::string Generate(emp::array<emp::array<T, 2>, SIZE> &data)

Generate the string describing the path associated with [data] Assumes [data] is an array of 2-element arrays describing (x,y) coordinates and makes the line that connects them

template <typename T, std::size_t SIZE>
Selection DrawShape(emp::array<emp::array<T, 2>, SIZE> &data, Selection &s)

Draws the path associated with [data] onto the [s] selection (must contain a single SVG) element).

Selection DrawShape(Dataset data, Selection s)

DrawShape will also accept a D3::Dataset.

template <typename T, std::size_t SIZE, std::size_t SIZE2>
Selection DrawShape(emp::array<emp::array<emp::array<T, 2>, SIZE>, SIZE2> &data)

If you pass a triple-nested array, it will be treated as an array of paths.

class RadialLineGenerator : public D3::BaseLineGenerator
#include <svg_shapes.h>

Subclassed by D3::RadialAreaGenerator

Public Functions

RadialLineGenerator()
void SetRadius(float radius)
void SetRadius(std::string radius)
void SetAngle(float angle)
void SetAngle(std::string angle)
void SetCurve(std::string curve)

Set the method used to interpolate a curve between points in the line. For allowed options, see the d3 documntation

void SetTension(float tension)

If interpolation is “bundle”, “cardinal”, “cardinal-open”, or “cardinal-closed”, a tension parameter is used.

void SetDefined(std::string defined)

Set a function indicating where the line is defined (i.e. valid) Can be a C++ function or a string indicating a Javascript function

template <typename T, size_t SIZE>
std::string Generate(emp::array<emp::array<T, 2>, SIZE> &data)

Generate the string describing the path associated with [data] Assumes [data] is an array of 2-element arrays describing (x,y) coordinates and makes the line that connects them

template <typename T, std::size_t SIZE>
Selection DrawShape(emp::array<emp::array<T, 2>, SIZE> &data, Selection &s)

Draws the path associated with [data] onto the [s] selection (must contain a single SVG) element).

Selection DrawShape(Dataset data, Selection s)

DrawShape will also accept a D3::Dataset.

template <typename T, std::size_t SIZE, std::size_t SIZE2>
Selection DrawShape(emp::array<emp::array<emp::array<T, 2>, SIZE>, SIZE2> &data)

If you pass a triple-nested array, it will be treated as an array of paths.

class SvgShapeGenerator : public D3::D3_Base
#include <svg_shapes.h>

A few particularly common shapes (circles, rectangles, and ellipses) have corresponding SVG elements that you can create directly. All other shapes (including lines) must be created by specifying a “path” describing their outline. Paths are defined with a mini-language that describes how you would draw the shape with a pen. You could write them by hand, but that’s rarely desirable (especially when you’re trying to systematically represent data). So d3 provides functions for generating functions that will convert data to paths. This is a base clase for all objects that manage such functions to inherit from. You probably want to instantiate derived versions, rather than this class directly.

Subclassed by D3::BaseLineGenerator, D3::SymbolGenerator

Public Functions

template <typename T, size_t SIZE>
std::string Generate(emp::array<emp::array<T, 2>, SIZE> &data)

Generate the string describing the path associated with [data] Assumes [data] is an array of 2-element arrays describing (x,y) coordinates and makes the line that connects them

template <typename T, std::size_t SIZE>
Selection DrawShape(emp::array<emp::array<T, 2>, SIZE> &data, Selection &s)

Draws the path associated with [data] onto the [s] selection (must contain a single SVG) element).

Selection DrawShape(Dataset data, Selection s)

DrawShape will also accept a D3::Dataset.

template <typename T, std::size_t SIZE, std::size_t SIZE2>
Selection DrawShape(emp::array<emp::array<emp::array<T, 2>, SIZE>, SIZE2> &data)

If you pass a triple-nested array, it will be treated as an array of paths.

Protected Functions

SvgShapeGenerator()
class SymbolGenerator : public D3::SvgShapeGenerator
#include <svg_shapes.h>

Generate symbols (“circle”, “cross” “diamond”, “square”, “triangle-down”, “triangle-up”). Often useful for making scatter plots.

Public Functions

SymbolGenerator()
void SetType(std::string type)

Set the type of symbol generated. Must be a C++ function, a string containing the name of a Javascript function (in the current window, d3, or emp namespaces), or a string specifying a type (“circle”, “cross” “diamond”, “square”, “triangle-down”, “triangle-up”).

void SetSize(int size)

Set size in pixels to [size] - can be an int, a C++ function, or string naming a Javascript function in the current window, the emp namespace, or the d3 namespace.

template <typename T, size_t SIZE>
std::string Generate(emp::array<emp::array<T, 2>, SIZE> &data)

Generate the string describing the path associated with [data] Assumes [data] is an array of 2-element arrays describing (x,y) coordinates and makes the line that connects them

template <typename T, std::size_t SIZE>
Selection DrawShape(emp::array<emp::array<T, 2>, SIZE> &data, Selection &s)

Draws the path associated with [data] onto the [s] selection (must contain a single SVG) element).

Selection DrawShape(Dataset data, Selection s)

DrawShape will also accept a D3::Dataset.

template <typename T, std::size_t SIZE, std::size_t SIZE2>
Selection DrawShape(emp::array<emp::array<emp::array<T, 2>, SIZE>, SIZE2> &data)

If you pass a triple-nested array, it will be treated as an array of paths.

Datasets

Tools to build common SVG shapes.

Note
This file is part of Empirical, https://github.com/devosoft/Empirical
Copyright
Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md
Date
2016-2018

namespace D3
class ArcGenerator : public D3::RadialAreaGenerator
#include <svg_shapes.h>

Public Functions

ArcGenerator()
void SetCornerRadius(float radius)
void SetCornerRadius(std::string radius)
void SetPadRadius(float radius)
void SetPadRadius(std::string radius)
void SetPadAngle(float angle)
void SetPadAngle(std::string angle)
void SetInnerRadius(float radius)
void SetInnerRadius(std::string radius)
void SetOuterRadius(float radius)
void SetOuterRadius(std::string radius)
void SetStartAngle(float angle)
void SetStartAngle(std::string angle)
void SetEndAngle(float angle)
void SetEndAngle(std::string angle)
void SetRadius(float radius)
void SetRadius(std::string radius)
void SetAngle(float angle)
void SetAngle(std::string angle)
void SetCurve(std::string curve)

Set the method used to interpolate a curve between points in the line. For allowed options, see the d3 documntation

void SetTension(float tension)

If interpolation is “bundle”, “cardinal”, “cardinal-open”, or “cardinal-closed”, a tension parameter is used.

void SetDefined(std::string defined)

Set a function indicating where the line is defined (i.e. valid) Can be a C++ function or a string indicating a Javascript function

template <typename T, size_t SIZE>
std::string Generate(emp::array<emp::array<T, 2>, SIZE> &data)

Generate the string describing the path associated with [data] Assumes [data] is an array of 2-element arrays describing (x,y) coordinates and makes the line that connects them

template <typename T, std::size_t SIZE>
Selection DrawShape(emp::array<emp::array<T, 2>, SIZE> &data, Selection &s)

Draws the path associated with [data] onto the [s] selection (must contain a single SVG) element).

Selection DrawShape(Dataset data, Selection s)

DrawShape will also accept a D3::Dataset.

template <typename T, std::size_t SIZE, std::size_t SIZE2>
Selection DrawShape(emp::array<emp::array<emp::array<T, 2>, SIZE>, SIZE2> &data)

If you pass a triple-nested array, it will be treated as an array of paths.

class AreaGenerator : public D3::LineGenerator
#include <svg_shapes.h>

An area is defined by two lines, with the area in between shaded.

Public Functions

AreaGenerator()
template <typename T>
void SetX0(T x)
template <typename T>
void SetY0(T y)
void SetX0(std::string x)
void SetY0(std::string y)
template <typename T>
void SetX1(T x)
template <typename T>
void SetY1(T y)
void SetX1(std::string x)
void SetY1(std::string y)
template <typename X_SCALE_TYPE>
void AddXScale(X_SCALE_TYPE &scale)

Often, when you’re drawing cartesion lines, you want to use a scale to transform numbers from range of your data to the range of pixels on your screen. Adding an X scale will cause the x-coordinates of all points on the line to be passed through that scale function. This stacks on top of whatever the current function for accessing x is (which means scales will also stack).

template <typename Y_SCALE_TYPE>
void AddYScale(Y_SCALE_TYPE &scale)

Often, when you’re drawing cartesion lines, you want to use a scale to transform numbers from range of your data to the range of pixels on your screen. Adding a Y scale will cause the y-coordinates of all points on the line to be passed through that scale function. This stacks on top of whatever the current function for accessing y is (which means scales will also stack).

void SetX(std::string x)

If the data that you are generating lines from is anything more complicated than a sequence of pairs of numbers, representing x and y (in that order), you need to tell the line generator how it should figure out what the x coordinate of a point in the line is. The parameter you pass to SetX should be instructions for doing so. It can either be a function (as a string indicating a Javascript function or as a literal C++ function) that accepts an element of the data sequence you are generating the line from, or it can be a constant, in which case the x coordinate of every point will be that constant.

Note: This function will re-set any scales that you’ve added to the X coordinate

As an example, the default function expects data like this (array of arrays): [[0,0], [1,1], [2,2]] And has (a Javascript equivalent of) this accessor: int x(emp::array<int, 2> d) {return d[0];}

If your data instead looked like this (array of Javascript objects with x and y values): [{x:0, y:0}, {x:1, y:1}, {x:2, y:2}] You might want to use an accessor like this: int x(JSONObject d) {return d.x();} Where JSONObject is a struct designed to hold necessary data from the Javascript object: struct JSONObject { EMP_BUILD_INTROSPECTIVE_TUPLE( int, x, int, y ) };

void SetY(std::string y)

If the data that you are generating lines from is anything more complicated than a sequence of pairs of numbers, representing x and y (in that order), you need to tell the line generator how it should figure out what the y coordinate of a point in the line is. The parameter you pass to SetY should be instructions for doing so. It can either be a function (as a string indicating a Javascript function or as a literal C++ function) that accepts an element of the data sequence you are generating the line from, or it can be a constant, in which case the y coordinate of every point will be that constant.

Note: This function will re-set any scales that you’ve added to the Y coordinate

As an example, the default function expects data like this (array of arrays): [[0,0], [1,1], [2,2]] And has (a Javascript equivalent of) this accessor: int x(emp::array<int, 2> d) {return d[1];}

If your data instead looked like this (array of Javascript objects with x and y values): [{x:0, y:0}, {x:1, y:1}, {x:2, y:2}] You might want to use an accessor like this: int x(JSONObject d) {return d.y();} Where JSONObject is a struct designed to hold necessary data from the Javascript object: struct JSONObject { EMP_BUILD_INTROSPECTIVE_TUPLE( int, x, int, y ) };

void SetCurve(std::string curve)

Set the method used to interpolate a curve between points in the line. For allowed options, see the d3 documntation

void SetTension(float tension)

If interpolation is “bundle”, “cardinal”, “cardinal-open”, or “cardinal-closed”, a tension parameter is used.

void SetDefined(std::string defined)

Set a function indicating where the line is defined (i.e. valid) Can be a C++ function or a string indicating a Javascript function

template <typename T, size_t SIZE>
std::string Generate(emp::array<emp::array<T, 2>, SIZE> &data)

Generate the string describing the path associated with [data] Assumes [data] is an array of 2-element arrays describing (x,y) coordinates and makes the line that connects them

template <typename T, std::size_t SIZE>
Selection DrawShape(emp::array<emp::array<T, 2>, SIZE> &data, Selection &s)

Draws the path associated with [data] onto the [s] selection (must contain a single SVG) element).

Selection DrawShape(Dataset data, Selection s)

DrawShape will also accept a D3::Dataset.

template <typename T, std::size_t SIZE, std::size_t SIZE2>
Selection DrawShape(emp::array<emp::array<emp::array<T, 2>, SIZE>, SIZE2> &data)

If you pass a triple-nested array, it will be treated as an array of paths.

class BaseLineGenerator : public D3::SvgShapeGenerator
#include <svg_shapes.h>

Base class for generating both cartesian and radial lines You don’t normally want to instantiate this - use LineGenerator or RadialLineGenerator instead.

Subclassed by D3::LineGenerator, D3::RadialLineGenerator

Public Functions

BaseLineGenerator()
void SetCurve(std::string curve)

Set the method used to interpolate a curve between points in the line. For allowed options, see the d3 documntation

void SetTension(float tension)

If interpolation is “bundle”, “cardinal”, “cardinal-open”, or “cardinal-closed”, a tension parameter is used.

void SetDefined(std::string defined)

Set a function indicating where the line is defined (i.e. valid) Can be a C++ function or a string indicating a Javascript function

template <typename T, size_t SIZE>
std::string Generate(emp::array<emp::array<T, 2>, SIZE> &data)

Generate the string describing the path associated with [data] Assumes [data] is an array of 2-element arrays describing (x,y) coordinates and makes the line that connects them

template <typename T, std::size_t SIZE>
Selection DrawShape(emp::array<emp::array<T, 2>, SIZE> &data, Selection &s)

Draws the path associated with [data] onto the [s] selection (must contain a single SVG) element).

Selection DrawShape(Dataset data, Selection s)

DrawShape will also accept a D3::Dataset.

template <typename T, std::size_t SIZE, std::size_t SIZE2>
Selection DrawShape(emp::array<emp::array<emp::array<T, 2>, SIZE>, SIZE2> &data)

If you pass a triple-nested array, it will be treated as an array of paths.

class ChordGenerator : public D3::RadialAreaGenerator
#include <svg_shapes.h>

Public Functions

ChordGenerator()
template <typename T>
void SetSource(T source)
void SetSource(std::string source)
template <typename T>
void SetTarget(T target)
void SetTarget(std::string target)
void SetInnerRadius(float radius)
void SetInnerRadius(std::string radius)
void SetOuterRadius(float radius)
void SetOuterRadius(std::string radius)
void SetStartAngle(float angle)
void SetStartAngle(std::string angle)
void SetEndAngle(float angle)
void SetEndAngle(std::string angle)
void SetRadius(float radius)
void SetRadius(std::string radius)
void SetAngle(float angle)
void SetAngle(std::string angle)
void SetCurve(std::string curve)

Set the method used to interpolate a curve between points in the line. For allowed options, see the d3 documntation

void SetTension(float tension)

If interpolation is “bundle”, “cardinal”, “cardinal-open”, or “cardinal-closed”, a tension parameter is used.

void SetDefined(std::string defined)

Set a function indicating where the line is defined (i.e. valid) Can be a C++ function or a string indicating a Javascript function

template <typename T, size_t SIZE>
std::string Generate(emp::array<emp::array<T, 2>, SIZE> &data)

Generate the string describing the path associated with [data] Assumes [data] is an array of 2-element arrays describing (x,y) coordinates and makes the line that connects them

template <typename T, std::size_t SIZE>
Selection DrawShape(emp::array<emp::array<T, 2>, SIZE> &data, Selection &s)

Draws the path associated with [data] onto the [s] selection (must contain a single SVG) element).

Selection DrawShape(Dataset data, Selection s)

DrawShape will also accept a D3::Dataset.

template <typename T, std::size_t SIZE, std::size_t SIZE2>
Selection DrawShape(emp::array<emp::array<emp::array<T, 2>, SIZE>, SIZE2> &data)

If you pass a triple-nested array, it will be treated as an array of paths.

class LineGenerator : public D3::BaseLineGenerator
#include <svg_shapes.h>

Generator for regular old (cartesian) lines.

Subclassed by D3::AreaGenerator, D3::LinkGenerator

Public Functions

LineGenerator()
template <typename X_SCALE_TYPE>
void AddXScale(X_SCALE_TYPE &scale)

Often, when you’re drawing cartesion lines, you want to use a scale to transform numbers from range of your data to the range of pixels on your screen. Adding an X scale will cause the x-coordinates of all points on the line to be passed through that scale function. This stacks on top of whatever the current function for accessing x is (which means scales will also stack).

template <typename Y_SCALE_TYPE>
void AddYScale(Y_SCALE_TYPE &scale)

Often, when you’re drawing cartesion lines, you want to use a scale to transform numbers from range of your data to the range of pixels on your screen. Adding a Y scale will cause the y-coordinates of all points on the line to be passed through that scale function. This stacks on top of whatever the current function for accessing y is (which means scales will also stack).

void SetX(std::string x)

If the data that you are generating lines from is anything more complicated than a sequence of pairs of numbers, representing x and y (in that order), you need to tell the line generator how it should figure out what the x coordinate of a point in the line is. The parameter you pass to SetX should be instructions for doing so. It can either be a function (as a string indicating a Javascript function or as a literal C++ function) that accepts an element of the data sequence you are generating the line from, or it can be a constant, in which case the x coordinate of every point will be that constant.

Note: This function will re-set any scales that you’ve added to the X coordinate

As an example, the default function expects data like this (array of arrays): [[0,0], [1,1], [2,2]] And has (a Javascript equivalent of) this accessor: int x(emp::array<int, 2> d) {return d[0];}

If your data instead looked like this (array of Javascript objects with x and y values): [{x:0, y:0}, {x:1, y:1}, {x:2, y:2}] You might want to use an accessor like this: int x(JSONObject d) {return d.x();} Where JSONObject is a struct designed to hold necessary data from the Javascript object: struct JSONObject { EMP_BUILD_INTROSPECTIVE_TUPLE( int, x, int, y ) };

void SetY(std::string y)

If the data that you are generating lines from is anything more complicated than a sequence of pairs of numbers, representing x and y (in that order), you need to tell the line generator how it should figure out what the y coordinate of a point in the line is. The parameter you pass to SetY should be instructions for doing so. It can either be a function (as a string indicating a Javascript function or as a literal C++ function) that accepts an element of the data sequence you are generating the line from, or it can be a constant, in which case the y coordinate of every point will be that constant.

Note: This function will re-set any scales that you’ve added to the Y coordinate

As an example, the default function expects data like this (array of arrays): [[0,0], [1,1], [2,2]] And has (a Javascript equivalent of) this accessor: int x(emp::array<int, 2> d) {return d[1];}

If your data instead looked like this (array of Javascript objects with x and y values): [{x:0, y:0}, {x:1, y:1}, {x:2, y:2}] You might want to use an accessor like this: int x(JSONObject d) {return d.y();} Where JSONObject is a struct designed to hold necessary data from the Javascript object: struct JSONObject { EMP_BUILD_INTROSPECTIVE_TUPLE( int, x, int, y ) };

void SetCurve(std::string curve)

Set the method used to interpolate a curve between points in the line. For allowed options, see the d3 documntation

void SetTension(float tension)

If interpolation is “bundle”, “cardinal”, “cardinal-open”, or “cardinal-closed”, a tension parameter is used.

void SetDefined(std::string defined)

Set a function indicating where the line is defined (i.e. valid) Can be a C++ function or a string indicating a Javascript function

template <typename T, size_t SIZE>
std::string Generate(emp::array<emp::array<T, 2>, SIZE> &data)

Generate the string describing the path associated with [data] Assumes [data] is an array of 2-element arrays describing (x,y) coordinates and makes the line that connects them

template <typename T, std::size_t SIZE>
Selection DrawShape(emp::array<emp::array<T, 2>, SIZE> &data, Selection &s)

Draws the path associated with [data] onto the [s] selection (must contain a single SVG) element).

Selection DrawShape(Dataset data, Selection s)

DrawShape will also accept a D3::Dataset.

template <typename T, std::size_t SIZE, std::size_t SIZE2>
Selection DrawShape(emp::array<emp::array<emp::array<T, 2>, SIZE>, SIZE2> &data)

If you pass a triple-nested array, it will be treated as an array of paths.

class LinkGenerator : public D3::LineGenerator
#include <svg_shapes.h>

Public Functions

LinkGenerator(std::string type)
void SetSource(std::string source)
void SetTarget(std::string target)
template <typename X_SCALE_TYPE>
void AddXScale(X_SCALE_TYPE &scale)

Often, when you’re drawing cartesion lines, you want to use a scale to transform numbers from range of your data to the range of pixels on your screen. Adding an X scale will cause the x-coordinates of all points on the line to be passed through that scale function. This stacks on top of whatever the current function for accessing x is (which means scales will also stack).

template <typename Y_SCALE_TYPE>
void AddYScale(Y_SCALE_TYPE &scale)

Often, when you’re drawing cartesion lines, you want to use a scale to transform numbers from range of your data to the range of pixels on your screen. Adding a Y scale will cause the y-coordinates of all points on the line to be passed through that scale function. This stacks on top of whatever the current function for accessing y is (which means scales will also stack).

void SetX(std::string x)

If the data that you are generating lines from is anything more complicated than a sequence of pairs of numbers, representing x and y (in that order), you need to tell the line generator how it should figure out what the x coordinate of a point in the line is. The parameter you pass to SetX should be instructions for doing so. It can either be a function (as a string indicating a Javascript function or as a literal C++ function) that accepts an element of the data sequence you are generating the line from, or it can be a constant, in which case the x coordinate of every point will be that constant.

Note: This function will re-set any scales that you’ve added to the X coordinate

As an example, the default function expects data like this (array of arrays): [[0,0], [1,1], [2,2]] And has (a Javascript equivalent of) this accessor: int x(emp::array<int, 2> d) {return d[0];}

If your data instead looked like this (array of Javascript objects with x and y values): [{x:0, y:0}, {x:1, y:1}, {x:2, y:2}] You might want to use an accessor like this: int x(JSONObject d) {return d.x();} Where JSONObject is a struct designed to hold necessary data from the Javascript object: struct JSONObject { EMP_BUILD_INTROSPECTIVE_TUPLE( int, x, int, y ) };

void SetY(std::string y)

If the data that you are generating lines from is anything more complicated than a sequence of pairs of numbers, representing x and y (in that order), you need to tell the line generator how it should figure out what the y coordinate of a point in the line is. The parameter you pass to SetY should be instructions for doing so. It can either be a function (as a string indicating a Javascript function or as a literal C++ function) that accepts an element of the data sequence you are generating the line from, or it can be a constant, in which case the y coordinate of every point will be that constant.

Note: This function will re-set any scales that you’ve added to the Y coordinate

As an example, the default function expects data like this (array of arrays): [[0,0], [1,1], [2,2]] And has (a Javascript equivalent of) this accessor: int x(emp::array<int, 2> d) {return d[1];}

If your data instead looked like this (array of Javascript objects with x and y values): [{x:0, y:0}, {x:1, y:1}, {x:2, y:2}] You might want to use an accessor like this: int x(JSONObject d) {return d.y();} Where JSONObject is a struct designed to hold necessary data from the Javascript object: struct JSONObject { EMP_BUILD_INTROSPECTIVE_TUPLE( int, x, int, y ) };

void SetCurve(std::string curve)

Set the method used to interpolate a curve between points in the line. For allowed options, see the d3 documntation

void SetTension(float tension)

If interpolation is “bundle”, “cardinal”, “cardinal-open”, or “cardinal-closed”, a tension parameter is used.

void SetDefined(std::string defined)

Set a function indicating where the line is defined (i.e. valid) Can be a C++ function or a string indicating a Javascript function

template <typename T, size_t SIZE>
std::string Generate(emp::array<emp::array<T, 2>, SIZE> &data)

Generate the string describing the path associated with [data] Assumes [data] is an array of 2-element arrays describing (x,y) coordinates and makes the line that connects them

template <typename T, std::size_t SIZE>
Selection DrawShape(emp::array<emp::array<T, 2>, SIZE> &data, Selection &s)

Draws the path associated with [data] onto the [s] selection (must contain a single SVG) element).

Selection DrawShape(Dataset data, Selection s)

DrawShape will also accept a D3::Dataset.

template <typename T, std::size_t SIZE, std::size_t SIZE2>
Selection DrawShape(emp::array<emp::array<emp::array<T, 2>, SIZE>, SIZE2> &data)

If you pass a triple-nested array, it will be treated as an array of paths.

class RadialAreaGenerator : public D3::RadialLineGenerator
#include <svg_shapes.h>

Subclassed by D3::ArcGenerator, D3::ChordGenerator

Public Functions

RadialAreaGenerator()
void SetInnerRadius(float radius)
void SetInnerRadius(std::string radius)
void SetOuterRadius(float radius)
void SetOuterRadius(std::string radius)
void SetStartAngle(float angle)
void SetStartAngle(std::string angle)
void SetEndAngle(float angle)
void SetEndAngle(std::string angle)
void SetRadius(float radius)
void SetRadius(std::string radius)
void SetAngle(float angle)
void SetAngle(std::string angle)
void SetCurve(std::string curve)

Set the method used to interpolate a curve between points in the line. For allowed options, see the d3 documntation

void SetTension(float tension)

If interpolation is “bundle”, “cardinal”, “cardinal-open”, or “cardinal-closed”, a tension parameter is used.

void SetDefined(std::string defined)

Set a function indicating where the line is defined (i.e. valid) Can be a C++ function or a string indicating a Javascript function

template <typename T, size_t SIZE>
std::string Generate(emp::array<emp::array<T, 2>, SIZE> &data)

Generate the string describing the path associated with [data] Assumes [data] is an array of 2-element arrays describing (x,y) coordinates and makes the line that connects them

template <typename T, std::size_t SIZE>
Selection DrawShape(emp::array<emp::array<T, 2>, SIZE> &data, Selection &s)

Draws the path associated with [data] onto the [s] selection (must contain a single SVG) element).

Selection DrawShape(Dataset data, Selection s)

DrawShape will also accept a D3::Dataset.

template <typename T, std::size_t SIZE, std::size_t SIZE2>
Selection DrawShape(emp::array<emp::array<emp::array<T, 2>, SIZE>, SIZE2> &data)

If you pass a triple-nested array, it will be treated as an array of paths.

class RadialLineGenerator : public D3::BaseLineGenerator
#include <svg_shapes.h>

Subclassed by D3::RadialAreaGenerator

Public Functions

RadialLineGenerator()
void SetRadius(float radius)
void SetRadius(std::string radius)
void SetAngle(float angle)
void SetAngle(std::string angle)
void SetCurve(std::string curve)

Set the method used to interpolate a curve between points in the line. For allowed options, see the d3 documntation

void SetTension(float tension)

If interpolation is “bundle”, “cardinal”, “cardinal-open”, or “cardinal-closed”, a tension parameter is used.

void SetDefined(std::string defined)

Set a function indicating where the line is defined (i.e. valid) Can be a C++ function or a string indicating a Javascript function

template <typename T, size_t SIZE>
std::string Generate(emp::array<emp::array<T, 2>, SIZE> &data)

Generate the string describing the path associated with [data] Assumes [data] is an array of 2-element arrays describing (x,y) coordinates and makes the line that connects them

template <typename T, std::size_t SIZE>
Selection DrawShape(emp::array<emp::array<T, 2>, SIZE> &data, Selection &s)

Draws the path associated with [data] onto the [s] selection (must contain a single SVG) element).

Selection DrawShape(Dataset data, Selection s)

DrawShape will also accept a D3::Dataset.

template <typename T, std::size_t SIZE, std::size_t SIZE2>
Selection DrawShape(emp::array<emp::array<emp::array<T, 2>, SIZE>, SIZE2> &data)

If you pass a triple-nested array, it will be treated as an array of paths.

class SvgShapeGenerator : public D3::D3_Base
#include <svg_shapes.h>

A few particularly common shapes (circles, rectangles, and ellipses) have corresponding SVG elements that you can create directly. All other shapes (including lines) must be created by specifying a “path” describing their outline. Paths are defined with a mini-language that describes how you would draw the shape with a pen. You could write them by hand, but that’s rarely desirable (especially when you’re trying to systematically represent data). So d3 provides functions for generating functions that will convert data to paths. This is a base clase for all objects that manage such functions to inherit from. You probably want to instantiate derived versions, rather than this class directly.

Subclassed by D3::BaseLineGenerator, D3::SymbolGenerator

Public Functions

template <typename T, size_t SIZE>
std::string Generate(emp::array<emp::array<T, 2>, SIZE> &data)

Generate the string describing the path associated with [data] Assumes [data] is an array of 2-element arrays describing (x,y) coordinates and makes the line that connects them

template <typename T, std::size_t SIZE>
Selection DrawShape(emp::array<emp::array<T, 2>, SIZE> &data, Selection &s)

Draws the path associated with [data] onto the [s] selection (must contain a single SVG) element).

Selection DrawShape(Dataset data, Selection s)

DrawShape will also accept a D3::Dataset.

template <typename T, std::size_t SIZE, std::size_t SIZE2>
Selection DrawShape(emp::array<emp::array<emp::array<T, 2>, SIZE>, SIZE2> &data)

If you pass a triple-nested array, it will be treated as an array of paths.

Protected Functions

SvgShapeGenerator()
class SymbolGenerator : public D3::SvgShapeGenerator
#include <svg_shapes.h>

Generate symbols (“circle”, “cross” “diamond”, “square”, “triangle-down”, “triangle-up”). Often useful for making scatter plots.

Public Functions

SymbolGenerator()
void SetType(std::string type)

Set the type of symbol generated. Must be a C++ function, a string containing the name of a Javascript function (in the current window, d3, or emp namespaces), or a string specifying a type (“circle”, “cross” “diamond”, “square”, “triangle-down”, “triangle-up”).

void SetSize(int size)

Set size in pixels to [size] - can be an int, a C++ function, or string naming a Javascript function in the current window, the emp namespace, or the d3 namespace.

template <typename T, size_t SIZE>
std::string Generate(emp::array<emp::array<T, 2>, SIZE> &data)

Generate the string describing the path associated with [data] Assumes [data] is an array of 2-element arrays describing (x,y) coordinates and makes the line that connects them

template <typename T, std::size_t SIZE>
Selection DrawShape(emp::array<emp::array<T, 2>, SIZE> &data, Selection &s)

Draws the path associated with [data] onto the [s] selection (must contain a single SVG) element).

Selection DrawShape(Dataset data, Selection s)

DrawShape will also accept a D3::Dataset.

template <typename T, std::size_t SIZE, std::size_t SIZE2>
Selection DrawShape(emp::array<emp::array<emp::array<T, 2>, SIZE>, SIZE2> &data)

If you pass a triple-nested array, it will be treated as an array of paths.