set_target_properties(test_common PROPERTIES CXX_STANDARD_REQUIRED ON)
target_include_directories(test_common PRIVATE
../lib
+ ../lib/cgraph++
)
target_include_directories(test_common SYSTEM PRIVATE
${Boost_INCLUDE_DIRS}
#include "svg_analyzer.h"
#include "svgpp_context.h"
#include "svgpp_document_traverser.h"
+#include <cgraph++/AGraph.h>
+#include <gvc++/GVContext.h>
+#include <gvc++/GVLayout.h>
+#include <gvc++/GVRenderData.h>
SVGAnalyzer::SVGAnalyzer(char *text)
: m_svg(SVG::SVGElement(SVG::SVGElementType::Svg)) {
void SVGAnalyzer::set_y(double y) { current_element().attributes.y = y; }
+SVGAnalyzer SVGAnalyzer::make_from_dot(const std::string &dot_source,
+ const std::string &engine) {
+ auto g = CGraph::AGraph{dot_source};
+
+ const auto demand_loading = false;
+ auto gvc = GVC::GVContext{lt_preloaded_symbols, demand_loading};
+
+ const auto layout = GVC::GVLayout(std::move(gvc), std::move(g), engine);
+
+ const auto result = layout.render("svg");
+ return SVGAnalyzer{result.c_str()};
+}
+
void SVGAnalyzer::set_transform(double a, double b, double c, double d,
double e, double f) {
current_element().attributes.transform = {a, b, c, d, e, f};
void set_width(double width) override;
void set_x(double x) override;
void set_y(double y) override;
+ /// Create an SVGAnalyzer from DOT source using the `engine` layout engine.
+ ///
+ /// \param dot_source The DOT source
+ /// \param engine The Graphviz layout engine
+ static SVGAnalyzer make_from_dot(const std::string &dot_source,
+ const std::string &engine = "dot");
std::size_t num_svgs() const { return m_num_svgs; };
std::size_t num_groups() const { return m_num_groups; };
std::size_t num_circles() const { return m_num_circles; };
#include "svg_analyzer.h"
#include "test_utilities.h"
-#include <cgraph++/AGraph.h>
-#include <gvc++/GVContext.h>
-#include <gvc++/GVLayout.h>
-#include <gvc++/GVRenderData.h>
TEST_CASE("Graph rankdir", "Test that the Graphviz `rankdir` attribute affects "
"the relative placement of nodes and edges "
auto dot = fmt::format(
"digraph g1 {{rankdir={}; node [shape={} fontname=Courier]; a -> b}}",
rankdir, shape);
- auto g = CGraph::AGraph{dot};
- const auto demand_loading = false;
- auto gvc = GVC::GVContext{lt_preloaded_symbols, demand_loading};
-
- const auto layout = GVC::GVLayout(std::move(gvc), std::move(g), "dot");
-
- const auto result = layout.render("svg");
- SVGAnalyzer svg_analyzer{result.c_str()};
+ const auto engine = "dot";
+ auto svg_analyzer = SVGAnalyzer::make_from_dot(dot, engine);
REQUIRE(svg_analyzer.graphs().size() == 1);
const auto &graph = svg_analyzer.graphs().back();