2018-12-02 21:08:43 +08:00
|
|
|
/*
|
|
|
|
Copyright (c) 2008-2018 Jan W. Krieger (<jan@jkrieger.de>)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 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/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-12-19 00:13:18 +08:00
|
|
|
#include "jkqtplotter/jkqtpgraphsimpulses.h"
|
2018-12-02 21:08:43 +08:00
|
|
|
#include "jkqtplotter/jkqtpbaseplotter.h"
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <QDebug>
|
|
|
|
#include <iostream>
|
|
|
|
#include "jkqtplottertools/jkqtptools.h"
|
2018-12-19 00:13:18 +08:00
|
|
|
#include "jkqtplotter/jkqtpgraphsimage.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;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-12-12 06:00:43 +08:00
|
|
|
JKQTPimpulsesHorizontalGraph::JKQTPimpulsesHorizontalGraph(JKQtBasePlotter* parent):
|
2018-12-02 21:08:43 +08:00
|
|
|
JKQTPxyGraph(parent)
|
|
|
|
{
|
|
|
|
baseline=0;
|
|
|
|
color=QColor("red");
|
|
|
|
lineWidth=3;
|
|
|
|
parentPlotStyle=-1;
|
|
|
|
|
|
|
|
if (parent) { // get style settings from parent object
|
|
|
|
parentPlotStyle=parent->getNextStyle();
|
|
|
|
color=parent->getPlotStyle(parentPlotStyle).color();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-12 06:00:43 +08:00
|
|
|
JKQTPimpulsesHorizontalGraph::JKQTPimpulsesHorizontalGraph(JKQtPlotter* parent):
|
2018-12-02 21:08:43 +08:00
|
|
|
JKQTPxyGraph(parent)
|
|
|
|
{
|
|
|
|
baseline=0;
|
|
|
|
color=QColor("red");
|
|
|
|
lineWidth=3;
|
|
|
|
parentPlotStyle=-1;
|
|
|
|
|
|
|
|
if (parent) { // get style settings from parent object
|
|
|
|
parentPlotStyle=parent->getNextStyle();
|
|
|
|
color=parent->getPlotStyle(parentPlotStyle).color();
|
|
|
|
}
|
|
|
|
}
|
2018-12-12 06:00:43 +08:00
|
|
|
void JKQTPimpulsesHorizontalGraph::draw(JKQTPEnhancedPainter& painter) {
|
2018-12-02 21:08:43 +08:00
|
|
|
#ifdef JKQTBP_AUTOTIMER
|
2018-12-12 06:00:43 +08:00
|
|
|
JKQTPAutoOutputTimer jkaaot("JKQTPimpulsesHorizontalGraph::draw");
|
2018-12-02 21:08:43 +08:00
|
|
|
#endif
|
|
|
|
if (parent==nullptr) return;
|
|
|
|
JKQTPdatastore* datastore=parent->getDatastore();
|
|
|
|
if (datastore==nullptr) return;
|
|
|
|
|
|
|
|
drawErrorsBefore(painter);
|
|
|
|
|
|
|
|
painter.save();
|
|
|
|
|
|
|
|
QPen p=painter.pen();
|
|
|
|
p.setColor(color);
|
|
|
|
p.setWidthF(qMax(JKQTPLOTTER_ABS_MIN_LINEWIDTH, parent->pt2px(painter, lineWidth*parent->get_lineWidthMultiplier())));
|
|
|
|
p.setStyle(Qt::SolidLine);
|
|
|
|
p.setCapStyle(Qt::FlatCap);
|
|
|
|
|
|
|
|
int imax=qMin(datastore->getColumn(static_cast<size_t>(xColumn)).getRows(), datastore->getColumn(static_cast<size_t>(yColumn)).getRows());
|
|
|
|
int imin=0;
|
|
|
|
// interpret data ranges
|
|
|
|
if (datarange_start>-1) {
|
2018-12-16 21:59:39 +08:00
|
|
|
imin=qMin(datarange_start, static_cast<int>(imax));
|
2018-12-02 21:08:43 +08:00
|
|
|
}
|
|
|
|
if (datarange_end>-1) {
|
2018-12-16 21:59:39 +08:00
|
|
|
imax=qMin(datarange_end, static_cast<int>(imax));
|
2018-12-02 21:08:43 +08:00
|
|
|
}
|
|
|
|
if (imax<imin) {
|
|
|
|
int h=imin;
|
|
|
|
imin=imax;
|
|
|
|
imax=h;
|
|
|
|
}
|
|
|
|
if (imin<0) imin=0;
|
|
|
|
if (imax<0) imax=0;
|
|
|
|
|
|
|
|
//double xold=-1;
|
|
|
|
//double yold=-1;
|
2018-12-28 05:52:00 +08:00
|
|
|
double x0=transformX(baseline);
|
|
|
|
if (parent->get_xAxis()->isLogAxis()) {
|
|
|
|
if (baseline>0 && baseline>parent->get_xAxis()->getMin()) x0=transformX(baseline);
|
|
|
|
else x0=transformX(parent->get_xAxis()->getMin());
|
2018-12-02 21:08:43 +08:00
|
|
|
}
|
2018-12-28 05:52:00 +08:00
|
|
|
// double y0=transformY(baseline);
|
|
|
|
// if (parent->get_yAxis()->isLogAxis()) {
|
|
|
|
// y0=transformY(parent->get_yAxis()->getMin());
|
|
|
|
// if (baseline>0 && baseline>parent->get_yAxis()->getMin()) y0=transformY(baseline);
|
|
|
|
// else y0=transformY(parent->get_yAxis()->getMin());
|
2018-12-02 21:08:43 +08:00
|
|
|
// }
|
|
|
|
//bool first=false;
|
|
|
|
QVector<QLineF> lines;
|
|
|
|
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)) {
|
2018-12-28 05:52:00 +08:00
|
|
|
double x=transformX(xv);
|
|
|
|
double y=transformY(yv);
|
2018-12-02 21:08:43 +08:00
|
|
|
|
|
|
|
|
|
|
|
lines.append(QLineF(x0, y, x, y));
|
|
|
|
|
|
|
|
// xold=x;
|
|
|
|
// yold=y;
|
|
|
|
//first=true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
painter.setPen(p);
|
|
|
|
if (lines.size()>0) painter.drawLines(lines);
|
|
|
|
painter.restore();
|
|
|
|
|
|
|
|
drawErrorsAfter(painter);
|
|
|
|
}
|
|
|
|
|
2018-12-12 06:00:43 +08:00
|
|
|
void JKQTPimpulsesHorizontalGraph::drawKeyMarker(JKQTPEnhancedPainter& painter, QRectF& rect) {
|
2018-12-02 21:08:43 +08:00
|
|
|
|
|
|
|
|
|
|
|
painter.save();
|
|
|
|
QPen p=painter.pen();
|
|
|
|
p.setColor(color);
|
|
|
|
p.setStyle(Qt::SolidLine);
|
|
|
|
p.setCapStyle(Qt::FlatCap);
|
|
|
|
p.setWidthF(qMax(JKQTPLOTTER_ABS_MIN_LINEWIDTH,qMin(parent->pt2px(painter, qMax(.01, lineWidth)), rect.height()/2.0)*parent->get_lineWidthMultiplier()));
|
|
|
|
painter.setPen(p);
|
|
|
|
int y=rect.top()+rect.height()/2.0;
|
|
|
|
painter.drawLine(rect.left(), y, rect.right(), y);
|
|
|
|
painter.restore();
|
|
|
|
}
|
|
|
|
|
2018-12-12 06:00:43 +08:00
|
|
|
QColor JKQTPimpulsesHorizontalGraph::getKeyLabelColor() {
|
2018-12-02 21:08:43 +08:00
|
|
|
return color;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-12-12 06:00:43 +08:00
|
|
|
JKQTPimpulsesVerticalGraph::JKQTPimpulsesVerticalGraph(JKQtBasePlotter* parent):
|
|
|
|
JKQTPimpulsesHorizontalGraph(parent)
|
2018-12-02 21:08:43 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-12-12 06:00:43 +08:00
|
|
|
JKQTPimpulsesVerticalGraph::JKQTPimpulsesVerticalGraph(JKQtPlotter *parent):
|
|
|
|
JKQTPimpulsesHorizontalGraph(parent)
|
2018-12-02 21:08:43 +08:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-12-12 06:00:43 +08:00
|
|
|
void JKQTPimpulsesVerticalGraph::draw(JKQTPEnhancedPainter& painter) {
|
2018-12-02 21:08:43 +08:00
|
|
|
#ifdef JKQTBP_AUTOTIMER
|
2018-12-12 06:00:43 +08:00
|
|
|
JKQTPAutoOutputTimer jkaaot("JKQTPimpulsesVerticalGraph::draw");
|
2018-12-02 21:08:43 +08:00
|
|
|
#endif
|
|
|
|
if (parent==nullptr) return;
|
|
|
|
JKQTPdatastore* datastore=parent->getDatastore();
|
|
|
|
if (datastore==nullptr) return;
|
|
|
|
|
|
|
|
drawErrorsBefore(painter);
|
|
|
|
|
|
|
|
painter.save();
|
|
|
|
|
|
|
|
QPen p=painter.pen();
|
|
|
|
p.setColor(color);
|
|
|
|
p.setWidthF(qMax(JKQTPLOTTER_ABS_MIN_LINEWIDTH, parent->pt2px(painter, lineWidth*parent->get_lineWidthMultiplier())));
|
|
|
|
p.setStyle(Qt::SolidLine);
|
|
|
|
p.setCapStyle(Qt::FlatCap);
|
|
|
|
|
|
|
|
int imax=qMin(datastore->getColumn(static_cast<size_t>(xColumn)).getRows(), datastore->getColumn(static_cast<size_t>(yColumn)).getRows());
|
|
|
|
int imin=0;
|
|
|
|
// interpret data ranges
|
|
|
|
if (datarange_start>-1) {
|
2018-12-16 21:59:39 +08:00
|
|
|
imin=qMin(datarange_start, static_cast<int>(imax));
|
2018-12-02 21:08:43 +08:00
|
|
|
}
|
|
|
|
if (datarange_end>-1) {
|
2018-12-16 21:59:39 +08:00
|
|
|
imax=qMin(datarange_end, static_cast<int>(imax));
|
2018-12-02 21:08:43 +08:00
|
|
|
}
|
|
|
|
if (imax<imin) {
|
|
|
|
int h=imin;
|
|
|
|
imin=imax;
|
|
|
|
imax=h;
|
|
|
|
}
|
|
|
|
if (imin<0) imin=0;
|
|
|
|
if (imax<0) imax=0;
|
|
|
|
|
|
|
|
//double xold=-1;
|
|
|
|
//double yold=-1;
|
|
|
|
//bool first=false;
|
2018-12-28 05:52:00 +08:00
|
|
|
// double x0=transformX(baseline);
|
|
|
|
// if (parent->get_xAxis()->isLogAxis()) {
|
|
|
|
// if (baseline>0 && baseline>parent->get_xAxis()->getMin()) x0=transformX(baseline);
|
|
|
|
// else x0=transformX(parent->get_xAxis()->getMin());
|
2018-12-02 21:08:43 +08:00
|
|
|
// }
|
2018-12-28 05:52:00 +08:00
|
|
|
double y0=transformY(baseline);
|
|
|
|
if (parent->get_yAxis()->isLogAxis()) {
|
|
|
|
y0=transformY(parent->get_yAxis()->getMin());
|
|
|
|
if (baseline>0 && baseline>parent->get_yAxis()->getMin()) y0=transformY(baseline);
|
|
|
|
else y0=transformY(parent->get_yAxis()->getMin());
|
2018-12-02 21:08:43 +08:00
|
|
|
}
|
|
|
|
QVector<QLineF> lines;
|
|
|
|
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) ) {
|
2018-12-28 05:52:00 +08:00
|
|
|
double x=transformX(xv);
|
|
|
|
double y=transformY(yv);
|
2018-12-02 21:08:43 +08:00
|
|
|
|
|
|
|
|
|
|
|
lines.append(QLineF(x, y0, x, y));
|
|
|
|
|
|
|
|
//xold=x;
|
|
|
|
//yold=y;
|
|
|
|
//first=true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
painter.setPen(p);
|
|
|
|
if (lines.size()>0) painter.drawLines(lines);
|
|
|
|
painter.restore();
|
|
|
|
|
|
|
|
drawErrorsAfter(painter);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-12-12 06:00:43 +08:00
|
|
|
QPen JKQTPimpulsesHorizontalGraph::getPen(JKQTPEnhancedPainter& painter) const {
|
2018-12-02 21:08:43 +08:00
|
|
|
QPen p;
|
|
|
|
p.setColor(color);
|
|
|
|
p.setWidthF(qMax(JKQTPLOTTER_ABS_MIN_LINEWIDTH,parent->pt2px(painter, parent->get_lineWidthMultiplier()*lineWidth)));
|
|
|
|
return p;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-12-12 06:00:43 +08:00
|
|
|
JKQTPimpulsesHorizontalErrorGraph::JKQTPimpulsesHorizontalErrorGraph(JKQtBasePlotter *parent):
|
|
|
|
JKQTPimpulsesHorizontalGraph(parent), JKQTPxGraphErrors()
|
|
|
|
{
|
|
|
|
setErrorColorFromGraphColor(color);
|
|
|
|
}
|
|
|
|
|
|
|
|
JKQTPimpulsesHorizontalErrorGraph::JKQTPimpulsesHorizontalErrorGraph(JKQtPlotter *parent):
|
|
|
|
JKQTPimpulsesHorizontalGraph(parent), JKQTPxGraphErrors()
|
|
|
|
{
|
|
|
|
setErrorColorFromGraphColor(color);
|
|
|
|
}
|
|
|
|
|
2018-12-28 05:52:00 +08:00
|
|
|
bool JKQTPimpulsesHorizontalErrorGraph::usesColumn(int c) const
|
2018-12-02 21:08:43 +08:00
|
|
|
{
|
2018-12-12 06:00:43 +08:00
|
|
|
return JKQTPimpulsesHorizontalGraph::usesColumn(c)|| JKQTPxGraphErrors::errorUsesColumn(c);
|
2018-12-02 21:08:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void JKQTPimpulsesHorizontalErrorGraph::drawErrorsAfter(JKQTPEnhancedPainter &painter)
|
|
|
|
{
|
2018-12-28 05:52:00 +08:00
|
|
|
if (sortData==JKQTPxyGraph::Unsorted) plotErrorIndicators(painter, parent, this, xColumn, yColumn, datarange_start, datarange_end);
|
|
|
|
else plotErrorIndicators(painter, parent, this, xColumn, yColumn, datarange_start, datarange_end, 0, 0, &sortedIndices);
|
2018-12-02 21:08:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
JKQTPimpulsesVerticalErrorGraph::JKQTPimpulsesVerticalErrorGraph(JKQtBasePlotter *parent):
|
2018-12-12 06:00:43 +08:00
|
|
|
JKQTPimpulsesVerticalGraph(parent), JKQTPyGraphErrors()
|
2018-12-02 21:08:43 +08:00
|
|
|
{
|
|
|
|
setErrorColorFromGraphColor(color);
|
|
|
|
}
|
|
|
|
|
|
|
|
JKQTPimpulsesVerticalErrorGraph::JKQTPimpulsesVerticalErrorGraph(JKQtPlotter *parent):
|
2018-12-12 06:00:43 +08:00
|
|
|
JKQTPimpulsesVerticalGraph(parent), JKQTPyGraphErrors()
|
2018-12-02 21:08:43 +08:00
|
|
|
{
|
|
|
|
setErrorColorFromGraphColor(color);
|
|
|
|
}
|
|
|
|
|
2018-12-28 05:52:00 +08:00
|
|
|
bool JKQTPimpulsesVerticalErrorGraph::usesColumn(int c) const
|
2018-12-02 21:08:43 +08:00
|
|
|
{
|
2018-12-12 06:00:43 +08:00
|
|
|
return JKQTPimpulsesVerticalGraph::usesColumn(c)|| JKQTPyGraphErrors::errorUsesColumn(c);
|
2018-12-02 21:08:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void JKQTPimpulsesVerticalErrorGraph::drawErrorsAfter(JKQTPEnhancedPainter &painter)
|
|
|
|
{
|
2018-12-28 05:52:00 +08:00
|
|
|
if (sortData==JKQTPxyGraph::Unsorted) plotErrorIndicators(painter, parent, this, xColumn, yColumn, datarange_start, datarange_end);
|
|
|
|
else plotErrorIndicators(painter, parent, this, xColumn, yColumn, datarange_start, datarange_end, 0, 0, &sortedIndices);
|
2018-12-02 21:08:43 +08:00
|
|
|
|
|
|
|
}
|