Skip to content

Commit

Permalink
fix labeling
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreaGuarracino committed Feb 7, 2024
1 parent 8c83537 commit daa1c9a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
7 changes: 3 additions & 4 deletions src/algorithms/draw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 << "<text font-family=\"Arial\" font-size=\"20\" fill=\"#000000\" stroke=\"#000000\">";

if (node_id_to_label_map.count(graph.get_id(handle))){
out << "<text font-family=\"Arial\" font-size=\"20\" fill=\"#000000\" stroke=\"#000000\" x=\"" << (X[a] * scale) - x_off << "\" y=\"" << (Y[a] * scale) - x_off << "\">";
auto vals = split(node_id_to_label_map[graph.get_id(handle)], '\n');
for (auto x : vals){
out << "<tspan x=\"" << (X[a] * scale) - x_off << "\" dy=\"1.0em\">" << x << "</tspan>";
Expand Down
20 changes: 12 additions & 8 deletions src/subcommand/draw_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit daa1c9a

Please sign in to comment.