| 1 |
#pragma once |
| 2 |
|
| 3 |
#include <string> |
| 4 |
#include <string_view> |
| 5 |
|
| 6 |
#include "graphviz_node.h" |
| 7 |
#include "svg_element.h" |
| 8 |
|
| 9 |
/** |
| 10 |
* @brief The GraphvizEdge class represents a Graphviz edge according to the DOT |
| 11 |
* language |
| 12 |
*/ |
| 13 |
|
| 14 |
class GraphvizEdge { |
| 15 |
public: |
| 16 |
GraphvizEdge() = delete; |
| 17 |
explicit GraphvizEdge(SVG::SVGElement &svg_g_element); |
| 18 |
|
| 19 |
/// Add an SVG `rect` element to the edge's corresponding `g` element. The |
| 20 |
/// `rect` is represes the bounding box of the edge. |
| 21 |
void add_bbox(); |
| 22 |
/// Add an SVG `rect` element to the edge's corresponding `g` element. The |
| 23 |
/// `rect` represents the outline bounding box of the edge. The outline |
| 24 |
/// bounding box is the bounding box with penwidth taken into account. |
| 25 |
void add_outline_bbox(); |
| 26 |
/// Add an SVG `rect` element representing the overlap between the outline |
| 27 |
/// bounding box of the edge and the specified node, to the corresponding `g` |
| 28 |
/// element. The outline bounding box is the bounding box with penwidth taken |
| 29 |
/// into account. |
| 30 |
void add_outline_overlap_bbox(const GraphvizNode &node, double tolerance = 0); |
| 31 |
/// Return the edge arrowhead/arrowtail with the specified index. If there's |
| 32 |
/// both an arrowhead and an arrowtail, the arrowtail is at index 0 and the |
| 33 |
/// arrowhead is at index 1. If there's only one, it's at index 0. Throws an |
| 34 |
/// exception if there's no arrow at the specified index. |
| 35 |
SVG::SVGRect |
| 36 |
arrowhead_outline_bbox(std::string_view dir, |
| 37 |
std::string_view primitive_arrow_shape) const; |
| 38 |
/// Return the outline bounding box of the edge arrowtail. The outline |
| 39 |
/// bounding box is the bounding box with penwidth taken into account. |
| 40 |
SVG::SVGRect |
| 41 |
arrowtail_outline_bbox(std::string_view dir, |
| 42 |
std::string_view primitive_arrow_shape) const; |
| 43 |
/// Return the bounding box of the edge |
| 44 |
SVG::SVGRect bbox() const; |
| 45 |
/// Return the center of the edge's bounding box |
| 46 |
SVG::SVGPoint center() const; |
| 47 |
/// Return the edge's `color` attribute in RGB hex format if the opacity is |
| 48 |
/// 100 % or in RGBA hex format otherwise. |
| 49 |
std::string color() const; |
| 50 |
/// Return the 'edgeop' according to the DOT language specification. Note that |
| 51 |
/// this is not the same as the 'id' attribute of an edge. |
| 52 |
std::string_view edgeop() const; |
| 53 |
/// Return the edge's `fillcolor` attribute in RGB hex format if the opacity |
| 54 |
/// is 100 % or in RGBA hex format otherwise. |
| 55 |
std::string fillcolor() const; |
| 56 |
/// Return the outline bounding box of the edge. The outline bounding box is |
| 57 |
/// the bounding box with penwidth taken into account. |
| 58 |
SVG::SVGRect outline_bbox() const; |
| 59 |
/// Return the edge stem, i.e., the part of the edge that does not include any |
| 60 |
/// arrowhead or arrowtail |
| 61 |
SVG::SVGElement &stem() const; |
| 62 |
/// Return the edge's `penwidth` attribute |
| 63 |
double penwidth() const; |
| 64 |
/// Return a non-mutable reference to the SVG `g` element corresponding to the |
| 65 |
/// edge |
| 66 |
const SVG::SVGElement &svg_g_element() const; |
| 67 |
|
| 68 |
private: |
| 69 |
/// The 'edgeop' according to the DOT language specification |
| 70 |
std::string m_edgeop; |
| 71 |
/// The SVG `g` element corresponding to the edge |
| 72 |
SVG::SVGElement &m_svg_g_element; |
| 73 |
}; |