16#include "attributes.hpp"
22 constexpr float rad = 3.14159265358979f / 180.0f;
24 template <
class T,
class... Ts>
25 struct x :
public attribute::element_t,
public impl::io_t< x<T,Ts...>> {
26 using value_type = tag::axis::x_t;
27 using attribute::element_t::color;
28 using attribute::element_t::position;
29 using font_t = attribute::font_t;
30 using layout_t = attribute::layout_t;
31 using degree_t = attribute::degree_t;
32 using position_t = attribute::position_t;
33 using attribute_t = plot::attribute::element_t;
35 x(
const std::vector<T>& labels, Ts... args)
36 : attribute::element_t(args...), labels(labels) {
37 if( !rotate ) rotate = degree_t{-90.0} ;
38 dx.resize(labels.size()); dy.resize(labels.size());
39 set_font( arg::get<font_t>(args...) );
41 void ostream( impl::canvas_t& os )
const {
43 attribute_t text_attr;
44 text_attr.rotate = this->rotate;
45 os.group(position->x, position->y, *
this,
47 for(std::size_t i=0; i<labels.size(); i++)
48 os.text(labels[i], static_cast<std::size_t>(dx[i]), static_cast<std::size_t>(dy[i]), text_attr);
51 void set_font(
const std::optional<font_t>& font_ ){
52 this->font = font_ ? font_ : font_t{
"Ubuntu Mono",
"bold", 6};
53 this->grid = 1.6f * font->size;
54 for (std::size_t i=0; i < labels.size(); i++)
55 dy[i] = 0.0f, dx[i] = i * grid;
56 float angle = rotate->value * rad;
57 float max = utils::size_of_max_value( labels ) * 0.6f * font->size * std::abs(std::sin(angle));
59 position = position_t{
static_cast<std::size_t
>(2 * grid),
static_cast<std::size_t
>(max)};
62 return static_cast<float>(
63 std::get<std::size_t>(position->x)) - 0.5f * grid;
65 const std::vector<T>& labels;
66 std::vector<float> dx,dy;
67 float grid = 0, max_x = 0;
70 template <
class T,
class... Ts>
71 struct y :
public attribute::element_t, impl::io_t< y<T, Ts...>> {
72 using value_type = tag::axis::y_t;
73 using attribute::element_t::position;
74 using attribute::element_t::color;
75 using font_t = attribute::font_t;
76 using layout_t = attribute::layout_t;
77 using degree_t = attribute::degree_t;
78 using position_t = attribute::position_t;
79 using attribute_t = plot::attribute::element_t;
81 y(
const std::vector<T>& labels, Ts... args)
82 : attribute::element_t(args...), labels(labels) {
83 if( !rotate ) rotate = degree_t{0.0} ;
84 this->layout = plot::layout::vertical;
85 dx.resize(labels.size()); dy.resize(labels.size());
86 set_font( arg::get<font_t>(args...) );
89 void ostream( impl::canvas_t& os )
const {
92 attribute_t text_attr;
93 os.group(position->x, position->y, *
this,
95 for(std::size_t i=0; i<labels.size(); i++)
96 os.text(labels[i], static_cast<std::size_t>(dx[i]), static_cast<std::size_t>(dy[i] + .25 * grid), text_attr);
100 void set_font(
const std::optional<font_t>& font_ ){
101 this->font = font_ ? font_ : font_t{
"Ubuntu Mono",
"bold", 6};
102 this->grid = 1.2f * font->size;
103 for (std::size_t i=0; i < labels.size(); i++)
104 dx[i] = 0.0f, dy[i] = i * grid;
106 position = position_t{std::size_t{0}, std::size_t{0}};
110 return dy.back() + grid;
113 float angle = rotate->value * rad;
114 float max = utils::size_of_max_value( labels ) * 0.6f * font->size * std::abs(std::cos(angle));
116 return static_cast<float>(
117 std::get<std::size_t>(position->x)) + max;
120 const std::vector<T>& labels;
121 std::vector<float> dx,dy;
122 float grid = 0, max_x = 0, max_y = 0;