From ea9ed942341c7984cb0ec09d0fa1045938967692 Mon Sep 17 00:00:00 2001 From: AndreaGuarracino Date: Tue, 16 Apr 2024 16:41:02 -0500 Subject: [PATCH] put labes on top of everything --- src/algorithms/draw.cpp | 44 ++++++++++++++++++++++++----------------- 1 file changed, 26 insertions(+), 18 deletions(-) diff --git a/src/algorithms/draw.cpp b/src/algorithms/draw.cpp index e95c2d0b..07f989ba 100644 --- a/src/algorithms/draw.cpp +++ b/src/algorithms/draw.cpp @@ -244,6 +244,7 @@ void draw_svg(std::ostream &out, //const algorithms::color_t node_color = !node_id_to_color.empty() ? node_id_to_color[graph.get_id(handle)] : COLOR_BLACK; std::vector highlights; + std::vector nodes_with_labels; for (auto& handle : component) { algorithms::color_t color = node_id_to_color.empty() ? COLOR_BLACK : node_id_to_color[graph.get_id(handle)]; @@ -273,27 +274,11 @@ void draw_svg(std::ostream &out, // Check if this is a node with a label if (node_id_to_label_map.count(graph.get_id(handle))){ - // Collect the labels that can be put without overlapping identical ones - std::vector labels; - for (auto text : node_id_to_label_map[graph.get_id(handle)]){ - if (!is_too_close(newEndpoints.x2, newEndpoints.y2, text, 30.0, placed_labels)) { - labels.push_back(text); - } - } - // Check if there is something to label - if (!labels.empty()){ - out << ""; - for (auto text : labels){ - out << "" << text << ""; - placed_labels.emplace_back(newEndpoints.x2, newEndpoints.y2, text); // Record the label's placement - } - out << "" - << std::endl; - } + nodes_with_labels.push_back(handle); } } - // color highlights + // Color highlights and put them after grey nodes to have colored nodes on top of grey ones for (auto& handle : highlights) { Coordinates newEndpoints = adjustNodeEndpoints(handle, X, Y, scale, x_off, y_off, sparsification_factor, lengthen_left_nodes); algorithms::color_t color = node_id_to_color.empty() ? COLOR_BLACK : node_id_to_color[graph.get_id(handle)]; @@ -310,6 +295,29 @@ void draw_svg(std::ostream &out, << "\"/>" << std::endl; } + + // Render labels at the end, to have them on top of everything + for (auto& handle : nodes_with_labels) { + Coordinates newEndpoints = adjustNodeEndpoints(handle, X, Y, scale, x_off, y_off, sparsification_factor, lengthen_left_nodes); + + // Collect the labels that can be put without overlapping identical ones + std::vector labels; + for (auto text : node_id_to_label_map[graph.get_id(handle)]){ + if (!is_too_close(newEndpoints.x2, newEndpoints.y2, text, 30.0, placed_labels)) { + labels.push_back(text); + } + } + // Check if there is something to label + if (!labels.empty()){ + out << ""; + for (auto text : labels){ + out << "" << text << ""; + placed_labels.emplace_back(newEndpoints.x2, newEndpoints.y2, text); // Record the label's placement + } + out << "" + << std::endl; + } + } } // todo, edges, paths, coverage, bins