| 1 |
#pragma once |
| 2 |
|
| 3 |
#include <stdexcept> |
| 4 |
#include <string> |
| 5 |
#include <vector> |
| 6 |
|
| 7 |
#include "graphviz_edge.h" |
| 8 |
#include "graphviz_node.h" |
| 9 |
|
| 10 |
/** |
| 11 |
* @brief The GraphvizGraph class represents a Graphviz graph according to the |
| 12 |
* DOT language |
| 13 |
*/ |
| 14 |
|
| 15 |
class GraphvizGraph { |
| 16 |
public: |
| 17 |
GraphvizGraph() = delete; |
| 18 |
explicit GraphvizGraph(SVG::SVGElement &g_element); |
| 19 |
|
| 20 |
/// Add SVG `rect` elements representing the bounding boxes of nodes and edges |
| 21 |
/// to the corresponding `g` elements |
| 22 |
void add_bboxes(); |
| 23 |
/// Add a Graphviz edge to the graph |
| 24 |
void add_edge(SVG::SVGElement &svg_g_element); |
| 25 |
/// Add a Graphviz node to the graph |
| 26 |
void add_node(SVG::SVGElement &svg_g_element); |
| 27 |
/// Add SVG `rect` elements representing the overlap between the outline |
| 28 |
/// bounding box of nodes and edges. The outline bounding box is the bounding |
| 29 |
/// box with penwidth taken into account. |
| 30 |
void add_node_edge_outline_bbox_overlaps(double tolerance = 0); |
| 31 |
/// Add SVG `rect` elements representing the outline bounding boxes of nodes |
| 32 |
/// and edges to the corresponding `g` elements. The outline bounding box is |
| 33 |
/// the bounding box with penwidth taken into account. |
| 34 |
void add_outline_bboxes(); |
| 35 |
const GraphvizEdge &edge(std::string_view edgeop) const; |
| 36 |
/// Return a non-mutable reference to the list of Graphviz edges |
| 37 |
const std::vector<GraphvizEdge> &edges() const; |
| 38 |
/// Return the node with the specified `node_id` |
| 39 |
const GraphvizNode &node(std::string_view node_id) const; |
| 40 |
/// Return a non-mutable reference to the list of Graphviz nodes |
| 41 |
const std::vector<GraphvizNode> &nodes() const; |
| 42 |
/// Return a non-mutable reference to the SVG `g` element corresponding to the |
| 43 |
/// graph |
| 44 |
const SVG::SVGElement &svg_g_element() const; |
| 45 |
|
| 46 |
private: |
| 47 |
/// A list of edges belonging to this graph |
| 48 |
std::vector<GraphvizEdge> m_edges; |
| 49 |
/// The `ID` according to the DOT language specification. Note that this is |
| 50 |
/// not the same as the `id` attribute of a graph |
| 51 |
std::string m_graph_id; |
| 52 |
/// A list of nodes belonging to this graph |
| 53 |
std::vector<GraphvizNode> m_nodes; |
| 54 |
/// The SVG `g` element corresponding to the graph |
| 55 |
SVG::SVGElement &m_svg_g_element; |
| 56 |
}; |