#include "graphviz_edge.h"
GraphvizEdge::GraphvizEdge(SVG::SVGElement &svg_g_element)
- : m_svg_g_element(svg_g_element) {}
+ : m_edgeop(svg_g_element.graphviz_id), m_svg_g_element(svg_g_element) {}
+
+std::string_view GraphvizEdge::edgeop() const { return m_edgeop; }
const SVG::SVGElement &GraphvizEdge::svg_g_element() const {
return m_svg_g_element;
#pragma once
+#include <string>
+#include <string_view>
+
#include "svg_element.h"
/**
GraphvizEdge() = delete;
explicit GraphvizEdge(SVG::SVGElement &svg_g_element);
+ std::string_view edgeop() const;
/// Return a non-mutable reference to the SVG `g` element corresponding to the
/// edge
const SVG::SVGElement &svg_g_element() const;
private:
+ /// The 'edgeop' according to the DOT language specification. Note that this
+ /// is not the same as the 'id' attribute of an edge
+ std::string m_edgeop;
/// The SVG `g` element corresponding to the edge
SVG::SVGElement &m_svg_g_element;
};
const std::vector<GraphvizEdge> &GraphvizGraph::edges() const {
return m_edges;
}
+
+const GraphvizEdge &GraphvizGraph::edge(std::string_view edgeop) const {
+ for (auto &edge : m_edges) {
+ if (edge.edgeop() == edgeop) {
+ return edge;
+ }
+ }
+ throw std::runtime_error("Unknown edge '" + std::string{edgeop} +
+ "' in graph " + m_graph_id);
+}
void add_edge(SVG::SVGElement &svg_g_element);
/// Add a Graphviz node to the graph
void add_node(SVG::SVGElement &svg_g_element);
+ 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;
/// Return the node with the specified `node_id`
const auto &graph = svgAnalyzer.graphs().back();
const auto node_a = graph.node("a");
const auto node_b = graph.node("b");
+ const auto edge_ab = graph.edge("a->b");
if (rankdir == "TB") {
CHECK(node_a.center().is_higher_than(node_b.center()));
} else if (rankdir == "BT") {