A toolkit for working with phylogenetic data.
v0.19.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 <algorithm>
37 #include <ostream>
38 
39 namespace genesis {
40 namespace utils {
41 
42 // =================================================================================================
43 // Svg Group
44 // =================================================================================================
45 
46 // -------------------------------------------------------------
47 // Members
48 // -------------------------------------------------------------
49 
51 {
52  // Get bounding box of all elements and the dimensions of the document.
53  SvgBox bbox;
54  for( auto const& elem : content_ ) {
55  bbox = SvgBox::combine( bbox, elem.bounding_box() );
56  }
57  return bbox;
58 }
59 
60 void SvgGroup::write( std::ostream& out, size_t indent, SvgDrawingOptions const& options ) const
61 {
62  out << repeat( SvgDocument::indentation_string, indent );
63  out << "<g";
64 
65  if( ! id.empty() ) {
66  out << svg_attribute( "id", id );
67  }
68  transform.write( out );
69 
70  out << ">\n";
71 
72  // Print content.
73  for( auto const& elem : content_ ) {
74  elem.write( out, indent + 1, options );
75  }
76 
77  out << repeat( SvgDocument::indentation_string, indent );
78  out << "</g>\n";
79 }
80 
81 SvgGroup& SvgGroup::add( SvgObject const& object )
82 {
83  content_.push_back( object );
84  return *this;
85 }
86 
88 {
89  content_.push_back( std::move( object ));
90  return *this;
91 }
92 
94 {
95  std::reverse( content_.begin(), content_.end() );
96  return *this;
97 }
98 
100 {
101  return add( object );
102 }
103 
105 {
106  return add( std::move( object ));
107 }
108 
109 } // namespace utils
110 } // namespace genesis
static SvgBox combine(SvgBox const &lhs, SvgBox const &rhs)
std::vector< SvgObject > content_
Definition: group.hpp:119
void write(std::ostream &out, size_t indent=0, SvgDrawingOptions const &options=SvgDrawingOptions()) const
Definition: group.cpp:60
std::string svg_attribute(std::string const &name, T const &value, std::string const &unit="")
SvgBox bounding_box() const
Definition: group.cpp:50
std::string repeat(std::string const &word, size_t times)
Take a string and repeat it a given number of times.
Definition: string.cpp:377
self_type & add(SvgObject const &object)
Add an SvgObject to the document.
Definition: group.cpp:81
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:231
Provides some commonly used string utility functions.
SvgTransform transform
Definition: group.hpp:120
void write(std::ostream &out) const
Definition: attributes.cpp:304
self_type & reverse()
Reverse the order to the stored SvgObjects.
Definition: group.cpp:93
static std::string indentation_string
bool empty() const
Definition: group.hpp:102
self_type & operator<<(SvgObject const &object)
Shortcut operator for add(), which allows an even more fluent interface.
Definition: group.cpp:99