GraphvizEdge::GraphvizEdge(SVG::SVGElement &svg_g_element)
: m_edgeop(svg_g_element.graphviz_id), m_svg_g_element(svg_g_element) {}
+void GraphvizEdge::add_bbox() { m_svg_g_element.add_bbox(); }
+
std::string_view GraphvizEdge::edgeop() const { return m_edgeop; }
std::string GraphvizEdge::fillcolor() const {
GraphvizEdge() = delete;
explicit GraphvizEdge(SVG::SVGElement &svg_g_element);
+ /// Add an SVG `rect` element to the edge's corresponding `g` element. The
+ /// `rect` is represes the bounding box of the edge.
+ void add_bbox();
/// Return the bounding box of the edge
SVG::SVGRect bbox() const;
/// Return the center of the edge's bounding box
throw std::runtime_error{
fmt::format("Unknown edge '{}' in graph '{}'", edgeop, m_graph_id)};
}
+
+void GraphvizGraph::add_bboxes() {
+ for (auto &node : m_nodes) {
+ node.add_bbox();
+ }
+ for (auto &edge : m_edges) {
+ edge.add_bbox();
+ }
+}
GraphvizGraph() = delete;
explicit GraphvizGraph(SVG::SVGElement &g_element);
+ /// Add SVG `rect` elements representing the bounding boxes of nodes and edges
+ /// to the corresponding `g` elements
+ void add_bboxes();
/// Add a Graphviz edge to the graph
void add_edge(SVG::SVGElement &svg_g_element);
/// Add a Graphviz node to the graph
GraphvizNode::GraphvizNode(SVG::SVGElement &svg_element)
: m_node_id(svg_element.graphviz_id), m_svg_g_element(svg_element) {}
+void GraphvizNode::add_bbox() { m_svg_g_element.add_bbox(); }
+
SVG::SVGPoint GraphvizNode::center() const { return bbox().center(); }
std::string GraphvizNode::color() const {
GraphvizNode() = delete;
explicit GraphvizNode(SVG::SVGElement &svg_element);
+ /// Add an SVG `rect` element representing the bounding box of the node to the
+ /// corresponding `g` element
+ void add_bbox();
/// Return the node's bounding box
SVG::SVGRect bbox() const;
/// Return the center of the node's bounding box
void SVGAnalyzer::set_y(double y) { current_element().attributes.y = y; }
+void SVGAnalyzer::add_bboxes() {
+ for (auto &graph : m_graphs) {
+ graph.add_bboxes();
+ }
+}
+
SVGAnalyzer SVGAnalyzer::make_from_dot(const std::string &dot_source,
const std::string &engine) {
auto g = CGraph::AGraph{dot_source};
void set_width(double width) override;
void set_x(double x) override;
void set_y(double y) override;
+ /// Add SVG `rect` elements representing the bounding boxes of nodes and edges
+ /// to the corresponding `g` elements
+ void add_bboxes();
/// Create an SVGAnalyzer from DOT source using the `engine` layout engine.
///
/// \param dot_source The DOT source
return rgb_to_hex(color, opacity);
}
+void SVG::SVGElement::add_bbox() {
+ const auto bbox = SVGElement::bbox();
+ add_rect(bbox, "green");
+}
+
void SVG::SVGElement::add_rect(SVGRect rect, const std::string color) {
SVG::SVGElement element{SVG::SVGElementType::Rect};
element.attributes.x = rect.x;
SVGElement() = delete;
explicit SVGElement(SVG::SVGElementType type);
+ /// Add an SVG `rect` element representing the bounding box of the edge to the
+ /// element
+ void add_bbox();
/// Add an SVG `rect` element as a child to the element
void add_rect(SVG::SVGRect rect, std::string color);
/// \brief Return the value of an attribute retrieved from the element and its