svg_shapes.hpp

Tools to build common SVG shapes.

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

Public Functions

inline ArcGenerator()
inline void SetCornerRadius(float radius)
inline void SetCornerRadius(std::string radius)
inline void SetPadRadius(float radius)
inline void SetPadRadius(std::string radius)
inline void SetPadAngle(float angle)
inline void SetPadAngle(std::string angle)
class AreaGenerator : public D3::LineGenerator
#include <svg_shapes.hpp>

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

Public Functions

inline AreaGenerator()
template<typename T>
inline void SetX0(T x)
template<typename T>
inline void SetY0(T y)
inline void SetX0(std::string x)
inline void SetY0(std::string y)
template<typename T>
inline void SetX1(T x)
template<typename T>
inline void SetY1(T y)
inline void SetX1(std::string x)
inline void SetY1(std::string y)
class BaseLineGenerator : public D3::SvgShapeGenerator
#include <svg_shapes.hpp>

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

inline BaseLineGenerator()
inline 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

inline void SetTension(float tension)

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

inline 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

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

Public Functions

inline ChordGenerator()
template<typename T>
inline void SetSource(T source)
inline void SetSource(std::string source)
template<typename T>
inline void SetTarget(T target)
inline void SetTarget(std::string target)
class LineGenerator : public D3::BaseLineGenerator
#include <svg_shapes.hpp>

Generator for regular old (cartesian) lines.

Subclassed by D3::AreaGenerator, D3::LinkGenerator

Public Functions

inline LineGenerator()
template<typename X_SCALE_TYPE>
inline 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>
inline 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).

inline 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(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 ) };

inline 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(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 ) };

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

Public Functions

inline LinkGenerator(std::string type)
inline void SetSource(std::string source)
inline void SetTarget(std::string target)
class RadialAreaGenerator : public D3::RadialLineGenerator
#include <svg_shapes.hpp>

Subclassed by D3::ArcGenerator, D3::ChordGenerator

Public Functions

inline RadialAreaGenerator()
inline void SetInnerRadius(float radius)
inline void SetInnerRadius(std::string radius)
inline void SetOuterRadius(float radius)
inline void SetOuterRadius(std::string radius)
inline void SetStartAngle(float angle)
inline void SetStartAngle(std::string angle)
inline void SetEndAngle(float angle)
inline void SetEndAngle(std::string angle)
class RadialLineGenerator : public D3::BaseLineGenerator
#include <svg_shapes.hpp>

Subclassed by D3::RadialAreaGenerator

Public Functions

inline RadialLineGenerator()
inline void SetRadius(float radius)
inline void SetRadius(std::string radius)
inline void SetAngle(float angle)
inline void SetAngle(std::string angle)
class SvgShapeGenerator : public D3::D3_Base
#include <svg_shapes.hpp>

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>
inline std::string Generate(array<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>
inline Selection DrawShape(array<array<T, 2>, SIZE> &data, Selection &s)

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

inline Selection DrawShape(Dataset data, Selection s)

DrawShape will also accept a D3::Dataset.

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

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

Protected Functions

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

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

Public Functions

inline SymbolGenerator()
inline 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”).

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