A toolkit for working with phylogenetic data.
v0.20.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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-2018 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 
47 enum class LayoutShape
48 {
49  kCircular,
51 };
52 
53 enum class LayoutType
54 {
55  kPhylogram,
57 };
58 
59 // =================================================================================================
60 // Layout Base
61 // =================================================================================================
62 
64 {
65 public:
66 
67  // -------------------------------------------------------------
68  // Constructors and Rule of Five
69  // -------------------------------------------------------------
70 
71  LayoutBase() = default;
72 
74  Tree const& orig_tree,
75  LayoutType const drawing_type = LayoutType::kCladogram,
76  bool ladderize = true
77  ) {
78  type( drawing_type );
79  tree( orig_tree, ladderize );
80  }
81 
82  virtual ~LayoutBase() = default;
83 
84  LayoutBase( LayoutBase const& ) = default;
85  LayoutBase( LayoutBase&& ) = default;
86 
87  LayoutBase& operator= ( LayoutBase const& ) = default;
88  LayoutBase& operator= ( LayoutBase&& ) = default;
89 
90  // -------------------------------------------------------------
91  // Tree
92  // -------------------------------------------------------------
93 
94  void tree( Tree const& orig_tree, bool ladderize = true );
95  Tree const& tree() const;
96 
97  void set_edge_strokes( utils::SvgStroke const& stroke );
98  void set_edge_strokes( std::vector< utils::SvgStroke > const& strokes );
99 
100  void set_edge_spreading_strokes( utils::SvgStroke const& stroke );
101  void set_edge_spreading_strokes( std::vector< utils::SvgStroke > const& strokes );
102 
103  void set_edge_distance_strokes( utils::SvgStroke const& stroke );
104  void set_edge_distance_strokes( std::vector< utils::SvgStroke > const& strokes );
105 
106  void set_edge_shapes( utils::SvgGroup const& shape );
107  void set_edge_shapes( std::vector< utils::SvgGroup> const& shapes );
108 
109  void set_node_shapes( utils::SvgGroup const& shape );
110  void set_node_shapes( std::vector< utils::SvgGroup> const& shapes );
111 
112  // -------------------------------------------------------------
113  // Drawing
114  // -------------------------------------------------------------
115 
117  {
118  return to_svg_document_();
119  }
120 
121  // -------------------------------------------------------------
122  // Options
123  // -------------------------------------------------------------
124 
125  void text_template( utils::SvgText const& tt );
127  utils::SvgText const& text_template() const;
128 
129  void type( LayoutType const drawing_type );
130  LayoutType type() const;
131 
132  // -------------------------------------------------------------
133  // Protected Functions
134  // -------------------------------------------------------------
135 
136 protected:
137 
138  Tree& tree();
139 
140  // -------------------------------------------------------------
141  // Virtual Functions
142  // -------------------------------------------------------------
143 
144 protected:
145 
146  virtual utils::SvgDocument to_svg_document_() const = 0;
147 
148  // -------------------------------------------------------------
149  // Private Members
150  // -------------------------------------------------------------
151 
152 private:
153 
154  void init_tree_( Tree const& orig_tree );
155  void init_layout_();
156 
157  void set_node_spreadings_();
158  void set_node_distances_phylogram_();
159  void set_node_distances_cladogram_();
160 
161  // -------------------------------------------------------------
162  // Data Members
163  // -------------------------------------------------------------
164 
165 private:
166 
167  LayoutTree tree_;
168 
170 
171  utils::SvgText text_template_ = utils::SvgText();
172 
173 };
174 
175 } // namespace tree
176 } // namespace genesis
177 
178 #endif // include guard
void set_node_shapes(utils::SvgGroup const &shape)
LayoutType type() const
virtual ~LayoutBase()=default
LayoutBase & operator=(LayoutBase const &)=default
utils::SvgDocument to_svg_document() const
void set_edge_shapes(utils::SvgGroup const &shape)
virtual utils::SvgDocument to_svg_document_() const =0
Tree const & tree() const
Definition: layout_base.cpp:69
void set_edge_distance_strokes(utils::SvgStroke const &stroke)
Class for representing phylogenetic trees.
Definition: tree/tree.hpp:95
void ladderize(Tree &tree, LadderizeOrder order)
void set_edge_strokes(utils::SvgStroke const &stroke)
Definition: layout_base.cpp:74
LayoutBase(Tree const &orig_tree, LayoutType const drawing_type=LayoutType::kCladogram, bool ladderize=true)
Definition: layout_base.hpp:73
void set_edge_spreading_strokes(utils::SvgStroke const &stroke)
Definition: layout_base.cpp:86
utils::SvgText & text_template()