From daa1c9a5d2dfc4d13f056335b332fd226040716a Mon Sep 17 00:00:00 2001 From: AndreaGuarracino Date: Wed, 7 Feb 2024 21:52:27 +0100 Subject: [PATCH] fix labeling --- src/algorithms/draw.cpp | 7 +++---- src/subcommand/draw_main.cpp | 20 ++++++++++++-------- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/algorithms/draw.cpp b/src/algorithms/draw.cpp index 5f6e0cda..2625a94d 100644 --- a/src/algorithms/draw.cpp +++ b/src/algorithms/draw.cpp @@ -162,10 +162,9 @@ void draw_svg(std::ostream &out, } else { highlights.push_back(handle); } - - // Check if number_bool_packing::unpack_number(handle) is even, becasue each node is present twice - if (node_id_to_label_map.count(graph.get_id(handle)) && (number_bool_packing::unpack_number(handle) % 2) == 0){ - out << ""; + + if (node_id_to_label_map.count(graph.get_id(handle))){ + out << ""; auto vals = split(node_id_to_label_map[graph.get_id(handle)], '\n'); for (auto x : vals){ out << "" << x << ""; diff --git a/src/subcommand/draw_main.cpp b/src/subcommand/draw_main.cpp index 58bfdeae..fd95633b 100644 --- a/src/subcommand/draw_main.cpp +++ b/src/subcommand/draw_main.cpp @@ -168,22 +168,26 @@ int main_draw(int argc, char **argv) { } } + bool first_handle_taken = path_range.name.empty(); // To avoid checking if there is no name to take algorithms::for_handle_in_path_range( graph, path_handle, path_range.begin.offset, path_range.end.offset, [&](const handle_t& handle) { - node_id_to_color[graph.get_id(handle)] = path_color; + const auto node_id = graph.get_id(handle); + node_id_to_color[node_id] = path_color; + + if (!first_handle_taken) { + first_handle_taken = true; + if (node_id_to_label_map.find(node_id) == node_id_to_label_map.end()) { + node_id_to_label_map[node_id] = path_range.name; + } else{ + node_id_to_label_map[node_id] = node_id_to_label_map[node_id] + "\n" + path_range.name; + } + } }); } } } - - std::cerr << node_id_to_label_map.size() << " labels found" << std::endl; - for (auto x : node_id_to_label_map) { - std::cerr << "Node " << x.first << " has label " << x.second << std::endl; - } - - const uint64_t _png_height = png_height ? args::get(png_height) : 1000; const double _png_line_width = png_line_width ? args::get(png_line_width) : 10.0; const bool _color_paths = args::get(color_paths);