A library for working with phylogenetic and population genetic data.
v0.32.0
group.hpp
Go to the documentation of this file.
1 #ifndef GENESIS_UTILS_FORMATS_SVG_GROUP_H_
2 #define GENESIS_UTILS_FORMATS_SVG_GROUP_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 
38 
39 #include <iosfwd>
40 #include <stdexcept>
41 #include <unordered_map>
42 
43 namespace genesis {
44 namespace utils {
45 
46 // =================================================================================================
47 // Svg Group
48 // =================================================================================================
49 
50 struct SvgGroup
51 {
52 public:
53 
54  // -------------------------------------------------------------
55  // Typedefs and Enums
56  // -------------------------------------------------------------
57 
59 
60  // -------------------------------------------------------------
61  // Constructors and Rule of Five
62  // -------------------------------------------------------------
63 
64  SvgGroup() = default;
65  ~SvgGroup() = default;
66 
67  SvgGroup( SvgGroup const& ) = default;
68  SvgGroup( SvgGroup&& ) = default;
69 
70  SvgGroup& operator= ( SvgGroup const& ) = default;
71  SvgGroup& operator= ( SvgGroup&& ) = default;
72 
73  // -------------------------------------------------------------
74  // Drawing Function
75  // -------------------------------------------------------------
76 
77  SvgBox bounding_box() const;
78 
79  void write(
80  std::ostream& out,
81  size_t indent = 0,
82  SvgDrawingOptions const& options = SvgDrawingOptions()
83  ) const;
84 
90  self_type& add( SvgObject const& object );
91  self_type& add( SvgObject&& object );
92 
96  self_type& reverse();
97 
105  self_type& set_hyperlink( std::string const& value )
106  {
107  hyperlink_ = std::unordered_map<std::string, std::string>{{ "href", value }};
108  return *this;
109  }
110 
118  self_type& set_hyperlink( std::unordered_map<std::string, std::string> const& values )
119  {
120  if( values.count( "href" ) == 0 ) {
121  throw std::invalid_argument(
122  "Cannot set an SVG Group hyperlink without the `href` tag."
123  );
124  }
125  hyperlink_ = values;
126  return *this;
127  }
128 
132  self_type& operator << ( SvgObject const& object );
133  self_type& operator << ( SvgObject&& object );
134 
135  bool empty() const
136  {
137  return content_.empty();
138  }
139 
140  operator bool() const
141  {
142  return ! content_.empty();
143  }
144 
145  void clear()
146  {
147  id = "";
148  content_.clear();
149  transform.clear();
150  hyperlink_.clear();
151  }
152 
153  // -------------------------------------------------------------
154  // Properties
155  // -------------------------------------------------------------
156 
157  std::string id;
158  std::vector< SvgObject > content_;
160  std::unordered_map<std::string, std::string> hyperlink_;
161 
162 };
163 
164 } // namespace utils
165 } // namespace genesis
166 
167 #endif // include guard
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::SvgTransform::clear
void clear()
Definition: attributes.hpp:682
genesis::utils::SvgGroup::content_
std::vector< SvgObject > content_
Definition: group.hpp:158
genesis::utils::SvgGroup::hyperlink_
std::unordered_map< std::string, std::string > hyperlink_
Definition: group.hpp:160
genesis::utils::SvgBox
Definition: utils/formats/svg/helper.hpp:127
std.hpp
Provides some valuable additions to STD.
genesis::utils::SvgGroup::set_hyperlink
self_type & set_hyperlink(std::unordered_map< std::string, std::string > const &values)
Tweak to allow making parts of an image cickable.
Definition: group.hpp:118
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::SvgTransform
Definition: attributes.hpp:238
genesis::utils::SvgGroup::empty
bool empty() const
Definition: group.hpp:135
genesis::utils::SvgGroup::SvgGroup
SvgGroup()=default
genesis::utils::SvgGroup::~SvgGroup
~SvgGroup()=default
genesis::utils::SvgGroup::operator=
SvgGroup & operator=(SvgGroup const &)=default
genesis::utils::SvgGroup::bounding_box
SvgBox bounding_box() const
Definition: group.cpp:50
genesis::utils::SvgGroup::id
std::string id
Definition: group.hpp:157
attributes.hpp
genesis::utils::SvgGroup::transform
SvgTransform transform
Definition: group.hpp:159
genesis::utils::SvgGroup::add
self_type & add(SvgObject const &object)
Add an SvgObject to the document.
Definition: group.cpp:107
genesis::utils::SvgGroup::operator<<
self_type & operator<<(SvgObject const &object)
Shortcut operator for add(), which allows an even more fluent interface.
Definition: group.cpp:125
genesis::utils::SvgDrawingOptions
Definition: utils/formats/svg/helper.hpp:213
genesis::utils::SvgGroup
Definition: group.hpp:50
genesis::utils::SvgGroup::clear
void clear()
Definition: group.hpp:145
genesis::utils::SvgObject
Definition: object.hpp:46
object.hpp
genesis::utils::SvgGroup::set_hyperlink
self_type & set_hyperlink(std::string const &value)
Simple tweak to allow making parts of an image clickable.
Definition: group.hpp:105
genesis::utils::SvgGroup::write
void write(std::ostream &out, size_t indent=0, SvgDrawingOptions const &options=SvgDrawingOptions()) const
Definition: group.cpp:66
genesis::utils::SvgGroup::reverse
self_type & reverse()
Reverse the order to the stored SvgObjects.
Definition: group.cpp:119
genesis::utils::SvgGroup::self_type
SvgGroup self_type
Definition: group.hpp:58