A library for working with phylogenetic and population genetic data.
v0.32.0
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-2023 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 <lczech@carnegiescience.edu>
23  Department of Plant Biology, Carnegie Institution For Science
24  260 Panama Street, Stanford, CA 94305, USA
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 const& 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
genesis::utils::Color
Definition: color.hpp:47
helper.hpp
genesis::utils::indent
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:719
genesis::utils::SvgGradientLinear::id
std::string id
Definition: gradient.hpp:168
genesis::utils::SvgGradientLinear::stops
std::vector< SvgGradientStop > stops
Definition: gradient.hpp:175
genesis::utils::SvgGradientStop::self_type
SvgGradientStop self_type
Definition: gradient.hpp:60
genesis::utils::SvgGradientStop::~SvgGradientStop
~SvgGradientStop()=default
genesis::utils::SvgGradientLinear::point_2
SvgPoint point_2
Definition: gradient.hpp:171
genesis::utils::SvgGradientLinear::add_stop
SvgGradientLinear & add_stop(SvgGradientStop const &stop)
Definition: gradient.cpp:180
genesis::utils::SvgPoint
Definition: utils/formats/svg/helper.hpp:57
genesis::utils::SvgGradientLinear::spread_method
SpreadMethod spread_method
Definition: gradient.hpp:173
genesis::utils::SvgGradientLinear::SvgGradientLinear
SvgGradientLinear(std::string const &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
genesis::utils::SvgGradientStop::operator<
bool operator<(self_type const &rhs) const
Definition: gradient.cpp:68
genesis::utils::SvgGradientStop::SvgGradientStop
SvgGradientStop(double offset, Color const &stop_color=Color())
Definition: gradient.hpp:66
genesis::utils::SvgGradientLinear::SpreadMethod
SpreadMethod
Definition: gradient.hpp:112
genesis::utils::SvgGradientLinear::write
void write(std::ostream &out, size_t indent=0) const
Definition: gradient.cpp:121
genesis
Container namespace for all symbols of genesis in order to keep them separate when used as a library.
Definition: placement/formats/edge_color.cpp:42
genesis::utils::SvgGradientLinear::SvgGradientLinear
SvgGradientLinear()=default
genesis::utils::SvgGradientLinear
Definition: gradient.hpp:102
genesis::utils::SvgGradientStop::operator=
SvgGradientStop & operator=(SvgGradientStop const &)=default
genesis::utils::SvgGradientLinear::~SvgGradientLinear
~SvgGradientLinear()=default
genesis::utils::SvgTransform
Definition: attributes.hpp:238
genesis::utils::SvgGradientLinear::SpreadMethod::kReflect
@ kReflect
color.hpp
Header of Color class.
genesis::utils::SvgGradientLinear::operator=
SvgGradientLinear & operator=(SvgGradientLinear const &)=default
genesis::utils::SvgGradientLinear::set_stops
SvgGradientLinear & set_stops(std::map< double, Color > const &ranges)
Definition: gradient.cpp:169
genesis::utils::SvgGradientLinear::SpreadMethod::kPad
@ kPad
attributes.hpp
genesis::utils::SvgGradientLinear::transform
SvgTransform transform
Definition: gradient.hpp:176
genesis::utils::SvgGradientLinear::SpreadMethod::kRepeat
@ kRepeat
genesis::utils::SvgGradientStop::write
void write(std::ostream &out) const
Definition: gradient.cpp:58
genesis::utils::SvgGradientStop::offset
double offset
Definition: gradient.hpp:97
genesis::utils::SvgGradientStop
Definition: gradient.hpp:52
genesis::utils::SvgGradientLinear::validate
void validate() const
Definition: gradient.cpp:77
genesis::utils::SvgGradientLinear::point_1
SvgPoint point_1
Definition: gradient.hpp:170
genesis::utils::SvgGradientStop::validate
void validate() const
Definition: gradient.cpp:47
genesis::utils::SvgGradientLinear::empty
bool empty() const
Definition: gradient.cpp:186
genesis::utils::SvgGradientStop::stop_color
Color stop_color
Definition: gradient.hpp:98