Initial plotting support.
This commit is contained in:
parent
df450a7be0
commit
c2027801be
34 changed files with 756 additions and 20 deletions
|
@ -2,6 +2,7 @@ add_subdirectory(test_utils)
|
|||
|
||||
add_subdirectory(geometry)
|
||||
add_subdirectory(graphics)
|
||||
add_subdirectory(publishing)
|
||||
add_subdirectory(ui_controls)
|
||||
|
||||
file(COPY data/ DESTINATION ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/test_data)
|
||||
|
@ -16,8 +17,7 @@ set(TEST_MODULES
|
|||
image
|
||||
ipc
|
||||
network
|
||||
mesh
|
||||
publishing
|
||||
mesh
|
||||
video
|
||||
web
|
||||
windows)
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
#include "CircleNode.h"
|
||||
#include "LineNode.h"
|
||||
#include "PathNode.h"
|
||||
#include "PolygonNode.h"
|
||||
|
||||
void addRect(const Point& loc, std::vector<std::unique_ptr<MaterialNode> >& nodes, double radius = 0.0)
|
||||
{
|
||||
|
@ -43,6 +44,17 @@ void addPath(const Point& loc, const std::string& path, std::vector<std::unique_
|
|||
nodes.push_back(std::move(node));
|
||||
}
|
||||
|
||||
void addPolygon(const Point& loc, std::vector<std::unique_ptr<MaterialNode> >& nodes)
|
||||
{
|
||||
auto p0 = Point{ 0.0, 0.0 };
|
||||
auto p1 = Point{ 150.0, 0.0 };
|
||||
auto p2 = Point{ 75.0, 75.0 };
|
||||
|
||||
auto node = std::make_unique<PolygonNode>(loc);
|
||||
node->setPoints({ p0, p1, p2 });
|
||||
nodes.push_back(std::move(node));
|
||||
}
|
||||
|
||||
void addShapes(const Point& start_loc, std::vector<std::unique_ptr<MaterialNode> >& nodes, bool use_fill = false)
|
||||
{
|
||||
auto loc = start_loc;
|
||||
|
@ -57,6 +69,9 @@ void addShapes(const Point& start_loc, std::vector<std::unique_ptr<MaterialNode>
|
|||
loc.move(100, 0);
|
||||
addLine(loc, nodes);
|
||||
|
||||
loc.move(200, 0);
|
||||
addPolygon(loc, nodes);
|
||||
|
||||
loc = Point(10, 150);
|
||||
addRect(loc, nodes, 10.0);
|
||||
|
||||
|
|
|
@ -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})
|
33
test/publishing/TestPlotting.cpp
Normal file
33
test/publishing/TestPlotting.cpp
Normal 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");
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue