axis.hpp
Handle drawing of axes on D3 graphts.
-
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.hpp>
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
-
inline 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");
.
-
inline Axis &Draw(Selection &selection)
Draw axis on [selection] (must contain a single SVG element) with intelligent default positioning
-
template<typename T>
inline Axis &ApplyAxis(const SelectionOrTransition<T> &selection)
-
inline 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].
-
inline SCALE_TYPE &GetScale()
Get a reference to this object’s scale.
-
inline 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.
-
inline 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.
-
inline 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>
inline 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
-
inline Axis(std::string type, std::string label = "")
-
template<typename SCALE_X_TYPE = D3::LinearScale, typename SCALE_Y_TYPE = D3::LinearScale>