forked from alandefreitas/matplotplusplus
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlegend.h
More file actions
166 lines (128 loc) 路 4.85 KB
/
Copy pathlegend.h
File metadata and controls
166 lines (128 loc) 路 4.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
//
// Created by Alan Freitas on 2020-07-04.
//
#ifndef MATPLOTPLUSPLUS_LEGEND_H
#define MATPLOTPLUSPLUS_LEGEND_H
#include <array>
#include <matplot/core/line_spec.h>
#include <matplot/util/handle_types.h>
#include <string>
#include <vector>
namespace matplot {
class axes_type;
class MATPLOT_EXPORTS legend {
public:
enum class horizontal_alignment { left, center, right };
enum class vertical_alignment { top, center, bottom };
enum class general_alignment {
topleft,
top,
topright,
left,
center,
right,
bottomleft,
bottom,
bottomright,
};
public:
legend() = default;
legend(class axes_type *parent);
legend(class axes_type *parent,
std::initializer_list<std::string> names);
legend(class axes_type *parent, const std::vector<std::string> &names);
public /* useful functions */:
void touch();
const std::string &operator[](size_t index) const;
std::string &operator[](size_t index);
bool empty() const;
size_t size() const;
std::vector<std::string>::const_iterator begin() const;
std::vector<std::string>::iterator begin();
std::vector<std::string>::const_iterator end() const;
std::vector<std::string>::iterator end();
public /* getter and setters */:
std::vector<std::string> &strings();
const std::vector<std::string> &strings() const;
void strings(const std::vector<std::string> &strings);
void inside(bool inside);
bool inside() const;
bool label_after_sample() const;
void label_after_sample(bool label_after_sample);
bool box() const;
void box(bool box);
const line_spec &box_line() const;
line_spec &box_line();
void box_line(const line_spec &box_line);
bool vertical() const;
void vertical(bool vertical);
bool horizontal() const;
void horizontal(bool horizontal);
// Legend location given a reference position
// If the position is automatic, the reference is the xlim
// If the position is a manual point, the reference is this point
general_alignment location() const;
void location(general_alignment alignment);
horizontal_alignment horizontal_location() const;
void horizontal_location(horizontal_alignment horizontal_location);
vertical_alignment vertical_location() const;
void vertical_location(vertical_alignment vertical_location);
bool manual_position() const;
void manual_position(bool manual_position);
const std::array<float, 2> &position() const;
void position(const std::array<float, 2> &position);
bool invert() const;
void invert(bool invert);
size_t num_columns() const;
void num_columns(size_t num_columns);
size_t num_rows() const;
void num_rows(size_t num_rows);
bool visible() const;
void visible(bool visible);
const std::string &title() const;
void title(std::string_view title);
const std::string &font_name() const;
void font_name(std::string_view font_name);
float font_size() const;
void font_size(float font_size);
const std::string &font_angle() const;
void font_angle(std::string_view font_angle);
const std::string &font_weight() const;
void font_weight(std::string_view font_weight);
const color_array &text_color() const;
void text_color(const color_array &text_color);
template <class T> void text_color(T c) { text_color(to_array(c)); }
bool opaque() const;
void opaque(bool opaque);
private:
// The keys
std::vector<std::string> strings_{};
std::string title_{""};
// Positioning
bool inside_{true};
bool manual_position_{false};
std::array<float, 2> position_{0.0, 0.0};
horizontal_alignment horizontal_location_{horizontal_alignment::right};
vertical_alignment vertical_location_{vertical_alignment::top};
// Font
std::string font_name_{"Helvetica"};
float font_size_{11};
std::string font_angle_{"normal"};
std::string font_weight_{"bold"};
color_array text_color_{0., 0, 0, 0};
// Style
bool box_{true};
line_spec box_line_{"k-"};
// color_array color_{0., 1, 1, 1};
bool vertical_{true};
bool label_after_sample_{true};
bool invert_{false};
bool visible_{true};
bool opaque_{true};
size_t num_columns_{0};
size_t num_rows_{0};
// Parent xlim
class axes_type *parent_{nullptr};
};
} // namespace matplot
#endif // MATPLOTPLUSPLUS_LEGEND_H