A toolkit for working with phylogenetic data.
v0.18.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-2017 Lucas Czech
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  void validate() const;
89  void write( std::ostream& out ) const;
90 
91  // -------------------------------------------------------------
92  // Properties
93  // -------------------------------------------------------------
94 
95  double offset;
97 
98 };
99 
101 {
102 public:
103 
104  // -------------------------------------------------------------
105  // Typedefs and Enums
106  // -------------------------------------------------------------
107 
109 
110  enum class SpreadMethod
111  {
112  kPad,
113  kRepeat,
114  kReflect
115  };
116 
117  // -------------------------------------------------------------
118  // Constructors and Rule of Five
119  // -------------------------------------------------------------
120 
131  std::string id,
132  SvgPoint point_1 = SvgPoint( 0.0, 0.0 ),
133  SvgPoint point_2 = SvgPoint( 1.0, 0.0 )
134  )
135  : id( id )
136  , point_1( point_1 )
137  , point_2( point_2 )
138  {
139  validate();
140  }
141 
142  ~SvgGradientLinear() = default;
143 
144  SvgGradientLinear( SvgGradientLinear const& ) = default;
145  SvgGradientLinear( SvgGradientLinear&& ) = default;
146 
147  SvgGradientLinear& operator= ( SvgGradientLinear const& ) = default;
149 
150  // -------------------------------------------------------------
151  // Drawing Function
152  // -------------------------------------------------------------
153 
154  void validate() const;
155  void write( std::ostream& out, size_t indent = 0 ) const;
156 
157  SvgGradientLinear& set_stops( std::map<double, Color> const& ranges );
158 
159  // -------------------------------------------------------------
160  // Properties
161  // -------------------------------------------------------------
162 
163  std::string id;
164 
167 
169 
170  std::vector< SvgGradientStop > stops;
172 
173 };
174 
175 } // namespace utils
176 } // namespace genesis
177 
178 #endif // include guard
std::vector< SvgGradientStop > stops
Definition: gradient.hpp:170
Header of Color class.
SvgGradientStop(double offset, Color const &stop_color=Color())
Definition: gradient.hpp:66
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:158
void write(std::ostream &out, size_t indent=0) const
Definition: gradient.cpp:82
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:130
SvgGradientStop & operator=(SvgGradientStop const &)=default
SvgGradientLinear & operator=(SvgGradientLinear const &)=default
SvgGradientLinear & set_stops(std::map< double, Color > const &ranges)
Definition: gradient.cpp:125
void write(std::ostream &out) const
Definition: gradient.cpp:55