svg_shapes.hpp
Tools to build common SVG shapes.
-
namespace D3
-
class ArcGenerator : public D3::RadialAreaGenerator
- #include <svg_shapes.hpp>
-
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()
-
inline AreaGenerator()
-
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 BaseLineGenerator()
-
class ChordGenerator : public D3::RadialAreaGenerator
- #include <svg_shapes.hpp>
-
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 ) };
-
inline LineGenerator()
-
class LinkGenerator : public D3::LineGenerator
- #include <svg_shapes.hpp>
-
class RadialAreaGenerator : public D3::RadialLineGenerator
- #include <svg_shapes.hpp>
Subclassed by D3::ArcGenerator, D3::ChordGenerator
-
class RadialLineGenerator : public D3::BaseLineGenerator
- #include <svg_shapes.hpp>
Subclassed by D3::RadialAreaGenerator
-
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
Protected Functions
-
inline SvgShapeGenerator()
-
template<typename T, size_t SIZE>
-
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.
-
inline SymbolGenerator()
-
class ArcGenerator : public D3::RadialAreaGenerator