diff --git a/JKQtPlotterBuildAllExamples.pro b/JKQtPlotterBuildAllExamples.pro index 4fc779db0e..0c0ed5e3c5 100644 --- a/JKQtPlotterBuildAllExamples.pro +++ b/JKQtPlotterBuildAllExamples.pro @@ -72,6 +72,8 @@ addSimpleTest(parametriccurve) addSimpleTest(parsedfunctionplot) addSimpleTest(functionplot) addSimpleTest(geometric) +addSimpleTest(geo_simple) +addSimpleTest(geo_arrows) addSimpleTest(ui) addSimpleTest(boxplot) addSimpleTest(advplotstyling) diff --git a/doc/dox/examples_and_tutorials.dox b/doc/dox/examples_and_tutorials.dox index f3c50e856c..eb9705e9d3 100644 --- a/doc/dox/examples_and_tutorials.dox +++ b/doc/dox/examples_and_tutorials.dox @@ -75,6 +75,9 @@ All test-projects are Qt-projects that use qmake to build. You can load them int \image html geo_arrows_small.png \subpage JKQTPlotterGeometricArrows `JKQTPGeoArrow`, ... + \image html geo_simple_small.png + \subpage JKQTPlotterGeometricGraphsSimple + `JKQTPGeoEllipse`, `JKQTPGeoArc`, `JKQTPGeoChord`, `JKQTPGeoPie` \subsection jkqtp_extut_keyaxesstyles Styling the Plot, Keys, Axes, ... diff --git a/examples/README.md b/examples/README.md index 30698657c2..73c3ddafa3 100644 --- a/examples/README.md +++ b/examples/README.md @@ -25,12 +25,13 @@ All test-projects are Qt-projects that use qmake to build. You can load them int | [![](https://raw.githubusercontent.com/jkriege2/JKQtPlotter/master/screenshots/boxplot_small.png)](https://github.com/jkriege2/JKQtPlotter/tree/master/examples/boxplot) | [Plotting Box Plots](https://github.com/jkriege2/JKQtPlotter/tree/master/examples/boxplot) | `JKQTPBoxplotVerticalGraph`, `JKQTPBoxplotHorizontalGraph` | | [![](https://raw.githubusercontent.com/jkriege2/JKQtPlotter/master/screenshots/violinplot_small.png)](https://github.com/jkriege2/JKQtPlotter/tree/master/examples/violinplot) | [Plotting Violin Plots](https://github.com/jkriege2/JKQtPlotter/tree/master/examples/violinplot) | `JKQTPViolinplotVerticalElement`, `JKQTPViolinplotHorizontalElement` | -## Styling the Plot, Keys, Axes, ... +## Geometric Plot Objects and Annotations | Screenshot | Description | Notes | |:-------------:| ------------- | ------------- | | [![](https://raw.githubusercontent.com/jkriege2/JKQtPlotter/master/screenshots/geometric_small.png)](https://github.com/jkriege2/JKQtPlotter/tree/master/examples/geometric) | [Plotting Geometric Objects](https://github.com/jkriege2/JKQtPlotter/tree/master/examples/geometric) | | | [![](https://raw.githubusercontent.com/jkriege2/JKQtPlotter/master/screenshots/geo_arrows_small.png)](https://github.com/jkriege2/JKQtPlotter/tree/master/examples/geo_arrows) | [Plotting Arrows](https://github.com/jkriege2/JKQtPlotter/tree/master/examples/geo_arrows) | | +| [![](https://raw.githubusercontent.com/jkriege2/JKQtPlotter/master/screenshots/geo_simple_small.png)](https://github.com/jkriege2/JKQtPlotter/tree/master/examples/geo_simple) | [Plotting Arrows](https://github.com/jkriege2/JKQtPlotter/tree/master/examples/geo_simple) | | ## Styling the Plot, Keys, Axes, ... diff --git a/examples/geo_simple/CMakeLists.txt b/examples/geo_simple/CMakeLists.txt new file mode 100644 index 0000000000..06211f58d2 --- /dev/null +++ b/examples/geo_simple/CMakeLists.txt @@ -0,0 +1,29 @@ +cmake_minimum_required(VERSION 3.0) + +set(EXAMPLE_NAME geo_simple) +set(EXENAME jkqtptest_${EXAMPLE_NAME}) + +message( STATUS ".. Building Example ${EXAMPLE_NAME}" ) + + +# Set up source files +set(SOURCES ${EXAMPLE_NAME}.cpp) +set(HEADERS ) +set(RESOURCES ) +set(UIS ) + +add_executable(${EXENAME} WIN32 ${SOURCES} ${HEADERS} ${RESOURCES} ${UIS}) +target_include_directories(${EXENAME} PRIVATE ../../lib) +if(JKQtPlotter_BUILD_STATIC_LIBS) + target_link_libraries(${EXENAME} JKQTPlotterLib) +elseif(JKQtPlotter_BUILD_SHARED_LIBS) + target_link_libraries(${EXENAME} JKQTPlotterSharedLib) +endif() + + + +# Installation +install(TARGETS ${EXENAME} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + +#Installation of Qt DLLs on Windows +jkqtplotter_deployqt(${EXENAME}) diff --git a/examples/geo_simple/README.md b/examples/geo_simple/README.md new file mode 100644 index 0000000000..1d1afa1a4c --- /dev/null +++ b/examples/geo_simple/README.md @@ -0,0 +1,5 @@ +# Example (JKQTPlotter): Generating Demo-Plots of Geometric Objects for Documentation {#JKQTPlotterGeometricGraphsSimple} + +This project contains code that is used to generate the example graphs for geometric objects from teh documentation. + +The source code of the main application can be found in [`geo_simple.cpp`](https://github.com/jkriege2/JKQtPlotter/tree/master/examples/geo_simple/geo_simple.cpp). \ No newline at end of file diff --git a/examples/geo_simple/geo_simple.cpp b/examples/geo_simple/geo_simple.cpp new file mode 100644 index 0000000000..1ef5c5264f --- /dev/null +++ b/examples/geo_simple/geo_simple.cpp @@ -0,0 +1,186 @@ +/** \example geo_simple.cpp + * This project contains code that is used to generate the example graphs for geometric objects from teh documentation. + * + * \ref JKQTPlotterGeometricGraphsSimple + */ +#include +#include +#include +#include "jkqtplotter/jkqtplotter.h" +#include "jkqtplotter/graphs/jkqtpgeometric.h" + + +template +void drawExample(JKQTPlotter* plot, double x0, double y0, double wid, double heig, double angleStart, double angleStop) { + plot->addGraph(new JKQTPGeoRectangle(plot,x0, y0, wid, heig, QColor("orange"), 1, Qt::PenStyle::DashLine)); + plot->addGraph(new JKQTPGeoEllipse(plot,x0, y0, wid, heig, QColor("orange"), 1, Qt::PenStyle::DashLine)); + TELLIPSEPART* obj; + plot->addGraph(obj=new TELLIPSEPART(plot,x0, y0, wid, heig, 10, angleStop , QColor("blue"), 4, Qt::PenStyle::SolidLine)); + JKQTPGeoBaseFilled* fillobj=dynamic_cast(obj); + if (fillobj) { + fillobj->setFillColor(QColor("lightblue")); + fillobj->setAlpha(0.8); + } + plot->addGraph(new JKQTPGeoSymbol(plot, x0, y0, JKQTPCircle, 5, QColor("red"))); + plot->addGraph(new JKQTPGeoLine(plot, x0, y0, x0+wid/2.0*cos(angleStart/180.0*JKQTPSTATISTICS_PI),y0+heig/2.0*sin(angleStart/180.0*JKQTPSTATISTICS_PI), QColor("orange"))); + plot->addGraph(new JKQTPGeoText(plot, x0+wid*1.1/2.0*cos(angleStart/180.0*JKQTPSTATISTICS_PI),y0+heig*1.1/2.0*sin(angleStart/180.0*JKQTPSTATISTICS_PI), "\\alpha_\\text{start}="+QString::number(angleStart, 'f', 0)+"\\degree", 10, QColor("orange"))); + plot->addGraph(new JKQTPGeoLine(plot, x0, y0, x0+wid/2.0*cos(angleStop/180.0*JKQTPSTATISTICS_PI),y0+heig/2.0*sin(angleStop/180.0*JKQTPSTATISTICS_PI), QColor("red"))); + plot->addGraph(new JKQTPGeoText(plot, x0+wid*1.1/2.0*cos(angleStop/180.0*JKQTPSTATISTICS_PI),y0+heig*1.1/2.0*sin(angleStop/180.0*JKQTPSTATISTICS_PI), "\\alpha_\\text{stop}="+QString::number(angleStop, 'f', 0)+"\\degree", 10, QColor("red"))); + plot->addGraph(new JKQTPGeoLine(plot, x0, y0, x0+wid/2.0*cos(0/180.0*JKQTPSTATISTICS_PI),y0+heig/2.0*sin(0/180.0*JKQTPSTATISTICS_PI), QColor("orange"))); + plot->addGraph(new JKQTPGeoText(plot, x0+wid*1.1/2.0*cos(0/180.0*JKQTPSTATISTICS_PI),y0+heig*1.1/2.0*sin(0/180.0*JKQTPSTATISTICS_PI), "0\\degree", 10, QColor("orange"))); + plot->addGraph(new JKQTPGeoText(plot, x0,y0-0.05*heig, "(x,y)", 10, QColor("red"))); + plot->addGraph(new JKQTPGeoText(plot, x0,y0-heig*1.1/2.0, "width="+QString::number(wid, 'f', 1), 10, QColor("red"))); + plot->addGraph(new JKQTPGeoText(plot, x0-wid*1.05/2.0,y0, "height="+QString::number(heig, 'f', 1), 10, QColor("red"))); + +} + + + +void drawEllExample(JKQTPlotter* plot, double x0, double y0, double wid, double heig, double angle=0) { + JKQTPGeoRectangle* rec; + plot->addGraph(rec=new JKQTPGeoRectangle(plot,x0, y0, wid, heig, QColor("orange"), 1, Qt::PenStyle::DashLine)); + rec->setAngle(angle); + JKQTPGeoEllipse* fillobj; + plot->addGraph(fillobj=new JKQTPGeoEllipse(plot,x0, y0, wid, heig, QColor("blue"), 1, Qt::PenStyle::DashLine)); + fillobj->setFillColor(QColor("lightblue")); + fillobj->setAlpha(0.8); + fillobj->setAngle(angle); + plot->addGraph(new JKQTPGeoSymbol(plot, x0, y0, JKQTPCircle, 5, QColor("red"))); + plot->addGraph(new JKQTPGeoText(plot, x0,y0-0.05*heig, "(x,y)", 10, QColor("red"))); + if (fabs(angle)<0.01) { + plot->addGraph(new JKQTPGeoText(plot, x0,y0-heig*1.1/2.0, "width="+QString::number(wid, 'f', 1), 10, QColor("red"))); + plot->addGraph(new JKQTPGeoText(plot, x0-wid*1.05/2.0,y0, "height="+QString::number(heig, 'f', 1), 10, QColor("red"))); + } else { + plot->addGraph(new JKQTPGeoLine(plot, x0, y0, x0+wid/2.0*cos(angle/180.0*JKQTPSTATISTICS_PI),y0+heig/2.0*sin(angle/180.0*JKQTPSTATISTICS_PI), QColor("red"))); + plot->addGraph(new JKQTPGeoText(plot, x0+wid*1.1/2.0*cos(angle/180.0*JKQTPSTATISTICS_PI),y0+heig*1.1/2.0*sin(angle/180.0*JKQTPSTATISTICS_PI), "\\alpha="+QString::number(angle, 'f', 0)+"\\degree", 10, QColor("red"))); + plot->addGraph(new JKQTPGeoLine(plot, x0, y0, x0+wid/2.0*cos(0/180.0*JKQTPSTATISTICS_PI),y0+heig/2.0*sin(0/180.0*JKQTPSTATISTICS_PI), QColor("orange"))); + plot->addGraph(new JKQTPGeoText(plot, x0+wid*1.1/2.0*cos(0/180.0*JKQTPSTATISTICS_PI),y0+heig*1.1/2.0*sin(0/180.0*JKQTPSTATISTICS_PI), "0\\degree", 10, QColor("orange"))); + } + +} + +int main(int argc, char* argv[]) +{ + QApplication app(argc, argv); + + // 1. create a Widget with a plotter and some control-elements + QWidget widMain; + QGridLayout* layMain=new QGridLayout; + widMain.setLayout(layMain); + JKQTPlotter* plot=new JKQTPlotter(&widMain); + JKQTPlotter* plotlog=new JKQTPlotter(&widMain); + layMain->addWidget(plot, 1,0,1,3); + layMain->addWidget(plotlog, 1,3,1,3); + layMain->setRowStretch(1,1); + QCheckBox* chk; + QComboBox* cmb; + // combobox to select what to draw + layMain->addWidget(new QLabel(QObject::tr("Object: "), &widMain), 0, 1); + layMain->addWidget(cmb=new QComboBox(&widMain), 0, 2); + cmb->addItem(QObject::tr("JKQTPGeoArc")); + cmb->addItem(QObject::tr("JKQTPGeoPie")); + cmb->addItem(QObject::tr("JKQTPGeoChord")); + cmb->addItem(QObject::tr("JKQTPGeoEllipse")); + cmb->addItem(QObject::tr("JKQTPGeoEllipse, angle=-35deg")); + cmb->setCurrentIndex(0); + auto drawFunctor=[&](int index) { + plot->clearGraphs(); + plotlog->clearGraphs(); + if (index==0) { + drawExample(plot, 1,1,1,1.5,10,110); + drawExample(plotlog, 1,1,1,1.5,10,110); + } else if (index==1) { + drawExample(plot, 1,1,1,1.5,10,110); + drawExample(plotlog, 1,1,1,1.5,10,110); + } else if (index==2) { + drawExample(plot, 1,1,1,1.5,10,110); + drawExample(plotlog, 1,1,1,1.5,10,110); + } else if (index==3) { + drawEllExample(plot, 1,1,1,1.5); + drawEllExample(plotlog, 1,1,1,1.5); + } else if (index==4) { + drawEllExample(plot, 1,1,1,1.5,-35); + drawEllExample(plotlog, 1,1,1,1.5,-35); + } + plot->zoomToFit(); + plotlog->zoomToFit(); + }; + QObject::connect(cmb, static_cast(&QComboBox::currentIndexChanged), drawFunctor); + + // when checkbox is toggled: aspect-ration is maintained, or not + layMain->addWidget(chk=new QCheckBox(QObject::tr("maintain aspect ratio"), &widMain), 0, 3); + chk->setChecked(true); + QObject::connect(chk, &QCheckBox::toggled, [&](bool checked) { + plot->getPlotter()->setMaintainAspectRatio(checked); + plot->getPlotter()->setMaintainAxisAspectRatio(checked); + plotlog->getPlotter()->setMaintainAspectRatio(checked); + plotlog->getPlotter()->setMaintainAxisAspectRatio(checked); + }); + // when checkbox is toggled: aspect-ration is maintained, or not + layMain->addWidget(new QLabel(QObject::tr("DrawMode: "), &widMain), 0, 4); + layMain->addWidget(cmb=new QComboBox(&widMain), 0, 5); + cmb->addItem(QObject::tr("DrawAsGraphicElement")); + cmb->addItem(QObject::tr("DrawAsMathematicalCurve")); + cmb->setCurrentIndex(0); + QObject::connect(cmb, static_cast(&QComboBox::currentIndexChanged), [&](int index) { + for (size_t i=0; igetPlotter()->getGraphCount(); i++) { + JKQTPPlotObject* obj=dynamic_cast(plot->getPlotter()->getGraph(i)); + if (obj) { + obj->setDrawMode((index==0)?JKQTPPlotObject::DrawAsGraphicElement:JKQTPPlotObject::DrawAsMathematicalCurve); + } + } + plot->redrawPlot(); + for (size_t i=0; igetPlotter()->getGraphCount(); i++) { + JKQTPPlotObject* obj=dynamic_cast(plotlog->getPlotter()->getGraph(i)); + if (obj) { + obj->setDrawMode((index==0)?JKQTPPlotObject::DrawAsGraphicElement:JKQTPPlotObject::DrawAsMathematicalCurve); + } + } + plotlog->redrawPlot(); + }); + + + + // 2. format graph: + // 2.1 set the asxpect ratio to 1 + plot->getPlotter()->setMaintainAspectRatio(true); + plot->getPlotter()->setAspectRatio(1); + plot->getPlotter()->setMaintainAxisAspectRatio(true); + plot->getPlotter()->setAxisAspectRatio(1); + // 2.2 set the asxpect ratio to 1 + plot->getXAxis()->setDrawGrid(true); + plot->getYAxis()->setDrawGrid(true); + plot->getXAxis()->setDrawMinorGrid(true); + plot->getYAxis()->setDrawMinorGrid(true); + // 2.3 show 9 minor ticks between two major ticks + plot->getXAxis()->setMinorTicks(9); + plot->getYAxis()->setMinorTicks(9); + // 2.4 set log-axes + plotlog->getXAxis()->setLogAxis(true); + plotlog->getYAxis()->setLogAxis(true); + // 2.5 set the asxpect ratio to 1 + plotlog->getPlotter()->setMaintainAspectRatio(true); + plotlog->getPlotter()->setAspectRatio(1); + plotlog->getPlotter()->setMaintainAxisAspectRatio(true); + plotlog->getPlotter()->setAxisAspectRatio(1); + // 2.6 set the asxpect ratio to 1 + plotlog->getXAxis()->setDrawGrid(true); + plotlog->getYAxis()->setDrawGrid(true); + plotlog->getXAxis()->setDrawMinorGrid(true); + plotlog->getYAxis()->setDrawMinorGrid(true); + // 2.7 show 9 minor ticks between two major ticks + plotlog->getXAxis()->setMinorTicks(9); + plotlog->getYAxis()->setMinorTicks(9); + + + cmb->setCurrentIndex(0); + drawFunctor(0); + + + + // 4. show plotter and make it a decent size + widMain.show(); + widMain.resize(800,500); + + return app.exec(); +} diff --git a/examples/geo_simple/geo_simple.pro b/examples/geo_simple/geo_simple.pro new file mode 100644 index 0000000000..03e1aac4f7 --- /dev/null +++ b/examples/geo_simple/geo_simple.pro @@ -0,0 +1,27 @@ +# source code for this simple demo +SOURCES = geo_simple.cpp + +# configure Qt +CONFIG += link_prl qt +QT += core gui xml svg +greaterThan(QT_MAJOR_VERSION, 4): QT += widgets printsupport + +# output executable name +TARGET = geo_simple + +# include JKQTPlotter source code +DEPENDPATH += ../../lib ../../staticlib +INCLUDEPATH += ../../lib +CONFIG (debug, debug|release) { + LIBS += -L../../qmake/staticlib/jkqtplotterlib/debug -ljkqtplotterlib_debug +} else { + LIBS += -L../../qmake/staticlib/jkqtplotterlib/release -ljkqtplotterlib +} +message("LIBS = $$LIBS") + +win32-msvc*: DEFINES += _USE_MATH_DEFINES +win32-msvc*: DEFINES += NOMINMAX + + + + diff --git a/examples/geo_simple/geo_simple_and_lib.pro b/examples/geo_simple/geo_simple_and_lib.pro new file mode 100644 index 0000000000..e3b3a93e13 --- /dev/null +++ b/examples/geo_simple/geo_simple_and_lib.pro @@ -0,0 +1,8 @@ +TEMPLATE = subdirs + +SUBDIRS += jkqtplotterlib geo_simple + +jkqtplotterlib.file = ../../qmake/staticlib/jkqtplotterlib/jkqtplotterlib.pro + +geo_simple.file=$$PWD/geo_simple.pro +geo_simple.depends = jkqtplotterlib diff --git a/screenshots/geo_simple.png b/screenshots/geo_simple.png new file mode 100644 index 0000000000..d784f6ce12 Binary files /dev/null and b/screenshots/geo_simple.png differ diff --git a/screenshots/geo_simple_small.png b/screenshots/geo_simple_small.png new file mode 100644 index 0000000000..257e5f87d7 Binary files /dev/null and b/screenshots/geo_simple_small.png differ