]> granicus.if.org Git - graphviz/commitdiff
tests: SVGAnalyzer: add support for adding outline bounding boxes to the re-created SVG
authorMagnus Jacobsson <Magnus.Jacobsson@berotec.se>
Sat, 27 Aug 2022 11:13:59 +0000 (13:13 +0200)
committerMagnus Jacobsson <Magnus.Jacobsson@berotec.se>
Mon, 12 Sep 2022 07:46:17 +0000 (09:46 +0200)
This will be used in upcoming commits to highlight Graphviz component
boundaries.

Towards https://gitlab.com/graphviz/graphviz/-/issues/372.

tests/graphviz_edge.cpp
tests/graphviz_edge.h
tests/graphviz_graph.cpp
tests/graphviz_graph.h
tests/graphviz_node.cpp
tests/graphviz_node.h
tests/svg_analyzer.cpp
tests/svg_analyzer.h
tests/svg_element.cpp
tests/svg_element.h

index b32f3495ff48459abd14cc2e73dd12911ccdc27b..40ffd8e9e399ab568eac04acde07749a65d4cd02 100644 (file)
@@ -8,6 +8,8 @@ GraphvizEdge::GraphvizEdge(SVG::SVGElement &svg_g_element)
 
 void GraphvizEdge::add_bbox() { m_svg_g_element.add_bbox(); }
 
+void GraphvizEdge::add_outline_bbox() { m_svg_g_element.add_outline_bbox(); }
+
 std::string_view GraphvizEdge::edgeop() const { return m_edgeop; }
 
 std::string GraphvizEdge::fillcolor() const {
index c3845719b7074f2aed2b4913325f5c974d91f0bd..aec812438006d32b51fcfe5516fe841ba44e2c79 100644 (file)
@@ -18,6 +18,10 @@ public:
   /// 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();
+  /// Add an SVG `rect` element to the edge's corresponding `g` element. The
+  /// `rect` represents the outline bounding box of the edge. The outline
+  /// bounding box is the bounding box with penwidth taken into account.
+  void add_outline_bbox();
   /// Return the bounding box of the edge
   SVG::SVGRect bbox() const;
   /// Return the center of the edge's bounding box
index 732c4cf26885af69c84037da760b56620440b52f..9b68e1bed9bdad7f1033779ba3aa3ba3c086639d 100644 (file)
@@ -55,3 +55,12 @@ void GraphvizGraph::add_bboxes() {
     edge.add_bbox();
   }
 }
+
+void GraphvizGraph::add_outline_bboxes() {
+  for (auto &node : m_nodes) {
+    node.add_outline_bbox();
+  }
+  for (auto &edge : m_edges) {
+    edge.add_outline_bbox();
+  }
+}
index 78902c51a76a15731dfa974287c241d776328a94..d5d77151156321fb575d03e06c07027186d2d374 100644 (file)
@@ -24,6 +24,10 @@ public:
   void add_edge(SVG::SVGElement &svg_g_element);
   /// Add a Graphviz node to the graph
   void add_node(SVG::SVGElement &svg_g_element);
+  /// Add SVG `rect` elements representing the outline bounding boxes of nodes
+  /// and edges to the corresponding `g` elements. The outline bounding box is
+  /// the bounding box with penwidth taken into account.
+  void add_outline_bboxes();
   const GraphvizEdge &edge(std::string_view edgeop) const;
   /// Return a non-mutable reference to the list of Graphviz edges
   const std::vector<GraphvizEdge> &edges() const;
index 209439cecb018108c66666ec6769f7dcbe1a4884..33872260fbccee354a22e139744321d4ea6d1fd4 100644 (file)
@@ -8,6 +8,8 @@ GraphvizNode::GraphvizNode(SVG::SVGElement &svg_element)
 
 void GraphvizNode::add_bbox() { m_svg_g_element.add_bbox(); }
 
+void GraphvizNode::add_outline_bbox() { m_svg_g_element.add_outline_bbox(); }
+
 SVG::SVGPoint GraphvizNode::center() const { return bbox().center(); }
 
 std::string GraphvizNode::color() const {
index cb3f8938624266b00dcecb4b7280a5db23004e47..9713dd3ef31fc687acb4b30da4259bff40e08f09 100644 (file)
@@ -18,6 +18,10 @@ public:
   /// Add an SVG `rect` element representing the bounding box of the node to the
   /// corresponding `g` element
   void add_bbox();
+  /// Add an SVG `rect` element representing the outline bounding box of the
+  /// node to the corresponding `g` element. The outline bounding box is the
+  /// bounding box with penwidth taken into account.
+  void add_outline_bbox();
   /// Return the node's bounding box
   SVG::SVGRect bbox() const;
   /// Return the center of the node's bounding box
index 5f365974489e68a6a39e2e8987be9923a7539f08..ab31825841e0744853137d77de6adbcfebf39e9d 100644 (file)
@@ -289,6 +289,12 @@ void SVGAnalyzer::add_bboxes() {
   }
 }
 
+void SVGAnalyzer::add_outline_bboxes() {
+  for (auto &graph : m_graphs) {
+    graph.add_outline_bboxes();
+  }
+}
+
 SVGAnalyzer SVGAnalyzer::make_from_dot(const std::string &dot_source,
                                        const std::string &engine) {
   auto g = CGraph::AGraph{dot_source};
index eb5fa20bc652a204e33126bb2e9c1c014e07dd45..72c745734b18f63ce8efc31eca96675b0b0c46f8 100644 (file)
@@ -61,6 +61,10 @@ public:
   /// Add SVG `rect` elements representing the bounding boxes of nodes and edges
   /// to the corresponding `g` elements
   void add_bboxes();
+  /// Add SVG `rect` elements representing the outline bounding boxes of nodes
+  /// and edges to the corresponding `g` elements. The outline bounding box is
+  /// the bounding box with penwidth taken into account.
+  void add_outline_bboxes();
   /// Create an SVGAnalyzer from DOT source using the `engine` layout engine.
   ///
   /// \param dot_source The DOT source
index 90769b63dbbc8afa13362a81eadcb36f1923f25d..eb7d3d31ff859e337b9c67e780f88cfadb2be9ef 100644 (file)
@@ -126,6 +126,11 @@ void SVG::SVGElement::add_rect(SVGRect rect, const std::string color) {
   children.push_back(element);
 }
 
+void SVG::SVGElement::add_outline_bbox() {
+  const auto bbox = SVGElement::outline_bbox();
+  add_rect(bbox, "blue");
+}
+
 SVG::SVGRect SVG::SVGElement::bbox(bool throw_if_bbox_not_defined) {
   if (!m_bbox.has_value()) {
     // negative width and height bbox that will be immediately replaced by the
index 5c48850d219e0437c122272e024f678a6bc639b0..1640995a8db06592d950a947e21e086516ebfc1f 100644 (file)
@@ -101,6 +101,10 @@ public:
   /// Add an SVG `rect` element representing the bounding box of the edge to the
   /// element
   void add_bbox();
+  /// Add an SVG `rect` element representing the outline bounding box of the
+  /// edge to the element. The outline bounding box is the bounding box with
+  /// stroke width taken into account.
+  void add_outline_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