A toolkit for working with phylogenetic data.
v0.20.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
gradient.hpp
Go to the documentation of this file.
1 #ifndef GENESIS_UTILS_FORMATS_SVG_GRADIENT_H_
2 #define GENESIS_UTILS_FORMATS_SVG_GRADIENT_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 
37 
38 #include <cassert>
39 #include <iosfwd>
40 #include <map>
41 #include <stdexcept>
42 #include <string>
43 #include <vector>
44 
45 namespace genesis {
46 namespace utils {
47 
48 // =================================================================================================
49 // Svg Gradient Stop
50 // =================================================================================================
51 
53 {
54 public:
55 
56  // -------------------------------------------------------------
57  // Typedefs and Enums
58  // -------------------------------------------------------------
59 
61 
62  // -------------------------------------------------------------
63  // Constructors and Rule of Five
64  // -------------------------------------------------------------
65 
67  double offset,
68  Color const& stop_color = Color()
69  )
70  : offset( offset )
72  {
73  validate();
74  }
75 
76  ~SvgGradientStop() = default;
77 
78  SvgGradientStop( SvgGradientStop const& ) = default;
79  SvgGradientStop( SvgGradientStop&& ) = default;
80 
81  SvgGradientStop& operator= ( SvgGradientStop const& ) = default;
83 
84  // -------------------------------------------------------------
85  // Drawing Function
86  // -------------------------------------------------------------
87 
88  bool operator< ( self_type const& rhs ) const;
89 
90  void validate() const;
91  void write( std::ostream& out ) const;
92 
93  // -------------------------------------------------------------
94  // Properties
95  // -------------------------------------------------------------
96 
97  double offset;
99 
100 };
101 
103 {
104 public:
105 
106  // -------------------------------------------------------------
107  // Typedefs and Enums
108  // -------------------------------------------------------------
109 
111 
112  enum class SpreadMethod
113  {
114  kPad,
115  kRepeat,
116  kReflect
117  };
118 
119  // -------------------------------------------------------------
120  // Constructors and Rule of Five
121  // -------------------------------------------------------------
122 
123  SvgGradientLinear() = default;
124 
135  std::string id,
136  SvgPoint point_1 = SvgPoint( 0.0, 0.0 ),
137  SvgPoint point_2 = SvgPoint( 1.0, 0.0 )
138  )
139  : id( id )
140  , point_1( point_1 )
141  , point_2( point_2 )
142  {}
143 
144  ~SvgGradientLinear() = default;
145 
146  SvgGradientLinear( SvgGradientLinear const& ) = default;
147  SvgGradientLinear( SvgGradientLinear&& ) = default;
148 
149  SvgGradientLinear& operator= ( SvgGradientLinear const& ) = default;
151 
152  // -------------------------------------------------------------
153  // Drawing Function
154  // -------------------------------------------------------------
155 
156  void validate() const;
157  void write( std::ostream& out, size_t indent = 0 ) const;
158 
159  SvgGradientLinear& set_stops( std::map<double, Color> const& ranges );
161 
162  bool empty() const;
163 
164  // -------------------------------------------------------------
165  // Properties
166  // -------------------------------------------------------------
167 
168  std::string id;
169 
172 
174 
175  std::vector< SvgGradientStop > stops;
177 
178 };
179 
180 } // namespace utils
181 } // namespace genesis
182 
183 #endif // include guard
std::vector< SvgGradientStop > stops
Definition: gradient.hpp:175
Header of Color class.
SvgGradientStop(double offset, Color const &stop_color=Color())
Definition: gradient.hpp:66
SvgGradientLinear & add_stop(SvgGradientStop const &stop)
Definition: gradient.cpp:180
bool operator<(self_type const &rhs) const
Definition: gradient.cpp:68
std::string indent(std::string const &text, std::string const &indentation)
Indent each line of text with indentation and return the result.
Definition: string.cpp:272
void write(std::ostream &out, size_t indent=0) const
Definition: gradient.cpp:121
SvgGradientLinear(std::string id, SvgPoint point_1=SvgPoint(0.0, 0.0), SvgPoint point_2=SvgPoint(1.0, 0.0))
Construct a gradient, with an ID and a vector determining its direction.
Definition: gradient.hpp:134
SvgGradientStop & operator=(SvgGradientStop const &)=default
SvgGradientLinear & operator=(SvgGradientLinear const &)=default
SvgGradientLinear & set_stops(std::map< double, Color > const &ranges)
Definition: gradient.cpp:169
void write(std::ostream &out) const
Definition: gradient.cpp:58