8#ifndef PLOT_ATTRIBUTE_HPP
9#define PLOT_ATTRIBUTE_HPP
24namespace plot::attribute {
25 enum class hue_t :
unsigned {
26 aliceblue=0xF0F8FF, blueviolet=0x8a2be2,
28 enum class align_t :
char {
29 left=0, center, right, top, bottom };
31 enum class weight_t :
char {
32 bold=0x0, normal=0x1, italic=0x2 };
35 using value_type = tag::degree_t;
38 struct ccw_t :
public degree_t {
39 using value_type = tag::ccw_t;
41 struct cw_t :
public degree_t {
42 using value_type = tag::cw_t;
44 struct radian_t :
public degree_t {
45 using value_type = tag::radian_t;
48 using value_type = tag::layout_t;
52 using value_type = tag::margin_t;
53 std::array<float,4> value;
58 using value_type = tag::color_t;
59 color_t(
unsigned value ) : color_t({value}){
61 color_t(
const std::initializer_list<unsigned int> list )
62 : length(list.size()), ptr(new unsigned[length]) {
63 std::copy(list.begin(),list.end(), ptr.get());
65 operator unsigned()
const {
68 const unsigned& operator[]( std::ptrdiff_t i)
const{
69 return ptr.get()[ i % length ];
76 std::shared_ptr<unsigned[]> ptr;
80 using value_type = tag::font_t;
82 font_t() : family(
"Arial, Helvetica, sans-serif"),
83 size(9), weight(
"normal") {
85 font_t(
const std::string& name,
const std::string& weight,
unsigned size)
86 : family(name), size(size), weight(weight){
88 font_t(
const std::string& name,
unsigned size)
89 : family(name), size(size), weight(
"normal"){
92 : family(
"Arial, Helvetica, sans-serif"), size(size), weight(
"normal"){
98 std::optional<std::string> style;
102 using value_type = tag::stroke_t;
106 std::optional<unsigned > linecap;
107 std::optional<unsigned> linejoin;
108 std::optional<unsigned> miterlimit;
112 using value_type = tag::opacity_t;
116 using value_type = tag::id_t;
121 using value_type = tag::position_t;
123 std::variant<std::size_t, align_t> x;
124 std::variant<std::size_t, align_t> y;
127 using value_type = tag::marker_t;
132 template <
class... Ts>
133 std::optional<degree_t> get_rotate(Ts... args){
134 using degree_tt =
typename arg::tpos<tag::degree_t, Ts...>;
135 using cw_tt =
typename arg::tpos<tag::cw_t, Ts...>;
136 using ccw_tt =
typename arg::tpos<tag::ccw_t, Ts...>;
138 auto tuple = std::forward_as_tuple(args...);
140 if constexpr( degree_tt::present )
141 return std::get<degree_tt::position>( tuple );
142 else if constexpr( cw_tt::present )
143 return std::get<cw_tt::position>( tuple );
144 else if constexpr( ccw_tt::present ){
145 return attribute::degree_t{ 360.0f - std::get<ccw_tt::position>( tuple ).value};
151 template <
class... Ts> element_t(Ts... args ){
152 auto tuple = std::forward_as_tuple(args...);
154 this->color = arg::get<color_t>(args...);
155 this->opacity = arg::get<opacity_t>(args...);
156 this->position = arg::get<position_t>(args...);
157 this->stroke = arg::get<stroke_t>(args...);
158 this->
id = arg::get<id_t>(args...);
159 this->rotate = get_rotate(args...);
161 using align_tt =
typename arg::tpos<attribute::align_t, Ts...>;
162 if constexpr( align_tt::present )
163 this->align = std::get<align_tt::value>( tuple );
164 this->layout = arg::get<layout_t>(args...);
165 this->font = arg::get<font_t>(args...);
168 std::optional<color_t> color;
169 std::optional<opacity_t> opacity;
170 std::optional<position_t> position;
171 std::optional<id_t> id;
172 std::optional<stroke_t> stroke;
173 std::optional<color_t> fill;
174 std::optional<degree_t> rotate;
175 std::optional<align_t> align;
176 std::optional<layout_t> layout;
177 std::optional<font_t> font;
178 std::optional<std::string> label;
179 std::optional<std::string> href;
184 using position = attribute::position_t;
185 using font = attribute::font_t;
186 using hue = attribute::hue_t;
187 using align = attribute::align_t;
188 using weight = attribute::weight_t;
189 using margin = attribute::margin_t;
191 using layout_t = attribute::layout_t;
192 static constexpr layout_t horizontal = attribute::layout_t{1};
193 static constexpr layout_t vertical = attribute::layout_t{0};
196 using marker_t = attribute::marker_t;
197 static constexpr marker_t rect = attribute::marker_t{1};
198 static constexpr marker_t circle = attribute::marker_t{2};
199 static constexpr marker_t hex = attribute::marker_t{3};
200 static constexpr marker_t star = attribute::marker_t{4};
201 static constexpr marker_t point = attribute::marker_t{5};
202 static constexpr marker_t line = attribute::marker_t{6};
205 using ccw = attribute::ccw_t;
206 using cw = attribute::cw_t;
207 using degree = attribute::degree_t;
208 using radian = attribute::radian_t;
209 static constexpr degree horizontal = attribute::degree_t{0.0f};
210 static constexpr degree no = attribute::degree_t{0.0f};
211 static constexpr degree vertical = attribute::degree_t{270.0f};
215 using fg = attribute::color_t;
216 using bg = attribute::color_t;
220 using value_type = tag::width_t;
224 using value_type = tag::height_t;