JKQTPlotter
an extensive Qt4/Qt5 Plotter framework (including a fast variant and a LaTeX equation renderer!), written fully in C/C++ and without external dependencies

this virtual base class of every element, which is part of a JKQTPlotter plot and may appear in its key (basically any type of graph, except overlay elements!) More...

#include <jkqtpgraphsbase.h>

Inheritance diagram for JKQTPPlotElement:
Collaboration diagram for JKQTPPlotElement:

Classes

struct  HitTestLocation
 Dataset for a single point on the graph, associated with its data-column index and a label that can be used by a basic implementation of hitTest() More...
 

Public Types

enum  HitTestMode {
  HitTestXY,
  HitTestXOnly,
  HitTestYOnly
}
 modes of operation for the function hitTest() More...
 

Public Member Functions

 JKQTPPlotElement (JKQTBasePlotter *parent=nullptr)
 class constructor More...
 
 JKQTPPlotElement (JKQTPlotter *parent)
 class constructor More...
 
virtual ~JKQTPPlotElement ()=default
 default wirtual destructor More...
 
virtual void draw (JKQTPEnhancedPainter &painter)=0
 plots the graph to the plotter object specified as parent More...
 
virtual void drawKeyMarker (JKQTPEnhancedPainter &painter, QRectF &rect)=0
 plots a key marker inside the specified rectangle rect More...
 
virtual void drawOutside (JKQTPEnhancedPainter &painter, QRect leftSpace, QRect rightSpace, QRect topSpace, QRect bottomSpace)
 plots outside the actual plot field of view (e.g. color bars, scale bars, ...) More...
 
QImage generateKeyMarker (QSize size=QSize(16, 16))
 returns an image with a key marker inside
More...
 
virtual QColor getKeyLabelColor () const =0
 returns the color to be used for the key label More...
 
virtual void getOutsideSize (JKQTPEnhancedPainter &painter, int &leftSpace, int &rightSpace, int &topSpace, int &bottomSpace)
 if the graph plots outside the actual plot field of view (e.g. color bars, scale bars, ...) More...
 
JKQTBasePlottergetParent ()
 returns the parent painter class More...
 
virtual QString getTitle () const
 returns the the title of the plot More...
 
virtual bool getXMinMax (double &minx, double &maxx, double &smallestGreaterZero)=0
 get the maximum and minimum x-value of the graph More...
 
virtual bool getYMinMax (double &miny, double &maxy, double &smallestGreaterZero)=0
 get the maximum and minimum y-value of the graph More...
 
virtual double hitTest (const QPointF &posSystem, QPointF *closestSpotSystem=nullptr, QString *label=nullptr, HitTestMode mode=HitTestXY) const
 returns the closest distance of the plot element to the (screen pixel) position pos, or NAN More...
 
virtual bool isHighlighted () const
 returns whether the graph is shown in a highlighted style in the plot More...
 
virtual bool isVisible () const
 returns whether the graph is visible in the plot More...
 
virtual void setHighlighted (bool __value)
 sets whether the graph is drawn in a highlighted style in the plot More...
 
virtual void setParent (JKQTBasePlotter *parent)
 sets the parent painter class More...
 
virtual void setParent (JKQTPlotter *parent)
 sets the parent painter class More...
 
virtual void setTitle (const QString &__value)
 sets the title of the plot (for display in key!). More...
 
virtual void setVisible (bool __value)
 sets whether the graph is visible in the plot More...
 

Protected Member Functions

void addHitTestData (const HitTestLocation &loc)
 clear the internal datastore for hitTest() More...
 
void addHitTestData (const QPointF &pos_, const QString &label_)
 clear the internal datastore for hitTest() More...
 
void addHitTestData (const QPointF &pos_, int index_, const QString &label_)
 clear the internal datastore for hitTest() More...
 
void addHitTestData (const QPointF &pos_, int index_=-1, JKQTPDatastore *datastore=nullptr)
 clear the internal datastore for hitTest(), this variant uses formatHitTestDefaultLabel() to auto-generate the label More...
 
void addHitTestData (double x_, double y_, const QString &label_)
 add a new point on the graph to the internal datastore for hitTest() More...
 
void addHitTestData (double x_, double y_, int index_, const QString &label_)
 clear the internal datastore for hitTest() More...
 
void addHitTestData (double x_, double y_, int index_=-1, JKQTPDatastore *datastore=nullptr)
 add a new point on the graph to the internal datastore for hitTest(), this variant uses formatHitTestDefaultLabel() to auto-generate the label More...
 
QPointF backTransform (const QPointF &x) const
 tool routine that back-transforms a QPointF according to the parent's transformation rules (pixels --> plot coordinate) More...
 
QPointF backTransform (double x, double y) const
 tool routine that back-transforms a QPointF according to the parent's transformation rules (pixels --> plot coordinate) More...
 
virtual double backtransformX (double x) const
 tool routine that backtransforms an x-coordinate (pixels --> plot coordinate) for this plot element More...
 
virtual double backtransformY (double y) const
 tool routine that backtransforms a y-coordinate (pixels --> plot coordinate) for this plot element More...
 
void clearHitTestData ()
 clear the internal datastore for hitTest() More...
 
virtual QString formatHitTestDefaultLabel (double x, double y, int index=-1, JKQTPDatastore *datastore=nullptr) const
 tool-function for hitTest(), which formats a default label, taking into account the x- and y-position (both provided) and optionally the errors of these positions. More...
 
void reserveHitTestData (int points)
 reserve list entries for up to points graph points in the internal datastore for hitTest() More...
 
QPointF transform (const QPointF &x) const
 tool routine that transforms a QPointF according to the parent's transformation rules (plot coordinate --> pixels) More...
 
QVector< QPointF > transform (const QVector< QPointF > &x) const
 tool routine that transforms a QVector<QPointF> according to the parent's transformation rules (plot coordinate --> pixels) More...
 
QPointF transform (double x, double y) const
 tool routine that transforms a QPointF according to the parent's transformation rules (plot coordinate --> pixels) More...
 
QPainterPath transformToLinePath (const QVector< QPointF > &x) const
 tool routine that transforms a QVector<QPointF> according to the parent's transformation rules and returns a (non-closed) path consisting of lines (plot coordinate --> pixels) More...
 
QPolygonF transformToPolygon (const QVector< QPointF > &x) const
 tool routine that transforms a QVector<QPointF> according to the parent's transformation rules and returns a polygon (plot coordinate --> pixels) More...
 
QVector< double > transformX (const QVector< double > &x) const
 transform all x-coordinates in a vector x More...
 
virtual double transformX (double x) const
 tool routine that transforms an x-coordinate (plot coordinate --> pixels) for this plot element More...
 
QVector< double > transformY (const QVector< double > &x) const
 transform all y-coordinates in a vector x More...
 
virtual double transformY (double y) const
 tool routine that transforms a y-coordinate (plot coordinate --> pixels) for this plot element More...
 

Protected Attributes

bool highlighted
 indicates whether the graph is shown in a "highlghted" in the plot More...
 
QVector< HitTestLocationm_hitTestData
 dataset with graph-points and associated data fro the function hitTest() More...
 
JKQTBasePlotterparent
 the plotter object this object belongs to More...
 
int parentPlotStyle
 internal storage for the used parent plot style More...
 
QString title
 title of the plot (for display in key!). If no title is supplied, no key entry is drawn. More...
 
bool visible
 indicates whether the graph is visible in the plot More...
 

Detailed Description

this virtual base class of every element, which is part of a JKQTPlotter plot and may appear in its key (basically any type of graph, except overlay elements!)

Each possible graph is represented by a child of this class. So additional plots may be created by deriving new JKQTPGraph classes. To do so implement/overwrite these functions:

Optionally you may also overwrite these functions to draw elements outside the actual plot area (like e.g. colorbars):

In addition this class provudes protected functions that do coordinate transforms based on the current coordinate system, of the paren JKQTPlotter (i.e. using the axes JKQTPLott:xAxis and JKQTPlotter::yAxis as basis for the plotting).

See also
Graph Class Structure

Member Enumeration Documentation

◆ HitTestMode

modes of operation for the function hitTest()

Enumerator
HitTestXY 

find closest point in x- and y-direction simulatneously (i.e. measure direct distance)

HitTestXOnly 

find closest point in x-direction only

HitTestYOnly 

find closest point in y-direction only

Constructor & Destructor Documentation

◆ JKQTPPlotElement() [1/2]

JKQTPPlotElement::JKQTPPlotElement ( JKQTBasePlotter parent = nullptr)
explicit

class constructor

◆ JKQTPPlotElement() [2/2]

JKQTPPlotElement::JKQTPPlotElement ( JKQTPlotter parent)
explicit

class constructor

◆ ~JKQTPPlotElement()

virtual JKQTPPlotElement::~JKQTPPlotElement ( )
virtualdefault

default wirtual destructor

Member Function Documentation

◆ addHitTestData() [1/7]

void JKQTPPlotElement::addHitTestData ( const HitTestLocation loc)
inlineprotected

clear the internal datastore for hitTest()

Note
This function has to be called at the start of draw()
See also
hitTest(), clearHitTestData(), m_hitTestData, HitTestLocation, reserveHitTestData()

◆ addHitTestData() [2/7]

void JKQTPPlotElement::addHitTestData ( const QPointF &  pos_,
const QString &  label_ 
)
inlineprotected

clear the internal datastore for hitTest()

Parameters
pos_position of the graph point in system coordinates
label_a label for this datapoint, that can e.g. be displayed in a tooltip for this point
See also
hitTest(), clearHitTestData(), m_hitTestData, HitTestLocation, reserveHitTestData()

◆ addHitTestData() [3/7]

void JKQTPPlotElement::addHitTestData ( const QPointF &  pos_,
int  index_,
const QString &  label_ 
)
inlineprotected

clear the internal datastore for hitTest()

Parameters
pos_position of the graph point in system coordinates
index_index of the graph point in the internal data columns
label_a label for this datapoint, that can e.g. be displayed in a tooltip for this point
See also
hitTest(), clearHitTestData(), m_hitTestData, HitTestLocation, reserveHitTestData()

◆ addHitTestData() [4/7]

void JKQTPPlotElement::addHitTestData ( const QPointF &  pos_,
int  index_ = -1,
JKQTPDatastore datastore = nullptr 
)
inlineprotected

clear the internal datastore for hitTest(), this variant uses formatHitTestDefaultLabel() to auto-generate the label

Parameters
pos_position of the graph point in system coordinates
index_index of the graph point in the internal data columns, or -1
datastoredatastore for formatHitTestDefaultLabel()
See also
hitTest(), clearHitTestData(), m_hitTestData, HitTestLocation, reserveHitTestData()

◆ addHitTestData() [5/7]

void JKQTPPlotElement::addHitTestData ( double  x_,
double  y_,
const QString &  label_ 
)
inlineprotected

add a new point on the graph to the internal datastore for hitTest()

Parameters
x_x-position of the graph point in system coordinates
y_y-position of the graph point in system coordinates
label_a label for this datapoint, that can e.g. be displayed in a tooltip for this point
See also
hitTest(), clearHitTestData(), m_hitTestData, HitTestLocation, reserveHitTestData()

◆ addHitTestData() [6/7]

void JKQTPPlotElement::addHitTestData ( double  x_,
double  y_,
int  index_,
const QString &  label_ 
)
inlineprotected

clear the internal datastore for hitTest()

Parameters
x_x-position of the graph point in system coordinates
y_y-position of the graph point in system coordinates
index_index of the graph point in the internal data columns
label_a label for this datapoint, that can e.g. be displayed in a tooltip for this point
See also
hitTest(), clearHitTestData(), m_hitTestData, HitTestLocation, reserveHitTestData()

◆ addHitTestData() [7/7]

void JKQTPPlotElement::addHitTestData ( double  x_,
double  y_,
int  index_ = -1,
JKQTPDatastore datastore = nullptr 
)
inlineprotected

add a new point on the graph to the internal datastore for hitTest(), this variant uses formatHitTestDefaultLabel() to auto-generate the label

Parameters
x_x-position of the graph point in system coordinates
y_y-position of the graph point in system coordinates
index_index of the graph point in the internal data columns, or -1
datastoredatastore for formatHitTestDefaultLabel()
See also
hitTest(), clearHitTestData(), m_hitTestData, HitTestLocation, reserveHitTestData()

◆ backTransform() [1/2]

QPointF JKQTPPlotElement::backTransform ( const QPointF &  x) const
inlineprotected

tool routine that back-transforms a QPointF according to the parent's transformation rules (pixels --> plot coordinate)

◆ backTransform() [2/2]

QPointF JKQTPPlotElement::backTransform ( double  x,
double  y 
) const
inlineprotected

tool routine that back-transforms a QPointF according to the parent's transformation rules (pixels --> plot coordinate)

◆ backtransformX()

virtual double JKQTPPlotElement::backtransformX ( double  x) const
protectedvirtual

tool routine that backtransforms an x-coordinate (pixels --> plot coordinate) for this plot element

◆ backtransformY()

virtual double JKQTPPlotElement::backtransformY ( double  y) const
protectedvirtual

tool routine that backtransforms a y-coordinate (pixels --> plot coordinate) for this plot element

◆ clearHitTestData()

void JKQTPPlotElement::clearHitTestData ( )
inlineprotected

clear the internal datastore for hitTest()

Note
This function has to be called at the start of draw()
See also
hitTest(), addHitTestData(), m_hitTestData, HitTestLocation

◆ draw()

◆ drawKeyMarker()

◆ drawOutside()

virtual void JKQTPPlotElement::drawOutside ( JKQTPEnhancedPainter painter,
QRect  leftSpace,
QRect  rightSpace,
QRect  topSpace,
QRect  bottomSpace 
)
virtual

plots outside the actual plot field of view (e.g. color bars, scale bars, ...)

Note
If you want to draw outside, then you'll also have to implement getOutsideSize(), so enough space is reserved

The four value supplied tell the method where to draw (inside one of the rectangles).

Reimplemented in JKQTPMathImage, JKQTPRGBMathImage, and JKQTPXYParametrizedScatterGraph.

◆ formatHitTestDefaultLabel()

virtual QString JKQTPPlotElement::formatHitTestDefaultLabel ( double  x,
double  y,
int  index = -1,
JKQTPDatastore datastore = nullptr 
) const
protectedvirtual

tool-function for hitTest(), which formats a default label, taking into account the x- and y-position (both provided) and optionally the errors of these positions.

Parameters
xx-position of the datapoint in system coordinates
yy-position of the datapoint in system coordinates
indexthe index of the data point in the associated data column(s), or -1 (optional!)
datastoreThe datastore to read error data from (optional!)
Returns
a LaTeX formatted label

◆ generateKeyMarker()

QImage JKQTPPlotElement::generateKeyMarker ( QSize  size = QSize(16, 16))

returns an image with a key marker inside

◆ getKeyLabelColor()

◆ getOutsideSize()

virtual void JKQTPPlotElement::getOutsideSize ( JKQTPEnhancedPainter painter,
int &  leftSpace,
int &  rightSpace,
int &  topSpace,
int &  bottomSpace 
)
virtual

if the graph plots outside the actual plot field of view (e.g. color bars, scale bars, ...)

Note
If you want to draw outside, then you'll also have to implement drawOutside()

Reimplemented in JKQTPMathImage, JKQTPRGBMathImage, and JKQTPXYParametrizedScatterGraph.

◆ getParent()

JKQTBasePlotter* JKQTPPlotElement::getParent ( )
inline

returns the parent painter class

◆ getTitle()

virtual QString JKQTPPlotElement::getTitle ( ) const
virtual

returns the the title of the plot

◆ getXMinMax()

◆ getYMinMax()

◆ hitTest()

virtual double JKQTPPlotElement::hitTest ( const QPointF &  posSystem,
QPointF *  closestSpotSystem = nullptr,
QString *  label = nullptr,
HitTestMode  mode = HitTestXY 
) const
virtual

returns the closest distance of the plot element to the (screen pixel) position pos, or NAN

This function is used to implement hit tests, i.e. to test whether a graph is close to a given position posSystem. The function will then return the distance of the closes graph-point and a label for this point. An example of what can be done with this function is the tooltip tool that JKQTPlotter provides via its context-menu/toolbar. This tool uses just the information of the closest point and its label to display a tooltip for that datapoint:

See also
jkqtpmdaToolTipForClosestDataPoint for details.
Parameters
posSystemposition to test in system coordinates
[out]closestSpotSystemoptional output of the closest point found on the plot element in system coordinates
[out]labeloptional output of a label for the closest point (that might e.g. be used in a tooltip)
modesearch mode, i.e. use sqrt(dx*dx+dy*dy) as distance, or just the absoulte values along one of the two coordinate axes. Note that the returned distance depends on this parameter!
Returns
NAN if not implemented, or if pos is very far from the plot element, or the closest distance (in screen pixels) of pos from the plot element. Note that the returned distance depends on the choosen mode !!! You can use JKQTPIsOKFloat() to check whether a valid distance was returned!

Since tha graph base class does not have any knowledge about how to perform a hit test on you specific graph, there is only a very general implementation in this class, which does not actually search through the graph itself, but searches through extra data that hs to be written during draw() and is stored in m_hitTestData. The implentation this base-class only searches this list of points+metadata to implement a basic hit-test. If the list is empty, of no close-by points are found (default), then hitTest() will simply return NAN.

When writing a new graph, you can therefore implement hitTest() in one of these ways:

You simply fill m_hitTestData with appropriate data and rely on the implementation in JKQTPPlotElement to do the work for you:

You then need to call clearHitTestData() at the start of your draw() function and whenever you draw a datapoint, you add its location and metadata to the internal storage with addHitTestData()

You derive from a graph class that already has an implementation. JKQTPXYGraph is an example of this. That class searches

through all x-/y-coordinates in the internally known columns and even takes into account possible graph errors in the label, when the graph is also derived from JKQTPXGraphErrorData or JKQTPYGraphErrorData. This implementation therefore covers most graph types pre-packaged with JKQTPlotter

You implement the function from scratch

See also
addHitTestData(), clearHitTestData(), m_hitTestData, HitTestLocation

Reimplemented in JKQTPXYGraph.

◆ isHighlighted()

virtual bool JKQTPPlotElement::isHighlighted ( ) const
virtual

returns whether the graph is shown in a highlighted style in the plot

◆ isVisible()

virtual bool JKQTPPlotElement::isVisible ( ) const
virtual

returns whether the graph is visible in the plot

◆ reserveHitTestData()

void JKQTPPlotElement::reserveHitTestData ( int  points)
inlineprotected

reserve list entries for up to points graph points in the internal datastore for hitTest()

Note
Call this after clearHitTestData() for improved speed of subsequent addHitTestData() calls!
See also
hitTest(), addHitTestData(), m_hitTestData, HitTestLocation

◆ setHighlighted()

virtual void JKQTPPlotElement::setHighlighted ( bool  __value)
virtual

sets whether the graph is drawn in a highlighted style in the plot

◆ setParent() [1/2]

virtual void JKQTPPlotElement::setParent ( JKQTBasePlotter parent)
virtual

sets the parent painter class

Reimplemented in JKQTPMathImage, JKQTPImage, JKQTPXYParametrizedScatterGraph, JKQTPOverlayImage, and JKQTPRGBMathImage.

◆ setParent() [2/2]

virtual void JKQTPPlotElement::setParent ( JKQTPlotter parent)
virtual

sets the parent painter class

◆ setTitle()

virtual void JKQTPPlotElement::setTitle ( const QString &  __value)
virtual

sets the title of the plot (for display in key!).

Note
If no title is supplied, no key entry is drawn.

Reimplemented in JKQTPMathImage, JKQTPRGBMathImage, JKQTPImage, and JKQTPOverlayImage.

◆ setVisible()

virtual void JKQTPPlotElement::setVisible ( bool  __value)
virtual

sets whether the graph is visible in the plot

◆ transform() [1/3]

QPointF JKQTPPlotElement::transform ( const QPointF &  x) const
inlineprotected

tool routine that transforms a QPointF according to the parent's transformation rules (plot coordinate --> pixels)

◆ transform() [2/3]

QVector<QPointF> JKQTPPlotElement::transform ( const QVector< QPointF > &  x) const
protected

tool routine that transforms a QVector<QPointF> according to the parent's transformation rules (plot coordinate --> pixels)

◆ transform() [3/3]

QPointF JKQTPPlotElement::transform ( double  x,
double  y 
) const
inlineprotected

tool routine that transforms a QPointF according to the parent's transformation rules (plot coordinate --> pixels)

◆ transformToLinePath()

QPainterPath JKQTPPlotElement::transformToLinePath ( const QVector< QPointF > &  x) const
protected

tool routine that transforms a QVector<QPointF> according to the parent's transformation rules and returns a (non-closed) path consisting of lines (plot coordinate --> pixels)

◆ transformToPolygon()

QPolygonF JKQTPPlotElement::transformToPolygon ( const QVector< QPointF > &  x) const
inlineprotected

tool routine that transforms a QVector<QPointF> according to the parent's transformation rules and returns a polygon (plot coordinate --> pixels)

◆ transformX() [1/2]

QVector<double> JKQTPPlotElement::transformX ( const QVector< double > &  x) const
protected

transform all x-coordinates in a vector x

◆ transformX() [2/2]

virtual double JKQTPPlotElement::transformX ( double  x) const
protectedvirtual

tool routine that transforms an x-coordinate (plot coordinate --> pixels) for this plot element

◆ transformY() [1/2]

QVector<double> JKQTPPlotElement::transformY ( const QVector< double > &  x) const
protected

transform all y-coordinates in a vector x

◆ transformY() [2/2]

virtual double JKQTPPlotElement::transformY ( double  y) const
protectedvirtual

tool routine that transforms a y-coordinate (plot coordinate --> pixels) for this plot element

Member Data Documentation

◆ highlighted

bool JKQTPPlotElement::highlighted
protected

indicates whether the graph is shown in a "highlghted" in the plot

◆ m_hitTestData

QVector<HitTestLocation> JKQTPPlotElement::m_hitTestData
protected

dataset with graph-points and associated data fro the function hitTest()

See also
hitTest(), HitTestLocation

◆ parent

JKQTBasePlotter* JKQTPPlotElement::parent
protected

the plotter object this object belongs to

◆ parentPlotStyle

int JKQTPPlotElement::parentPlotStyle
protected

internal storage for the used parent plot style

◆ title

QString JKQTPPlotElement::title
protected

title of the plot (for display in key!). If no title is supplied, no key entry is drawn.

◆ visible

bool JKQTPPlotElement::visible
protected

indicates whether the graph is visible in the plot


The documentation for this class was generated from the following file: