2018-11-25 21:53:26 +08:00
|
|
|
/*
|
2022-07-19 19:40:43 +08:00
|
|
|
Copyright (c) 2008-2022 Jan W. Krieger (<jan@jkrieger.de>)
|
2018-11-25 21:53:26 +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
|
2019-02-08 00:24:46 +08:00
|
|
|
the Free Software Foundation, either version 2.1 of the License, or
|
2018-11-25 21:53:26 +08:00
|
|
|
(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/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-12-19 00:13:18 +08:00
|
|
|
#include "jkqtplotter/jkqtpgraphsbase.h"
|
2018-11-26 03:25:44 +08:00
|
|
|
#include "jkqtplotter/jkqtpbaseplotter.h"
|
2018-11-25 21:53:26 +08:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <QDebug>
|
|
|
|
#include <iostream>
|
2019-05-30 04:40:02 +08:00
|
|
|
#include "jkqtplotter/jkqtptools.h"
|
2019-06-20 22:06:31 +08:00
|
|
|
#include "jkqtplotter/graphs/jkqtpimage.h"
|
2018-11-26 03:25:44 +08:00
|
|
|
#include "jkqtplotter/jkqtpbaseelements.h"
|
|
|
|
#include "jkqtplotter/jkqtplotter.h"
|
2018-12-28 05:52:00 +08:00
|
|
|
#include "jkqtpgraphsbase.h"
|
2019-02-08 00:24:46 +08:00
|
|
|
|
|
|
|
|
2018-11-25 21:53:26 +08:00
|
|
|
#define SmallestGreaterZeroCompare_xvsgz() if ((xvsgz>10.0*DBL_MIN)&&((smallestGreaterZero<10.0*DBL_MIN) || (xvsgz<smallestGreaterZero))) smallestGreaterZero=xvsgz;
|
|
|
|
|
2019-01-20 17:49:29 +08:00
|
|
|
JKQTPPlotElement::JKQTPPlotElement(JKQTBasePlotter* parent):
|
2018-11-25 21:53:26 +08:00
|
|
|
QObject(parent)
|
|
|
|
{
|
|
|
|
title="";
|
|
|
|
visible=true;
|
2019-04-22 19:27:50 +08:00
|
|
|
highlighted=false;
|
|
|
|
parentPlotStyle=-1;
|
2018-11-25 21:53:26 +08:00
|
|
|
setParent(parent);
|
|
|
|
}
|
|
|
|
|
2018-12-28 05:52:00 +08:00
|
|
|
|
2019-01-20 17:49:29 +08:00
|
|
|
JKQTPGraph::JKQTPGraph(JKQTBasePlotter* parent):
|
|
|
|
JKQTPPlotElement(parent)
|
2018-12-28 05:52:00 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-11-25 21:53:26 +08:00
|
|
|
|
2019-01-20 17:49:29 +08:00
|
|
|
QImage JKQTPPlotElement::generateKeyMarker(QSize size)
|
2018-11-25 21:53:26 +08:00
|
|
|
{
|
|
|
|
QImage img(size.width(),size.height(),QImage::Format_ARGB32);
|
2019-04-25 01:33:51 +08:00
|
|
|
if (parent) img.fill(Qt::transparent);//->getKeyBackgroundColor());
|
2018-11-25 21:53:26 +08:00
|
|
|
{
|
|
|
|
JKQTPEnhancedPainter painter(&img);
|
|
|
|
painter.setRenderHint(QPainter::Antialiasing, true);
|
|
|
|
painter.setRenderHint(QPainter::TextAntialiasing, true);
|
|
|
|
painter.setRenderHint(QPainter::SmoothPixmapTransform, true);
|
2022-04-21 16:57:24 +08:00
|
|
|
#if (QT_VERSION<QT_VERSION_CHECK(6, 0, 0))
|
2018-11-25 21:53:26 +08:00
|
|
|
painter.setRenderHint(QPainter::HighQualityAntialiasing, true);
|
2022-04-21 16:57:24 +08:00
|
|
|
#endif
|
2018-11-25 21:53:26 +08:00
|
|
|
QRectF rect(0,0,size.width(),size.height());
|
|
|
|
drawKeyMarker(painter, rect);
|
|
|
|
}
|
|
|
|
return img;
|
|
|
|
}
|
|
|
|
|
2019-02-03 21:04:48 +08:00
|
|
|
void JKQTPPlotElement::setTitle(const QString &__value)
|
|
|
|
{
|
|
|
|
this->title = __value;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString JKQTPPlotElement::getTitle() const
|
|
|
|
{
|
|
|
|
return this->title;
|
|
|
|
}
|
|
|
|
|
|
|
|
void JKQTPPlotElement::setVisible(bool __value)
|
|
|
|
{
|
|
|
|
this->visible = __value;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool JKQTPPlotElement::isVisible() const
|
|
|
|
{
|
|
|
|
return this->visible;
|
|
|
|
}
|
|
|
|
|
2019-04-22 19:27:50 +08:00
|
|
|
void JKQTPPlotElement::setHighlighted(bool __value)
|
|
|
|
{
|
|
|
|
highlighted=__value;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool JKQTPPlotElement::isHighlighted() const
|
|
|
|
{
|
|
|
|
return highlighted;
|
|
|
|
}
|
|
|
|
|
2018-11-25 21:53:26 +08:00
|
|
|
|
|
|
|
|
2018-12-28 05:52:00 +08:00
|
|
|
|
|
|
|
|
2019-01-20 17:49:29 +08:00
|
|
|
void JKQTPPlotElement::setParent(JKQTBasePlotter* parent) {
|
2018-11-25 21:53:26 +08:00
|
|
|
this->parent=parent;
|
|
|
|
QObject::setParent(parent);
|
|
|
|
}
|
|
|
|
|
2019-01-20 23:15:10 +08:00
|
|
|
void JKQTPPlotElement::setParent(JKQTPlotter *parent)
|
2018-11-25 21:53:26 +08:00
|
|
|
{
|
2019-01-26 03:16:04 +08:00
|
|
|
setParent(parent->getPlotter());
|
2018-11-25 21:53:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-01-20 17:49:29 +08:00
|
|
|
bool JKQTPGraph::getDataMinMax(int column, double &minx, double &maxx, double &smallestGreaterZero)
|
2018-11-25 21:53:26 +08:00
|
|
|
{
|
|
|
|
bool start=true;
|
|
|
|
minx=0;
|
|
|
|
maxx=0;
|
|
|
|
smallestGreaterZero=0;
|
|
|
|
|
|
|
|
if (parent==nullptr) return false;
|
|
|
|
|
2020-09-19 01:35:53 +08:00
|
|
|
const JKQTPDatastore* datastore=parent->getDatastore();
|
2018-11-25 21:53:26 +08:00
|
|
|
int imin=0;
|
2019-05-13 04:22:48 +08:00
|
|
|
int imax=static_cast<int>(datastore->getRows(column));
|
2019-02-03 21:04:48 +08:00
|
|
|
|
2018-11-25 21:53:26 +08:00
|
|
|
if (imin<0) imin=0;
|
|
|
|
if (imax<0) imax=0;
|
|
|
|
|
|
|
|
for (int i=imin; i<imax; i++) {
|
2019-05-06 01:31:20 +08:00
|
|
|
double xv=datastore->get(column,static_cast<size_t>(i));
|
2018-11-25 21:53:26 +08:00
|
|
|
if (start || xv>maxx) maxx=xv;
|
|
|
|
if (start || xv<minx) minx=xv;
|
|
|
|
double xvsgz;
|
|
|
|
xvsgz=xv; SmallestGreaterZeroCompare_xvsgz();
|
|
|
|
start=false;
|
|
|
|
}
|
|
|
|
return !start;
|
|
|
|
}
|
|
|
|
|
2019-01-20 17:49:29 +08:00
|
|
|
void JKQTPPlotElement::getOutsideSize(JKQTPEnhancedPainter& /*painter*/, int& leftSpace, int& rightSpace, int& topSpace, int& bottomspace) {
|
2018-11-25 21:53:26 +08:00
|
|
|
leftSpace=0;
|
|
|
|
rightSpace=0;
|
|
|
|
topSpace=0;
|
|
|
|
bottomspace=0;
|
|
|
|
}
|
|
|
|
|
2019-01-20 17:49:29 +08:00
|
|
|
void JKQTPPlotElement::drawOutside(JKQTPEnhancedPainter& /*painter*/, QRect /*leftSpace*/, QRect /*rightSpace*/, QRect /*topSpace*/, QRect /*bottomSpace*/) {
|
2018-12-28 05:52:00 +08:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-05-06 01:31:20 +08:00
|
|
|
|
|
|
|
QString JKQTPPlotElement::formatHitTestDefaultLabel(double x, double y, int index, JKQTPDatastore* datastore) const {
|
|
|
|
const JKQTPXGraphErrorData* errgx=dynamic_cast<const JKQTPXGraphErrorData*>(this);
|
|
|
|
QString xerrstr;
|
|
|
|
// retrieve x-error data
|
|
|
|
if (errgx && datastore) {
|
|
|
|
if (errgx->getXErrorColumn()>=0) {
|
|
|
|
if (errgx->getXErrorColumnLower()>=0) {
|
|
|
|
xerrstr=QString("\\:+%1\\:-%2")
|
2019-05-30 04:40:02 +08:00
|
|
|
.arg(jkqtp_floattolatexqstr(datastore->get(errgx->getXErrorColumn(),static_cast<size_t>(index)), 3))
|
|
|
|
.arg(jkqtp_floattolatexqstr(datastore->get(errgx->getXErrorColumnLower(),static_cast<size_t>(index)), 3));
|
2019-05-06 01:31:20 +08:00
|
|
|
} else {
|
|
|
|
xerrstr=QString("{\\:}{\\pm}%1")
|
2019-05-30 04:40:02 +08:00
|
|
|
.arg(jkqtp_floattolatexqstr(datastore->get(errgx->getXErrorColumn(),static_cast<size_t>(index)), 3));
|
2019-05-06 01:31:20 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// retrieve y-error data
|
|
|
|
const JKQTPYGraphErrorData* errgy=dynamic_cast<const JKQTPYGraphErrorData*>(this);
|
|
|
|
QString yerrstr;
|
|
|
|
if (errgy && datastore) {
|
|
|
|
if (errgy->getYErrorColumn()>=0) {
|
|
|
|
if (errgy->getYErrorColumnLower()>=0) {
|
|
|
|
yerrstr=QString("\\:+%1\\:-%2")
|
2019-05-30 04:40:02 +08:00
|
|
|
.arg(jkqtp_floattolatexqstr(datastore->get(errgy->getYErrorColumn(),static_cast<size_t>(index)), 3))
|
|
|
|
.arg(jkqtp_floattolatexqstr(datastore->get(errgy->getYErrorColumnLower(),static_cast<size_t>(index)), 3));
|
2019-05-06 01:31:20 +08:00
|
|
|
} else {
|
|
|
|
yerrstr=QString("{\\:}{\\pm}%1")
|
2019-05-30 04:40:02 +08:00
|
|
|
.arg(jkqtp_floattolatexqstr(datastore->get(errgy->getYErrorColumn(),static_cast<size_t>(index)), 3));
|
2019-05-06 01:31:20 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-05-30 04:40:02 +08:00
|
|
|
return QString("\\ensuremath{\\left[{\\:}%1%3{\\;},{\\;}%2%4{\\:}\\right]}").arg(jkqtp_floattolatexqstr(x, 3)).arg(jkqtp_floattolatexqstr(y, 3)).arg(xerrstr).arg(yerrstr);
|
2019-05-06 01:31:20 +08:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
double JKQTPPlotElement::hitTest(const QPointF & posSystem, QPointF* closestSpotSystem, QString* label, HitTestMode mode) const
|
|
|
|
{
|
2019-05-11 21:56:11 +08:00
|
|
|
if (parent==nullptr) return JKQTP_NAN;
|
2019-05-06 01:31:20 +08:00
|
|
|
|
|
|
|
int closest=-1;
|
2019-05-11 21:56:11 +08:00
|
|
|
double closedist=JKQTP_NAN;
|
|
|
|
double closedistsec=JKQTP_NAN;
|
2019-05-06 01:31:20 +08:00
|
|
|
QPointF closestPos;
|
|
|
|
QPointF posF=transform(posSystem);
|
|
|
|
for (int i=0; i<m_hitTestData.count(); i++) {
|
|
|
|
const QPointF x=m_hitTestData[i].pos;
|
|
|
|
const QPointF xpix = transform(x);
|
|
|
|
if (JKQTPIsOKFloat(xpix.x())&&JKQTPIsOKFloat(xpix.y())) {
|
|
|
|
double d=0, dsecondary=0;
|
|
|
|
switch (mode) {
|
|
|
|
case HitTestXY: d=sqrt(jkqtp_sqr(xpix.x()-posF.x())+jkqtp_sqr(xpix.y()-posF.y())); dsecondary=0; break;
|
|
|
|
case HitTestXOnly: d=fabs(xpix.x()-posF.x()); dsecondary=fabs(xpix.y()-posF.y()); break;
|
|
|
|
case HitTestYOnly: d=fabs(xpix.y()-posF.y()); dsecondary=fabs(xpix.x()-posF.x()); break;
|
|
|
|
}
|
|
|
|
if (closest<0 || d<closedist || (jkqtp_approximatelyEqual(d,closedist) && dsecondary<closedistsec)) {
|
|
|
|
closest=i;
|
|
|
|
closedist=d;
|
|
|
|
closedistsec=dsecondary;
|
|
|
|
closestPos=x;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (closest>=0) {
|
|
|
|
if (closestSpotSystem) *closestSpotSystem=closestPos;
|
|
|
|
if (label) *label=m_hitTestData[closest].label;
|
|
|
|
return closedist;
|
|
|
|
} else {
|
2019-05-11 21:56:11 +08:00
|
|
|
return JKQTP_NAN;
|
2019-05-06 01:31:20 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-20 17:49:29 +08:00
|
|
|
double JKQTPPlotElement::transformX(double x) const {
|
2019-01-26 03:16:04 +08:00
|
|
|
return parent->getXAxis()->x2p(x);
|
2018-12-28 05:52:00 +08:00
|
|
|
}
|
|
|
|
|
2019-01-20 17:49:29 +08:00
|
|
|
double JKQTPPlotElement::transformY(double y) const {
|
2019-01-26 03:16:04 +08:00
|
|
|
return parent->getYAxis()->x2p(y);
|
2018-12-28 05:52:00 +08:00
|
|
|
}
|
|
|
|
|
2019-06-17 01:15:07 +08:00
|
|
|
QVector<double> JKQTPPlotElement::transformX(const QVector<double>& x) const {
|
|
|
|
QVector<double> res;
|
|
|
|
res.resize(x.size());
|
|
|
|
for (int i=0; i<x.size(); i++) {
|
|
|
|
res[i]=parent->getXAxis()->x2p(x[i]);
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
QVector<double> JKQTPPlotElement::transformY(const QVector<double>& y) const {
|
|
|
|
QVector<double> res;
|
|
|
|
res.resize(y.size());
|
|
|
|
for (int i=0; i<y.size(); i++) {
|
|
|
|
res[i]=parent->getYAxis()->x2p(y[i]);
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-01-20 17:49:29 +08:00
|
|
|
double JKQTPPlotElement::backtransformX(double x) const {
|
2019-01-26 03:16:04 +08:00
|
|
|
return parent->getXAxis()->p2x(x);
|
2018-11-25 21:53:26 +08:00
|
|
|
}
|
|
|
|
|
2019-01-20 17:49:29 +08:00
|
|
|
double JKQTPPlotElement::backtransformY(double y) const {
|
2019-01-26 03:16:04 +08:00
|
|
|
return parent->getYAxis()->p2x(y);
|
2018-12-28 05:52:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-01-20 17:49:29 +08:00
|
|
|
bool JKQTPGraph::usesColumn(int /*column*/) const
|
2018-11-25 21:53:26 +08:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-01-20 17:49:29 +08:00
|
|
|
void JKQTPGraph::drawErrorsBefore(JKQTPEnhancedPainter &)
|
2018-11-25 21:53:26 +08:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-01-20 17:49:29 +08:00
|
|
|
void JKQTPGraph::drawErrorsAfter(JKQTPEnhancedPainter &)
|
2018-11-25 21:53:26 +08:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2022-08-25 23:46:57 +08:00
|
|
|
QPolygonF JKQTPPlotElement::transform(const QPolygonF &x) const {
|
|
|
|
QPolygonF res;
|
2018-12-28 05:52:00 +08:00
|
|
|
for (int i=0; i<x.size(); i++) {
|
|
|
|
res.append(transform(x[i]));
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
2018-11-25 21:53:26 +08:00
|
|
|
|
2022-08-25 23:46:57 +08:00
|
|
|
QPainterPath JKQTPPlotElement::transformToLinePath(const QPolygonF &x) const {
|
2018-12-28 05:52:00 +08:00
|
|
|
QPainterPath res;
|
|
|
|
if (x.size()>0) {
|
|
|
|
res.moveTo(transform(x[0]));
|
|
|
|
for (int i=1; i<x.size(); i++) {
|
|
|
|
res.lineTo(transform(x[i]));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
2018-11-25 21:53:26 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-01-20 17:49:29 +08:00
|
|
|
JKQTPXYGraph::JKQTPXYGraph(JKQTBasePlotter* parent):
|
- improved: geometric objects now use an adaptive drawing algorithm to represent curves (before e.g. ellipses were always separated into a fixed number of line-segments)
- improved: constructors and access functions for several geometric objects (e.g. more constructors, additional functions to retrieve parameters in diferent forms, iterators for polygons, ...)
- new: all geometric objects can either be drawn as graphic element (i.e. lines are straight line, even on non-linear axes), or as mathematical curve (i.e. on non-linear axes, lines become the appropriate curve representing the linear function, connecting the given start/end-points). The only exceptions are ellipses (and the derived arcs,pies,chords), which are always drawn as mathematical curves
2020-09-04 05:08:52 +08:00
|
|
|
JKQTPGraph(parent), xColumn(-1), yColumn(-1), sortData(Unsorted)
|
2018-11-25 21:53:26 +08:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-01-20 17:49:29 +08:00
|
|
|
bool JKQTPXYGraph::getXMinMax(double& minx, double& maxx, double& smallestGreaterZero) {
|
2018-11-25 21:53:26 +08:00
|
|
|
bool start=true;
|
|
|
|
minx=0;
|
|
|
|
maxx=0;
|
|
|
|
smallestGreaterZero=0;
|
|
|
|
|
|
|
|
if (parent==nullptr) return false;
|
|
|
|
|
2020-09-19 01:35:53 +08:00
|
|
|
const JKQTPDatastore* datastore=parent->getDatastore();
|
2018-11-25 21:53:26 +08:00
|
|
|
int imin=0;
|
2019-05-06 01:31:20 +08:00
|
|
|
int imax=0;
|
|
|
|
getIndexRange(imin, imax);
|
2018-11-25 21:53:26 +08:00
|
|
|
|
|
|
|
for (int i=imin; i<imax; i++) {
|
|
|
|
double xv=datastore->get(static_cast<size_t>(xColumn),static_cast<size_t>(i));
|
|
|
|
if (JKQTPIsOKFloat(xv)) {
|
|
|
|
if (start || xv>maxx) maxx=xv;
|
|
|
|
if (start || xv<minx) minx=xv;
|
|
|
|
double xvsgz;
|
|
|
|
xvsgz=xv; SmallestGreaterZeroCompare_xvsgz();
|
|
|
|
start=false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return !start;
|
|
|
|
}
|
|
|
|
|
2019-01-20 17:49:29 +08:00
|
|
|
bool JKQTPXYGraph::getYMinMax(double& miny, double& maxy, double& smallestGreaterZero) {
|
2018-11-25 21:53:26 +08:00
|
|
|
bool start=true;
|
|
|
|
miny=0;
|
|
|
|
maxy=0;
|
|
|
|
smallestGreaterZero=0;
|
|
|
|
|
|
|
|
if (parent==nullptr) return false;
|
|
|
|
|
2020-09-19 01:35:53 +08:00
|
|
|
const JKQTPDatastore* datastore=parent->getDatastore();
|
2018-11-25 21:53:26 +08:00
|
|
|
int imin=0;
|
2019-05-06 01:31:20 +08:00
|
|
|
int imax=0;
|
|
|
|
getIndexRange(imin, imax);
|
|
|
|
|
2018-11-25 21:53:26 +08:00
|
|
|
|
|
|
|
for (int i=imin; i<imax; i++) {
|
|
|
|
double yv=datastore->get(static_cast<size_t>(yColumn),static_cast<size_t>(i));
|
|
|
|
if (JKQTPIsOKFloat(yv)) {
|
|
|
|
if (start || yv>maxy) maxy=yv;
|
|
|
|
if (start || yv<miny) miny=yv;
|
|
|
|
double xvsgz;
|
|
|
|
xvsgz=yv; SmallestGreaterZeroCompare_xvsgz();
|
|
|
|
start=false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return !start;
|
|
|
|
}
|
|
|
|
|
2019-01-20 17:49:29 +08:00
|
|
|
bool JKQTPXYGraph::usesColumn(int column) const
|
2018-11-25 21:53:26 +08:00
|
|
|
{
|
|
|
|
return (column==xColumn)||(column==yColumn);
|
|
|
|
}
|
|
|
|
|
2019-05-06 01:31:20 +08:00
|
|
|
void JKQTPXYGraph::setXColumn(int __value)
|
|
|
|
{
|
|
|
|
this->xColumn = __value;
|
|
|
|
}
|
|
|
|
|
|
|
|
int JKQTPXYGraph::getXColumn() const
|
|
|
|
{
|
|
|
|
return this->xColumn;
|
|
|
|
}
|
|
|
|
|
|
|
|
void JKQTPXYGraph::setXColumn(size_t __value) {
|
|
|
|
this->xColumn = static_cast<int>(__value);
|
|
|
|
}
|
|
|
|
|
|
|
|
void JKQTPXYGraph::setYColumn(int __value)
|
|
|
|
{
|
|
|
|
this->yColumn = __value;
|
|
|
|
}
|
|
|
|
|
|
|
|
int JKQTPXYGraph::getYColumn() const
|
|
|
|
{
|
|
|
|
return this->yColumn;
|
|
|
|
}
|
|
|
|
|
2020-09-19 01:35:53 +08:00
|
|
|
void JKQTPXYGraph::setYColumn(size_t __value) {
|
|
|
|
this->yColumn = static_cast<int>(__value);
|
|
|
|
}
|
2019-05-06 01:31:20 +08:00
|
|
|
|
|
|
|
void JKQTPXYGraph::setDataSortOrder(JKQTPXYGraph::DataSortOrder __value)
|
|
|
|
{
|
|
|
|
this->sortData = __value;
|
|
|
|
}
|
|
|
|
|
|
|
|
JKQTPXYGraph::DataSortOrder JKQTPXYGraph::getDataSortOrder() const
|
|
|
|
{
|
|
|
|
return this->sortData;
|
|
|
|
}
|
|
|
|
|
2019-02-03 21:04:48 +08:00
|
|
|
void JKQTPXYGraph::setDataSortOrder(int __value) {
|
2019-05-06 01:31:20 +08:00
|
|
|
sortData=static_cast<DataSortOrder>(__value);
|
|
|
|
}
|
|
|
|
|
2019-05-13 04:22:48 +08:00
|
|
|
void JKQTPXYGraph::setXYColumns(size_t xCol, size_t yCol)
|
|
|
|
{
|
|
|
|
setXColumn(xCol);
|
|
|
|
setYColumn(yCol);
|
|
|
|
}
|
|
|
|
|
|
|
|
void JKQTPXYGraph::setXYColumns(int xCol, int yCol)
|
|
|
|
{
|
|
|
|
setXColumn(xCol);
|
|
|
|
setYColumn(yCol);
|
|
|
|
}
|
|
|
|
|
2022-04-21 16:57:24 +08:00
|
|
|
#if QT_VERSION<QT_VERSION_CHECK(6,0,0)
|
2019-05-13 04:22:48 +08:00
|
|
|
void JKQTPXYGraph::setXYColumns(std::pair<int, int> xyColPair)
|
|
|
|
{
|
|
|
|
setXColumn(xyColPair.first);
|
|
|
|
setYColumn(xyColPair.second);
|
|
|
|
}
|
|
|
|
|
|
|
|
void JKQTPXYGraph::setXYColumns(std::pair<size_t, size_t> xyColPair)
|
|
|
|
{
|
|
|
|
setXColumn(xyColPair.first);
|
|
|
|
setYColumn(xyColPair.second);
|
|
|
|
}
|
2022-04-21 16:57:24 +08:00
|
|
|
#endif
|
2019-05-13 04:22:48 +08:00
|
|
|
|
|
|
|
void JKQTPXYGraph::setXYColumns(QPair<int, int> xyColPair)
|
|
|
|
{
|
|
|
|
setXColumn(xyColPair.first);
|
|
|
|
setYColumn(xyColPair.second);
|
|
|
|
}
|
|
|
|
|
|
|
|
void JKQTPXYGraph::setXYColumns(QPair<size_t, size_t> xyColPair)
|
|
|
|
{
|
|
|
|
setXColumn(xyColPair.first);
|
|
|
|
setYColumn(xyColPair.second);
|
|
|
|
}
|
|
|
|
|
2019-05-06 01:31:20 +08:00
|
|
|
|
|
|
|
double JKQTPXYGraph::hitTest(const QPointF &posSystem, QPointF *closestSpotSystem, QString *label, HitTestMode mode) const
|
|
|
|
{
|
2019-05-11 21:56:11 +08:00
|
|
|
if (parent==nullptr) return JKQTP_NAN;
|
2019-05-06 01:31:20 +08:00
|
|
|
|
|
|
|
// check base-class implementation and use it, if it returns a vaid value
|
|
|
|
const double baseclassResult=JKQTPPlotElement::hitTest(posSystem, closestSpotSystem, label, mode);
|
|
|
|
if (JKQTPIsOKFloat(baseclassResult)) return baseclassResult;
|
|
|
|
|
2020-09-19 01:35:53 +08:00
|
|
|
const JKQTPDatastore* datastore=parent->getDatastore();
|
2019-05-06 01:31:20 +08:00
|
|
|
int imin=0;
|
|
|
|
int imax=0;
|
2019-05-11 21:56:11 +08:00
|
|
|
if (!getIndexRange(imin, imax)) return JKQTP_NAN;
|
2019-05-06 01:31:20 +08:00
|
|
|
|
|
|
|
|
|
|
|
int closest=-1;
|
2019-05-11 21:56:11 +08:00
|
|
|
double closedist=JKQTP_NAN;
|
|
|
|
double closedistsec=JKQTP_NAN;
|
2019-05-06 01:31:20 +08:00
|
|
|
QPointF closestPos;
|
|
|
|
QPointF posF=transform(posSystem);
|
|
|
|
for (int i=imin; i<imax; i++) {
|
|
|
|
const QPointF x(datastore->get(static_cast<size_t>(xColumn),static_cast<size_t>(i)), datastore->get(static_cast<size_t>(yColumn),static_cast<size_t>(i)));
|
|
|
|
const QPointF xpix = transform(x);
|
|
|
|
if (JKQTPIsOKFloat(xpix.x())&&JKQTPIsOKFloat(xpix.y())) {
|
|
|
|
double d=0, dsecondary=0;
|
|
|
|
switch (mode) {
|
|
|
|
case HitTestXY: d=sqrt(jkqtp_sqr(xpix.x()-posF.x())+jkqtp_sqr(xpix.y()-posF.y())); dsecondary=0; break;
|
|
|
|
case HitTestXOnly: d=fabs(xpix.x()-posF.x()); dsecondary=fabs(xpix.y()-posF.y()); break;
|
|
|
|
case HitTestYOnly: d=fabs(xpix.y()-posF.y()); dsecondary=fabs(xpix.x()-posF.x()); break;
|
|
|
|
}
|
|
|
|
if (closest<0 || d<closedist || (jkqtp_approximatelyEqual(d,closedist) && dsecondary<closedistsec)) {
|
|
|
|
closest=i;
|
|
|
|
closedist=d;
|
|
|
|
closedistsec=dsecondary;
|
|
|
|
closestPos=x;
|
|
|
|
//qDebug()<<"hitTest("<<posSystem<<"[="<<posF<<"pix]...): found closest="<<closest<<", closedist="<<closedist<<", closedistsec="<<closedistsec<<", closestPos="<<closestPos;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (closest>=0) {
|
|
|
|
if (label) *label=formatHitTestDefaultLabel(closestPos.x(), closestPos.y(), closest);
|
|
|
|
if (closestSpotSystem) *closestSpotSystem=closestPos;
|
|
|
|
return closedist;
|
|
|
|
} else {
|
2019-05-11 21:56:11 +08:00
|
|
|
return JKQTP_NAN;
|
2019-05-06 01:31:20 +08:00
|
|
|
}
|
2018-12-28 05:52:00 +08:00
|
|
|
}
|
|
|
|
|
2018-11-25 21:53:26 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
2019-01-20 17:49:29 +08:00
|
|
|
JKQTPSingleColumnGraph::JKQTPSingleColumnGraph(JKQTBasePlotter *parent):
|
2020-08-26 18:58:23 +08:00
|
|
|
JKQTPGraph(parent), dataColumn(-1), dataDirection(DataDirection::Y), sortData(Unsorted)
|
2018-11-25 21:53:26 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2019-02-08 00:24:46 +08:00
|
|
|
|
2019-04-22 19:27:50 +08:00
|
|
|
void JKQTPSingleColumnGraph::setDataColumn(int __value)
|
2018-11-25 21:53:26 +08:00
|
|
|
{
|
2019-04-22 19:27:50 +08:00
|
|
|
this->dataColumn = __value;
|
2019-05-30 04:40:02 +08:00
|
|
|
if (this->title.size()==0 && parent && __value>=0) this->title=parent->getDatastore()->getColumnName(static_cast<size_t>(__value));
|
2018-11-25 21:53:26 +08:00
|
|
|
}
|
|
|
|
|
2019-04-22 19:27:50 +08:00
|
|
|
int JKQTPSingleColumnGraph::getDataColumn() const
|
2018-11-25 21:53:26 +08:00
|
|
|
{
|
2019-04-22 19:27:50 +08:00
|
|
|
return this->dataColumn;
|
2018-11-25 21:53:26 +08:00
|
|
|
}
|
|
|
|
|
2019-04-22 23:19:52 +08:00
|
|
|
void JKQTPSingleColumnGraph::setDataColumn(size_t __value) {
|
|
|
|
this->dataColumn = static_cast<int>(__value);
|
2019-05-30 04:40:02 +08:00
|
|
|
if (this->title.size()==0 && parent) this->title=parent->getDatastore()->getColumnName(__value);
|
2019-04-22 23:19:52 +08:00
|
|
|
}
|
2018-11-25 21:53:26 +08:00
|
|
|
|
2019-04-22 23:19:52 +08:00
|
|
|
void JKQTPSingleColumnGraph::setDataSortOrder(JKQTPSingleColumnGraph::DataSortOrder __value)
|
2018-11-25 21:53:26 +08:00
|
|
|
{
|
2019-04-22 19:27:50 +08:00
|
|
|
this->sortData = __value;
|
2018-11-25 21:53:26 +08:00
|
|
|
}
|
|
|
|
|
2019-04-22 19:27:50 +08:00
|
|
|
JKQTPSingleColumnGraph::DataSortOrder JKQTPSingleColumnGraph::getDataSortOrder() const
|
2018-11-25 21:53:26 +08:00
|
|
|
{
|
2019-04-22 19:27:50 +08:00
|
|
|
return this->sortData;
|
2018-11-25 21:53:26 +08:00
|
|
|
}
|
|
|
|
|
2019-02-03 21:04:48 +08:00
|
|
|
void JKQTPSingleColumnGraph::setDataSortOrder(int __value) {
|
2019-05-06 01:31:20 +08:00
|
|
|
sortData=static_cast<DataSortOrder>(__value);
|
2018-12-28 05:52:00 +08:00
|
|
|
if (__value>0) sortData=Sorted;
|
|
|
|
}
|
|
|
|
|
2019-04-22 19:27:50 +08:00
|
|
|
void JKQTPSingleColumnGraph::setDataDirection(JKQTPSingleColumnGraph::DataDirection __value)
|
2018-11-25 21:53:26 +08:00
|
|
|
{
|
2019-04-22 19:27:50 +08:00
|
|
|
this->dataDirection = __value;
|
|
|
|
}
|
|
|
|
|
|
|
|
JKQTPSingleColumnGraph::DataDirection JKQTPSingleColumnGraph::getDataDirection() const
|
|
|
|
{
|
|
|
|
return this->dataDirection;
|
2018-11-25 21:53:26 +08:00
|
|
|
}
|
|
|
|
|
2019-04-22 19:27:50 +08:00
|
|
|
bool JKQTPSingleColumnGraph::usesColumn(int c) const
|
2018-11-25 21:53:26 +08:00
|
|
|
{
|
2019-04-22 19:27:50 +08:00
|
|
|
return c==dataColumn;
|
2018-11-25 21:53:26 +08:00
|
|
|
}
|
|
|
|
|
2019-04-22 19:27:50 +08:00
|
|
|
|
2019-01-20 17:49:29 +08:00
|
|
|
void JKQTPSingleColumnGraph::intSortData()
|
2018-11-25 21:53:26 +08:00
|
|
|
{
|
|
|
|
sortedIndices.clear();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (parent==nullptr) return ;
|
|
|
|
|
2020-09-19 01:35:53 +08:00
|
|
|
const JKQTPDatastore* datastore=parent->getDatastore();
|
2018-11-25 21:53:26 +08:00
|
|
|
int imin=0;
|
2019-05-06 01:31:20 +08:00
|
|
|
int imax=0;
|
|
|
|
getIndexRange(imin, imax);
|
2018-11-25 21:53:26 +08:00
|
|
|
|
|
|
|
QVector<double> datas;
|
|
|
|
|
2019-01-20 17:49:29 +08:00
|
|
|
if (sortData==JKQTPSingleColumnGraph::Sorted) {
|
2018-11-25 21:53:26 +08:00
|
|
|
|
|
|
|
for (int i=0; i<imax; i++) {
|
2019-05-06 01:31:20 +08:00
|
|
|
double xv=datastore->get(dataColumn,static_cast<size_t>(i));
|
2018-11-25 21:53:26 +08:00
|
|
|
sortedIndices<<i;
|
|
|
|
datas<<xv;
|
|
|
|
}
|
|
|
|
|
2019-05-23 04:20:00 +08:00
|
|
|
jkqtpQuicksortDual(datas.data(), sortedIndices.data(), datas.size());
|
2018-11-25 21:53:26 +08:00
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-06 01:31:20 +08:00
|
|
|
bool JKQTPSingleColumnGraph::getIndexRange(int &imin, int &imax) const
|
|
|
|
{
|
|
|
|
if (parent==nullptr) return false;
|
|
|
|
|
2020-09-19 01:35:53 +08:00
|
|
|
const JKQTPDatastore* datastore=parent->getDatastore();
|
|
|
|
if (dataColumn>=0) {
|
|
|
|
imin=0;
|
|
|
|
imax=static_cast<int>(datastore->getRows(static_cast<size_t>(dataColumn)));
|
|
|
|
if (imax<imin) {
|
|
|
|
int h=imin;
|
|
|
|
imin=imax;
|
|
|
|
imax=h;
|
|
|
|
}
|
|
|
|
if (imin<0) imin=0;
|
|
|
|
if (imax<0) imax=0;
|
|
|
|
return true;
|
2019-05-06 01:31:20 +08:00
|
|
|
}
|
2020-09-19 01:35:53 +08:00
|
|
|
return false;
|
2019-05-06 01:31:20 +08:00
|
|
|
}
|
|
|
|
|
2018-11-25 21:53:26 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-01-20 17:49:29 +08:00
|
|
|
void JKQTPXYGraph::intSortData()
|
2018-11-25 21:53:26 +08:00
|
|
|
{
|
|
|
|
sortedIndices.clear();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (parent==nullptr) return ;
|
2022-08-24 04:12:53 +08:00
|
|
|
if (sortData==JKQTPXYLineGraph::Unsorted) return ;
|
2018-11-25 21:53:26 +08:00
|
|
|
|
2019-01-20 17:49:29 +08:00
|
|
|
JKQTPDatastore* datastore=parent->getDatastore();
|
2018-11-25 21:53:26 +08:00
|
|
|
int imin=0;
|
2019-05-06 01:31:20 +08:00
|
|
|
int imax=0;
|
|
|
|
getIndexRange(imin, imax);
|
2018-11-25 21:53:26 +08:00
|
|
|
|
|
|
|
QVector<double> datas;
|
|
|
|
|
2019-01-20 17:49:29 +08:00
|
|
|
if (sortData==JKQTPXYLineGraph::SortedX) {
|
2018-11-25 21:53:26 +08:00
|
|
|
|
|
|
|
for (int i=0; i<imax; i++) {
|
|
|
|
double xv=datastore->get(static_cast<size_t>(xColumn),static_cast<size_t>(i));
|
|
|
|
sortedIndices<<i;
|
|
|
|
datas<<xv;
|
|
|
|
}
|
|
|
|
|
2019-05-23 04:20:00 +08:00
|
|
|
jkqtpQuicksortDual(datas.data(), sortedIndices.data(), datas.size());
|
2018-11-25 21:53:26 +08:00
|
|
|
|
|
|
|
|
2019-01-20 17:49:29 +08:00
|
|
|
} else if (sortData==JKQTPXYLineGraph::SortedY) {
|
2018-11-25 21:53:26 +08:00
|
|
|
|
|
|
|
for (int i=0; i<imax; i++) {
|
|
|
|
double xv=datastore->get(static_cast<size_t>(yColumn),static_cast<size_t>(i));
|
|
|
|
sortedIndices<<i;
|
|
|
|
datas<<xv;
|
|
|
|
}
|
|
|
|
|
2019-05-23 04:20:00 +08:00
|
|
|
jkqtpQuicksortDual(datas.data(), sortedIndices.data(), datas.size());
|
2018-11-25 21:53:26 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-06 01:31:20 +08:00
|
|
|
bool JKQTPXYGraph::getIndexRange(int& imin, int& imax) const
|
|
|
|
{
|
|
|
|
if (parent==nullptr) return false;
|
2020-09-19 01:35:53 +08:00
|
|
|
if (xColumn>=0 && yColumn>=0) {
|
|
|
|
JKQTPDatastore* datastore=parent->getDatastore();
|
|
|
|
imin=0;
|
|
|
|
imax=static_cast<int>(qMin(datastore->getRows(static_cast<size_t>(xColumn)), datastore->getRows(static_cast<size_t>(yColumn))));
|
|
|
|
// ensure correct order, i.e. imin<=imax
|
|
|
|
if (imax<imin) {
|
|
|
|
int h=imin;
|
|
|
|
imin=imax;
|
|
|
|
imax=h;
|
|
|
|
}
|
|
|
|
// ranges are always >=0
|
|
|
|
if (imin<0) imin=0;
|
|
|
|
if (imax<0) imax=0;
|
|
|
|
return true;
|
2019-05-06 01:31:20 +08:00
|
|
|
}
|
2020-09-19 01:35:53 +08:00
|
|
|
return false;
|
2019-05-06 01:31:20 +08:00
|
|
|
}
|
|
|
|
|
2018-11-25 21:53:26 +08:00
|
|
|
|
2018-12-28 05:52:00 +08:00
|
|
|
|
2020-09-21 19:15:57 +08:00
|
|
|
JKQTPGeometricPlotElement::JKQTPGeometricPlotElement(DrawMode drawMode, JKQTBasePlotter *parent):
|
- improved: geometric objects now use an adaptive drawing algorithm to represent curves (before e.g. ellipses were always separated into a fixed number of line-segments)
- improved: constructors and access functions for several geometric objects (e.g. more constructors, additional functions to retrieve parameters in diferent forms, iterators for polygons, ...)
- new: all geometric objects can either be drawn as graphic element (i.e. lines are straight line, even on non-linear axes), or as mathematical curve (i.e. on non-linear axes, lines become the appropriate curve representing the linear function, connecting the given start/end-points). The only exceptions are ellipses (and the derived arcs,pies,chords), which are always drawn as mathematical curves
2020-09-04 05:08:52 +08:00
|
|
|
JKQTPPlotElement(parent), m_drawMode(drawMode)
|
2018-12-28 05:52:00 +08:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
- improved: geometric objects now use an adaptive drawing algorithm to represent curves (before e.g. ellipses were always separated into a fixed number of line-segments)
- improved: constructors and access functions for several geometric objects (e.g. more constructors, additional functions to retrieve parameters in diferent forms, iterators for polygons, ...)
- new: all geometric objects can either be drawn as graphic element (i.e. lines are straight line, even on non-linear axes), or as mathematical curve (i.e. on non-linear axes, lines become the appropriate curve representing the linear function, connecting the given start/end-points). The only exceptions are ellipses (and the derived arcs,pies,chords), which are always drawn as mathematical curves
2020-09-04 05:08:52 +08:00
|
|
|
|
2020-09-21 19:15:57 +08:00
|
|
|
void JKQTPGeometricPlotElement::setDrawMode(JKQTPGeometricPlotElement::DrawMode mode)
|
2018-12-28 05:52:00 +08:00
|
|
|
{
|
- improved: geometric objects now use an adaptive drawing algorithm to represent curves (before e.g. ellipses were always separated into a fixed number of line-segments)
- improved: constructors and access functions for several geometric objects (e.g. more constructors, additional functions to retrieve parameters in diferent forms, iterators for polygons, ...)
- new: all geometric objects can either be drawn as graphic element (i.e. lines are straight line, even on non-linear axes), or as mathematical curve (i.e. on non-linear axes, lines become the appropriate curve representing the linear function, connecting the given start/end-points). The only exceptions are ellipses (and the derived arcs,pies,chords), which are always drawn as mathematical curves
2020-09-04 05:08:52 +08:00
|
|
|
m_drawMode=mode;
|
|
|
|
}
|
2018-12-28 05:52:00 +08:00
|
|
|
|
2020-09-21 19:15:57 +08:00
|
|
|
JKQTPGeometricPlotElement::DrawMode JKQTPGeometricPlotElement::getDrawMode() const
|
- improved: geometric objects now use an adaptive drawing algorithm to represent curves (before e.g. ellipses were always separated into a fixed number of line-segments)
- improved: constructors and access functions for several geometric objects (e.g. more constructors, additional functions to retrieve parameters in diferent forms, iterators for polygons, ...)
- new: all geometric objects can either be drawn as graphic element (i.e. lines are straight line, even on non-linear axes), or as mathematical curve (i.e. on non-linear axes, lines become the appropriate curve representing the linear function, connecting the given start/end-points). The only exceptions are ellipses (and the derived arcs,pies,chords), which are always drawn as mathematical curves
2020-09-04 05:08:52 +08:00
|
|
|
{
|
|
|
|
return m_drawMode;
|
2018-12-28 05:52:00 +08:00
|
|
|
}
|
|
|
|
|
2020-09-21 19:15:57 +08:00
|
|
|
JKQTPGeometricPlotElement::~JKQTPGeometricPlotElement()
|
2019-01-26 19:28:44 +08:00
|
|
|
= default;
|
2020-09-19 01:35:53 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
JKQTPXYYGraph::JKQTPXYYGraph(JKQTBasePlotter *parent):
|
|
|
|
JKQTPXYGraph(parent), yColumn2(-1)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
bool JKQTPXYYGraph::getYMinMax(double &miny, double &maxy, double &smallestGreaterZero)
|
|
|
|
{
|
|
|
|
bool start=true;
|
|
|
|
miny=0;
|
|
|
|
maxy=0;
|
|
|
|
smallestGreaterZero=0;
|
|
|
|
|
|
|
|
if (parent==nullptr) return false;
|
|
|
|
|
|
|
|
const JKQTPDatastore* datastore=parent->getDatastore();
|
|
|
|
int imin=0;
|
|
|
|
int imax=0;
|
2020-09-19 20:41:53 +08:00
|
|
|
if (getIndexRange(imin, imax)) {
|
2020-09-19 01:35:53 +08:00
|
|
|
|
|
|
|
|
2020-09-19 20:41:53 +08:00
|
|
|
for (int i=imin; i<imax; i++) {
|
|
|
|
const double yv=datastore->get(static_cast<size_t>(yColumn),static_cast<size_t>(i));
|
|
|
|
if (JKQTPIsOKFloat(yv)) {
|
|
|
|
if (start || yv>maxy) maxy=yv;
|
|
|
|
if (start || yv<miny) miny=yv;
|
|
|
|
double xvsgz;
|
|
|
|
xvsgz=yv; SmallestGreaterZeroCompare_xvsgz();
|
|
|
|
start=false;
|
|
|
|
}
|
|
|
|
const double yv2=datastore->get(static_cast<size_t>(yColumn2),static_cast<size_t>(i));
|
|
|
|
if (JKQTPIsOKFloat(yv2)) {
|
|
|
|
if (start || yv2>maxy) maxy=yv2;
|
|
|
|
if (start || yv2<miny) miny=yv2;
|
|
|
|
double xvsgz;
|
|
|
|
xvsgz=yv2; SmallestGreaterZeroCompare_xvsgz();
|
|
|
|
start=false;
|
|
|
|
}
|
2020-09-19 01:35:53 +08:00
|
|
|
}
|
2020-09-19 20:41:53 +08:00
|
|
|
return !start;
|
2020-09-19 01:35:53 +08:00
|
|
|
}
|
2020-09-19 20:41:53 +08:00
|
|
|
return false;
|
2020-09-19 01:35:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool JKQTPXYYGraph::usesColumn(int column) const
|
|
|
|
{
|
|
|
|
return (column==yColumn2) || JKQTPXYYGraph::usesColumn(column);
|
|
|
|
}
|
|
|
|
|
|
|
|
int JKQTPXYYGraph::getYColumn2() const
|
|
|
|
{
|
|
|
|
return yColumn2;
|
|
|
|
}
|
|
|
|
|
|
|
|
double JKQTPXYYGraph::hitTest(const QPointF &posSystem, QPointF *closestSpotSystem, QString *label, JKQTPPlotElement::HitTestMode mode) const
|
|
|
|
{
|
|
|
|
if (parent==nullptr) return JKQTP_NAN;
|
|
|
|
|
|
|
|
// check base-class implementation and use it, if it returns a vaid value
|
|
|
|
const double baseclassResult=JKQTPXYGraph::hitTest(posSystem, closestSpotSystem, label, mode);
|
|
|
|
if (JKQTPIsOKFloat(baseclassResult)) return baseclassResult;
|
|
|
|
|
|
|
|
const JKQTPDatastore* datastore=parent->getDatastore();
|
|
|
|
int imin=0;
|
|
|
|
int imax=0;
|
|
|
|
if (!getIndexRange(imin, imax)) return JKQTP_NAN;
|
|
|
|
|
|
|
|
|
|
|
|
int closest=-1;
|
|
|
|
double closedist=JKQTP_NAN;
|
|
|
|
double closedistsec=JKQTP_NAN;
|
|
|
|
QPointF closestPos;
|
|
|
|
QPointF posF=transform(posSystem);
|
|
|
|
for (int i=imin; i<imax; i++) {
|
|
|
|
const QPointF x(datastore->get(static_cast<size_t>(xColumn),static_cast<size_t>(i)), datastore->get(static_cast<size_t>(yColumn2),static_cast<size_t>(i)));
|
|
|
|
const QPointF xpix = transform(x);
|
|
|
|
if (JKQTPIsOKFloat(xpix.x())&&JKQTPIsOKFloat(xpix.y())) {
|
|
|
|
double d=0, dsecondary=0;
|
|
|
|
switch (mode) {
|
|
|
|
case HitTestXY: d=sqrt(jkqtp_sqr(xpix.x()-posF.x())+jkqtp_sqr(xpix.y()-posF.y())); dsecondary=0; break;
|
|
|
|
case HitTestXOnly: d=fabs(xpix.x()-posF.x()); dsecondary=fabs(xpix.y()-posF.y()); break;
|
|
|
|
case HitTestYOnly: d=fabs(xpix.y()-posF.y()); dsecondary=fabs(xpix.x()-posF.x()); break;
|
|
|
|
}
|
|
|
|
if (closest<0 || d<closedist || (jkqtp_approximatelyEqual(d,closedist) && dsecondary<closedistsec)) {
|
|
|
|
closest=i;
|
|
|
|
closedist=d;
|
|
|
|
closedistsec=dsecondary;
|
|
|
|
closestPos=x;
|
|
|
|
//qDebug()<<"hitTest("<<posSystem<<"[="<<posF<<"pix]...): found closest="<<closest<<", closedist="<<closedist<<", closedistsec="<<closedistsec<<", closestPos="<<closestPos;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (closest>=0) {
|
|
|
|
if (label) *label=formatHitTestDefaultLabel(closestPos.x(), closestPos.y(), closest);
|
|
|
|
if (closestSpotSystem) *closestSpotSystem=closestPos;
|
|
|
|
return closedist;
|
|
|
|
} else {
|
|
|
|
return JKQTP_NAN;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void JKQTPXYYGraph::setXYYColumns(size_t xCol, size_t yCol, size_t y2Col)
|
|
|
|
{
|
|
|
|
setXYColumns(xCol, yCol);
|
|
|
|
yColumn2=static_cast<int>(y2Col);
|
|
|
|
}
|
|
|
|
|
|
|
|
void JKQTPXYYGraph::setXYYColumns(int xCol, int yCol, int y2Col)
|
|
|
|
{
|
|
|
|
setXYColumns(xCol, yCol);
|
|
|
|
yColumn2=y2Col;
|
|
|
|
}
|
|
|
|
|
|
|
|
void JKQTPXYYGraph::setYColumn2(int __value)
|
|
|
|
{
|
|
|
|
yColumn2=__value;
|
|
|
|
}
|
|
|
|
|
|
|
|
void JKQTPXYYGraph::setYColumn2(size_t __value)
|
|
|
|
{
|
|
|
|
yColumn2=static_cast<int>(__value);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool JKQTPXYYGraph::getIndexRange(int &imin, int &imax) const
|
|
|
|
{
|
|
|
|
bool ok=JKQTPXYGraph::getIndexRange(imin, imax);
|
|
|
|
if (ok) {
|
|
|
|
if (parent==nullptr) return false;
|
|
|
|
if (yColumn2<0) return false;
|
|
|
|
const JKQTPDatastore* datastore=parent->getDatastore();
|
2022-07-23 22:05:13 +08:00
|
|
|
const int rows=static_cast<int>(datastore->getRows(static_cast<size_t>(yColumn2)));
|
2020-09-19 01:35:53 +08:00
|
|
|
imax=qMin<int>(imax, rows);
|
|
|
|
}
|
|
|
|
return ok;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
JKQTPXXYGraph::JKQTPXXYGraph(JKQTBasePlotter *parent):
|
|
|
|
JKQTPXYGraph(parent), xColumn2(-1)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
bool JKQTPXXYGraph::getXMinMax(double &minx, double &maxx, double &smallestGreaterZero)
|
|
|
|
{
|
|
|
|
bool start=true;
|
|
|
|
minx=0;
|
|
|
|
maxx=0;
|
|
|
|
smallestGreaterZero=0;
|
|
|
|
|
|
|
|
if (parent==nullptr) return false;
|
|
|
|
|
|
|
|
const JKQTPDatastore* datastore=parent->getDatastore();
|
|
|
|
int imin=0;
|
|
|
|
int imax=0;
|
2020-09-19 20:41:53 +08:00
|
|
|
if (getIndexRange(imin, imax)) {
|
2020-09-19 01:35:53 +08:00
|
|
|
|
|
|
|
|
2020-09-19 20:41:53 +08:00
|
|
|
for (int i=imin; i<imax; i++) {
|
|
|
|
const double xv=datastore->get(static_cast<size_t>(xColumn),static_cast<size_t>(i));
|
|
|
|
if (JKQTPIsOKFloat(xv)) {
|
|
|
|
if (start || xv>maxx) maxx=xv;
|
|
|
|
if (start || xv<minx) minx=xv;
|
|
|
|
double xvsgz;
|
|
|
|
xvsgz=xv; SmallestGreaterZeroCompare_xvsgz();
|
|
|
|
start=false;
|
|
|
|
}
|
|
|
|
const double xv2=datastore->get(static_cast<size_t>(xColumn2),static_cast<size_t>(i));
|
|
|
|
if (JKQTPIsOKFloat(xv2)) {
|
|
|
|
if (start || xv2>maxx) maxx=xv2;
|
|
|
|
if (start || xv2<minx) minx=xv2;
|
|
|
|
double xvsgz;
|
|
|
|
xvsgz=xv2; SmallestGreaterZeroCompare_xvsgz();
|
|
|
|
start=false;
|
|
|
|
}
|
2020-09-19 01:35:53 +08:00
|
|
|
}
|
2020-09-19 20:41:53 +08:00
|
|
|
return !start;
|
2020-09-19 01:35:53 +08:00
|
|
|
}
|
2020-09-19 20:41:53 +08:00
|
|
|
return false;
|
2020-09-19 01:35:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool JKQTPXXYGraph::usesColumn(int column) const
|
|
|
|
{
|
|
|
|
return (column==xColumn2) || JKQTPXXYGraph::usesColumn(column);
|
|
|
|
}
|
|
|
|
|
|
|
|
int JKQTPXXYGraph::getXColumn2() const
|
|
|
|
{
|
|
|
|
return xColumn2;
|
|
|
|
}
|
|
|
|
|
|
|
|
double JKQTPXXYGraph::hitTest(const QPointF &posSystem, QPointF *closestSpotSystem, QString *label, JKQTPPlotElement::HitTestMode mode) const
|
|
|
|
{
|
|
|
|
if (parent==nullptr) return JKQTP_NAN;
|
|
|
|
|
|
|
|
// check base-class implementation and use it, if it returns a vaid value
|
|
|
|
const double baseclassResult=JKQTPXYGraph::hitTest(posSystem, closestSpotSystem, label, mode);
|
|
|
|
if (JKQTPIsOKFloat(baseclassResult)) return baseclassResult;
|
|
|
|
|
|
|
|
const JKQTPDatastore* datastore=parent->getDatastore();
|
|
|
|
int imin=0;
|
|
|
|
int imax=0;
|
|
|
|
if (!getIndexRange(imin, imax)) return JKQTP_NAN;
|
|
|
|
|
|
|
|
|
|
|
|
int closest=-1;
|
|
|
|
double closedist=JKQTP_NAN;
|
|
|
|
double closedistsec=JKQTP_NAN;
|
|
|
|
QPointF closestPos;
|
|
|
|
QPointF posF=transform(posSystem);
|
|
|
|
for (int i=imin; i<imax; i++) {
|
|
|
|
const QPointF x(datastore->get(static_cast<size_t>(xColumn2),static_cast<size_t>(i)), datastore->get(static_cast<size_t>(yColumn),static_cast<size_t>(i)));
|
|
|
|
const QPointF xpix = transform(x);
|
|
|
|
if (JKQTPIsOKFloat(xpix.x())&&JKQTPIsOKFloat(xpix.y())) {
|
|
|
|
double d=0, dsecondary=0;
|
|
|
|
switch (mode) {
|
|
|
|
case HitTestXY: d=sqrt(jkqtp_sqr(xpix.x()-posF.x())+jkqtp_sqr(xpix.y()-posF.y())); dsecondary=0; break;
|
|
|
|
case HitTestXOnly: d=fabs(xpix.x()-posF.x()); dsecondary=fabs(xpix.y()-posF.y()); break;
|
|
|
|
case HitTestYOnly: d=fabs(xpix.y()-posF.y()); dsecondary=fabs(xpix.x()-posF.x()); break;
|
|
|
|
}
|
|
|
|
if (closest<0 || d<closedist || (jkqtp_approximatelyEqual(d,closedist) && dsecondary<closedistsec)) {
|
|
|
|
closest=i;
|
|
|
|
closedist=d;
|
|
|
|
closedistsec=dsecondary;
|
|
|
|
closestPos=x;
|
|
|
|
//qDebug()<<"hitTest("<<posSystem<<"[="<<posF<<"pix]...): found closest="<<closest<<", closedist="<<closedist<<", closedistsec="<<closedistsec<<", closestPos="<<closestPos;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (closest>=0) {
|
|
|
|
if (label) *label=formatHitTestDefaultLabel(closestPos.x(), closestPos.y(), closest);
|
|
|
|
if (closestSpotSystem) *closestSpotSystem=closestPos;
|
|
|
|
return closedist;
|
|
|
|
} else {
|
|
|
|
return JKQTP_NAN;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void JKQTPXXYGraph::setXXYColumns(size_t xCol, size_t x2Col, size_t yCol)
|
|
|
|
{
|
|
|
|
setXYColumns(xCol, yCol);
|
|
|
|
xColumn2=static_cast<int>(x2Col);
|
|
|
|
}
|
|
|
|
|
|
|
|
void JKQTPXXYGraph::setXXYColumns(int xCol, int x2Col, int yCol)
|
|
|
|
{
|
|
|
|
setXYColumns(xCol, yCol);
|
|
|
|
xColumn2=x2Col;
|
|
|
|
}
|
|
|
|
|
|
|
|
void JKQTPXXYGraph::setXColumn2(int __value)
|
|
|
|
{
|
|
|
|
xColumn2=__value;
|
|
|
|
}
|
|
|
|
|
|
|
|
void JKQTPXXYGraph::setXColumn2(size_t __value)
|
|
|
|
{
|
|
|
|
xColumn2=static_cast<int>(__value);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool JKQTPXXYGraph::getIndexRange(int &imin, int &imax) const
|
|
|
|
{
|
|
|
|
bool ok=JKQTPXYGraph::getIndexRange(imin, imax);
|
|
|
|
if (ok) {
|
|
|
|
if (parent==nullptr) return false;
|
|
|
|
if (xColumn2<0) return false;
|
|
|
|
const JKQTPDatastore* datastore=parent->getDatastore();
|
2022-07-23 22:05:13 +08:00
|
|
|
const int rows=static_cast<int>(datastore->getRows(static_cast<size_t>(xColumn2)));
|
2020-09-19 01:35:53 +08:00
|
|
|
imax=qMin<int>(imax, rows);
|
|
|
|
}
|
|
|
|
return ok;
|
|
|
|
}
|
2020-09-19 21:08:32 +08:00
|
|
|
|
|
|
|
JKQTPXYBaselineGraph::JKQTPXYBaselineGraph(JKQTBasePlotter *parent):
|
|
|
|
JKQTPXYGraph(parent), m_baseline(0.0)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
double JKQTPXYBaselineGraph::getBaseline() const
|
|
|
|
{
|
|
|
|
return m_baseline;
|
|
|
|
}
|
|
|
|
|
|
|
|
void JKQTPXYBaselineGraph::setBaseline(double __value)
|
|
|
|
{
|
|
|
|
m_baseline=__value;
|
|
|
|
}
|
2020-09-21 19:15:57 +08:00
|
|
|
|
2022-07-22 04:17:37 +08:00
|
|
|
JKQTPPlotAnnotationElement::JKQTPPlotAnnotationElement(JKQTBasePlotter *parent):
|
|
|
|
JKQTPPlotElement(parent)
|
2020-09-21 19:15:57 +08:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
JKQTPPlotAnnotationElement::~JKQTPPlotAnnotationElement()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|