A toolkit for working with phylogenetic data.
v0.18.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
group.cpp
Go to the documentation of this file.
1 /*
2  Genesis - A toolkit for working with phylogenetic data.
3  Copyright (C) 2014-2017 Lucas Czech
4 
5  This program is free software: you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation, either version 3 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 
18  Contact:
19  Lucas Czech <lucas.czech@h-its.org>
20  Exelixis Lab, Heidelberg Institute for Theoretical Studies
21  Schloss-Wolfsbrunnenweg 35, D-69118 Heidelberg, Germany
22 */
23 
32 
35 
36 #include <ostream>
37 
38 namespace genesis {
39 namespace utils {
40 
41 // =================================================================================================
42 // Svg Group
43 // =================================================================================================
44 
45 // -------------------------------------------------------------
46 // Members
47 // -------------------------------------------------------------
48 
50 {
51  // Get bounding box of all elements and the dimensions of the document.
52  SvgBox bbox;
53  for( auto const& elem : content_ ) {
54  bbox = SvgBox::combine( bbox, elem.bounding_box() );
55  }
56  return bbox;
57 }
58 
59 void SvgGroup::write( std::ostream& out, size_t indent, SvgDrawingOptions const& options ) const
60 {
61  out << repeat( SvgDocument::indentation_string, indent );
62  out << "<g";
63 
64  if( ! id.empty() ) {
65  out << svg_attribute( "id", id );
66  }
67  transform.write( out );
68 
69  out << ">\n";
70 
71  // Print content.
72  for( auto const& elem : content_ ) {
73  elem.write( out, indent + 1, options );
74  }
75 
76  out << repeat( SvgDocument::indentation_string, indent );
77  out << "</g>\n";
78 }
79 
80 SvgGroup& SvgGroup::add( SvgObject const& object )
81 {
82  content_.push_back( object );
83  return *this;
84 }
85 
87 {
88  content_.push_back( std::move( object ));
89  return *this;
90 }
91 
93 {
94  return add( object );
95 }
96 
98 {
99  return add( std::move( object ));
100 }
101 
102 } // namespace utils
103 } // namespace genesis
static SvgBox combine(SvgBox const &lhs, SvgBox const &rhs)
std::vector< SvgObject > content_
Definition: group.hpp:108
void write(std::ostream &out, size_t indent=0, SvgDrawingOptions const &options=SvgDrawingOptions()) const
Definition: group.cpp:59
std::string svg_attribute(std::string const &name, T const &value, std::string const &unit="")
SvgBox bounding_box() const
Definition: group.cpp:49
std::string repeat(std::string const &word, size_t times)
Take a string and repeat it a given number of times.
Definition: string.cpp:378
self_type & add(SvgObject const &object)
Add an SvgObject to the document.
Definition: group.cpp:80
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
Provides some commonly used string utility functions.
SvgTransform transform
Definition: group.hpp:109
void write(std::ostream &out) const
Definition: attributes.cpp:306
static std::string indentation_string
bool empty() const
Definition: group.hpp:98
self_type & operator<<(SvgObject const &object)
Shortcut operator for add(), which allows an even more fluent interface.
Definition: group.cpp:92