JKQTPlotter trunk/v5.0.0
an extensive Qt5+Qt6 Plotter framework (including a feature-richt plotter widget, a speed-optimized, but limited variant and a LaTeX equation renderer!), written fully in C/C++ and without external dependencies
Loading...
Searching...
No Matches
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;
}
This convenience specialisation of JKQTPGeoLine is used to draw a line with decorations (e....
Definition jkqtpgeolines.h:190
This JKQTPPlotAnnotationElement is used to display text. It uses the JKQTMathText class in order to d...
Definition jkqtpgeoannotations.h:185
JKQTPLineDecoratorStyle
symbols that can be used to plot a datapoint for a graph
Definition jkqtpdrawingtools.h:365
JKQTCOMMON_LIB_EXPORT QString JKQTPLineDecoratorStyle2String(JKQTPLineDecoratorStyle pos)
converts a JKQTPLineDecoratorStyle variable into a identifier string
@ JKQTPNoDecorator
no decorator, i.e. a simple line-end
Definition jkqtpdrawingtools.h:366
@ JKQTPLineDecoratorCount
can be used to iterate over all symbols using: for (int i=0; i<static_cast<int>(JKQTPLineDecoratorCou...
Definition jkqtpdrawingtools.h:392

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:

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);
plot.addGraph(polyLine);
This JKQTPGeometricPlotElement is used to draw a poly line.
Definition jkqtpgeolines.h:378
void setHeadDecoratorStyle(const JKQTPLineDecoratorStyle &__value)
set the head decorator style
void setTailDecoratorStyle(const JKQTPLineDecoratorStyle &__value)
set the tail decorator style
@ JKQTPCircleDecorator
an open circle tip
Definition jkqtpdrawingtools.h:375
@ JKQTPFilledDoubleArrow
a nice filled double-arrow tip
Definition jkqtpdrawingtools.h:374

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);
plot.addGraph(infLine);
This JKQTPGeometricPlotElement is used to draw an infinite line.
Definition jkqtpgeolines.h:279
void setHeadDecoratorStyle(const JKQTPLineDecoratorStyle &__value)
set the head decorator style

Here is the result:

geo_arrow_polylines

Screenshot

The result of the complete example looks like this:

geo_arrows