mirror of
https://github.com/jkriege2/JKQtPlotter.git
synced 2024-12-25 01:51:49 +08:00
added simple geometric example, which produces the images fro teh documentation
This commit is contained in:
parent
279ef7880a
commit
e97c0a13fe
@ -72,6 +72,8 @@ addSimpleTest(parametriccurve)
|
||||
addSimpleTest(parsedfunctionplot)
|
||||
addSimpleTest(functionplot)
|
||||
addSimpleTest(geometric)
|
||||
addSimpleTest(geo_simple)
|
||||
addSimpleTest(geo_arrows)
|
||||
addSimpleTest(ui)
|
||||
addSimpleTest(boxplot)
|
||||
addSimpleTest(advplotstyling)
|
||||
|
@ -75,6 +75,9 @@ All test-projects are Qt-projects that use qmake to build. You can load them int
|
||||
<tr><td> \image html geo_arrows_small.png
|
||||
<td> \subpage JKQTPlotterGeometricArrows
|
||||
<td> `JKQTPGeoArrow`, ...
|
||||
<tr><td> \image html geo_simple_small.png
|
||||
<td> \subpage JKQTPlotterGeometricGraphsSimple
|
||||
<td> `JKQTPGeoEllipse`, `JKQTPGeoArc`, `JKQTPGeoChord`, `JKQTPGeoPie`
|
||||
</table>
|
||||
|
||||
\subsection jkqtp_extut_keyaxesstyles Styling the Plot, Keys, Axes, ...
|
||||
|
@ -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, ...
|
||||
|
||||
|
29
examples/geo_simple/CMakeLists.txt
Normal file
29
examples/geo_simple/CMakeLists.txt
Normal file
@ -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})
|
5
examples/geo_simple/README.md
Normal file
5
examples/geo_simple/README.md
Normal file
@ -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).
|
186
examples/geo_simple/geo_simple.cpp
Normal file
186
examples/geo_simple/geo_simple.cpp
Normal file
@ -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 <QCheckBox>
|
||||
#include <QComboBox>
|
||||
#include <QApplication>
|
||||
#include "jkqtplotter/jkqtplotter.h"
|
||||
#include "jkqtplotter/graphs/jkqtpgeometric.h"
|
||||
|
||||
|
||||
template <class TELLIPSEPART>
|
||||
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<JKQTPGeoBaseFilled*>(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<JKQTPGeoArc>(plot, 1,1,1,1.5,10,110);
|
||||
drawExample<JKQTPGeoArc>(plotlog, 1,1,1,1.5,10,110);
|
||||
} else if (index==1) {
|
||||
drawExample<JKQTPGeoPie>(plot, 1,1,1,1.5,10,110);
|
||||
drawExample<JKQTPGeoPie>(plotlog, 1,1,1,1.5,10,110);
|
||||
} else if (index==2) {
|
||||
drawExample<JKQTPGeoChord>(plot, 1,1,1,1.5,10,110);
|
||||
drawExample<JKQTPGeoChord>(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<void (QComboBox::*)(int)>(&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<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), [&](int index) {
|
||||
for (size_t i=0; i<plot->getPlotter()->getGraphCount(); i++) {
|
||||
JKQTPPlotObject* obj=dynamic_cast<JKQTPPlotObject*>(plot->getPlotter()->getGraph(i));
|
||||
if (obj) {
|
||||
obj->setDrawMode((index==0)?JKQTPPlotObject::DrawAsGraphicElement:JKQTPPlotObject::DrawAsMathematicalCurve);
|
||||
}
|
||||
}
|
||||
plot->redrawPlot();
|
||||
for (size_t i=0; i<plotlog->getPlotter()->getGraphCount(); i++) {
|
||||
JKQTPPlotObject* obj=dynamic_cast<JKQTPPlotObject*>(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();
|
||||
}
|
27
examples/geo_simple/geo_simple.pro
Normal file
27
examples/geo_simple/geo_simple.pro
Normal file
@ -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
|
||||
|
||||
|
||||
|
||||
|
8
examples/geo_simple/geo_simple_and_lib.pro
Normal file
8
examples/geo_simple/geo_simple_and_lib.pro
Normal file
@ -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
|
BIN
screenshots/geo_simple.png
Normal file
BIN
screenshots/geo_simple.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 70 KiB |
BIN
screenshots/geo_simple_small.png
Normal file
BIN
screenshots/geo_simple_small.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 14 KiB |
Loading…
Reference in New Issue
Block a user