A toolkit for working with phylogenetic data.
v0.19.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
tickmarks.hpp
Go to the documentation of this file.
1 #ifndef GENESIS_UTILS_TOOLS_TICKMARKS_H_
2 #define GENESIS_UTILS_TOOLS_TICKMARKS_H_
3 
4 /*
5  Genesis - A toolkit for working with phylogenetic data.
6  Copyright (C) 2014-2018 Lucas Czech and HITS gGmbH
7 
8  This program is free software: you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation, either version 3 of the License, or
11  (at your option) any later version.
12 
13  This program is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with this program. If not, see <http://www.gnu.org/licenses/>.
20 
21  Contact:
22  Lucas Czech <lucas.czech@h-its.org>
23  Exelixis Lab, Heidelberg Institute for Theoretical Studies
24  Schloss-Wolfsbrunnenweg 35, D-69118 Heidelberg, Germany
25 */
26 
34 #include <cstddef>
35 #include <limits>
36 #include <vector>
37 
38 namespace genesis {
39 namespace utils {
40 
41 // =================================================================================================
42 // Tickmarks
43 // =================================================================================================
44 
48 struct Tickmarks
49 {
50 public:
51 
52  // -------------------------------------------------------------------------
53  // Helper Structs
54  // -------------------------------------------------------------------------
55 
56  struct LabeledTick
57  {
58  LabeledTick( double rel_pos, double lab )
59  : relative_position( rel_pos )
60  , label( lab )
61  {}
62 
64  double label;
65  };
66 
67  // -------------------------------------------------------------------------
68  // Constructors and Rule of Five
69  // -------------------------------------------------------------------------
70 
71  Tickmarks() = default;
72  ~Tickmarks() = default;
73 
74  Tickmarks(Tickmarks const&) = default;
75  Tickmarks(Tickmarks&&) = default;
76 
77  Tickmarks& operator= (Tickmarks const&) = default;
78  Tickmarks& operator= (Tickmarks&&) = default;
79 
80  // -------------------------------------------------------------------------
81  // Drudges
82  // -------------------------------------------------------------------------
83 
91  static double step_size( double interval_size, size_t target_steps );
92 
99  std::vector<double> linear_ticks( double min, double max, size_t target_steps );
100 
109  std::vector<LabeledTick> linear_labels( double min, double max, size_t target_steps );
110 
125  std::vector<LabeledTick> logarithmic_labels( double min, double max, double base = 10.0 );
126 
127  // -------------------------------------------------------------------------
128  // Data Members
129  // -------------------------------------------------------------------------
130 
131 public:
132 
136  bool include_min = true;
137 
141  bool include_max = true;
142 
147  bool undershoot_at_min = false;
148 
153  bool overshoot_at_max = false;
154 
158  double relative_epsilon = std::numeric_limits<double>::epsilon();
159 
160 };
161 
162 } // namespace utils
163 } // namespace genesis
164 
165 #endif // include guard
std::vector< double > linear_ticks(double min, double max, size_t target_steps)
Calculate a set of ticks that linearily span from min to max in approximately target_steps many steps...
Definition: tickmarks.cpp:83
LabeledTick(double rel_pos, double lab)
Definition: tickmarks.hpp:58
bool undershoot_at_min
Should the lowest value in the resulting list of ticks be below the provided min value (true) or not ...
Definition: tickmarks.hpp:147
double relative_epsilon
Relative epsilon used to exclude two tickmarks that are too close to each other.
Definition: tickmarks.hpp:158
Tickmarks & operator=(Tickmarks const &)=default
static double step_size(double interval_size, size_t target_steps)
Calculate a step size that fills the interval_size in approximately target_steps many steps...
Definition: tickmarks.cpp:47
bool overshoot_at_max
Should the highest value in the resulting list of ticks be above the provided max value (true) or not...
Definition: tickmarks.hpp:153
std::vector< LabeledTick > linear_labels(double min, double max, size_t target_steps)
Return a set of labels with relative positions between min and max, where the labels correspond to th...
Definition: tickmarks.cpp:140
bool include_max
Should the provided max value be included in the resulting list of ticks or not.
Definition: tickmarks.hpp:141
bool include_min
Should the provided min value be included in the resulting list of ticks or not.
Definition: tickmarks.hpp:136
std::vector< LabeledTick > logarithmic_labels(double min, double max, double base=10.0)
Return a set of labels with relative positions between min and max, where the labels correspond to lo...
Definition: tickmarks.cpp:155
Helper class to find "nice" tickmark intervals for creating scales and axes.
Definition: tickmarks.hpp:48