2019-04-22 19:27:50 +08:00
|
|
|
/*
|
2022-07-19 19:40:43 +08:00
|
|
|
Copyright (c) 2008-2022 Jan W. Krieger (<jan@jkrieger.de>)
|
2019-04-22 19:27:50 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
This software is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU Lesser General Public License (LGPL) as published by
|
|
|
|
the Free Software Foundation, either version 2.1 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU Lesser General Public License (LGPL) for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public License (LGPL)
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-06-20 22:06:31 +08:00
|
|
|
#include "jkqtplotter/graphs/jkqtpspecialline.h"
|
2019-04-22 19:27:50 +08:00
|
|
|
#include "jkqtplotter/jkqtpbaseplotter.h"
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <QDebug>
|
|
|
|
#include <iostream>
|
2019-05-30 04:40:02 +08:00
|
|
|
#include "jkqtplotter/jkqtptools.h"
|
|
|
|
#include "jkqtplotter/jkqtpimagetools.h"
|
2019-06-20 22:06:31 +08:00
|
|
|
#include "jkqtplotter/graphs/jkqtpimage.h"
|
2019-04-22 19:27:50 +08:00
|
|
|
#include "jkqtplotter/jkqtpbaseelements.h"
|
|
|
|
#include "jkqtplotter/jkqtplotter.h"
|
|
|
|
#define SmallestGreaterZeroCompare_xvsgz() if ((xvsgz>10.0*DBL_MIN)&&((smallestGreaterZero<10.0*DBL_MIN) || (xvsgz<smallestGreaterZero))) smallestGreaterZero=xvsgz;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-09-20 01:06:01 +08:00
|
|
|
JKQTPSpecialLineGraphBase::JKQTPSpecialLineGraphBase(JKQTBasePlotter* parent):
|
|
|
|
JKQTPXYBaselineGraph(parent), m_drawSymbols(false), m_specialLineType(JKQTPStepLeft)
|
2019-04-22 19:27:50 +08:00
|
|
|
{
|
|
|
|
parentPlotStyle=-1;
|
2020-09-26 21:58:58 +08:00
|
|
|
initLineStyle(parent, parentPlotStyle, JKQTPPlotStyleType::Default);
|
|
|
|
initFillStyle(parent, parentPlotStyle, JKQTPPlotStyleType::Default);
|
|
|
|
initSymbolStyle(parent, parentPlotStyle, JKQTPPlotStyleType::Default);
|
2020-09-19 20:55:46 +08:00
|
|
|
setFillCurve(false);
|
2019-04-22 19:27:50 +08:00
|
|
|
}
|
|
|
|
|
2020-09-20 01:06:01 +08:00
|
|
|
void JKQTPSpecialLineGraphBase::drawKeyMarker(JKQTPEnhancedPainter& painter, QRectF& rect) {
|
2019-04-22 19:27:50 +08:00
|
|
|
painter.save(); auto __finalpaint=JKQTPFinally([&painter]() {painter.restore();});
|
2022-08-30 15:44:40 +08:00
|
|
|
QPen p=getKeyLinePen(painter, rect, parent);
|
2019-04-22 19:27:50 +08:00
|
|
|
QPen np(Qt::NoPen);
|
|
|
|
QBrush b=getFillBrush(painter, parent);
|
|
|
|
const double y=rect.top()+rect.height()/2.0;
|
|
|
|
painter.setPen(np);
|
2020-09-19 20:55:46 +08:00
|
|
|
if (getDrawLine()) painter.setPen(p);
|
2019-04-22 19:27:50 +08:00
|
|
|
painter.setBrush(b);
|
2020-09-19 20:55:46 +08:00
|
|
|
if (getFillCurve()) painter.drawRect(rect);
|
|
|
|
if (!getFillCurve() && getDrawLine()) painter.drawLine(QLineF(rect.left(), y, rect.right(), y));
|
2019-04-22 19:27:50 +08:00
|
|
|
if (m_drawSymbols) {
|
2022-09-02 20:19:47 +08:00
|
|
|
JKQTPPlotSymbol(painter, rect.center().x(), rect.center().y(), getSymbolType(), getKeySymbolSizePx(painter, rect, parent), getKeySymbolLineWidthPx(painter, rect, parent), getKeyLabelColor(), getSymbolFillColor(),getSymbolFont());
|
2019-04-22 19:27:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-09-20 01:06:01 +08:00
|
|
|
|
|
|
|
QColor JKQTPSpecialLineGraphBase::getKeyLabelColor() const {
|
2019-04-22 19:27:50 +08:00
|
|
|
return getLineColor();
|
|
|
|
}
|
|
|
|
|
2020-09-20 01:06:01 +08:00
|
|
|
void JKQTPSpecialLineGraphBase::setDrawSymbols(bool __value)
|
2019-04-22 19:27:50 +08:00
|
|
|
{
|
|
|
|
m_drawSymbols=__value;
|
|
|
|
}
|
|
|
|
|
2020-09-20 01:06:01 +08:00
|
|
|
bool JKQTPSpecialLineGraphBase::getDrawSymbols() const
|
2019-04-22 19:27:50 +08:00
|
|
|
{
|
|
|
|
return m_drawSymbols;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-09-20 01:06:01 +08:00
|
|
|
void JKQTPSpecialLineGraphBase::setSpecialLineType(const JKQTPSpecialLineType &__value)
|
2019-04-22 19:27:50 +08:00
|
|
|
{
|
|
|
|
this->m_specialLineType = __value;
|
|
|
|
}
|
|
|
|
|
2020-09-20 01:06:01 +08:00
|
|
|
JKQTPSpecialLineType JKQTPSpecialLineGraphBase::getSpecialLineType() const
|
2019-04-22 19:27:50 +08:00
|
|
|
{
|
|
|
|
return this->m_specialLineType;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-09-20 01:06:01 +08:00
|
|
|
void JKQTPSpecialLineGraphBase::setColor(QColor c)
|
2019-04-22 19:27:50 +08:00
|
|
|
{
|
|
|
|
setLineColor(c);
|
|
|
|
setSymbolColor(c);
|
2020-09-26 21:58:58 +08:00
|
|
|
setSymbolFillColor(JKQTPGetDerivedColor(parent->getCurrentPlotterStyle().graphsStyle.defaultGraphStyle.symbolFillColorDerivationMode, c));
|
|
|
|
setFillColor(JKQTPGetDerivedColor(parent->getCurrentPlotterStyle().graphsStyle.defaultGraphStyle.fillColorDerivationMode, c));
|
2019-04-22 19:27:50 +08:00
|
|
|
c.setAlphaF(0.5);
|
|
|
|
setHighlightingLineColor(c);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-09-20 01:06:01 +08:00
|
|
|
|
|
|
|
JKQTPSpecialLineHorizontalGraph::JKQTPSpecialLineHorizontalGraph(JKQTBasePlotter* parent):
|
|
|
|
JKQTPSpecialLineGraphBase(parent)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
JKQTPSpecialLineHorizontalGraph::JKQTPSpecialLineHorizontalGraph(JKQTPlotter* parent):
|
|
|
|
JKQTPSpecialLineHorizontalGraph(parent->getPlotter())
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-04-22 19:27:50 +08:00
|
|
|
void JKQTPSpecialLineHorizontalGraph::draw(JKQTPEnhancedPainter& painter) {
|
|
|
|
#ifdef JKQTBP_AUTOTIMER
|
|
|
|
JKQTPAutoOutputTimer jkaaot("JKQTPSpecialLineHorizontalGraph::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);
|
2023-03-23 20:55:18 +08:00
|
|
|
const double xmin=transformX(getXAxis()->getMin());
|
|
|
|
const double xmax=transformX(getXAxis()->getMax());
|
|
|
|
const double ymin=transformY(getYAxis()->getMin());
|
|
|
|
const double ymax=transformY(getYAxis()->getMax());
|
2022-08-25 21:17:50 +08:00
|
|
|
const auto symType=getSymbolType();
|
|
|
|
const double symbolSize=parent->pt2px(painter, getSymbolSize());
|
|
|
|
const QMarginsF clipMargins=(symType==JKQTPNoSymbol)?QMarginsF(0,0,0,0):QMarginsF(symbolSize,symbolSize,symbolSize,symbolSize);
|
|
|
|
const QRectF cliprect=QRectF(qMin(xmin,xmax),qMin(ymin,ymax),fabs(xmax-xmin),fabs(ymax-ymin))+clipMargins;
|
2019-04-22 19:27:50 +08:00
|
|
|
|
2020-09-19 20:55:46 +08:00
|
|
|
int imax=0;
|
2019-04-22 19:27:50 +08:00
|
|
|
int imin=0;
|
|
|
|
|
2020-09-19 20:55:46 +08:00
|
|
|
if (getIndexRange(imin, imax)) {
|
|
|
|
|
|
|
|
|
2022-08-25 21:17:50 +08:00
|
|
|
QPolygonF pl, pf;
|
2022-08-25 23:46:57 +08:00
|
|
|
QPolygonF ps;
|
2020-09-19 20:55:46 +08:00
|
|
|
|
|
|
|
double xold=-1;
|
|
|
|
double yold=-1;
|
2020-09-19 21:08:32 +08:00
|
|
|
double y0=transformY(getBaseline());
|
2023-03-23 20:55:18 +08:00
|
|
|
if (getYAxis()->isLogAxis()) {
|
|
|
|
if (getBaseline()>0 && getBaseline()>getYAxis()->getMin()) y0=transformY(getBaseline());
|
|
|
|
else y0=transformY(getYAxis()->getMin());
|
2020-09-19 20:55:46 +08:00
|
|
|
}
|
2022-08-25 21:17:50 +08:00
|
|
|
bool firstPoint=true;
|
2020-09-19 20:55:46 +08:00
|
|
|
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)) {
|
|
|
|
ps.append(QPointF(x,y));
|
2022-08-25 21:17:50 +08:00
|
|
|
if (!firstPoint) {
|
2020-09-19 20:55:46 +08:00
|
|
|
//double xl1=xold;
|
|
|
|
//double yl1=yold;
|
|
|
|
//double xl2=x;
|
|
|
|
//double yl2=y;
|
|
|
|
|
|
|
|
if (m_specialLineType==JKQTPStepCenter) {
|
|
|
|
// x/y
|
|
|
|
// |--------*
|
|
|
|
// |
|
|
|
|
// *--------|
|
|
|
|
// xold/yold
|
|
|
|
const double d=(x-xold);
|
2022-08-25 21:17:50 +08:00
|
|
|
pf<<QPointF(xold+d/2.0, yold);
|
|
|
|
pf<<QPointF(xold+d/2.0, y);
|
|
|
|
pf<<QPointF(x, y);
|
2020-09-19 20:55:46 +08:00
|
|
|
if (getDrawLine()) {
|
2022-08-25 21:17:50 +08:00
|
|
|
pl<<QPointF(xold+d/2.0, yold);
|
|
|
|
pl<<QPointF(xold+d/2.0, y);
|
|
|
|
pl<<QPointF(x, y);
|
2020-09-19 20:55:46 +08:00
|
|
|
}
|
|
|
|
} else if (m_specialLineType==JKQTPStepLeft) {
|
|
|
|
// x/y
|
|
|
|
// |----------------*
|
|
|
|
// |
|
|
|
|
// *
|
|
|
|
// xold/yold
|
2022-08-25 21:17:50 +08:00
|
|
|
pf<<QPointF(xold, y);
|
|
|
|
pf<<QPointF(x, y);
|
2020-09-19 20:55:46 +08:00
|
|
|
if (getDrawLine()) {
|
2022-08-25 21:17:50 +08:00
|
|
|
pl<<QPointF(xold, y);
|
|
|
|
pl<<QPointF(x, y);
|
2020-09-19 20:55:46 +08:00
|
|
|
}
|
|
|
|
} else if (m_specialLineType==JKQTPStepRight) {
|
|
|
|
// x/y
|
|
|
|
// *
|
|
|
|
// |
|
|
|
|
// *----------------|
|
|
|
|
// xold/yold
|
2022-08-25 21:17:50 +08:00
|
|
|
pf<<QPointF(x, yold);
|
|
|
|
pf<<QPointF(x, y);
|
2020-09-19 20:55:46 +08:00
|
|
|
if (getDrawLine()) {
|
2022-08-25 21:17:50 +08:00
|
|
|
pl<<QPointF(x, yold);
|
|
|
|
pl<<QPointF(x, y);
|
2020-09-19 20:55:46 +08:00
|
|
|
}
|
|
|
|
} else if (m_specialLineType==JKQTPStepAverage) {
|
|
|
|
// x/y
|
|
|
|
// *
|
|
|
|
// |
|
|
|
|
// |----------------|
|
|
|
|
// |
|
|
|
|
// *
|
|
|
|
// xold/yold
|
|
|
|
//const double d=(x-xold);
|
|
|
|
const double h=(y-yold);
|
2022-08-25 21:17:50 +08:00
|
|
|
pf<<QPointF(xold, yold+h/2.0);
|
|
|
|
pf<<QPointF(x, yold+h/2.0);
|
|
|
|
pf<<QPointF(x,y);
|
2020-09-19 20:55:46 +08:00
|
|
|
if (getDrawLine()) {
|
2022-08-25 21:17:50 +08:00
|
|
|
pl<<QPointF(xold, yold+h/2.0);
|
|
|
|
pl<<QPointF(x, yold+h/2.0);
|
|
|
|
pl<<QPointF(x,y);
|
2020-09-19 20:55:46 +08:00
|
|
|
}
|
|
|
|
} else if (m_specialLineType==JKQTPDirectLine) {
|
|
|
|
// x/y
|
|
|
|
// /----*
|
|
|
|
// /----/
|
|
|
|
// *----/
|
|
|
|
// xold/yold
|
2022-08-25 21:17:50 +08:00
|
|
|
pf<<QPointF(x, y);
|
2020-09-19 20:55:46 +08:00
|
|
|
if (getDrawLine()) {
|
2022-08-25 21:17:50 +08:00
|
|
|
pl<<QPointF(x, y);
|
2020-09-19 20:55:46 +08:00
|
|
|
}
|
2019-04-22 19:27:50 +08:00
|
|
|
}
|
2020-09-19 20:55:46 +08:00
|
|
|
|
|
|
|
//std::cout<<"line ("<<xl1<<", "<<yl1<<") -- ("<<xl2<<", "<<yl2<<")"<<std::endl;
|
|
|
|
} else {
|
2022-08-25 21:17:50 +08:00
|
|
|
if (getDrawLine()) pl<<QPointF(x,y);
|
|
|
|
pf<<QPointF(x, y0);
|
|
|
|
pf<<QPointF(x, y);
|
2020-09-19 20:55:46 +08:00
|
|
|
//xstart=x;
|
|
|
|
//ystart=y0;
|
2019-04-22 19:27:50 +08:00
|
|
|
}
|
2020-09-19 20:55:46 +08:00
|
|
|
xold=x;
|
|
|
|
yold=y;
|
2022-08-25 21:17:50 +08:00
|
|
|
firstPoint=false;
|
2019-04-22 19:27:50 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-09-19 20:55:46 +08:00
|
|
|
if (getFillCurve()) {
|
2022-08-25 21:17:50 +08:00
|
|
|
pf<<QPointF(xold, y0);
|
2020-09-19 20:55:46 +08:00
|
|
|
}
|
|
|
|
painter.save();
|
|
|
|
auto __finalpaint=JKQTPFinally([&painter]() {painter.restore();});
|
2019-04-22 19:27:50 +08:00
|
|
|
|
2020-09-19 20:55:46 +08:00
|
|
|
if (getFillCurve()) {
|
2022-08-25 21:17:50 +08:00
|
|
|
painter.setBrush(b);
|
|
|
|
painter.setPen(Qt::NoPen);
|
|
|
|
painter.drawPolygon(pf.intersected(cliprect));
|
|
|
|
}
|
|
|
|
|
2022-08-25 23:46:57 +08:00
|
|
|
QList<QPolygonF> pl_fordrawing;
|
2022-08-25 21:17:50 +08:00
|
|
|
if (isHighlighted() || getDrawLine()) {
|
2022-09-02 04:21:24 +08:00
|
|
|
if (getUseNonvisibleLineCompression()) pl_fordrawing=JKQTPClipPolyLine(JKQTPSimplifyPolyLines(pl, getNonvisibleLineCompressionAgressiveness()), cliprect);
|
2022-08-26 04:33:07 +08:00
|
|
|
else pl_fordrawing=JKQTPClipPolyLine(pl, cliprect);
|
2020-09-19 20:55:46 +08:00
|
|
|
}
|
2019-04-22 19:27:50 +08:00
|
|
|
|
2020-09-19 20:55:46 +08:00
|
|
|
if (isHighlighted()) {
|
2022-08-25 21:17:50 +08:00
|
|
|
painter.setBrush(Qt::NoBrush);
|
2020-09-19 20:55:46 +08:00
|
|
|
painter.setPen(ph);
|
2022-08-26 04:33:07 +08:00
|
|
|
for (const QPolygonF& lines : pl_fordrawing) {
|
2022-08-31 04:24:24 +08:00
|
|
|
painter.drawPolylineFast(lines);
|
2022-08-25 21:17:50 +08:00
|
|
|
}
|
2020-09-19 20:55:46 +08:00
|
|
|
}
|
2019-04-22 19:27:50 +08:00
|
|
|
|
2020-09-19 20:55:46 +08:00
|
|
|
if (getDrawLine()) {
|
2022-08-25 21:17:50 +08:00
|
|
|
painter.setBrush(Qt::NoBrush);
|
2020-09-19 20:55:46 +08:00
|
|
|
painter.setPen(p);
|
2022-08-26 04:33:07 +08:00
|
|
|
for (const QPolygonF& lines : pl_fordrawing) {
|
2022-08-31 04:24:24 +08:00
|
|
|
painter.drawPolylineFast(lines);
|
2022-08-25 21:17:50 +08:00
|
|
|
}
|
2020-09-19 20:55:46 +08:00
|
|
|
}
|
2019-04-22 19:27:50 +08:00
|
|
|
|
2022-08-26 04:33:07 +08:00
|
|
|
|
2020-09-19 20:55:46 +08:00
|
|
|
if (m_drawSymbols) {
|
|
|
|
painter.save();
|
|
|
|
auto __finalpaintsym=JKQTPFinally([&painter]() {painter.restore();});
|
|
|
|
for (auto& ppoint: ps) {
|
2022-08-25 21:17:50 +08:00
|
|
|
if (cliprect.contains(ppoint)) plotStyledSymbol(parent, painter, ppoint.x(), ppoint.y());
|
2020-09-19 20:55:46 +08:00
|
|
|
}
|
2019-04-22 19:27:50 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
drawErrorsAfter(painter);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
JKQTPSpecialLineVerticalGraph::JKQTPSpecialLineVerticalGraph(JKQTBasePlotter *parent):
|
2020-09-20 01:06:01 +08:00
|
|
|
JKQTPSpecialLineGraphBase(parent)
|
2019-04-22 19:27:50 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
JKQTPSpecialLineVerticalGraph::JKQTPSpecialLineVerticalGraph(JKQTPlotter *parent):
|
2020-09-20 01:06:01 +08:00
|
|
|
JKQTPSpecialLineVerticalGraph(parent->getPlotter())
|
2019-04-22 19:27:50 +08:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void JKQTPSpecialLineVerticalGraph::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);
|
2023-03-23 20:55:18 +08:00
|
|
|
const double xmin=transformX(getXAxis()->getMin());
|
|
|
|
const double xmax=transformX(getXAxis()->getMax());
|
|
|
|
const double ymin=transformY(getYAxis()->getMin());
|
|
|
|
const double ymax=transformY(getYAxis()->getMax());
|
2022-08-25 21:17:50 +08:00
|
|
|
const auto symType=getSymbolType();
|
|
|
|
const double symbolSize=parent->pt2px(painter, getSymbolSize());
|
|
|
|
const QMarginsF clipMargins=(symType==JKQTPNoSymbol)?QMarginsF(0,0,0,0):QMarginsF(symbolSize,symbolSize,symbolSize,symbolSize);
|
|
|
|
const QRectF cliprect=QRectF(qMin(xmin,xmax),qMin(ymin,ymax),fabs(xmax-xmin),fabs(ymax-ymin))+clipMargins;
|
2019-04-22 19:27:50 +08:00
|
|
|
|
2020-09-19 20:55:46 +08:00
|
|
|
int imax=0;
|
2019-04-22 19:27:50 +08:00
|
|
|
int imin=0;
|
|
|
|
|
2020-09-19 20:55:46 +08:00
|
|
|
if (getIndexRange(imin, imax)) {
|
|
|
|
|
|
|
|
|
2022-08-25 21:17:50 +08:00
|
|
|
QPolygonF pl, pf;
|
2022-08-25 23:46:57 +08:00
|
|
|
QPolygonF ps;
|
2020-09-19 20:55:46 +08:00
|
|
|
|
|
|
|
double xold=-1;
|
|
|
|
double yold=-1;
|
2020-09-19 21:08:32 +08:00
|
|
|
double x0=transformX(getBaseline());
|
2023-03-23 20:55:18 +08:00
|
|
|
if (getXAxis()->isLogAxis()) {
|
|
|
|
if (getBaseline()>0 && getBaseline()>getXAxis()->getMin()) x0=transformX(getBaseline());
|
|
|
|
else x0=transformX(getXAxis()->getMin());
|
2020-09-19 20:55:46 +08:00
|
|
|
}
|
|
|
|
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)) {
|
|
|
|
ps.append(QPointF(x,y));
|
|
|
|
if (first) {
|
|
|
|
//double xl1=xold;
|
|
|
|
//double yl1=yold;
|
|
|
|
//double xl2=x;
|
|
|
|
//double yl2=y;
|
|
|
|
|
|
|
|
if (m_specialLineType==JKQTPStepCenter) {
|
|
|
|
double d=(y-yold);
|
2022-08-25 21:17:50 +08:00
|
|
|
pf<<QPointF(xold, yold+d/2.0);
|
|
|
|
pf<<QPointF(x, yold+d/2.0);
|
|
|
|
pf<<QPointF(x, y);
|
2020-09-19 20:55:46 +08:00
|
|
|
if (getDrawLine()) {
|
2022-08-25 21:17:50 +08:00
|
|
|
pl<<QPointF(xold, yold+d/2.0);
|
|
|
|
pl<<QPointF(x, yold+d/2.0);
|
|
|
|
pl<<QPointF(x, y);
|
2020-09-19 20:55:46 +08:00
|
|
|
}
|
|
|
|
} else if (m_specialLineType==JKQTPStepLeft) {
|
2022-08-25 21:17:50 +08:00
|
|
|
pf<<QPointF(x, yold);
|
|
|
|
pf<<QPointF(x, y);
|
2020-09-19 20:55:46 +08:00
|
|
|
if (getDrawLine()) {
|
2022-08-25 21:17:50 +08:00
|
|
|
pl<<QPointF(x, yold);
|
|
|
|
pl<<QPointF(x, y);
|
2020-09-19 20:55:46 +08:00
|
|
|
}
|
|
|
|
} else if (m_specialLineType==JKQTPStepRight) {
|
2022-08-25 21:17:50 +08:00
|
|
|
pf<<QPointF(xold, y);
|
|
|
|
pf<<QPointF(x, y);
|
2020-09-19 20:55:46 +08:00
|
|
|
if (getDrawLine()) {
|
2022-08-25 21:17:50 +08:00
|
|
|
pl<<QPointF(xold, y);
|
|
|
|
pl<<QPointF(x, y);
|
2020-09-19 20:55:46 +08:00
|
|
|
}
|
|
|
|
} else if (m_specialLineType==JKQTPStepAverage) {
|
|
|
|
// x/y
|
|
|
|
// |-------*
|
|
|
|
// |
|
|
|
|
// |
|
|
|
|
// |
|
|
|
|
// *--------|
|
|
|
|
// xold/yold
|
|
|
|
const double d=(x-xold);
|
|
|
|
//const double h=(y-yold);
|
2022-08-25 21:17:50 +08:00
|
|
|
pf<<QPointF(xold+d/2.0, yold);
|
|
|
|
pf<<QPointF(xold+d/2.0, y);
|
|
|
|
pf<<QPointF(x,y);
|
2020-09-19 20:55:46 +08:00
|
|
|
if (getDrawLine()) {
|
2022-08-25 21:17:50 +08:00
|
|
|
pl<<QPointF(xold+d/2.0, yold);
|
|
|
|
pl<<QPointF(xold+d/2.0, y);
|
|
|
|
pl<<QPointF(x,y);
|
2020-09-19 20:55:46 +08:00
|
|
|
}
|
|
|
|
} else if (m_specialLineType==JKQTPDirectLine) {
|
|
|
|
// x/y
|
|
|
|
// /----*
|
|
|
|
// /----/
|
|
|
|
// *----/
|
|
|
|
// xold/yold
|
2022-08-25 21:17:50 +08:00
|
|
|
pf<<QPointF(x, y);
|
2020-09-19 20:55:46 +08:00
|
|
|
if (getDrawLine()) {
|
2022-08-25 21:17:50 +08:00
|
|
|
pl<<QPointF(x, y);
|
2020-09-19 20:55:46 +08:00
|
|
|
}
|
2019-04-22 19:27:50 +08:00
|
|
|
}
|
2020-09-19 20:55:46 +08:00
|
|
|
|
|
|
|
//std::cout<<"line ("<<xl1<<", "<<yl1<<") -- ("<<xl2<<", "<<yl2<<")"<<std::endl;
|
|
|
|
} else {
|
2022-08-25 21:17:50 +08:00
|
|
|
if (getDrawLine()) pl<<QPointF(x,y);
|
|
|
|
pf<<QPointF(x0, y);
|
|
|
|
pf<<QPointF(x, y);
|
2019-04-22 19:27:50 +08:00
|
|
|
}
|
2020-09-19 20:55:46 +08:00
|
|
|
xold=x;
|
|
|
|
yold=y;
|
|
|
|
first=true;
|
2019-04-22 19:27:50 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-08-25 21:17:50 +08:00
|
|
|
pf<<QPointF(x0, yold);
|
2020-09-19 20:55:46 +08:00
|
|
|
painter.save(); auto __finalpaint=JKQTPFinally([&painter]() {painter.restore();});
|
2019-04-22 19:27:50 +08:00
|
|
|
|
2020-09-19 20:55:46 +08:00
|
|
|
if (getFillCurve()) {
|
2022-08-25 21:17:50 +08:00
|
|
|
painter.setBrush(b);
|
|
|
|
painter.setPen(Qt::NoPen);
|
|
|
|
painter.drawPolygon(pf.intersected(cliprect));
|
|
|
|
}
|
|
|
|
|
2022-08-25 23:46:57 +08:00
|
|
|
QList<QPolygonF> pl_fordrawing;
|
2022-08-25 21:17:50 +08:00
|
|
|
if (isHighlighted() || getDrawLine()) {
|
2022-09-02 04:21:24 +08:00
|
|
|
if (getUseNonvisibleLineCompression()) pl_fordrawing=JKQTPClipPolyLine(JKQTPSimplifyPolyLines(pl, getNonvisibleLineCompressionAgressiveness()), cliprect);
|
2022-08-26 04:33:07 +08:00
|
|
|
else pl_fordrawing=JKQTPClipPolyLine(pl, cliprect);
|
2020-09-19 20:55:46 +08:00
|
|
|
}
|
2019-04-22 19:27:50 +08:00
|
|
|
|
2020-09-19 20:55:46 +08:00
|
|
|
if (isHighlighted()) {
|
2022-08-25 21:17:50 +08:00
|
|
|
painter.setBrush(Qt::NoBrush);
|
2020-09-19 20:55:46 +08:00
|
|
|
painter.setPen(ph);
|
2022-08-26 04:33:07 +08:00
|
|
|
for (const QPolygonF& lines : pl_fordrawing) {
|
2022-08-31 04:24:24 +08:00
|
|
|
painter.drawPolylineFast(lines);
|
2022-08-25 21:17:50 +08:00
|
|
|
}
|
2020-09-19 20:55:46 +08:00
|
|
|
}
|
2019-04-22 19:27:50 +08:00
|
|
|
|
2020-09-19 20:55:46 +08:00
|
|
|
if (getDrawLine()) {
|
2022-08-25 21:17:50 +08:00
|
|
|
painter.setBrush(Qt::NoBrush);
|
2020-09-19 20:55:46 +08:00
|
|
|
painter.setPen(p);
|
2022-08-26 04:33:07 +08:00
|
|
|
for (const QPolygonF& lines : pl_fordrawing) {
|
2022-08-31 04:24:24 +08:00
|
|
|
painter.drawPolylineFast(lines);
|
2022-08-25 21:17:50 +08:00
|
|
|
}
|
2020-09-19 20:55:46 +08:00
|
|
|
}
|
2019-04-22 19:27:50 +08:00
|
|
|
|
2020-09-19 20:55:46 +08:00
|
|
|
if (m_drawSymbols) {
|
|
|
|
painter.save();
|
|
|
|
auto __finalpaintsym=JKQTPFinally([&painter]() {painter.restore();});
|
2022-08-25 21:17:50 +08:00
|
|
|
for (auto& ppoint: ps) {
|
|
|
|
if (cliprect.contains(ppoint)) plotStyledSymbol(parent, painter, ppoint.x(), ppoint.y());
|
2020-09-19 20:55:46 +08:00
|
|
|
}
|
2019-04-22 19:27:50 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
drawErrorsAfter(painter);
|
|
|
|
}
|
|
|
|
|
2022-09-10 19:38:29 +08:00
|
|
|
int JKQTPSpecialLineVerticalGraph::getKeyColumn() const
|
|
|
|
{
|
|
|
|
return getYColumn();
|
|
|
|
}
|
|
|
|
|
|
|
|
int JKQTPSpecialLineVerticalGraph::getValueColumn() const
|
|
|
|
{
|
|
|
|
return getXColumn();
|
|
|
|
}
|
|
|
|
|
|
|
|
void JKQTPSpecialLineVerticalGraph::setKeyColumn(int __value)
|
|
|
|
{
|
|
|
|
setYColumn(__value);
|
|
|
|
}
|
|
|
|
|
|
|
|
void JKQTPSpecialLineVerticalGraph::setValueColumn(int __value)
|
|
|
|
{
|
|
|
|
setXColumn(__value);
|
|
|
|
}
|
|
|
|
|
2019-04-22 19:27:50 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|