void SVGAnalyzer::on_exit_element() { m_elements_in_process.pop_back(); }
+SVG::SVGElement &SVGAnalyzer::grandparent_element() {
+ if (m_elements_in_process.empty()) {
+ throw std::runtime_error{"No current element to get grandparent of"};
+ }
+ if (m_elements_in_process.size() == 1) {
+ throw std::runtime_error{"No parent element"};
+ }
+ if (m_elements_in_process.size() == 2) {
+ throw std::runtime_error{"No grandparent element"};
+ }
+ return *m_elements_in_process.end()[-3];
+}
+
SVG::SVGElement &SVGAnalyzer::parent_element() {
if (m_elements_in_process.empty()) {
throw std::runtime_error{"No current element to get parent of"};
throw std::runtime_error{"Unexpected parent element of 'title' element"};
}
parent_element().graphviz_id = text;
+ // If the 'g' element corresponds to the graph, set the Graphviz ID also on
+ // the top level 'svg' element.
+ if (grandparent_element().type == SVG::SVGElementType::Svg) {
+ grandparent_element().graphviz_id = text;
+ }
}
}
/// Enter a new SVG element retrieved by the SVG document traverser into the
/// list of elements currently being processed
void enter_element(SVG::SVGElementType type);
+ /// Get the grandparent element of the current element being processed by the
+ /// SVG document traverser
+ SVG::SVGElement &grandparent_element();
/// Get the parent element of the current element being processed by the SVG
/// document traverser
SVG::SVGElement &parent_element();