+#include <stdexcept>
+
+#include <fmt/format.h>
+
#include "graphviz_graph.h"
GraphvizGraph::GraphvizGraph(SVG::SVGElement &svg_g_element)
return m_svg_g_element;
}
+const GraphvizNode &GraphvizGraph::node(std::string_view node_id) const {
+ for (auto &node : m_nodes) {
+ if (node.node_id() == node_id) {
+ return node;
+ }
+ }
+ throw std::runtime_error{
+ fmt::format("Unknown node '{}' in graph '{}'", node_id, m_graph_id)};
+}
+
void GraphvizGraph::add_edge(SVG::SVGElement &svg_g_element) {
m_edges.emplace_back(svg_g_element);
}
void add_node(SVG::SVGElement &svg_g_element);
/// Return a non-mutable reference to the list of Graphviz edges
const std::vector<GraphvizEdge> &edges() const;
+ /// Return the node with the specified `node_id`
+ const GraphvizNode &node(std::string_view node_id) const;
/// Return a non-mutable reference to the list of Graphviz nodes
const std::vector<GraphvizNode> &nodes() const;
/// Return a non-mutable reference to the SVG `g` element corresponding to the
#include "graphviz_node.h"
GraphvizNode::GraphvizNode(SVG::SVGElement &svg_element)
- : m_svg_g_element(svg_element) {}
+ : m_node_id(svg_element.graphviz_id), m_svg_g_element(svg_element) {}
+
+std::string_view GraphvizNode::node_id() const { return m_node_id; }
const SVG::SVGElement &GraphvizNode::svg_g_element() const {
return m_svg_g_element;
#pragma once
#include <string>
+#include <string_view>
#include "svg_element.h"
GraphvizNode() = delete;
explicit GraphvizNode(SVG::SVGElement &svg_element);
+ /// Return the node's `node_id` as defined by the DOT language
+ std::string_view node_id() const;
/// Return a non-mutable reference to the SVG `g` element corresponding to the
/// node
const SVG::SVGElement &svg_g_element() const;
private:
+ /// The `node_id` according to the DOT language specification. Note that this
+ /// is not the same as the `id` attribute of a node
+ std::string m_node_id;
/// The SVG `g` element corresponding to the node
SVG::SVGElement &m_svg_g_element;
};
SVGAnalyzer svgAnalyzer{result.c_str()};
REQUIRE(svgAnalyzer.graphs().size() == 1);
+ const auto &graph = svgAnalyzer.graphs().back();
+ const auto node_a = graph.node("a");
+ const auto node_b = graph.node("b");
}