Initial plotting support.

This commit is contained in:
jmsgrogan 2023-01-24 17:15:25 +00:00
parent df450a7be0
commit c2027801be
34 changed files with 756 additions and 20 deletions

View file

@ -1,13 +1,16 @@
set(PUBLISHING_UNIT_TEST_FILES
publishing/TestPdfWriter.cpp
publishing/TestDocumentConverter.cpp
publishing/TestSvgConverter.cpp
publishing/TestSvgToNodeConverter.cpp
publishing/TestLatexConverter.cpp
PARENT_SCOPE
)
set(PUBLISHING_UNIT_TEST_DEPENDENCIES
publishing
PARENT_SCOPE
)
set(MODULE_NAME publishing)
list(APPEND UNIT_TEST_FILES
TestPdfWriter.cpp
TestDocumentConverter.cpp
TestSvgConverter.cpp
TestSvgToNodeConverter.cpp
TestLatexConverter.cpp
TestPlotting.cpp
)
set(UNIT_TEST_TARGET_NAME ${MODULE_NAME}_unit_tests)
add_executable(${UNIT_TEST_TARGET_NAME} ${CMAKE_SOURCE_DIR}/test/test_runner.cpp ${UNIT_TEST_FILES})
target_link_libraries(${UNIT_TEST_TARGET_NAME} PUBLIC test_utils publishing)
set_property(TARGET ${UNIT_TEST_TARGET_NAME} PROPERTY FOLDER test/${MODULE_NAME})

View file

@ -0,0 +1,33 @@
#include "TestFramework.h"
#include "TestUtils.h"
#include "TestRenderUtils.h"
#include "Plot.h"
#include "PlotNode.h"
TEST_CASE(TestPlotting, "[publishing]")
{
auto plot = std::make_unique<Plot>();
plot->setXAxisCaption("X Axis");
plot->setYAxisCaption("Y Axis");
PlotSeries series("Series-1");
std::vector<Point> data{ {0.0, 0.0}, {10.0, 40.0}, {20.0, 80.0} };
series.setData(data);
plot->addSeries(series);
Point loc(10, 10);
auto plot_node = std::make_unique<PlotNode>(Transform(loc));
plot_node->setAxisEndStyle(LineEndNode::Style::CLOSED_ARROW);
plot_node->setContent(plot.get());
TestRenderer renderer(800, 800);
auto scene = renderer.getScene();
scene->addNode(plot_node.get());
renderer.writeSvg(TestUtils::getTestOutputDir(__FILE__) / "plot.svg");
renderer.write(TestUtils::getTestOutputDir(__FILE__) / "plot.png");
}