mirror of
https://github.com/jkriege2/JKQtPlotter.git
synced 2024-12-25 18:11:38 +08:00
improved/breaking change: reworked class hierarchy of filled line graphs
This commit is contained in:
parent
d638ff1e9c
commit
9e48a2e59e
@ -29,6 +29,7 @@ Changes, compared to \ref page_whatsnew_V2019_11 "v2019.11" include:
|
|||||||
<li>improved/breaking change: reworked class hierarchy of bar & impulse charts.</li>
|
<li>improved/breaking change: reworked class hierarchy of bar & impulse charts.</li>
|
||||||
<li>improved/breaking change: reworked class hierarchy of range charts.</li>
|
<li>improved/breaking change: reworked class hierarchy of range charts.</li>
|
||||||
<li>improved/breaking change: reworked class hierarchy of special line (step) graphs.</li>
|
<li>improved/breaking change: reworked class hierarchy of special line (step) graphs.</li>
|
||||||
|
<li>improved/breaking change: reworked class hierarchy of filled line graphs.</li>
|
||||||
<li>improved/breaking change: reworked graph Base-Classes (promoted several setters to slots, added Q_PROPERTY- and Q_ENUM-declarations...)</li>
|
<li>improved/breaking change: reworked graph Base-Classes (promoted several setters to slots, added Q_PROPERTY- and Q_ENUM-declarations...)</li>
|
||||||
<li>improved/breaking change: made more functions and function parameters const</li>
|
<li>improved/breaking change: made more functions and function parameters const</li>
|
||||||
<li>bugfixed/improved: aspect ratio handling in JKQTPlotter.</li>
|
<li>bugfixed/improved: aspect ratio handling in JKQTPlotter.</li>
|
||||||
|
@ -32,17 +32,50 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
JKQTPFilledCurveGraphBase::JKQTPFilledCurveGraphBase(JKQTBasePlotter *parent):
|
||||||
|
JKQTPXYBaselineGraph(parent)
|
||||||
|
{
|
||||||
|
parentPlotStyle=-1;
|
||||||
|
initLineStyle(parent, parentPlotStyle);
|
||||||
|
initFillStyle(parent, parentPlotStyle);
|
||||||
|
setFillCurve(true);
|
||||||
|
setDrawLine(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
QColor JKQTPFilledCurveGraphBase::getKeyLabelColor() const
|
||||||
|
{
|
||||||
|
return getLineColor();
|
||||||
|
}
|
||||||
|
|
||||||
|
void JKQTPFilledCurveGraphBase::drawKeyMarker(JKQTPEnhancedPainter &painter, QRectF &rect)
|
||||||
|
{
|
||||||
|
painter.save(); auto __finalpaint=JKQTPFinally([&painter]() {painter.restore();});
|
||||||
|
QPen p=getLinePen(painter, parent);
|
||||||
|
QPen np(Qt::NoPen);
|
||||||
|
QBrush b=getFillBrush(painter, parent);
|
||||||
|
const double y=rect.top()+rect.height()/2.0;
|
||||||
|
painter.setPen(np);
|
||||||
|
if (getDrawLine()) painter.setPen(p);
|
||||||
|
painter.setBrush(b);
|
||||||
|
if (getFillCurve()) painter.drawRect(rect);
|
||||||
|
if (!getFillCurve() && getDrawLine()) painter.drawLine(QLineF(rect.left(), y, rect.right(), y));
|
||||||
|
}
|
||||||
|
|
||||||
|
void JKQTPFilledCurveGraphBase::setColor(QColor c)
|
||||||
|
{
|
||||||
|
setLineColor(c);
|
||||||
|
setFillColor(JKQTPGetDerivedColor(parent->getCurrentPlotterStyle().graphFillColorDerivationMode, c));
|
||||||
|
c.setAlphaF(0.5);
|
||||||
|
setHighlightingLineColor(c);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
JKQTPFilledCurveXGraph::JKQTPFilledCurveXGraph(JKQTBasePlotter* parent):
|
JKQTPFilledCurveXGraph::JKQTPFilledCurveXGraph(JKQTBasePlotter* parent):
|
||||||
JKQTPSpecialLineHorizontalGraph(parent)
|
JKQTPFilledCurveGraphBase(parent)
|
||||||
{
|
{
|
||||||
setDrawLine(true);
|
|
||||||
setDrawSymbols(false);
|
|
||||||
setFillCurve(true);
|
|
||||||
setSpecialLineType(JKQTPDirectLine);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
JKQTPFilledCurveXGraph::JKQTPFilledCurveXGraph(JKQTPlotter *parent):
|
JKQTPFilledCurveXGraph::JKQTPFilledCurveXGraph(JKQTPlotter *parent):
|
||||||
@ -51,15 +84,95 @@ JKQTPFilledCurveXGraph::JKQTPFilledCurveXGraph(JKQTPlotter *parent):
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void JKQTPFilledCurveXGraph::draw(JKQTPEnhancedPainter& painter) {
|
||||||
|
#ifdef JKQTBP_AUTOTIMER
|
||||||
|
JKQTPAutoOutputTimer jkaaot("JKQTPFilledCurveXGraph::draw");
|
||||||
|
#endif
|
||||||
|
if (parent==nullptr) return;
|
||||||
|
JKQTPDatastore* datastore=parent->getDatastore();
|
||||||
|
if (datastore==nullptr) return;
|
||||||
|
|
||||||
|
drawErrorsBefore(painter);
|
||||||
|
|
||||||
|
QPen p=getLinePen(painter, parent);
|
||||||
|
QPen ph=getHighlightingLinePen(painter, parent);
|
||||||
|
QPen np(Qt::NoPen);
|
||||||
|
QBrush b=getFillBrush(painter, parent);
|
||||||
|
|
||||||
|
int imax=0;
|
||||||
|
int imin=0;
|
||||||
|
|
||||||
|
if (getIndexRange(imin, imax)) {
|
||||||
|
|
||||||
|
|
||||||
|
QPainterPath pl, pf;
|
||||||
|
|
||||||
|
double xold=-1;
|
||||||
|
double yold=-1;
|
||||||
|
double y0=transformY(getBaseline());
|
||||||
|
if (parent->getYAxis()->isLogAxis()) {
|
||||||
|
y0=transformY(parent->getYAxis()->getMin());
|
||||||
|
if (getBaseline()>0 && getBaseline()>parent->getYAxis()->getMin()) y0=transformY(getBaseline());
|
||||||
|
else y0=transformY(parent->getYAxis()->getMin());
|
||||||
|
}
|
||||||
|
bool subsequentItem=false;
|
||||||
|
intSortData();
|
||||||
|
for (int iii=imin; iii<imax; iii++) {
|
||||||
|
const int i=qBound(imin, getDataIndex(iii), imax);
|
||||||
|
const double xv=datastore->get(static_cast<size_t>(xColumn),static_cast<size_t>(i));
|
||||||
|
const double yv=datastore->get(static_cast<size_t>(yColumn),static_cast<size_t>(i));
|
||||||
|
//std::cout<<"(xv, yv) = ( "<<xv<<", "<<yv<<" )\n";
|
||||||
|
if (JKQTPIsOKFloat(xv) && JKQTPIsOKFloat(yv)) {
|
||||||
|
const double x=transformX(xv);
|
||||||
|
const double y=transformY(yv);
|
||||||
|
if (JKQTPIsOKFloat(x) && JKQTPIsOKFloat(y)) {
|
||||||
|
if (subsequentItem) {
|
||||||
|
pf.lineTo(x, y);
|
||||||
|
if (getDrawLine()) {
|
||||||
|
pl.lineTo(x, y);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (getDrawLine()) pl.moveTo(x,y);
|
||||||
|
pf.moveTo(x, y0);
|
||||||
|
pf.lineTo(x, y);
|
||||||
|
}
|
||||||
|
xold=x;
|
||||||
|
yold=y;
|
||||||
|
subsequentItem=true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (getFillCurve()) {
|
||||||
|
pf.lineTo(xold, y0);
|
||||||
|
pf.closeSubpath();
|
||||||
|
}
|
||||||
|
painter.save();
|
||||||
|
auto __finalpaint=JKQTPFinally([&painter]() {painter.restore();});
|
||||||
|
|
||||||
|
if (getFillCurve()) {
|
||||||
|
painter.fillPath(pf, b);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isHighlighted()) {
|
||||||
|
painter.setBrush(QBrush(Qt::transparent));
|
||||||
|
painter.setPen(ph);
|
||||||
|
painter.drawPath(pl);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (getDrawLine()) {
|
||||||
|
painter.setBrush(QBrush(Qt::transparent));
|
||||||
|
painter.setPen(p);
|
||||||
|
painter.drawPath(pl);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
drawErrorsAfter(painter);
|
||||||
|
}
|
||||||
|
|
||||||
JKQTPFilledCurveYGraph::JKQTPFilledCurveYGraph(JKQTBasePlotter* parent):
|
JKQTPFilledCurveYGraph::JKQTPFilledCurveYGraph(JKQTBasePlotter* parent):
|
||||||
JKQTPSpecialLineVerticalGraph(parent)
|
JKQTPFilledCurveGraphBase(parent)
|
||||||
{
|
{
|
||||||
setDrawLine(true);
|
|
||||||
setDrawSymbols(false);
|
|
||||||
setFillCurve(true);
|
|
||||||
setSpecialLineType(JKQTPDirectLine);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
JKQTPFilledCurveYGraph::JKQTPFilledCurveYGraph(JKQTPlotter *parent):
|
JKQTPFilledCurveYGraph::JKQTPFilledCurveYGraph(JKQTPlotter *parent):
|
||||||
@ -68,6 +181,90 @@ JKQTPFilledCurveYGraph::JKQTPFilledCurveYGraph(JKQTPlotter *parent):
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void JKQTPFilledCurveYGraph::draw(JKQTPEnhancedPainter &painter)
|
||||||
|
{
|
||||||
|
#ifdef JKQTBP_AUTOTIMER
|
||||||
|
JKQTPAutoOutputTimer jkaaot("JKQTPSpecialLineVerticalGraph::draw");
|
||||||
|
#endif
|
||||||
|
if (parent==nullptr) return;
|
||||||
|
JKQTPDatastore* datastore=parent->getDatastore();
|
||||||
|
if (datastore==nullptr) return;
|
||||||
|
|
||||||
|
drawErrorsBefore(painter);
|
||||||
|
|
||||||
|
QPen p=getLinePen(painter, parent);
|
||||||
|
QPen ph=getHighlightingLinePen(painter, parent);
|
||||||
|
QPen np(Qt::NoPen);
|
||||||
|
QBrush b=getFillBrush(painter, parent);
|
||||||
|
|
||||||
|
int imax=0;
|
||||||
|
int imin=0;
|
||||||
|
|
||||||
|
if (getIndexRange(imin, imax)) {
|
||||||
|
|
||||||
|
|
||||||
|
QPainterPath pl, pf;
|
||||||
|
|
||||||
|
double xold=-1;
|
||||||
|
double yold=-1;
|
||||||
|
double x0=transformX(getBaseline());
|
||||||
|
if (parent->getXAxis()->isLogAxis()) {
|
||||||
|
if (getBaseline()>0 && getBaseline()>parent->getXAxis()->getMin()) x0=transformX(getBaseline());
|
||||||
|
else x0=transformX(parent->getXAxis()->getMin());
|
||||||
|
}
|
||||||
|
bool first=false;
|
||||||
|
intSortData();
|
||||||
|
for (int iii=imin; iii<imax; iii++) {
|
||||||
|
const int i=qBound(imin, getDataIndex(iii), imax);
|
||||||
|
const double xv=datastore->get(static_cast<size_t>(xColumn),static_cast<size_t>(i));
|
||||||
|
const double yv=datastore->get(static_cast<size_t>(yColumn),static_cast<size_t>(i));
|
||||||
|
//std::cout<<"(xv, yv) = ( "<<xv<<", "<<yv<<" )\n";
|
||||||
|
if (JKQTPIsOKFloat(xv) && JKQTPIsOKFloat(yv)) {
|
||||||
|
const double x=transformX(xv);
|
||||||
|
const double y=transformY(yv);
|
||||||
|
if (JKQTPIsOKFloat(x) && JKQTPIsOKFloat(y)) {
|
||||||
|
if (first) {
|
||||||
|
|
||||||
|
pf.lineTo(x, y);
|
||||||
|
if (getDrawLine()) {
|
||||||
|
pl.lineTo(x, y);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (getDrawLine()) pl.moveTo(x,y);
|
||||||
|
pf.moveTo(x0, y);
|
||||||
|
pf.lineTo(x, y);
|
||||||
|
}
|
||||||
|
xold=x;
|
||||||
|
yold=y;
|
||||||
|
first=true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pf.lineTo(x0, yold);
|
||||||
|
pf.closeSubpath();
|
||||||
|
painter.save(); auto __finalpaint=JKQTPFinally([&painter]() {painter.restore();});
|
||||||
|
|
||||||
|
if (getFillCurve()) {
|
||||||
|
painter.fillPath(pf, b);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isHighlighted()) {
|
||||||
|
painter.setBrush(QBrush(Qt::transparent));
|
||||||
|
painter.setPen(ph);
|
||||||
|
painter.drawPath(pl);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (getDrawLine()) {
|
||||||
|
painter.setBrush(QBrush(Qt::transparent));
|
||||||
|
painter.setPen(p);
|
||||||
|
painter.drawPath(pl);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
drawErrorsAfter(painter);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
JKQTPFilledCurveXErrorGraph::JKQTPFilledCurveXErrorGraph(JKQTBasePlotter *parent):
|
JKQTPFilledCurveXErrorGraph::JKQTPFilledCurveXErrorGraph(JKQTBasePlotter *parent):
|
||||||
@ -349,3 +546,4 @@ QColor JKQTPFilledHorizontalRangeGraph::getKeyLabelColor() const
|
|||||||
{
|
{
|
||||||
return getLineColor();
|
return getLineColor();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,6 +30,33 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/** \brief a Base class for filled curve graphs like e.g. JKQTPFilledCurveXGraph
|
||||||
|
* \ingroup jkqtplotter_linesymbolgraphs_simple
|
||||||
|
*
|
||||||
|
* \image html filledgraphs.png
|
||||||
|
*
|
||||||
|
* \see JKQTPFilledCurveXGraph, JKQTPFilledCurveYGraph
|
||||||
|
*/
|
||||||
|
class JKQTPLOTTER_LIB_EXPORT JKQTPFilledCurveGraphBase: public JKQTPXYBaselineGraph, public JKQTPGraphLineAndFillStyleMixin {
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
/** \brief class constructor */
|
||||||
|
explicit JKQTPFilledCurveGraphBase(JKQTBasePlotter* parent=nullptr);
|
||||||
|
|
||||||
|
/** \brief returns the color to be used for the key label */
|
||||||
|
virtual QColor getKeyLabelColor() const override;
|
||||||
|
/** \brief plots a key marker inside the specified rectangle \a rect */
|
||||||
|
virtual void drawKeyMarker(JKQTPEnhancedPainter& painter, QRectF& rect) override;
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
/** \brief set line-color, fill color and symbol color */
|
||||||
|
void setColor(QColor c);
|
||||||
|
protected:
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*! \brief This implements filled curve plots where the area is filled between the plot line and the x-Axis.
|
/*! \brief This implements filled curve plots where the area is filled between the plot line and the x-Axis.
|
||||||
\ingroup jkqtplotter_filledgraphs
|
\ingroup jkqtplotter_filledgraphs
|
||||||
|
|
||||||
@ -37,13 +64,15 @@
|
|||||||
|
|
||||||
\see \ref JKQTPlotterFilledGraphs
|
\see \ref JKQTPlotterFilledGraphs
|
||||||
*/
|
*/
|
||||||
class JKQTPLOTTER_LIB_EXPORT JKQTPFilledCurveXGraph: public JKQTPSpecialLineHorizontalGraph {
|
class JKQTPLOTTER_LIB_EXPORT JKQTPFilledCurveXGraph: public JKQTPFilledCurveGraphBase {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
/** \brief class constructor */
|
/** \brief class constructor */
|
||||||
JKQTPFilledCurveXGraph(JKQTBasePlotter* parent=nullptr);
|
JKQTPFilledCurveXGraph(JKQTBasePlotter* parent=nullptr);
|
||||||
/** \brief class constructor */
|
/** \brief class constructor */
|
||||||
JKQTPFilledCurveXGraph(JKQTPlotter* parent);
|
JKQTPFilledCurveXGraph(JKQTPlotter* parent);
|
||||||
|
/** \brief plots the graph to the plotter object specified as parent */
|
||||||
|
void draw(JKQTPEnhancedPainter &painter);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -85,7 +114,7 @@ class JKQTPLOTTER_LIB_EXPORT JKQTPFilledCurveXErrorGraph: public JKQTPFilledCurv
|
|||||||
\see \ref JKQTPlotterFilledGraphs
|
\see \ref JKQTPlotterFilledGraphs
|
||||||
|
|
||||||
*/
|
*/
|
||||||
class JKQTPLOTTER_LIB_EXPORT JKQTPFilledCurveYGraph: public JKQTPSpecialLineVerticalGraph {
|
class JKQTPLOTTER_LIB_EXPORT JKQTPFilledCurveYGraph: public JKQTPFilledCurveGraphBase {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
/** \brief class constructor */
|
/** \brief class constructor */
|
||||||
@ -93,6 +122,8 @@ class JKQTPLOTTER_LIB_EXPORT JKQTPFilledCurveYGraph: public JKQTPSpecialLineVert
|
|||||||
/** \brief class constructor */
|
/** \brief class constructor */
|
||||||
JKQTPFilledCurveYGraph(JKQTPlotter* parent);
|
JKQTPFilledCurveYGraph(JKQTPlotter* parent);
|
||||||
|
|
||||||
|
/** \brief plots the graph to the plotter object specified as parent */
|
||||||
|
void draw(JKQTPEnhancedPainter &painter);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user