59 throw std::invalid_argument(
60 "Tree is not bifurcating. Cannot draw heat tree with inner node rows."
64 std::vector<size_t> tmp;
65 auto visits = std::vector<size_t>( tree.
node_count(), 0 );
67 auto const node_index = it.node().index();
71 ++visits[ node_index ];
77 tmp.push_back( node_index );
85 }
else if(
is_leaf( it.node() ) || visits[ node_index ] == 2 ) {
86 tmp.push_back( node_index );
97 auto result = std::vector<size_t>( sorting.size() );
98 for(
size_t i = 0; i < sorting.size(); ++i ) {
99 assert( sorting[i] < result.size() );
100 result[ sorting[i] ] = i;
123 std::vector<size_t>
const& order
125 if( order.size() != mat.
rows() ) {
126 throw std::invalid_argument(
"Wrong order size for reordering matrix rows." );
130 for(
size_t r = 0; r < order.size(); ++r ) {
131 assert( order[r] < mat.
rows() );
132 result.row(r) = mat.
row( order[r] ).to_vector();
174 layout.height( std::max( 100.0, 6.0 *
static_cast<double>( params.
tree.
node_count() )));
175 layout.width( layout.height() / 2.0 );
176 layout.align_labels(
true );
177 layout.text_template().anchor = SvgText::Anchor::kEnd;
187 throw std::runtime_error(
188 "Matrix has wrong size for making a heat tree. Has to be either tree.node_count(), "
189 "tree.node_count() - 1, or leaf_edge_count( tree )."
195 spacer_stroke.dash_array = std::vector<double>({ 2.0, 0.5 });
196 spacer_stroke.dash_offset = 2.0;
197 layout.set_label_spacer_strokes( spacer_stroke, layout.inner_node_spreading() );
201 std::vector<SvgStroke> strokes;
203 auto stroke = params.
stroke;
204 stroke.
color = color;
205 stroke.line_cap = SvgStroke::LineCap::kRound;
206 strokes.push_back( std::move( stroke ));
208 layout.set_edge_strokes( strokes );
226 if( ! tree_color_map.
empty() ) {
229 svg_pal_settings.direction = SvgColorBarSettings::Direction::kLeftToRight;
230 svg_pal_settings.width = layout.
width();
231 svg_pal_settings.
height = svg_pal_height;
233 auto svg_scale =
make_svg_color_bar( svg_pal_settings, tree_color_map, tree_color_norm );
242 if( ! svg_scale.first.empty() ) {
243 svg_doc.
defs.push_back( svg_scale.first );
245 svg_doc << std::move( svg_scale.second );
250 grid.pal_top = svg_pal_top;
251 grid.pal_height = svg_pal_height;
268 matrix, svg_mat_set, std::vector<std::string>{}, params.
column_labels
274 auto const svg_matrix_width = svg_matrix.bounding_box().width();
275 svg_doc << std::move( svg_matrix );
279 grid.matrix_left = svg_matrix_left;
280 grid.matrix_width = svg_matrix_width;
296 std::string matrix_bmp;
300 auto const pixel_height = layout.
height() /
static_cast<double>( matrix.
rows() - 1 );
301 auto const pixel_width = pixel_height;
303 auto const offset_y = - pixel_width / 2.0;
310 static_cast<double>( matrix.
cols() ) * pixel_width,
311 static_cast<double>( matrix.
rows() ) * pixel_height
314 img.
rendering = SvgImage::ImageRendering::kPixelated;
315 svg_doc << std::move( img );
316 svg_doc.
margin.
right +=
static_cast<double>( matrix.
cols() ) * pixel_width + 200;
319 grid.matrix_left = offset_x;
320 grid.matrix_width =
static_cast<double>( matrix.
cols() ) * pixel_width;
332 if( ! matrix_color_map.
empty() ) {
335 svg_pal_settings.direction = SvgColorBarSettings::Direction::kLeftToRight;
336 svg_pal_settings.width = grid.matrix_width;
337 svg_pal_settings.height = grid.pal_height;
339 auto svg_scale =
make_svg_color_bar( svg_pal_settings, matrix_color_map, matrix_color_norm );
343 grid.matrix_left, grid.pal_top
348 if( ! svg_scale.first.empty() ) {
349 svg_doc.
defs.push_back( svg_scale.first );
351 svg_doc << std::move( svg_scale.second );
398 auto svg_doc = layout.to_svg_document();
399 svg_doc.margin.left = svg_doc.margin.top = svg_doc.margin.bottom = svg_doc.margin.right = 200;
403 layout, tree_color_map, tree_color_norm, svg_doc, grid
419 matrix_color_map, matrix_color_norm, svg_doc, grid