A library for working with phylogenetic and population genetic data.
v0.27.0
layout_base.hpp
Go to the documentation of this file.
1 #ifndef GENESIS_TREE_DRAWING_LAYOUT_BASE_H_
2 #define GENESIS_TREE_DRAWING_LAYOUT_BASE_H_
3 
4 /*
5  Genesis - A toolkit for working with phylogenetic data.
6  Copyright (C) 2014-2019 Lucas Czech and HITS gGmbH
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 
36 
37 #include <string>
38 #include <vector>
39 
40 namespace genesis {
41 namespace tree {
42 
43 // =================================================================================================
44 // Layout Shape and Type
45 // =================================================================================================
46 
50 enum class LayoutShape
51 {
52  kCircular,
54 };
55 
62 enum class LayoutType
63 {
64  kPhylogram,
66 };
67 
80 enum class LayoutSpreading
81 {
84  kAllNodes
85 };
86 
87 // =================================================================================================
88 // Layout Base
89 // =================================================================================================
90 
92 {
93 public:
94 
95  // -------------------------------------------------------------
96  // Constructors and Rule of Five
97  // -------------------------------------------------------------
98 
99  LayoutBase() = default;
100 
102  Tree const& orig_tree,
103  LayoutType const drawing_type = LayoutType::kCladogram,
104  bool ladderize = true
105  ) {
106  type( drawing_type );
107  tree( orig_tree, ladderize );
108  }
109 
110  virtual ~LayoutBase() = default;
111 
112  LayoutBase( LayoutBase const& ) = default;
113  LayoutBase( LayoutBase&& ) = default;
114 
115  LayoutBase& operator= ( LayoutBase const& ) = default;
116  LayoutBase& operator= ( LayoutBase&& ) = default;
117 
118  // -------------------------------------------------------------
119  // Tree
120  // -------------------------------------------------------------
121 
122  void tree( Tree const& orig_tree, bool ladderize = true );
123  Tree const& tree() const;
124 
125  // -------------------------------------------------------------
126  // Edge Strokes
127  // -------------------------------------------------------------
128 
129  void set_edge_strokes( utils::SvgStroke const& stroke );
130  void set_edge_strokes( std::vector< utils::SvgStroke > const& strokes );
131 
132  void set_edge_spreading_strokes( utils::SvgStroke const& stroke );
133  void set_edge_spreading_strokes( std::vector< utils::SvgStroke > const& strokes );
134 
135  void set_edge_distance_strokes( utils::SvgStroke const& stroke );
136  void set_edge_distance_strokes( std::vector< utils::SvgStroke > const& strokes );
137 
139  utils::SvgStroke const& stroke,
141  );
142  void set_label_spacer_strokes( std::vector< utils::SvgStroke > const& strokes );
143 
144  // -------------------------------------------------------------
145  // Edge and Node Shapes
146  // -------------------------------------------------------------
147 
148  void set_edge_shapes( utils::SvgGroup const& shape );
149  void set_edge_shapes( std::vector< utils::SvgGroup> const& shapes );
150 
151  void set_node_shapes( utils::SvgGroup const& shape );
152  void set_node_shapes( std::vector< utils::SvgGroup> const& shapes );
153 
154  // -------------------------------------------------------------
155  // Drawing
156  // -------------------------------------------------------------
157 
159  {
160  return to_svg_document_();
161  }
162 
163  // -------------------------------------------------------------
164  // Options
165  // -------------------------------------------------------------
166 
167  void type( LayoutType const drawing_type );
168  LayoutType type() const;
169 
172 
188  void align_labels( bool value );
189  bool align_labels() const;
190 
195  void extra_spacer( double value );
196  double extra_spacer() const;
197 
198  void text_template( utils::SvgText const& tt );
200  utils::SvgText const& text_template() const;
201 
202  // -------------------------------------------------------------
203  // Protected Functions
204  // -------------------------------------------------------------
205 
206 protected:
207 
208  Tree& tree();
209 
210  // -------------------------------------------------------------
211  // Virtual Functions
212  // -------------------------------------------------------------
213 
214 protected:
215 
216  virtual utils::SvgDocument to_svg_document_() const = 0;
217 
218  // -------------------------------------------------------------
219  // Private Members
220  // -------------------------------------------------------------
221 
222 private:
223 
224  void init_tree_( Tree const& orig_tree );
225  void init_layout_();
226 
227  void set_node_spreadings_leaves_();
228  void set_node_spreadings_all_( LayoutSpreading spreading );
229  void set_node_distances_phylogram_();
230  void set_node_distances_cladogram_();
231 
232  // -------------------------------------------------------------
233  // Data Members
234  // -------------------------------------------------------------
235 
236 private:
237 
238  LayoutTree tree_;
239 
241  LayoutSpreading inner_node_spreading_ = LayoutSpreading::kLeafNodesOnly;
242 
243  bool align_labels_ = false;
244  double extra_spacer_ = 10.0;
245 
246  utils::SvgText text_template_ = utils::SvgText();
247 
248 };
249 
250 } // namespace tree
251 } // namespace genesis
252 
253 #endif // include guard
genesis::tree::LayoutShape
LayoutShape
Shape of the tree for drawing, either circular or rectangular.
Definition: layout_base.hpp:50
genesis::tree::LayoutBase::set_edge_distance_strokes
void set_edge_distance_strokes(utils::SvgStroke const &stroke)
Definition: layout_base.cpp:115
genesis::tree::LayoutBase::to_svg_document
utils::SvgDocument to_svg_document() const
Definition: layout_base.hpp:158
genesis::tree::LayoutBase::set_edge_shapes
void set_edge_shapes(utils::SvgGroup const &shape)
Definition: layout_base.cpp:203
genesis::tree::LayoutBase::type
LayoutType type() const
Definition: layout_base.cpp:500
genesis::tree::LayoutSpreading::kLeafNodesOnly
@ kLeafNodesOnly
genesis::tree::LayoutBase::set_node_shapes
void set_node_shapes(utils::SvgGroup const &shape)
Definition: layout_base.cpp:227
genesis::tree::LayoutBase
Definition: layout_base.hpp:91
genesis::tree::LayoutType
LayoutType
Type of tree for drawing, either phylogram or cladogram.
Definition: layout_base.hpp:62
genesis::tree::LayoutBase::extra_spacer
double extra_spacer() const
Definition: layout_base.cpp:533
genesis::tree::LayoutBase::~LayoutBase
virtual ~LayoutBase()=default
genesis::tree::LayoutType::kPhylogram
@ kPhylogram
genesis::tree::LayoutBase::set_edge_spreading_strokes
void set_edge_spreading_strokes(utils::SvgStroke const &stroke)
Definition: layout_base.cpp:91
genesis::tree::LayoutBase::tree
Tree const & tree() const
Definition: layout_base.cpp:65
genesis::tree::LayoutBase::set_label_spacer_strokes
void set_label_spacer_strokes(utils::SvgStroke const &stroke, LayoutSpreading spreading=LayoutSpreading::kLeafNodesOnly)
Definition: layout_base.cpp:139
genesis::tree::ladderize
void ladderize(Tree &tree, LadderizeOrder order)
Ladderize a Tree, that is, order its subtrees by size.
Definition: tree/function/manipulation.cpp:840
genesis::tree::LayoutBase::set_edge_strokes
void set_edge_strokes(utils::SvgStroke const &stroke)
Definition: layout_base.cpp:79
genesis::utils::SvgStroke
Definition: attributes.hpp:49
genesis::tree::LayoutBase::to_svg_document_
virtual utils::SvgDocument to_svg_document_() const =0
genesis::tree::Tree
Class for representing phylogenetic trees.
Definition: tree/tree.hpp:97
genesis::tree::LayoutShape::kCircular
@ kCircular
genesis::tree::LayoutSpreading::kAllNodes
@ kAllNodes
genesis::tree::LayoutBase::inner_node_spreading
LayoutSpreading inner_node_spreading() const
Definition: layout_base.cpp:513
genesis::tree::LayoutBase::operator=
LayoutBase & operator=(LayoutBase const &)=default
genesis::tree::LayoutBase::LayoutBase
LayoutBase(Tree const &orig_tree, LayoutType const drawing_type=LayoutType::kCladogram, bool ladderize=true)
Definition: layout_base.hpp:101
genesis::tree::LayoutShape::kRectangular
@ kRectangular
genesis::tree::LayoutBase::LayoutBase
LayoutBase()=default
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::tree::LayoutBase::text_template
utils::SvgText & text_template()
Definition: layout_base.cpp:543
genesis::utils::SvgDocument
Definition: svg/document.hpp:49
genesis::tree::LayoutType::kCladogram
@ kCladogram
genesis::utils::SvgText
Definition: text.hpp:47
svg.hpp
layout_tree.hpp
genesis::utils::SvgGroup
Definition: group.hpp:50
genesis::tree::LayoutBase::align_labels
bool align_labels() const
Definition: layout_base.cpp:523
genesis::tree::LayoutSpreading::kAllNodesButRoot
@ kAllNodesButRoot
genesis::tree::LayoutSpreading
LayoutSpreading
Spreading of the nodes of a tree for drawing.
Definition: layout_base.hpp:80