16#include "attributes.hpp"
21 struct text :
public attribute::element_t,
public impl::io_t<text> {
22 using value_type = tag::text_t;
23 text( std::initializer_list<std::string> il) {
24 std::copy(il.begin(), il.end(), std::back_inserter(values));
26 template <
class... Ts>
27 text(
const std::string& value , Ts... args )
28 : attribute::element_t(args...) {
29 values.push_back(value);
32 void ostream( impl::canvas_t& )
const {
35 std::vector<std::string> values;
38 template <
class... Ts>
39 struct title :
public attribute::element_t,
40 public impl::io_t<title<Ts...>> {
41 using value_type = tag::title_t;
42 using attribute::element_t::position;
43 using attribute::element_t::color;
44 using font_t = attribute::font_t;
46 title(
const std::string& txt, Ts... args)
47 : attribute::element_t(args...), txt(txt) {
48 this->font = arg::get<font_t>(args...);
52 if( !this->font ) this->font = font_t{
"Arial, Helvetica, sans-serif",
"bold", 8u};
55 void ostream( impl::canvas_t& os )
const {
58 const auto pos = position.value_or(attribute::position_t{});
59 os.text(txt, pos.x, pos.y, *
this );
61 const std::string txt;
64 template <
class... Ts>
65 struct footnote :
public attribute::element_t,
public impl::io_t<footnote<Ts...>> {
66 using value_type = tag::footnote_t;
67 footnote(
const std::string&, Ts...) {
69 void ostream( impl::canvas_t& )
const {
72 template <
class... Ts>
73 struct legend :
public attribute::element_t,
public impl::io_t<legend<Ts...>> {
74 using value_type = tag::legend_t;
75 using attribute::element_t::position;
76 using attribute::element_t::color;
77 using font_t = attribute::font_t;
78 using attribute_t = plot::attribute::element_t;
79 using align_t = plot::attribute::align_t;
80 using color_t = plot::attribute::color_t;
82 legend(Ts... args) : attribute::element_t(args...) {
84 this->font = font_t();
85 this->font->size *= 0.7;
87 this->values = arg::get<text>(args...)->values;
90 void ostream( impl::canvas_t& os )
const {
91 std::size_t font_width =
static_cast<std::size_t
>(.8 * font->size);
92 attribute_t text_attr, marker_attr, group_attr;
93 group_attr.font = this->font; group_attr.position = this->position;
94 color_t palette = color.value();
95 float width = os.grid_x ? os.grid_x.value() :
static_cast<float>(font_width);
96 float height = os.grid_y ? os.grid_y.value() :
static_cast<float>(font_width);
97 os.group(position->x, position->y, group_attr,
99 for(std::size_t i=0, j=0; i<values.size(); j +=
static_cast<std::size_t
>(6 * width), i++){
100 marker_attr.color = palette[i];
101 os.text(values[i],
static_cast<std::size_t
>(j + 1.25 * width) , std::size_t{0}, text_attr);
102 os.rect(
static_cast<float>(j), - height, .9f*width, .9f*height, 1.5f, 1.5f, marker_attr);
107 std::vector<std::string> values;
109 struct style : text {
110 using value_type = tag::style_t;
111 style(
const std::string& txt) : text( txt ) {