2018-12-02 21:08:43 +08:00
|
|
|
/*
|
2019-01-20 23:15:10 +08:00
|
|
|
Copyright (c) 2008-2019 Jan W. Krieger (<jan@jkrieger.de>)
|
2018-12-02 21:08:43 +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-12-02 21:08:43 +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/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-06-20 22:06:31 +08:00
|
|
|
#include "jkqtplotter/graphs/jkqtpimpulses.h"
|
2018-12-02 21:08:43 +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"
|
2019-06-20 22:06:31 +08:00
|
|
|
#include "jkqtplotter/graphs/jkqtpimage.h"
|
2018-12-02 21:08:43 +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;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-01-20 17:49:29 +08:00
|
|
|
JKQTPImpulsesHorizontalGraph::JKQTPImpulsesHorizontalGraph(JKQTBasePlotter* parent):
|
|
|
|
JKQTPXYGraph(parent)
|
2018-12-02 21:08:43 +08:00
|
|
|
{
|
|
|
|
baseline=0;
|
2019-04-22 19:27:50 +08:00
|
|
|
drawSymbols=false;
|
|
|
|
initLineStyle(parent, parentPlotStyle);
|
|
|
|
initSymbolStyle(parent, parentPlotStyle);
|
|
|
|
setLineWidth(3);
|
2018-12-02 21:08:43 +08:00
|
|
|
}
|
|
|
|
|
2019-01-20 23:15:10 +08:00
|
|
|
JKQTPImpulsesHorizontalGraph::JKQTPImpulsesHorizontalGraph(JKQTPlotter* parent):
|
2019-04-22 19:27:50 +08:00
|
|
|
JKQTPImpulsesHorizontalGraph(parent->getPlotter())
|
2018-12-02 21:08:43 +08:00
|
|
|
{
|
|
|
|
}
|
2019-04-22 19:27:50 +08:00
|
|
|
|
2019-01-20 17:49:29 +08:00
|
|
|
void JKQTPImpulsesHorizontalGraph::draw(JKQTPEnhancedPainter& painter) {
|
2018-12-02 21:08:43 +08:00
|
|
|
#ifdef JKQTBP_AUTOTIMER
|
2019-01-20 17:49:29 +08:00
|
|
|
JKQTPAutoOutputTimer jkaaot("JKQTPImpulsesHorizontalGraph::draw");
|
2018-12-02 21:08:43 +08:00
|
|
|
#endif
|
|
|
|
if (parent==nullptr) return;
|
2019-01-20 17:49:29 +08:00
|
|
|
JKQTPDatastore* datastore=parent->getDatastore();
|
2018-12-02 21:08:43 +08:00
|
|
|
if (datastore==nullptr) return;
|
|
|
|
|
|
|
|
drawErrorsBefore(painter);
|
2019-02-08 00:24:46 +08:00
|
|
|
{
|
|
|
|
painter.save(); auto __finalpaint=JKQTPFinally([&painter]() {painter.restore();});
|
|
|
|
|
2019-04-22 19:27:50 +08:00
|
|
|
QPen p=getLinePen(painter, parent);
|
2019-02-08 00:24:46 +08:00
|
|
|
p.setCapStyle(Qt::FlatCap);
|
|
|
|
|
2019-06-22 20:21:32 +08:00
|
|
|
int imax=static_cast<int>(qMin(datastore->getRows(static_cast<size_t>(xColumn)), datastore->getRows(static_cast<size_t>(yColumn))));
|
2019-02-08 00:24:46 +08:00
|
|
|
int imin=0;
|
|
|
|
if (imax<imin) {
|
|
|
|
int h=imin;
|
|
|
|
imin=imax;
|
|
|
|
imax=h;
|
2018-12-02 21:08:43 +08:00
|
|
|
}
|
2019-02-08 00:24:46 +08:00
|
|
|
if (imin<0) imin=0;
|
|
|
|
if (imax<0) imax=0;
|
|
|
|
|
|
|
|
//double xold=-1;
|
|
|
|
//double yold=-1;
|
|
|
|
double x0=transformX(baseline);
|
|
|
|
if (parent->getXAxis()->isLogAxis()) {
|
|
|
|
if (baseline>0 && baseline>parent->getXAxis()->getMin()) x0=transformX(baseline);
|
|
|
|
else x0=transformX(parent->getXAxis()->getMin());
|
|
|
|
}
|
|
|
|
// double y0=transformY(baseline);
|
|
|
|
// if (parent->getYAxis()->isLogAxis()) {
|
|
|
|
// y0=transformY(parent->getYAxis()->getMin());
|
|
|
|
// if (baseline>0 && baseline>parent->getYAxis()->getMin()) y0=transformY(baseline);
|
|
|
|
// else y0=transformY(parent->getYAxis()->getMin());
|
|
|
|
// }
|
|
|
|
//bool first=false;
|
|
|
|
QVector<QLineF> lines;
|
2019-04-22 19:27:50 +08:00
|
|
|
QVector<QPointF> points;
|
2019-02-08 00:24:46 +08:00
|
|
|
intSortData();
|
|
|
|
for (int iii=imin; iii<imax; iii++) {
|
|
|
|
int i=qBound(imin, getDataIndex(iii), imax);
|
|
|
|
double xv=datastore->get(static_cast<size_t>(xColumn),static_cast<size_t>(i));
|
|
|
|
double yv=datastore->get(static_cast<size_t>(yColumn),static_cast<size_t>(i));
|
|
|
|
if (JKQTPIsOKFloat(xv) && JKQTPIsOKFloat(yv)) {
|
|
|
|
double x=transformX(xv);
|
|
|
|
double y=transformY(yv);
|
|
|
|
|
|
|
|
|
|
|
|
lines.append(QLineF(x0, y, x, y));
|
2019-04-22 19:27:50 +08:00
|
|
|
points.append(QPointF(x,y));
|
2019-02-08 00:24:46 +08:00
|
|
|
// xold=x;
|
|
|
|
// yold=y;
|
|
|
|
//first=true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
painter.setPen(p);
|
|
|
|
if (lines.size()>0) painter.drawLines(lines);
|
2019-04-22 19:27:50 +08:00
|
|
|
if (drawSymbols && points.size()>0) {
|
|
|
|
painter.save(); auto __finalpaint=JKQTPFinally([&painter]() {painter.restore();});
|
|
|
|
for (auto& p: points) {
|
|
|
|
plotStyledSymbol(parent, painter, p.x(), p.y());
|
|
|
|
}
|
|
|
|
}
|
2018-12-02 21:08:43 +08:00
|
|
|
|
2019-02-08 00:24:46 +08:00
|
|
|
}
|
2018-12-02 21:08:43 +08:00
|
|
|
drawErrorsAfter(painter);
|
|
|
|
}
|
|
|
|
|
2019-01-20 17:49:29 +08:00
|
|
|
void JKQTPImpulsesHorizontalGraph::drawKeyMarker(JKQTPEnhancedPainter& painter, QRectF& rect) {
|
2018-12-02 21:08:43 +08:00
|
|
|
|
|
|
|
|
2019-02-08 00:24:46 +08:00
|
|
|
painter.save(); auto __finalpaint=JKQTPFinally([&painter]() {painter.restore();});
|
2019-04-22 19:27:50 +08:00
|
|
|
QPen p=getLinePen(painter, parent);
|
2018-12-02 21:08:43 +08:00
|
|
|
p.setCapStyle(Qt::FlatCap);
|
|
|
|
painter.setPen(p);
|
|
|
|
int y=rect.top()+rect.height()/2.0;
|
|
|
|
painter.drawLine(rect.left(), y, rect.right(), y);
|
2019-02-08 00:24:46 +08:00
|
|
|
|
2018-12-02 21:08:43 +08:00
|
|
|
}
|
|
|
|
|
2019-04-22 19:27:50 +08:00
|
|
|
QColor JKQTPImpulsesHorizontalGraph::getKeyLabelColor() const {
|
|
|
|
return getLineColor();
|
|
|
|
}
|
|
|
|
|
|
|
|
void JKQTPImpulsesHorizontalGraph::setColor(QColor c)
|
|
|
|
{
|
|
|
|
setLineColor(c);
|
|
|
|
setSymbolColor(c);
|
|
|
|
setSymbolFillColor(JKQTPGetDerivedColor(parent->getCurrentPlotterStyle().graphFillColorDerivationMode, c));
|
|
|
|
c.setAlphaF(0.5);
|
|
|
|
setHighlightingLineColor(c);
|
|
|
|
}
|
|
|
|
|
|
|
|
void JKQTPImpulsesHorizontalGraph::setBaseline(double __value)
|
|
|
|
{
|
|
|
|
this->baseline = __value;
|
|
|
|
}
|
|
|
|
|
|
|
|
double JKQTPImpulsesHorizontalGraph::getBaseline() const
|
|
|
|
{
|
|
|
|
return this->baseline;
|
|
|
|
}
|
|
|
|
|
|
|
|
void JKQTPImpulsesHorizontalGraph::setDrawSymbols(bool __value)
|
|
|
|
{
|
|
|
|
drawSymbols=__value;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool JKQTPImpulsesHorizontalGraph::getDrawSymbols() const
|
|
|
|
{
|
|
|
|
return drawSymbols;
|
2018-12-02 21:08:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-01-20 17:49:29 +08:00
|
|
|
JKQTPImpulsesVerticalGraph::JKQTPImpulsesVerticalGraph(JKQTBasePlotter* parent):
|
|
|
|
JKQTPImpulsesHorizontalGraph(parent)
|
2018-12-02 21:08:43 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2019-01-20 23:15:10 +08:00
|
|
|
JKQTPImpulsesVerticalGraph::JKQTPImpulsesVerticalGraph(JKQTPlotter *parent):
|
2019-01-20 17:49:29 +08:00
|
|
|
JKQTPImpulsesHorizontalGraph(parent)
|
2018-12-02 21:08:43 +08:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-01-20 17:49:29 +08:00
|
|
|
void JKQTPImpulsesVerticalGraph::draw(JKQTPEnhancedPainter& painter) {
|
2018-12-02 21:08:43 +08:00
|
|
|
#ifdef JKQTBP_AUTOTIMER
|
2019-01-20 17:49:29 +08:00
|
|
|
JKQTPAutoOutputTimer jkaaot("JKQTPImpulsesVerticalGraph::draw");
|
2018-12-02 21:08:43 +08:00
|
|
|
#endif
|
|
|
|
if (parent==nullptr) return;
|
2019-01-20 17:49:29 +08:00
|
|
|
JKQTPDatastore* datastore=parent->getDatastore();
|
2018-12-02 21:08:43 +08:00
|
|
|
if (datastore==nullptr) return;
|
|
|
|
|
|
|
|
drawErrorsBefore(painter);
|
2019-02-08 00:24:46 +08:00
|
|
|
{
|
|
|
|
painter.save(); auto __finalpaint=JKQTPFinally([&painter]() {painter.restore();});
|
|
|
|
|
2019-04-22 19:27:50 +08:00
|
|
|
QPen p=getLinePen(painter, parent);
|
2019-02-08 00:24:46 +08:00
|
|
|
p.setCapStyle(Qt::FlatCap);
|
|
|
|
|
2019-06-22 20:21:32 +08:00
|
|
|
int imax=static_cast<int>(qMin(datastore->getRows(static_cast<size_t>(xColumn)), datastore->getRows(static_cast<size_t>(yColumn))));
|
2019-02-08 00:24:46 +08:00
|
|
|
int imin=0;
|
|
|
|
if (imax<imin) {
|
|
|
|
int h=imin;
|
|
|
|
imin=imax;
|
|
|
|
imax=h;
|
2018-12-02 21:08:43 +08:00
|
|
|
}
|
2019-02-08 00:24:46 +08:00
|
|
|
if (imin<0) imin=0;
|
|
|
|
if (imax<0) imax=0;
|
|
|
|
|
|
|
|
//double xold=-1;
|
|
|
|
//double yold=-1;
|
|
|
|
//bool first=false;
|
|
|
|
// double x0=transformX(baseline);
|
|
|
|
// if (parent->getXAxis()->isLogAxis()) {
|
|
|
|
// if (baseline>0 && baseline>parent->getXAxis()->getMin()) x0=transformX(baseline);
|
|
|
|
// else x0=transformX(parent->getXAxis()->getMin());
|
|
|
|
// }
|
|
|
|
double y0=transformY(baseline);
|
|
|
|
if (parent->getYAxis()->isLogAxis()) {
|
|
|
|
y0=transformY(parent->getYAxis()->getMin());
|
|
|
|
if (baseline>0 && baseline>parent->getYAxis()->getMin()) y0=transformY(baseline);
|
|
|
|
else y0=transformY(parent->getYAxis()->getMin());
|
|
|
|
}
|
|
|
|
QVector<QLineF> lines;
|
2019-04-22 19:27:50 +08:00
|
|
|
QVector<QPointF> points;
|
2019-02-08 00:24:46 +08:00
|
|
|
intSortData();
|
|
|
|
for (int iii=imin; iii<imax; iii++) {
|
|
|
|
int i=qBound(imin, getDataIndex(iii), imax);
|
|
|
|
double xv=datastore->get(static_cast<size_t>(xColumn),static_cast<size_t>(i));
|
|
|
|
double yv=datastore->get(static_cast<size_t>(yColumn),static_cast<size_t>(i));
|
|
|
|
if (JKQTPIsOKFloat(xv) && JKQTPIsOKFloat(yv) ) {
|
|
|
|
double x=transformX(xv);
|
|
|
|
double y=transformY(yv);
|
|
|
|
|
|
|
|
|
|
|
|
lines.append(QLineF(x, y0, x, y));
|
2019-04-22 19:27:50 +08:00
|
|
|
points.append(QPointF(x,y));
|
2019-02-08 00:24:46 +08:00
|
|
|
//xold=x;
|
|
|
|
//yold=y;
|
|
|
|
//first=true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
painter.setPen(p);
|
|
|
|
if (lines.size()>0) painter.drawLines(lines);
|
2019-04-22 19:27:50 +08:00
|
|
|
if (drawSymbols && points.size()>0) {
|
|
|
|
painter.save(); auto __finalpaint=JKQTPFinally([&painter]() {painter.restore();});
|
|
|
|
for (auto& p: points) {
|
|
|
|
plotStyledSymbol(parent, painter, p.x(), p.y());
|
|
|
|
}
|
|
|
|
}
|
2018-12-02 21:08:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
drawErrorsAfter(painter);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-01-20 17:49:29 +08:00
|
|
|
JKQTPImpulsesHorizontalErrorGraph::JKQTPImpulsesHorizontalErrorGraph(JKQTBasePlotter *parent):
|
2019-05-06 01:31:20 +08:00
|
|
|
JKQTPImpulsesHorizontalGraph(parent)
|
2018-12-12 06:00:43 +08:00
|
|
|
{
|
2019-04-22 19:27:50 +08:00
|
|
|
setErrorColorFromGraphColor(getLineColor());
|
2019-05-06 01:31:20 +08:00
|
|
|
initErrorStyle(parent, parentPlotStyle);
|
2018-12-12 06:00:43 +08:00
|
|
|
}
|
|
|
|
|
2019-01-20 23:15:10 +08:00
|
|
|
JKQTPImpulsesHorizontalErrorGraph::JKQTPImpulsesHorizontalErrorGraph(JKQTPlotter *parent):
|
2019-02-08 00:24:46 +08:00
|
|
|
JKQTPImpulsesHorizontalErrorGraph(parent->getPlotter())
|
2018-12-12 06:00:43 +08:00
|
|
|
{
|
2019-02-08 00:24:46 +08:00
|
|
|
|
2018-12-12 06:00:43 +08:00
|
|
|
}
|
|
|
|
|
2019-01-20 17:49:29 +08:00
|
|
|
bool JKQTPImpulsesHorizontalErrorGraph::usesColumn(int c) const
|
2018-12-02 21:08:43 +08:00
|
|
|
{
|
2019-01-20 17:49:29 +08:00
|
|
|
return JKQTPImpulsesHorizontalGraph::usesColumn(c)|| JKQTPXGraphErrors::errorUsesColumn(c);
|
2018-12-02 21:08:43 +08:00
|
|
|
}
|
|
|
|
|
2019-01-20 17:49:29 +08:00
|
|
|
void JKQTPImpulsesHorizontalErrorGraph::drawErrorsAfter(JKQTPEnhancedPainter &painter)
|
2018-12-02 21:08:43 +08:00
|
|
|
{
|
2019-02-03 21:04:48 +08:00
|
|
|
if (sortData==JKQTPXYGraph::Unsorted) plotErrorIndicators(painter, parent, this, xColumn, yColumn);
|
|
|
|
else plotErrorIndicators(painter, parent, this, xColumn, yColumn, 0, 0, &sortedIndices);
|
2018-12-02 21:08:43 +08:00
|
|
|
}
|
|
|
|
|
2019-01-20 17:49:29 +08:00
|
|
|
JKQTPImpulsesVerticalErrorGraph::JKQTPImpulsesVerticalErrorGraph(JKQTBasePlotter *parent):
|
2019-05-06 01:31:20 +08:00
|
|
|
JKQTPImpulsesVerticalGraph(parent)
|
2018-12-02 21:08:43 +08:00
|
|
|
{
|
2019-04-22 19:27:50 +08:00
|
|
|
setErrorColorFromGraphColor(getLineColor());
|
2019-05-06 01:31:20 +08:00
|
|
|
initErrorStyle(parent, parentPlotStyle);
|
2018-12-02 21:08:43 +08:00
|
|
|
}
|
|
|
|
|
2019-01-20 23:15:10 +08:00
|
|
|
JKQTPImpulsesVerticalErrorGraph::JKQTPImpulsesVerticalErrorGraph(JKQTPlotter *parent):
|
2019-02-08 00:24:46 +08:00
|
|
|
JKQTPImpulsesVerticalErrorGraph(parent->getPlotter())
|
2018-12-02 21:08:43 +08:00
|
|
|
{
|
2019-02-08 00:24:46 +08:00
|
|
|
|
2018-12-02 21:08:43 +08:00
|
|
|
}
|
|
|
|
|
2019-01-20 17:49:29 +08:00
|
|
|
bool JKQTPImpulsesVerticalErrorGraph::usesColumn(int c) const
|
2018-12-02 21:08:43 +08:00
|
|
|
{
|
2019-01-20 17:49:29 +08:00
|
|
|
return JKQTPImpulsesVerticalGraph::usesColumn(c)|| JKQTPYGraphErrors::errorUsesColumn(c);
|
2018-12-02 21:08:43 +08:00
|
|
|
}
|
|
|
|
|
2019-01-20 17:49:29 +08:00
|
|
|
void JKQTPImpulsesVerticalErrorGraph::drawErrorsAfter(JKQTPEnhancedPainter &painter)
|
2018-12-02 21:08:43 +08:00
|
|
|
{
|
2019-02-03 21:04:48 +08:00
|
|
|
if (sortData==JKQTPXYGraph::Unsorted) plotErrorIndicators(painter, parent, this, xColumn, yColumn);
|
|
|
|
else plotErrorIndicators(painter, parent, this, xColumn, yColumn, 0, 0, &sortedIndices);
|
2018-12-02 21:08:43 +08:00
|
|
|
|
|
|
|
}
|