Debian Codegraph @

tests/graphviz_node.cpp

raw
1 #include <string>
2
3 #include "graphviz_node.h"
4 #include "svg_element.h"
5
6 GraphvizNode::GraphvizNode(SVG::SVGElement &svg_element)
7 : m_node_id(svg_element.graphviz_id), m_svg_g_element(svg_element) {}
8
9 void GraphvizNode::add_bbox() { m_svg_g_element.add_bbox(); }
10
11 void GraphvizNode::add_outline_bbox() { m_svg_g_element.add_outline_bbox(); }
12
13 SVG::SVGPoint GraphvizNode::center() const { return bbox().center(); }
14
15 std::string GraphvizNode::color() const {
16 const auto stroke = m_svg_g_element.attribute_from_subtree<std::string>(
17 &SVG::SVGAttributes::stroke, &SVG::SVGElement::is_shape_element, "");
18 const auto stroke_opacity = m_svg_g_element.attribute_from_subtree<double>(
19 &SVG::SVGAttributes::stroke_opacity, &SVG::SVGElement::is_shape_element,
20 1);
21 return SVG::to_dot_color(stroke, stroke_opacity);
22 }
23
24 std::string GraphvizNode::fillcolor() const {
25 const auto fill = m_svg_g_element.attribute_from_subtree<std::string>(
26 &SVG::SVGAttributes::fill, &SVG::SVGElement::is_shape_element, "");
27 const auto fill_opacity = m_svg_g_element.attribute_from_subtree<double>(
28 &SVG::SVGAttributes::fill_opacity, &SVG::SVGElement::is_shape_element, 1);
29 return SVG::to_dot_color(fill, fill_opacity);
30 }
31
32 double GraphvizNode::penwidth() const {
33 return m_svg_g_element.attribute_from_subtree<double>(
34 &SVG::SVGAttributes::stroke_width, &SVG::SVGElement::is_shape_element, 1);
35 }
36
37 std::string_view GraphvizNode::node_id() const { return m_node_id; }
38
39 SVG::SVGRect GraphvizNode::bbox() const { return m_svg_g_element.bbox(); }
40
41 SVG::SVGRect GraphvizNode::outline_bbox() const {
42 return m_svg_g_element.outline_bbox();
43 }
44
45 const SVG::SVGElement &GraphvizNode::svg_g_element() const {
46 return m_svg_g_element;
47 }