A toolkit for working with phylogenetic data.
v0.24.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 
138  void set_label_spacer_strokes(
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 
170  void inner_node_spreading( LayoutSpreading value );
171  LayoutSpreading inner_node_spreading() const;
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 );
199  utils::SvgText& text_template();
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
void ladderize(Tree &tree, LadderizeOrder order)
Ladderize a Tree, that is, order its subtrees by size.
utils::SvgDocument to_svg_document() const
Container namespace for all symbols of genesis in order to keep them separate when used as a library...
Class for representing phylogenetic trees.
Definition: tree/tree.hpp:97
LayoutSpreading
Spreading of the nodes of a tree for drawing.
Definition: layout_base.hpp:80
LayoutShape
Shape of the tree for drawing, either circular or rectangular.
Definition: layout_base.hpp:50
LayoutType
Type of tree for drawing, either phylogram or cladogram.
Definition: layout_base.hpp:62
LayoutBase(Tree const &orig_tree, LayoutType const drawing_type=LayoutType::kCladogram, bool ladderize=true)