JKQtPlotter/examples/geo_arrows
jkriege2 b0df7a1fd7 NEW/BREAKING: provide general targets JKQTPlotter5/6::JKQTPlotter5/6, JKQTPlotter5/6::JKQTMathText5/6, ... which are independent of the type of build (shared/static)
NEW/BREAKING: refactor CMake-Code, so static/dynamic switch is done via <code>BUILD_SHARED_LIBS</code>, which retires <code>JKQtPlotter_BUILD_STATIC_LIBS</code>, <code>JKQtPlotter_BUILD_SHARED_LIBS</code> and removes the capability to build static and shared libraries in one location (fixes issue #104)
NEW: prepareed library for CMake's <a href="https://cmake.org/cmake/help/latest/module/FetchContent.html">FetchContent</a>-API
NEW: the different sub-libraries JKQTPlotter, JKQTFastPlotter (DEPRECATED), JKQTMath, JKQTMathText can be activated/deactivated with CMake options JKQtPlotter_BUILD_LIB_JKQTPLOTTER, JKQtPlotter_BUILD_LIB_JKQTFASTPLOTTER, JKQtPlotter_BUILD_LIB_JKQTMATHTEXT, JKQtPlotter_BUILD_LIB_JKQTMATH
2024-01-16 13:07:08 +01:00
..
CMakeLists.txt NEW/BREAKING: provide general targets JKQTPlotter5/6::JKQTPlotter5/6, JKQTPlotter5/6::JKQTMathText5/6, ... which are independent of the type of build (shared/static) 2024-01-16 13:07:08 +01:00
geo_arrows_and_lib.pro improved arrows in geometric elements: 2020-08-23 13:13:53 +02:00
geo_arrows.cpp updated many documentation images to auto-generated ones 2022-08-28 22:48:14 +02:00
geo_arrows.pro improved arrows in geometric elements: 2020-08-23 13:13:53 +02:00
README.md - breaking: geometric elements constructor: removed all styling properties, added setStyle()-functions to replace them. This is necessary to better work with the extended Styling system 2020-09-26 15:58:58 +02:00

Example (JKQTPlotter): Plotting Arrows

This project shows the capabilities of JKQTPlotter to also draw arrows as geometric elements, using JKQTPGeoArrow. The arrow head/tail are defined by the enum values in JKQTPLineDecoratorStyle.

The source code of the main application can be found in geo_arrows.cpp. First a plot is generated. Then several types of arrows are plotted onto the JKQtPlotter.

Different types of arrows

A first table shows all available arrow tips in different sizes.

     for (size_t i=0; i<static_cast<size_t>(JKQTPLineDecoratorCount); i++) {
        auto const decor=static_cast<JKQTPLineDecoratorStyle>(i);
        plot.addGraph(a=new JKQTPGeoArrow(&plot, 0.1,  arr_y, 0.3, arr_y+0.05, decor, JKQTPNoDecorator));
		a->setStyle(QColor("red"), 0.2);
        plot.addGraph(a=new JKQTPGeoArrow(&plot, 0.4,  arr_y, 0.6, arr_y+0.05, decor, JKQTPNoDecorator));
		a->setStyle(QColor("red"), 0.5);
        plot.addGraph(a=new JKQTPGeoArrow(&plot, 0.7,  arr_y, 0.9, arr_y+0.05, decor, JKQTPNoDecorator));
		a->setStyle(QColor("red"), 1);
        plot.addGraph(a=new JKQTPGeoArrow(&plot, 1.0,  arr_y, 1.3, arr_y+0.05, decor, JKQTPNoDecorator));
		a->setStyle(QColor("red"), 2);
        plot.addGraph(a=new JKQTPGeoArrow(&plot, 1.4,  arr_y, 1.7, arr_y+0.05, decor, JKQTPNoDecorator));
		a->setStyle(QColor("red"), 3);
        plot.addGraph(new JKQTPGeoText(&plot, a->getX2()+0.05, a->getY2(), "\\verb{"+JKQTPLineDecoratorStyle2String(decor)+"}", 12, a->getLineColor()));
        arr_y+=arr_deltay;
    }

Here is the resulting table:

geo_arrow_tips

Note how the head-size scales with the line-width, but not linearly, but rather sub-linearly, so the tips do not grow too strongly.

Also note that all arrows end at the designated line-end (here indicated by dashed grey lines), even circles and rectangle:

geo_arrow_tipsatlineend

Classes with support for arrows

You can use JKQTPGeoArrow and JKQTPGeoLine to draw arrows (JKQTPGeoArrow is just a convenience class that enables arrows by default, otherwise it is equal to JKQTPGeoLine).

In addition, also other classes can show line-decorators:

  • JKQTPGeoLine
  • JKQTPGeoPolyLines
  • JKQTPGeoInfiniteLine .

Here is an example of how to actiavate them for a JKQTPGeoPolyLines:

    QVector<QPointF> points; points<<QPointF(3,  0.6)<<QPointF(4,  0.5)<<QPointF(3,  1.2)<<QPointF(4,  1.0);
    JKQTPGeoPolyLines* polyLine=new JKQTPGeoPolyLines(&plot, points);
    polyLine->setHeadDecoratorStyle(JKQTPFilledDoubleArrow);
    polyLine->setTailDecoratorStyle(JKQTPCircleDecorator);
    plot.addGraph(polyLine);

Here is the result:

geo_arrow_polylines

For the class JKQTPGeoInfiniteLine the start can be decorated with an arrow (only if two_sided==false!):

    JKQTPGeoInfiniteLine* infLine=new JKQTPGeoInfiniteLine(&plot, 1.5, 0.2, 1, 0.25);
    infLine->setHeadDecoratorStyle(JKQTPFilledDoubleArrow);
    plot.addGraph(infLine);

Here is the result:

geo_arrow_polylines

Screenshot

The result of the complete example looks like this:

geo_arrows