75 using namespace utils;
101 size_t max_text_len = 0;
103 for(
auto const& node :
tree().nodes() ) {
105 auto const& node_data = node.data<LayoutNodeData>();
106 auto const& prnt_data =
tree().
node_at( node_data.parent_index ).
data<LayoutNodeData>();
108 auto const node_x = node_data.distance *
width;
109 auto const node_y = node_data.spreading *
height;
112 auto edge_ptr =
edge_between( node,
tree().node_at( node_data.parent_index ) );
116 auto const& edge_data = edge_ptr->data<LayoutEdgeData>();
119 auto spreading_stroke = edge_data.spreading_stroke;
120 auto distance_stroke = edge_data.distance_stroke;
125 auto const dist_start_x = prnt_data.distance *
width;
126 auto const dist_start_y = node_y;
129 tree_lines << SvgLine(
130 prnt_data.distance *
width, prnt_data.spreading *
height,
131 dist_start_x, dist_start_y,
134 tree_lines << SvgLine(
135 dist_start_x, dist_start_y,
141 if( ! edge_data.shape.empty() ) {
142 auto const shape_x = ( dist_start_x + node_x ) / 2.0;
143 auto const shape_y = ( dist_start_y + node_y ) / 2.0;
145 auto es = edge_data.shape;
146 es.transform.append( SvgTransform::Translate( shape_x, shape_y ));
147 edge_shapes << std::move( es );
159 auto label_dist = node_x;
169 auto label_path = SvgPath( node_data.spacer_stroke, SvgFill( SvgFill::Type::kNone ));
170 label_path.elements.push_back(
173 label_path.elements.push_back(
176 taxa_lines << label_path;
185 if( node_data.name !=
"" ) {
193 label.text = node_data.name;
194 label.alignment_baseline = SvgText::AlignmentBaseline::kMiddle;
197 label.transform.append( SvgTransform::Translate( label_dist + 5, node_y ));
198 taxa_names << std::move( label );
199 max_text_len = std::max( max_text_len, node_data.name.size() );
203 if( ! node_data.shape.empty() ) {
204 auto ns = node_data.shape;
205 ns.transform.append( SvgTransform::Translate( node_x, node_y ));
206 node_shapes << std::move( ns );
212 tree_lines.reverse();
215 auto const marg_a = std::max( 20.0,
text_template().font.size );
216 auto const marg_r = std::max( 25.0, max_text_len *
text_template().font.size );
217 doc.margin = SvgMargin( marg_a, marg_r, marg_a, marg_a );
220 doc << std::move( tree_lines );
221 if( ! taxa_lines.empty() ) {
222 doc << std::move( taxa_lines );
224 if( ! taxa_names.empty() ) {
225 doc << std::move( taxa_names );
227 if( ! edge_shapes.empty() ) {
228 doc << std::move( edge_shapes );
230 if( ! node_shapes.empty() ) {
231 doc << std::move( node_shapes );