- bugfix: improved handling of DRAGZOOM-UserAction for log-log plots

- code (style) improvements
This commit is contained in:
jkriege2 2020-09-08 20:15:33 +02:00
parent f77bc97ca5
commit 95d885bc2c
16 changed files with 207 additions and 261 deletions

View File

@ -103,9 +103,7 @@ QVector<QPolygonF> JKQTPUnifyLinesToPolygons(const QVector<QLineF> &lines, doubl
} }
//return res.toVector(); //return res.toVector();
// clean the resulting polygon // clean the resulting polygon
for (QPolygonF& p: res) { std::transform(res.begin(), res.end(), res.begin(), std::bind(&JKQTPCleanPolygon, std::placeholders::_1, distanceThreshold));
p=JKQTPCleanPolygon(p, distanceThreshold);
}
int maxIterations=100; int maxIterations=100;
int iter=0; int iter=0;
@ -266,7 +264,7 @@ QVector<QPointF> JKQTPAdaptiveFunctionGraphEvaluator::evaluate(double tmin, doub
for (double t=tmin+delta_t0; t<tmax; t=t+delta_t0) { for (double t=tmin+delta_t0; t<tmax; t=t+delta_t0) {
const double treal=t; const double treal=t;
intData.insert_after(a, std::pair<double, QPointF>(treal, fxy(treal))); intData.insert_after(a, std::pair<double, QPointF>(treal, fxy(treal)));
InternalList::iterator b=a; b++; InternalList::iterator b=a; ++b;
//qDebug()<<"t="<<t<<", dist(a,b)="<<std::distance(a,b); //qDebug()<<"t="<<t<<", dist(a,b)="<<std::distance(a,b);
refine(intData, a, b, 0); refine(intData, a, b, 0);
//qDebug()<<" after refine: dist(a,b)="<<std::distance(a,b); //qDebug()<<" after refine: dist(a,b)="<<std::distance(a,b);
@ -299,7 +297,7 @@ void JKQTPAdaptiveFunctionGraphEvaluator::refine(JKQTPAdaptiveFunctionGraphEvalu
const double slope_mid_b=(pb.y()-pmid.y())/(pb.x()-pmid.x()); const double slope_mid_b=(pb.y()-pmid.y())/(pb.x()-pmid.x());
if (fabs(slope_mid_b-slope_a_mid)>slopeTolerance || delta>minPixelPerSample) { if (fabs(slope_mid_b-slope_a_mid)>slopeTolerance || delta>minPixelPerSample) {
intData.insert_after(a, std::pair<double, QPointF>(tmid, pmid)); intData.insert_after(a, std::pair<double, QPointF>(tmid, pmid));
InternalList::iterator abmid=a; abmid++; InternalList::iterator abmid=a; ++abmid;
refine(intData, a, abmid, degree+1); refine(intData, a, abmid, degree+1);
refine(intData, abmid, b, degree+1); refine(intData, abmid, b, degree+1);
} }
@ -324,9 +322,7 @@ QVector<QPointF> JKQTPSplitPolylineIntoPoints(const QVector<QPointF> &line, std:
for (int i=1; i<line.size(); i++) { for (int i=1; i<line.size(); i++) {
const QVector<QPointF> ps=JKQTPSplitLineIntoPoints(QLineF(line[i-1], line[i]), fTransform); const QVector<QPointF> ps=JKQTPSplitLineIntoPoints(QLineF(line[i-1], line[i]), fTransform);
result.reserve(result.size()+ps.size()); result.reserve(result.size()+ps.size());
for (auto& p: ps) { std::copy_if(ps.begin(), ps.end(), std::back_inserter(result), [&](const QPointF&p) { return result.size()==0 || result.last()!=p; });
if (result.size()==0 || result.last()!=p) result.push_back(p);
}
//qDebug()<<"line: "<<QLineF(line[i-1], line[i])<<" --> ps.size()="<<ps.size()<<", result.size()="<<result.size(); //qDebug()<<"line: "<<QLineF(line[i-1], line[i])<<" --> ps.size()="<<ps.size()<<", result.size()="<<result.size();
} }
} }

View File

@ -397,7 +397,7 @@ class JKQTFASTPLOTTER_LIB_EXPORT JKQTFastPlotter : public QGLWidget {
/** \brief return x-pixel coordinate from x coordinate */ /** \brief return x-pixel coordinate from x coordinate */
inline double x2p(double x) { inline double x2p(double x) {
if (xAxisLog) { if (xAxisLog) {
if (x<0) return xOffset+log(xMin/10.0)/JKQTPSTATISTICS_LN10*xScale; if (x<=0) return xOffset+log(xMin/10.0)/JKQTPSTATISTICS_LN10*xScale;
return xOffset+log(x)/JKQTPSTATISTICS_LN10*xScale; return xOffset+log(x)/JKQTPSTATISTICS_LN10*xScale;
} else { } else {
return xOffset+x*xScale; return xOffset+x*xScale;
@ -416,7 +416,7 @@ class JKQTFASTPLOTTER_LIB_EXPORT JKQTFastPlotter : public QGLWidget {
/** \brief return y-pixel coordinate from y coordinate */ /** \brief return y-pixel coordinate from y coordinate */
inline double y2p(double y) { inline double y2p(double y) {
if (yAxisLog) { if (yAxisLog) {
if (y<0) return yOffset-log(yMin/10.0)/JKQTPSTATISTICS_LN10*yScale; if (y<=0) return yOffset-log(yMin/10.0)/JKQTPSTATISTICS_LN10*yScale;
return yOffset-log(y)/JKQTPSTATISTICS_LN10*yScale; return yOffset-log(y)/JKQTPSTATISTICS_LN10*yScale;
} else { } else {
return yOffset-y*yScale; return yOffset-y*yScale;

View File

@ -342,13 +342,13 @@ void JKQTPBarHorizontalGraph::draw(JKQTPEnhancedPainter& painter) {
if (parent->getXAxis()->isLogAxis()) x0=transformX(parent->getXAxis()->getMin()); if (parent->getXAxis()->isLogAxis()) x0=transformX(parent->getXAxis()->getMin());
// double y0=transformY(0); // double y0=transformY(0);
// if (parent->getYAxis()->isLogAxis()) y0=transformY(parent->getYAxis()->getMin()); // if (parent->getYAxis()->isLogAxis()) y0=transformY(parent->getYAxis()->getMin());
double delta=1;
double deltap=0;
double deltam=0;
{ {
painter.save(); auto __finalpaint=JKQTPFinally([&painter]() {painter.restore();}); painter.save(); auto __finalpaint=JKQTPFinally([&painter]() {painter.restore();});
intSortData(); intSortData();
const bool hasStackPar=hasStackParent(); const bool hasStackPar=hasStackParent();
double delta=1;
double deltap=0;
double deltam=0;
for (int iii=imin; iii<imax; iii++) { for (int iii=imin; iii<imax; iii++) {
int i=qBound(imin, getDataIndex(iii), imax); int i=qBound(imin, getDataIndex(iii), imax);
double xv=datastore->get(static_cast<size_t>(xColumn),static_cast<size_t>(i)); double xv=datastore->get(static_cast<size_t>(xColumn),static_cast<size_t>(i));
@ -625,8 +625,8 @@ bool JKQTPBarHorizontalErrorGraph::getXMinMax(double &minx, double &maxx, double
if (start || xv<minx) minx=xv; if (start || xv<minx) minx=xv;
xvsgz=xv; SmallestGreaterZeroCompare_xvsgz(); xvsgz=xv; SmallestGreaterZeroCompare_xvsgz();
start=false; start=false;
if (start || xvv>maxx) maxx=xvv; if (xvv>maxx) maxx=xvv;
if (start || xvv<minx) minx=xvv; if (xvv<minx) minx=xvv;
xvsgz=xvv; SmallestGreaterZeroCompare_xvsgz(); xvsgz=xvv; SmallestGreaterZeroCompare_xvsgz();
start=false; start=false;
} }

View File

@ -119,13 +119,13 @@ void JKQTPContourPlot::draw(JKQTPEnhancedPainter &painter)
// transform into plot coordinates // transform into plot coordinates
for(auto polygon =contourLinesCache.at(i).begin(); polygon!=contourLinesCache.at(i).end();++polygon ) { for(auto polygon =contourLinesCache.at(i).begin(); polygon!=contourLinesCache.at(i).end();++polygon ) {
contourLinesTransformedSingleLevel.push_back(QPolygonF()); contourLinesTransformedSingleLevel.push_back(QPolygonF());
for (auto& p: *polygon) { for (auto& poly: *polygon) {
contourLinesTransformedSingleLevel.last().append(transform(x+p.x()/double(Nx-1)*width, y+p.y()/double(Ny-1)*height)); contourLinesTransformedSingleLevel.last().append(transform(x+poly.x()/double(Nx-1)*width, y+poly.y()/double(Ny-1)*height));
} }
//qDebug()<<lineTranformed; //qDebug()<<lineTranformed;
} }
for (const QPolygonF& p: contourLinesTransformedSingleLevel) { for (const QPolygonF& poly: contourLinesTransformedSingleLevel) {
painter.drawPolyline(p); painter.drawPolyline(poly);
} }
} }
} }

View File

@ -93,7 +93,7 @@ void JKQTPEvaluatedFunctionWithErrorsGraphDrawingBase::drawKeyMarker(JKQTPEnhanc
if (drawLine) painter.setPen(p); if (drawLine) painter.setPen(p);
painter.setBrush(b); painter.setBrush(b);
if (fillCurve) painter.drawRect(rect); if (fillCurve) painter.drawRect(rect);
if (!fillCurve & drawLine) painter.drawLine(QLineF(rect.left(), y, rect.right(), y)); if (!fillCurve && drawLine) painter.drawLine(QLineF(rect.left(), y, rect.right(), y));
} }

View File

@ -33,21 +33,33 @@
JKQTPXYFunctionLineGraphBase::JKQTPXYFunctionLineGraphBase(JKQTBasePlotter* parent): JKQTPXYFunctionLineGraphBase::JKQTPXYFunctionLineGraphBase(double tmin_, double tmax_, JKQTBasePlotter *parent):
JKQTPEvaluatedFunctionGraphBase(parent), JKQTPEvaluatedFunctionGraphBase(parent),
tmin(0.0), tmin(tmin_),
tmax(1.0) tmax(tmax_)
{ {
initLineStyle(parent, parentPlotStyle); initLineStyle(parent, parentPlotStyle);
setMaxRefinementDegree(8); setMaxRefinementDegree(8);
} }
JKQTPXYFunctionLineGraphBase::JKQTPXYFunctionLineGraphBase(double tmin_, double tmax_, JKQTPlotter *parent):
JKQTPXYFunctionLineGraphBase(tmin_,tmax_,parent->getPlotter())
{
}
JKQTPXYFunctionLineGraphBase::JKQTPXYFunctionLineGraphBase(JKQTBasePlotter* parent):
JKQTPXYFunctionLineGraphBase(0,1,parent)
{
}
JKQTPXYFunctionLineGraphBase::JKQTPXYFunctionLineGraphBase(JKQTPlotter* parent): JKQTPXYFunctionLineGraphBase::JKQTPXYFunctionLineGraphBase(JKQTPlotter* parent):
JKQTPXYFunctionLineGraphBase(parent->getPlotter()) JKQTPXYFunctionLineGraphBase(parent->getPlotter())
{ {
} }
JKQTPXYFunctionLineGraphBase::~JKQTPXYFunctionLineGraphBase() JKQTPXYFunctionLineGraphBase::~JKQTPXYFunctionLineGraphBase()
{ {
@ -161,13 +173,9 @@ JKQTPXYFunctionLineGraph::JKQTPXYFunctionLineGraph(JKQTPlotter* parent):
} }
JKQTPXYFunctionLineGraph::JKQTPXYFunctionLineGraph(const jkqtpSimpleParametricCurveFunctionType &f, const QString &title_, double tmin_, double tmax_, JKQTBasePlotter *parent): JKQTPXYFunctionLineGraph::JKQTPXYFunctionLineGraph(const jkqtpSimpleParametricCurveFunctionType &f, const QString &title_, double tmin_, double tmax_, JKQTBasePlotter *parent):
JKQTPXYFunctionLineGraph(parent) JKQTPXYFunctionLineGraphBase(tmin_, tmax_, parent), plotFunction(), simplePlotFunction(f)
{ {
tmin=tmin_;
tmax=tmax_;
setTitle(title_); setTitle(title_);
plotFunction=jkqtpParametricCurveFunctionType();
simplePlotFunction=f;
} }
JKQTPXYFunctionLineGraph::JKQTPXYFunctionLineGraph(const jkqtpSimpleParametricCurveFunctionType &f, const QString &title_, double tmin_, double tmax_, JKQTPlotter *parent): JKQTPXYFunctionLineGraph::JKQTPXYFunctionLineGraph(const jkqtpSimpleParametricCurveFunctionType &f, const QString &title_, double tmin_, double tmax_, JKQTPlotter *parent):
@ -178,14 +186,9 @@ JKQTPXYFunctionLineGraph::JKQTPXYFunctionLineGraph(const jkqtpSimpleParametricCu
JKQTPXYFunctionLineGraph::JKQTPXYFunctionLineGraph(jkqtpSimpleParametricCurveFunctionType &&f, const QString &title_, double tmin_, double tmax_, JKQTBasePlotter *parent): JKQTPXYFunctionLineGraph::JKQTPXYFunctionLineGraph(jkqtpSimpleParametricCurveFunctionType &&f, const QString &title_, double tmin_, double tmax_, JKQTBasePlotter *parent):
JKQTPXYFunctionLineGraph(parent) JKQTPXYFunctionLineGraphBase(tmin_, tmax_, parent), plotFunction(), simplePlotFunction(std::move(f))
{ {
tmin=tmin_;
tmax=tmax_;
setTitle(title_); setTitle(title_);
plotFunction=jkqtpParametricCurveFunctionType();
simplePlotFunction=std::move(f);
data.clear();
} }
JKQTPXYFunctionLineGraph::JKQTPXYFunctionLineGraph(jkqtpSimpleParametricCurveFunctionType &&f, const QString &title_, double tmin_, double tmax_, JKQTPlotter *parent): JKQTPXYFunctionLineGraph::JKQTPXYFunctionLineGraph(jkqtpSimpleParametricCurveFunctionType &&f, const QString &title_, double tmin_, double tmax_, JKQTPlotter *parent):
@ -195,14 +198,9 @@ JKQTPXYFunctionLineGraph::JKQTPXYFunctionLineGraph(jkqtpSimpleParametricCurveFun
} }
JKQTPXYFunctionLineGraph::JKQTPXYFunctionLineGraph(jkqtpParametricCurveFunctionType &&f, const QString &title_, double tmin_, double tmax_, JKQTBasePlotter *parent): JKQTPXYFunctionLineGraph::JKQTPXYFunctionLineGraph(jkqtpParametricCurveFunctionType &&f, const QString &title_, double tmin_, double tmax_, JKQTBasePlotter *parent):
JKQTPXYFunctionLineGraph(parent) JKQTPXYFunctionLineGraphBase(tmin_, tmax_, parent), plotFunction(std::move(f)), simplePlotFunction()
{ {
tmin=tmin_;
tmax=tmax_;
setTitle(title_); setTitle(title_);
simplePlotFunction=jkqtpSimpleParametricCurveFunctionType();
plotFunction=std::move(f);
data.clear();
} }
JKQTPXYFunctionLineGraph::JKQTPXYFunctionLineGraph(jkqtpParametricCurveFunctionType &&f, const QString &title_, double tmin_, double tmax_, JKQTPlotter *parent): JKQTPXYFunctionLineGraph::JKQTPXYFunctionLineGraph(jkqtpParametricCurveFunctionType &&f, const QString &title_, double tmin_, double tmax_, JKQTPlotter *parent):
@ -212,14 +210,9 @@ JKQTPXYFunctionLineGraph::JKQTPXYFunctionLineGraph(jkqtpParametricCurveFunctionT
} }
JKQTPXYFunctionLineGraph::JKQTPXYFunctionLineGraph(const jkqtpParametricCurveFunctionType &f, const QString &title_, double tmin_, double tmax_, JKQTBasePlotter *parent): JKQTPXYFunctionLineGraph::JKQTPXYFunctionLineGraph(const jkqtpParametricCurveFunctionType &f, const QString &title_, double tmin_, double tmax_, JKQTBasePlotter *parent):
JKQTPXYFunctionLineGraph(parent) JKQTPXYFunctionLineGraphBase(tmin_, tmax_, parent), plotFunction(f), simplePlotFunction()
{ {
tmin=tmin_;
tmax=tmax_;
setTitle(title_); setTitle(title_);
simplePlotFunction=jkqtpSimpleParametricCurveFunctionType();
plotFunction=std::move(f);
data.clear();
} }
JKQTPXYFunctionLineGraph::JKQTPXYFunctionLineGraph(const jkqtpParametricCurveFunctionType &f, const QString &title_, double tmin_, double tmax_, JKQTPlotter *parent): JKQTPXYFunctionLineGraph::JKQTPXYFunctionLineGraph(const jkqtpParametricCurveFunctionType &f, const QString &title_, double tmin_, double tmax_, JKQTPlotter *parent):

View File

@ -61,6 +61,13 @@ public:
/** \brief class constructor */ /** \brief class constructor */
JKQTPXYFunctionLineGraphBase(JKQTPlotter* parent); JKQTPXYFunctionLineGraphBase(JKQTPlotter* parent);
/** \brief class constructor */
JKQTPXYFunctionLineGraphBase(double tmin_, double tmax_, JKQTBasePlotter* parent);
/** \brief class constructor */
JKQTPXYFunctionLineGraphBase(double tmin_, double tmax_, JKQTPlotter* parent);
/** \brief class destructor */ /** \brief class destructor */
virtual ~JKQTPXYFunctionLineGraphBase() override; virtual ~JKQTPXYFunctionLineGraphBase() override;

View File

@ -190,22 +190,22 @@ void JKQTPRGBMathImage::getOutsideSize(JKQTPEnhancedPainter& painter, int& leftS
getDataMinMax(internalDataMin, internalDataMax); getDataMinMax(internalDataMin, internalDataMax);
if (data) { if (data) {
if (colorBarRightVisible) { if (colorBarRightVisible) {
if (!colorbarsSideBySide || (colorbarsSideBySide && !firstC)) rightSpace+=parent->pt2px(painter, colorBarWidth+colorBarOffset); if (!colorbarsSideBySide || !firstC) rightSpace+=parent->pt2px(painter, colorBarWidth+colorBarOffset);
colorBarRightAxis->setRange(internalDataMin, internalDataMax); colorBarRightAxis->setRange(internalDataMin, internalDataMax);
colorBarRightAxis->setAxisWidth(sizeFactor*colorBarRelativeHeight*parent->getPlotHeight()); colorBarRightAxis->setAxisWidth(sizeFactor*colorBarRelativeHeight*parent->getPlotHeight());
colorBarRightAxisB->setAxisLabel(imageNameR); colorBarRightAxisB->setAxisLabel(imageNameR);
QSizeF s2=colorBarRightAxis->getSize2(painter); QSizeF s2=colorBarRightAxis->getSize2(painter);
QSizeF s1=colorBarRightAxis->getSize1(painter); QSizeF s1=colorBarRightAxis->getSize1(painter);
if (!colorbarsSideBySide || (colorbarsSideBySide && !firstC)) rightSpace+=parent->pt2px(painter, colorBarWidth+colorBarOffset)+static_cast<double>(s2.width()+s1.width()); if (!colorbarsSideBySide || !firstC) rightSpace+=parent->pt2px(painter, colorBarWidth+colorBarOffset)+static_cast<double>(s2.width()+s1.width());
} }
if (colorBarTopVisible) { if (colorBarTopVisible) {
//if (!colorbarsSideBySide || (colorbarsSideBySide && !firstC)) topSpace+=parent->pt2px(painter, colorBarWidth+colorBarOffset); //if (!colorbarsSideBySide || !firstC) topSpace+=parent->pt2px(painter, colorBarWidth+colorBarOffset);
colorBarTopAxis->setRange(internalDataMin, internalDataMax); colorBarTopAxis->setRange(internalDataMin, internalDataMax);
colorBarTopAxis->setAxisWidth(sizeFactor*colorBarRelativeHeight*parent->getPlotWidth()); colorBarTopAxis->setAxisWidth(sizeFactor*colorBarRelativeHeight*parent->getPlotWidth());
colorBarTopAxisB->setAxisLabel(imageNameR); colorBarTopAxisB->setAxisLabel(imageNameR);
QSizeF s2=colorBarTopAxisB->getSize2(painter); QSizeF s2=colorBarTopAxisB->getSize2(painter);
QSizeF s1=colorBarTopAxisB->getSize2(painter); QSizeF s1=colorBarTopAxisB->getSize2(painter);
if (!colorbarsSideBySide || (colorbarsSideBySide && !firstC)) topSpace+=parent->pt2px(painter, colorBarWidth+colorBarOffset)+static_cast<double>(s2.height()+s1.height()); if (!colorbarsSideBySide || !firstC) topSpace+=parent->pt2px(painter, colorBarWidth+colorBarOffset)+static_cast<double>(s2.height()+s1.height());
} }
firstC=true; firstC=true;
} }
@ -213,22 +213,22 @@ void JKQTPRGBMathImage::getOutsideSize(JKQTPEnhancedPainter& painter, int& leftS
getDataMinMaxG(internalDataMinG, internalDataMaxG); getDataMinMaxG(internalDataMinG, internalDataMaxG);
if (dataG) { if (dataG) {
if (colorBarRightVisible) { if (colorBarRightVisible) {
if (!colorbarsSideBySide || (colorbarsSideBySide && !firstC)) rightSpace+=parent->pt2px(painter, colorBarWidth+colorBarOffset); if (!colorbarsSideBySide || !firstC) rightSpace+=parent->pt2px(painter, colorBarWidth+colorBarOffset);
colorBarRightAxisG->setRange(internalDataMinG, internalDataMaxG); colorBarRightAxisG->setRange(internalDataMinG, internalDataMaxG);
colorBarRightAxisG->setAxisWidth(sizeFactor*colorBarRelativeHeight*parent->getPlotHeight()); colorBarRightAxisG->setAxisWidth(sizeFactor*colorBarRelativeHeight*parent->getPlotHeight());
colorBarRightAxisB->setAxisLabel(imageNameG); colorBarRightAxisB->setAxisLabel(imageNameG);
QSizeF s2=colorBarRightAxis->getSize2(painter); QSizeF s2=colorBarRightAxis->getSize2(painter);
QSizeF s1=colorBarRightAxis->getSize1(painter); QSizeF s1=colorBarRightAxis->getSize1(painter);
if (!colorbarsSideBySide || (colorbarsSideBySide && !firstC)) rightSpace+=parent->pt2px(painter, colorBarWidth+colorBarOffset)+static_cast<double>(s2.width()+s1.width()); if (!colorbarsSideBySide || !firstC) rightSpace+=parent->pt2px(painter, colorBarWidth+colorBarOffset)+static_cast<double>(s2.width()+s1.width());
} }
if (colorBarTopVisible) { if (colorBarTopVisible) {
//if (!colorbarsSideBySide || (colorbarsSideBySide && !firstC)) topSpace+=parent->pt2px(painter, colorBarWidth+colorBarOffset); //if (!colorbarsSideBySide || !firstC) topSpace+=parent->pt2px(painter, colorBarWidth+colorBarOffset);
colorBarTopAxisG->setRange(internalDataMinG, internalDataMaxG); colorBarTopAxisG->setRange(internalDataMinG, internalDataMaxG);
colorBarTopAxisG->setAxisWidth(sizeFactor*colorBarRelativeHeight*parent->getPlotWidth()); colorBarTopAxisG->setAxisWidth(sizeFactor*colorBarRelativeHeight*parent->getPlotWidth());
colorBarTopAxisB->setAxisLabel(imageNameG); colorBarTopAxisB->setAxisLabel(imageNameG);
QSizeF s2=colorBarTopAxisB->getSize2(painter); QSizeF s2=colorBarTopAxisB->getSize2(painter);
QSizeF s1=colorBarTopAxisB->getSize1(painter); QSizeF s1=colorBarTopAxisB->getSize1(painter);
if (!colorbarsSideBySide || (colorbarsSideBySide && !firstC)) topSpace+=parent->pt2px(painter, colorBarWidth+colorBarOffset)+static_cast<double>(s2.height()+s1.height()); if (!colorbarsSideBySide || !firstC) topSpace+=parent->pt2px(painter, colorBarWidth+colorBarOffset)+static_cast<double>(s2.height()+s1.height());
} }
firstC=true; firstC=true;
} }
@ -236,22 +236,22 @@ void JKQTPRGBMathImage::getOutsideSize(JKQTPEnhancedPainter& painter, int& leftS
getDataMinMaxB(internalDataMinB, internalDataMaxB); getDataMinMaxB(internalDataMinB, internalDataMaxB);
if (dataB) { if (dataB) {
if (colorBarRightVisible) { if (colorBarRightVisible) {
if (!colorbarsSideBySide || (colorbarsSideBySide && !firstC)) rightSpace+=parent->pt2px(painter, colorBarWidth+colorBarOffset); if (!colorbarsSideBySide || !firstC) rightSpace+=parent->pt2px(painter, colorBarWidth+colorBarOffset);
colorBarRightAxisB->setRange(internalDataMinB, internalDataMaxB); colorBarRightAxisB->setRange(internalDataMinB, internalDataMaxB);
colorBarRightAxisB->setAxisWidth(sizeFactor*colorBarRelativeHeight*parent->getPlotHeight()); colorBarRightAxisB->setAxisWidth(sizeFactor*colorBarRelativeHeight*parent->getPlotHeight());
colorBarRightAxisB->setAxisLabel(imageNameB); colorBarRightAxisB->setAxisLabel(imageNameB);
QSizeF s2=colorBarRightAxis->getSize2(painter); QSizeF s2=colorBarRightAxis->getSize2(painter);
QSizeF s1=colorBarRightAxis->getSize1(painter); QSizeF s1=colorBarRightAxis->getSize1(painter);
if (!colorbarsSideBySide || (colorbarsSideBySide && !firstC)) rightSpace+=parent->pt2px(painter, colorBarWidth+colorBarOffset)+static_cast<double>(s2.width()+s1.width()); if (!colorbarsSideBySide || !firstC) rightSpace+=parent->pt2px(painter, colorBarWidth+colorBarOffset)+static_cast<double>(s2.width()+s1.width());
} }
if (colorBarTopVisible) { if (colorBarTopVisible) {
//if (!colorbarsSideBySide || (colorbarsSideBySide && !firstC)) topSpace+=parent->pt2px(painter, colorBarWidth+colorBarOffset); //if (!colorbarsSideBySide || !firstC) topSpace+=parent->pt2px(painter, colorBarWidth+colorBarOffset);
colorBarTopAxisB->setRange(internalDataMinB, internalDataMaxB); colorBarTopAxisB->setRange(internalDataMinB, internalDataMaxB);
colorBarTopAxisB->setAxisWidth(sizeFactor*colorBarRelativeHeight*parent->getPlotWidth()); colorBarTopAxisB->setAxisWidth(sizeFactor*colorBarRelativeHeight*parent->getPlotWidth());
colorBarTopAxisB->setAxisLabel(imageNameB); colorBarTopAxisB->setAxisLabel(imageNameB);
QSizeF s2=colorBarTopAxisB->getSize2(painter); QSizeF s2=colorBarTopAxisB->getSize2(painter);
QSizeF s1=colorBarTopAxisB->getSize1(painter); QSizeF s1=colorBarTopAxisB->getSize1(painter);
if (!colorbarsSideBySide || (colorbarsSideBySide && !firstC)) topSpace+=parent->pt2px(painter, colorBarWidth+colorBarOffset)+static_cast<double>(s2.height()+s1.height()); if (!colorbarsSideBySide || !firstC) topSpace+=parent->pt2px(painter, colorBarWidth+colorBarOffset)+static_cast<double>(s2.height()+s1.height());
} }
firstC=true; firstC=true;
} }

View File

@ -89,11 +89,6 @@ void JKQTPXYLineGraph::draw(JKQTPEnhancedPainter& painter) {
if (imin<0) imin=0; if (imin<0) imin=0;
if (imax<0) imax=0; if (imax<0) imax=0;
//qDebug()<<"JKQTPXYLineGraph::draw(): "<<3<<" imin="<<imin<<" imax="<<imax;
//double xold=-1;
//double yold=-1;
//bool first=false;
//QVector<QLineF> lines;
std::vector<QPolygonF> vec_linesP; std::vector<QPolygonF> vec_linesP;
vec_linesP.push_back(QPolygonF()); vec_linesP.push_back(QPolygonF());
intSortData(); intSortData();
@ -223,17 +218,18 @@ bool JKQTPXYLineErrorGraph::getXMinMax(double &minx, double &maxx, double &small
if (imax<0) imax=0; if (imax<0) imax=0;
for (int i=imin; i<imax; i++) { for (int i=imin; i<imax; i++) {
double xvsgz;
double xv=datastore->get(static_cast<size_t>(xColumn),static_cast<size_t>(i))+getXErrorU(i, datastore); double xv=datastore->get(static_cast<size_t>(xColumn),static_cast<size_t>(i))+getXErrorU(i, datastore);
if (JKQTPIsOKFloat(xv)) { if (JKQTPIsOKFloat(xv)) {
if (start || xv>maxx) maxx=xv; if (start || xv>maxx) maxx=xv;
if (start || xv<minx) minx=xv; if (start || xv<minx) minx=xv;
xvsgz=xv; SmallestGreaterZeroCompare_xvsgz(); const double xvsgz=xv; SmallestGreaterZeroCompare_xvsgz();
start=false; start=false;
xv=datastore->get(static_cast<size_t>(xColumn),static_cast<size_t>(i))-getXErrorL(i, datastore); }
xv=datastore->get(static_cast<size_t>(xColumn),static_cast<size_t>(i))-getXErrorL(i, datastore);
if (JKQTPIsOKFloat(xv)) {
if (start || xv>maxx) maxx=xv; if (start || xv>maxx) maxx=xv;
if (start || xv<minx) minx=xv; if (start || xv<minx) minx=xv;
xvsgz=xv; SmallestGreaterZeroCompare_xvsgz(); const double xvsgz=xv; SmallestGreaterZeroCompare_xvsgz();
start=false; start=false;
} }
} }
@ -269,13 +265,14 @@ bool JKQTPXYLineErrorGraph::getYMinMax(double &miny, double &maxy, double &small
if (JKQTPIsOKFloat(yv)) { if (JKQTPIsOKFloat(yv)) {
if (start || yv>maxy) maxy=yv; if (start || yv>maxy) maxy=yv;
if (start || yv<miny) miny=yv; if (start || yv<miny) miny=yv;
double xvsgz; const double xvsgz=yv; SmallestGreaterZeroCompare_xvsgz();
xvsgz=yv; SmallestGreaterZeroCompare_xvsgz();
start=false; start=false;
yv=datastore->get(static_cast<size_t>(yColumn),static_cast<size_t>(i))-getYErrorL(i, datastore); }
yv=datastore->get(static_cast<size_t>(yColumn),static_cast<size_t>(i))-getYErrorL(i, datastore);
if (JKQTPIsOKFloat(yv)) {
if (start || yv>maxy) maxy=yv; if (start || yv>maxy) maxy=yv;
if (start || yv<miny) miny=yv; if (start || yv<miny) miny=yv;
xvsgz=yv; SmallestGreaterZeroCompare_xvsgz(); const double xvsgz=yv; SmallestGreaterZeroCompare_xvsgz();
start=false; start=false;
} }
} }
@ -378,20 +375,21 @@ void JKQTPXYParametrizedScatterGraph::draw(JKQTPEnhancedPainter &painter)
if (imin<0) imin=0; if (imin<0) imin=0;
if (imax<0) imax=0; if (imax<0) imax=0;
//qDebug()<<"JKQTPXYLineGraph::draw(): "<<3<<" imin="<<imin<<" imax="<<imax;
double xold=-1;
double yold=-1;
bool first=false;
QVector<QLineF> lines; QVector<QLineF> lines;
QPolygonF linesP; QPolygonF linesP;
QVector<QColor> linecols; QVector<QColor> linecols;
QVector<QColor> linecolss; QVector<QColor> linecolss;
QVector<double> linewidths; QVector<double> linewidths;
intSortData(); //qDebug()<<"JKQTPXYLineGraph::draw(): "<<3<<" imin="<<imin<<" imax="<<imax;
double specSymbSize=0;
bool hasSpecSymbSize=false;
{ {
painter.save(); auto __finalpaintinner=JKQTPFinally([&painter]() {painter.restore();}); painter.save(); auto __finalpaintinner=JKQTPFinally([&painter]() {painter.restore();});
double xold=-1;
double yold=-1;
bool first=false;
intSortData();
double specSymbSize=0;
bool hasSpecSymbSize=false;
for (int iii=imin; iii<imax; iii++) { for (int iii=imin; iii<imax; iii++) {
int i=qBound(imin, getDataIndex(iii), imax); int i=qBound(imin, getDataIndex(iii), imax);
double xv=datastore->get(static_cast<size_t>(xColumn),static_cast<size_t>(i)); double xv=datastore->get(static_cast<size_t>(xColumn),static_cast<size_t>(i));
@ -912,17 +910,18 @@ bool JKQTPXYParametrizedErrorScatterGraph::getXMinMax(double &minx, double &maxx
if (imax<0) imax=0; if (imax<0) imax=0;
for (int i=imin; i<imax; i++) { for (int i=imin; i<imax; i++) {
double xvsgz; const double xv=datastore->get(static_cast<size_t>(xColumn),static_cast<size_t>(i))+getXErrorU(i, datastore);
double xv=datastore->get(static_cast<size_t>(xColumn),static_cast<size_t>(i))+getXErrorU(i, datastore); if (JKQTPIsOKFloat(xv) ) {
double xvv=datastore->get(static_cast<size_t>(xColumn),static_cast<size_t>(i))-getXErrorL(i, datastore);
if (JKQTPIsOKFloat(xv) && JKQTPIsOKFloat(xvv) ) {
if (start || xv>maxx) maxx=xv; if (start || xv>maxx) maxx=xv;
if (start || xv<minx) minx=xv; if (start || xv<minx) minx=xv;
xvsgz=xv; SmallestGreaterZeroCompare_xvsgz(); const double xvsgz=xv; SmallestGreaterZeroCompare_xvsgz();
}
const double xvv=datastore->get(static_cast<size_t>(xColumn),static_cast<size_t>(i))-getXErrorL(i, datastore);
if (JKQTPIsOKFloat(xvv)) {
start=false; start=false;
if (start || xvv>maxx) maxx=xvv; if (start || xvv>maxx) maxx=xvv;
if (start || xvv<minx) minx=xvv; if (start || xvv<minx) minx=xvv;
xvsgz=xvv; SmallestGreaterZeroCompare_xvsgz(); const double xvsgz=xvv; SmallestGreaterZeroCompare_xvsgz();
start=false; start=false;
} }
} }
@ -955,17 +954,18 @@ bool JKQTPXYParametrizedErrorScatterGraph::getYMinMax(double &miny, double &maxy
if (imax<0) imax=0; if (imax<0) imax=0;
for (int i=imin; i<imax; i++) { for (int i=imin; i<imax; i++) {
double yv=datastore->get(static_cast<size_t>(yColumn),static_cast<size_t>(i))+getYErrorU(i, datastore); const double yv=datastore->get(static_cast<size_t>(yColumn),static_cast<size_t>(i))+getYErrorU(i, datastore);
double yvv=datastore->get(static_cast<size_t>(yColumn),static_cast<size_t>(i))-getYErrorL(i, datastore); if (JKQTPIsOKFloat(yv)) {
if (JKQTPIsOKFloat(yv) && JKQTPIsOKFloat(yvv) ) {
if (start || yv>maxy) maxy=yv; if (start || yv>maxy) maxy=yv;
if (start || yv<miny) miny=yv; if (start || yv<miny) miny=yv;
double xvsgz; const double xvsgz=yv; SmallestGreaterZeroCompare_xvsgz();
xvsgz=yv; SmallestGreaterZeroCompare_xvsgz();
start=false; start=false;
}
const double yvv=datastore->get(static_cast<size_t>(yColumn),static_cast<size_t>(i))-getYErrorL(i, datastore);
if (JKQTPIsOKFloat(yvv) ) {
if (start || yvv>maxy) maxy=yvv; if (start || yvv>maxy) maxy=yvv;
if (start || yvv<miny) miny=yvv; if (start || yvv<miny) miny=yvv;
xvsgz=yvv; SmallestGreaterZeroCompare_xvsgz(); const double xvsgz=yvv; SmallestGreaterZeroCompare_xvsgz();
start=false; start=false;
} }
} }

View File

@ -57,7 +57,7 @@ class JKQTPLOTTER_LIB_EXPORT JKQTPXYLineGraph: public JKQTPXYGraph, public JKQTP
Q_OBJECT Q_OBJECT
public: public:
/** \brief class constructor */ /** \brief class constructor */
JKQTPXYLineGraph(JKQTBasePlotter* parent=nullptr); explicit JKQTPXYLineGraph(JKQTBasePlotter* parent=nullptr);
/** \brief class constructor */ /** \brief class constructor */
JKQTPXYLineGraph(JKQTPlotter* parent); JKQTPXYLineGraph(JKQTPlotter* parent);

View File

@ -68,7 +68,7 @@ void JKQTPSpecialLineHorizontalGraph::drawKeyMarker(JKQTPEnhancedPainter& painte
if (m_drawLine) painter.setPen(p); if (m_drawLine) painter.setPen(p);
painter.setBrush(b); painter.setBrush(b);
if (m_fillCurve) painter.drawRect(rect); if (m_fillCurve) painter.drawRect(rect);
if (!m_fillCurve & m_drawLine) painter.drawLine(QLineF(rect.left(), y, rect.right(), y)); if (!m_fillCurve && m_drawLine) painter.drawLine(QLineF(rect.left(), y, rect.right(), y));
if (m_drawSymbols) { if (m_drawSymbols) {
plotStyledSymbol(parent, painter, rect.center().x(), rect.center().y(), rect.width()*0.5); plotStyledSymbol(parent, painter, rect.center().x(), rect.center().y(), rect.width()*0.5);
} }
@ -308,8 +308,8 @@ void JKQTPSpecialLineHorizontalGraph::draw(JKQTPEnhancedPainter& painter) {
if (m_drawSymbols) { if (m_drawSymbols) {
painter.save(); painter.save();
auto __finalpaintsym=JKQTPFinally([&painter]() {painter.restore();}); auto __finalpaintsym=JKQTPFinally([&painter]() {painter.restore();});
for (auto& p: ps) { for (auto& ppoint: ps) {
plotStyledSymbol(parent, painter, p.x(), p.y()); plotStyledSymbol(parent, painter, ppoint.x(), ppoint.y());
} }
} }
@ -480,9 +480,9 @@ void JKQTPSpecialLineVerticalGraph::draw(JKQTPEnhancedPainter& painter) {
if (m_drawSymbols) { if (m_drawSymbols) {
painter.save(); painter.save();
auto __finalpaint=JKQTPFinally([&painter]() {painter.restore();}); auto __finalpaintsym=JKQTPFinally([&painter]() {painter.restore();});
for (auto& p: ps) { for (auto& point: ps) {
plotStyledSymbol(parent, painter, p.x(), p.y()); plotStyledSymbol(parent, painter, point.x(), point.y());
} }
} }

View File

@ -35,9 +35,11 @@ JKQTPXFunctionLineGraph *jkqtpstatAddLinearWeightedRegression(JKQTPXYGraph *data
JKQTBasePlotter* plt=datagraph->getParent(); JKQTBasePlotter* plt=datagraph->getParent();
JKQTPDatastore* ds=plt->getDatastore(); JKQTPDatastore* ds=plt->getDatastore();
JKQTPYGraphErrorData* ge=dynamic_cast<JKQTPYGraphErrorData*>(datagraph); JKQTPYGraphErrorData* ge=dynamic_cast<JKQTPYGraphErrorData*>(datagraph);
if (ge) {
JKQTPASSERT_M(ge!=nullptr, "datagraph needs to be convertible to JKQTPYGraphErrorData with a dynamic_cast!"); return jkqtpstatAddLinearWeightedRegression(plt, ds->begin(datagraph->getXColumn()), ds->end(datagraph->getXColumn()), ds->begin(datagraph->getYColumn()), ds->end(datagraph->getYColumn()), ds->begin(ge->getYErrorColumn()), ds->end(ge->getYErrorColumn()), coeffA, coeffB, fixA, fixB, &jkqtp_inversePropSaveDefault<double>);
return jkqtpstatAddLinearWeightedRegression(plt, ds->begin(datagraph->getXColumn()), ds->end(datagraph->getXColumn()), ds->begin(datagraph->getYColumn()), ds->end(datagraph->getYColumn()), ds->begin(ge->getYErrorColumn()), ds->end(ge->getYErrorColumn()), coeffA, coeffB, fixA, fixB, &jkqtp_inversePropSaveDefault<double>); } else {
throw std::runtime_error("datagraph needs to be convertible to JKQTPYGraphErrorData with a dynamic_cast!");
}
} }
JKQTPXFunctionLineGraph *jkqtpstatAddRobustIRLSLinearRegression(JKQTPXYGraph *datagraph, double *coeffA, double *coeffB, bool fixA, bool fixB, double p, int iterations) JKQTPXFunctionLineGraph *jkqtpstatAddRobustIRLSLinearRegression(JKQTPXYGraph *datagraph, double *coeffA, double *coeffB, bool fixA, bool fixB, double p, int iterations)
@ -60,8 +62,11 @@ JKQTPXFunctionLineGraph *jkqtpstatAddWeightedRegression(JKQTPXYGraph *datagraph,
JKQTPDatastore* ds=plt->getDatastore(); JKQTPDatastore* ds=plt->getDatastore();
JKQTPYGraphErrorData* ge=dynamic_cast<JKQTPYGraphErrorData*>(datagraph); JKQTPYGraphErrorData* ge=dynamic_cast<JKQTPYGraphErrorData*>(datagraph);
JKQTPASSERT_M(ge!=nullptr, "datagraph needs to be convertible to JKQTPYGraphErrorData with a dynamic_cast!"); if (ge) {
return jkqtpstatAddWeightedRegression(plt, type, ds->begin(datagraph->getXColumn()), ds->end(datagraph->getXColumn()), ds->begin(datagraph->getYColumn()), ds->end(datagraph->getYColumn()), ds->begin(ge->getYErrorColumn()), ds->end(ge->getYErrorColumn()), coeffA, coeffB, fixA, fixB, &jkqtp_inversePropSaveDefault<double>); return jkqtpstatAddWeightedRegression(plt, type, ds->begin(datagraph->getXColumn()), ds->end(datagraph->getXColumn()), ds->begin(datagraph->getYColumn()), ds->end(datagraph->getYColumn()), ds->begin(ge->getYErrorColumn()), ds->end(ge->getYErrorColumn()), coeffA, coeffB, fixA, fixB, &jkqtp_inversePropSaveDefault<double>);
} else {
throw std::runtime_error("datagraph needs to be convertible to JKQTPYGraphErrorData with a dynamic_cast!");
}
} }
JKQTPXFunctionLineGraph *jkqtpstatAddRobustIRLSRegression(JKQTPXYGraph *datagraph, JKQTPStatRegressionModelType type, double *coeffA, double *coeffB, bool fixA, bool fixB, double p, int iterations) JKQTPXFunctionLineGraph *jkqtpstatAddRobustIRLSRegression(JKQTPXYGraph *datagraph, JKQTPStatRegressionModelType type, double *coeffA, double *coeffB, bool fixA, bool fixB, double p, int iterations)

View File

@ -239,11 +239,6 @@ JKQTBasePlotter::JKQTBasePlotter(bool datastore_internal, QObject* parent, JKQTP
actSavePDF=new QAction(QIcon(":/JKQTPlotter/jkqtp_savepdf.png"), tr("Save P&DF"), this); actSavePDF=new QAction(QIcon(":/JKQTPlotter/jkqtp_savepdf.png"), tr("Save P&DF"), this);
actSavePDF->setToolTip(tr("Save as PDF")); actSavePDF->setToolTip(tr("Save as PDF"));
//toolbar->addAction(actSavePDF); //toolbar->addAction(actSavePDF);
#if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0))
actSavePS=new QAction(QIcon(":/JKQTPlotter/jkqtp_saveps.png"), "Save P&S", this);
actSavePS->setToolTip("Save as PostScript");
//toolbar->addAction(actSavePS);
#endif
actSaveSVG=new QAction(QIcon(":/JKQTPlotter/jkqtp_savesvg.png"), tr("Save S&VG"), this); actSaveSVG=new QAction(QIcon(":/JKQTPlotter/jkqtp_savesvg.png"), tr("Save S&VG"), this);
actSaveSVG->setToolTip(tr("Save as Scalable Vector Graphics (SVG)")); actSaveSVG->setToolTip(tr("Save as Scalable Vector Graphics (SVG)"));
//toolbar->addAction(actSaveSVG); //toolbar->addAction(actSaveSVG);
@ -278,9 +273,6 @@ JKQTBasePlotter::JKQTBasePlotter(bool datastore_internal, QObject* parent, JKQTP
connect(actShowPlotData, SIGNAL(triggered()), this, SLOT(showPlotData())); connect(actShowPlotData, SIGNAL(triggered()), this, SLOT(showPlotData()));
connect(actSavePDF, SIGNAL(triggered()), this, SLOT(saveAsPDF())); connect(actSavePDF, SIGNAL(triggered()), this, SLOT(saveAsPDF()));
#if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0))
connect(actSavePS, SIGNAL(triggered()), this, SLOT(saveAsPS()));
#endif
connect(actSaveSVG, SIGNAL(triggered()), this, SLOT(saveAsSVG())); connect(actSaveSVG, SIGNAL(triggered()), this, SLOT(saveAsSVG()));
connect(actSavePix, SIGNAL(triggered()), this, SLOT(saveAsPixelImage())); connect(actSavePix, SIGNAL(triggered()), this, SLOT(saveAsPixelImage()));
@ -700,9 +692,15 @@ void JKQTBasePlotter::setXY(double xminn, double xmaxx, double yminn, double yma
xAxis->setRange(xminn, xmaxx); xAxis->setRange(xminn, xmaxx);
yAxis->setRange(yminn, ymaxx); yAxis->setRange(yminn, ymaxx);
if (maintainAxisAspectRatio) { if (maintainAxisAspectRatio) {
double mid=(yAxis->getMax()+yAxis->getMin())/2.0; if (xAxis->isLinearAxis() && yAxis->isLinearAxis()) {
double w=fabs(xmaxx-xminn)/axisAspectRatio; const double mid=(yAxis->getMax()+yAxis->getMin())/2.0;
yAxis->setRange(mid-w/2.0, mid+w/2.0); const double w=fabs(xmaxx-xminn)/axisAspectRatio;
yAxis->setRange(mid-w/2.0, mid+w/2.0);
} else if (xAxis->isLogAxis() && yAxis->isLogAxis()) {
const double mid=(log(yAxis->getMax())+log(yAxis->getMin()))/2.0;
const double w=fabs(log(xmaxx)-log(xminn))/axisAspectRatio;
yAxis->setRange(exp(mid-w/2.0), exp(mid+w/2.0));
}
} }
if (emitSignals) emit zoomChangedLocally(xAxis->getMin(), xAxis->getMax(), yAxis->getMin(), yAxis->getMax(), this); if (emitSignals) emit zoomChangedLocally(xAxis->getMin(), xAxis->getMax(), yAxis->getMin(), yAxis->getMax(), this);
} }
@ -710,19 +708,31 @@ void JKQTBasePlotter::setXY(double xminn, double xmaxx, double yminn, double yma
void JKQTBasePlotter::setX(double xminn, double xmaxx){ void JKQTBasePlotter::setX(double xminn, double xmaxx){
xAxis->setRange(xminn, xmaxx); xAxis->setRange(xminn, xmaxx);
if (maintainAxisAspectRatio) { if (maintainAxisAspectRatio) {
double mid=(yAxis->getMax()+yAxis->getMin())/2.0; if (xAxis->isLinearAxis() && yAxis->isLinearAxis()) {
double w=fabs(xmaxx-xminn)/axisAspectRatio; const double mid=(yAxis->getMax()+yAxis->getMin())/2.0;
yAxis->setRange(mid-w/2.0, mid+w/2.0); const double w=fabs(xmaxx-xminn)/axisAspectRatio;
yAxis->setRange(mid-w/2.0, mid+w/2.0);
} else if (xAxis->isLogAxis() && yAxis->isLogAxis()) {
const double mid=(log(yAxis->getMax())+log(yAxis->getMin()))/2.0;
const double w=fabs(log(xmaxx)-log(xminn))/axisAspectRatio;
yAxis->setRange(exp(mid-w/2.0), exp(mid+w/2.0));
}
} }
if (emitSignals) emit zoomChangedLocally(xAxis->getMin(), xAxis->getMax(), yAxis->getMin(), yAxis->getMax(), this); if (emitSignals) emit zoomChangedLocally(xAxis->getMin(), xAxis->getMax(), yAxis->getMin(), yAxis->getMax(), this);
} }
void JKQTBasePlotter::setY(double yminn, double ymaxx){ void JKQTBasePlotter::setY(double yminn, double ymaxx) {
yAxis->setRange(yminn, ymaxx); yAxis->setRange(yminn, ymaxx);
if (maintainAxisAspectRatio) { if (maintainAxisAspectRatio) {
double mid=(xAxis->getMax()+xAxis->getMin())/2.0; if (xAxis->isLinearAxis() && yAxis->isLinearAxis()) {
double w=fabs(ymaxx-yminn)*axisAspectRatio; const double mid=(xAxis->getMax()+xAxis->getMin())/2.0;
xAxis->setRange(mid-w/2.0, mid+w/2.0); const double w=fabs(ymaxx-yminn)*axisAspectRatio;
xAxis->setRange(mid-w/2.0, mid+w/2.0);
} else if (xAxis->isLogAxis() && yAxis->isLogAxis()) {
const double mid=(log(xAxis->getMax())+log(xAxis->getMin()))/2.0;
const double w=fabs(log(ymaxx)-log(yminn))/axisAspectRatio;
xAxis->setRange(exp(mid-w/2.0), exp(mid+w/2.0));
}
} }
if (emitSignals) emit zoomChangedLocally(xAxis->getMin(), xAxis->getMax(), yAxis->getMin(), yAxis->getMax(), this); if (emitSignals) emit zoomChangedLocally(xAxis->getMin(), xAxis->getMax(), yAxis->getMin(), yAxis->getMax(), this);
} }
@ -1438,14 +1448,14 @@ void JKQTBasePlotter::gridPaint(JKQTPEnhancedPainter& painter, QSizeF pageRect,
for (int i=0; i< gridPrintingList.size(); i++) { for (int i=0; i< gridPrintingList.size(); i++) {
//std::cout<<"printing "<<i<<" ...\n"; //std::cout<<"printing "<<i<<" ...\n";
painter.save(); auto __finalpaintinnerloop=JKQTPFinally([&painter]() {painter.restore();}); painter.save(); auto __finalpaintinnerloop=JKQTPFinally([&painter]() {painter.restore();});
int t_x=0; int gt_x=0;
int t_y=0; int gt_y=0;
//std::cout<<"printing "<<i<<" @g "<<gridPrintingList[i].x<<", "<<gridPrintingList[i].y<<" ...\n"; //std::cout<<"printing "<<i<<" @g "<<gridPrintingList[i].x<<", "<<gridPrintingList[i].y<<" ...\n";
//std::cout<<"colrowlistsizes "<<gridPrintingColumns.size()<<", "<<gridPrintingRows.size()<<" ...\n"; //std::cout<<"colrowlistsizes "<<gridPrintingColumns.size()<<", "<<gridPrintingRows.size()<<" ...\n";
for (size_t j=0; j<gridPrintingList[i].x; j++) { t_x+= static_cast<int>(gridPrintingColumns[static_cast<int>(j)]); } for (size_t j=0; j<gridPrintingList[i].x; j++) { gt_x+= static_cast<int>(gridPrintingColumns[static_cast<int>(j)]); }
for (size_t j=0; j<gridPrintingList[i].y; j++) { t_y+= static_cast<int>(gridPrintingRows[static_cast<int>(j)]); } for (size_t j=0; j<gridPrintingList[i].y; j++) { gt_y+= static_cast<int>(gridPrintingRows[static_cast<int>(j)]); }
//std::cout<<"printing "<<i<<" @ "<<t_x<<", "<<t_y<<" ...\n"; //std::cout<<"printing "<<i<<" @ "<<t_x<<", "<<t_y<<" ...\n";
painter.translate(t_x, t_y); painter.translate(gt_x, gt_y);
gridPrintingList[i].plotter->drawPlot(painter, showOverlays); gridPrintingList[i].plotter->drawPlot(painter, showOverlays);
} }
@ -1505,14 +1515,14 @@ void JKQTBasePlotter::gridPaintOverlays(JKQTPEnhancedPainter &painter, QSizeF pa
for (int i=0; i< gridPrintingList.size(); i++) { for (int i=0; i< gridPrintingList.size(); i++) {
//std::cout<<"printing "<<i<<" ...\n"; //std::cout<<"printing "<<i<<" ...\n";
painter.save(); auto __finalpaintinnerloop=JKQTPFinally([&painter]() {painter.restore();}); painter.save(); auto __finalpaintinnerloop=JKQTPFinally([&painter]() {painter.restore();});
int t_x=0; int gt_x=0;
int t_y=0; int gt_y=0;
//std::cout<<"printing "<<i<<" @g "<<gridPrintingList[i].x<<", "<<gridPrintingList[i].y<<" ...\n"; //std::cout<<"printing "<<i<<" @g "<<gridPrintingList[i].x<<", "<<gridPrintingList[i].y<<" ...\n";
//std::cout<<"colrowlistsizes "<<gridPrintingColumns.size()<<", "<<gridPrintingRows.size()<<" ...\n"; //std::cout<<"colrowlistsizes "<<gridPrintingColumns.size()<<", "<<gridPrintingRows.size()<<" ...\n";
for (size_t j=0; j<gridPrintingList[i].x; j++) { t_x+= static_cast<int>(gridPrintingColumns[static_cast<int>(j)]); } for (size_t j=0; j<gridPrintingList[i].x; j++) { gt_x+= static_cast<int>(gridPrintingColumns[static_cast<int>(j)]); }
for (size_t j=0; j<gridPrintingList[i].y; j++) { t_y+= static_cast<int>(gridPrintingRows[static_cast<int>(j)]); } for (size_t j=0; j<gridPrintingList[i].y; j++) { gt_y+= static_cast<int>(gridPrintingRows[static_cast<int>(j)]); }
//std::cout<<"printing "<<i<<" @ "<<t_x<<", "<<t_y<<" ...\n"; //std::cout<<"printing "<<i<<" @ "<<t_x<<", "<<t_y<<" ...\n";
painter.translate(t_x, t_y); painter.translate(gt_x, gt_y);
gridPrintingList[i].plotter->drawOverlaysWithHints(painter); gridPrintingList[i].plotter->drawOverlaysWithHints(painter);
} }
@ -1752,10 +1762,10 @@ bool JKQTBasePlotter::printpreviewNew(QPaintDevice* paintDevice, bool setAbsolut
bool res=false; bool res=false;
if (printer) { if (printer) {
if (!displayPreview || dlg->exec()==QDialog::Accepted) { if (!displayPreview || dlg->exec()==QDialog::Accepted) {
qDebug()<<svg<<printer<<delPrinter; //qDebug()<<svg<<printer<<delPrinter;
if (svg) { if (svg) {
printpreviewPaintRequestedNew(svg); printpreviewPaintRequestedNew(svg);
} else if (printer && !delPrinter) { } else if (!delPrinter) {
printpreviewPaintRequestedNew(printer); printpreviewPaintRequestedNew(printer);
} else { } else {
printpreviewPaintRequestedNew(paintDevice); printpreviewPaintRequestedNew(paintDevice);
@ -2377,7 +2387,7 @@ void JKQTBasePlotter::drawNonGrid(JKQTPEnhancedPainter& painter, const QRect& re
if ((scale*static_cast<double>(widgetWidth)/paintMagnification>static_cast<double>(rect.width())) || (scale*static_cast<double>(widgetHeight)/paintMagnification>static_cast<double>(rect.height()))) { if ((scale*static_cast<double>(widgetWidth)/paintMagnification>static_cast<double>(rect.width())) || (scale*static_cast<double>(widgetHeight)/paintMagnification>static_cast<double>(rect.height()))) {
scale=static_cast<double>(rect.height())/static_cast<double>(widgetHeight)*paintMagnification; scale=static_cast<double>(rect.height())/static_cast<double>(widgetHeight)*paintMagnification;
} }
painter.save(); auto __finalpaint=JKQTPFinally([&painter]() {painter.restore();}); painter.save(); auto __finalpaintinner=JKQTPFinally([&painter]() {painter.restore();});
// scale the plot so it fits on the page // scale the plot so it fits on the page
painter.scale(scale, scale); painter.scale(scale, scale);
#ifdef JKQTBP_DEBUGTIMING #ifdef JKQTBP_DEBUGTIMING
@ -3293,12 +3303,6 @@ QAction *JKQTBasePlotter::getActionSavePDF() const {
return this->actSavePDF; return this->actSavePDF;
} }
#if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0))
QAction *JKQTBasePlotter::getActionSavePS() const {
return this->actSavePS;
}
#endif
QAction *JKQTBasePlotter::getActionSavePix() const { QAction *JKQTBasePlotter::getActionSavePix() const {
return this->actSavePix; return this->actSavePix;
} }
@ -3704,51 +3708,12 @@ void JKQTBasePlotter::saveAsPDF(const QString& filename, bool displayPreview) {
saveUserSettings(); saveUserSettings();
} }
void JKQTBasePlotter::saveAsPS(const QString& filename, bool displayPreview) {
#if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0))
loadUserSettings();
QString fn=filename;
if (fn.isEmpty()) {
fn = QFileDialog::getSaveFileName(nullptr, tr("Save Plot"),
currentSaveDirectory,
tr("PostScript File (*.ps)"));
if (!fn.isEmpty()) currentSaveDirectory=QFileInfo(fn).absolutePath();
}
if (!fn.isEmpty()) {
QPrinter* printer=new QPrinter;
bool doLandscape=widgetWidth>widgetHeight;
if (gridPrinting) {
gridPrintingCalc();
doLandscape=gridPrintingSize.width()>gridPrintingSize.height();
}
if (doLandscape) {
printer->setOrientation(QPrinter::Landscape);
} else {
printer->setOrientation(QPrinter::Portrait);
}
printer->setOutputFormat(QPrinter::PostScriptFormat);
printer->setColorMode(QPrinter::Color);
printer->setOutputFileName(fn);
printer->setPageMargins(0,0,0,0,QPrinter::Millimeter);
printpreviewNew(printer, true, -1.0, -1.0, displayPreview);
delete printer;
}
saveUserSettings();
#else
saveAsPDF(filename+".pdf", displayPreview);
#endif
}
void JKQTBasePlotter::saveImage(const QString& filename, bool displayPreview) { void JKQTBasePlotter::saveImage(const QString& filename, bool displayPreview) {
loadUserSettings(); loadUserSettings();
QString fn=filename; QString fn=filename;
QStringList filt; QStringList filt;
filt<<tr("Portable Document Format PDF [Qt] (*.pdf)"); filt<<tr("Portable Document Format PDF [Qt] (*.pdf)");
#if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0))
filt<<tr("PostScript [Qt] (*.ps)");
#endif
filt<<tr("Scalable Vector Graphics [Qt] (*.svg)"); filt<<tr("Scalable Vector Graphics [Qt] (*.svg)");
filt<<tr("PNG Image [Qt] (*.png)"); filt<<tr("PNG Image [Qt] (*.png)");
filt<<tr("BMP Image [Qt] (*.bmp)"); filt<<tr("BMP Image [Qt] (*.bmp)");
@ -3763,8 +3728,6 @@ void JKQTBasePlotter::saveImage(const QString& filename, bool displayPreview) {
for (int i=0; i<writerformats.size(); i++) { for (int i=0; i<writerformats.size(); i++) {
filt<<QString("%1 Image (*.%2)").arg(QString(writerformats[i]).toUpper()).arg(QString(writerformats[i].toLower())); filt<<QString("%1 Image (*.%2)").arg(QString(writerformats[i]).toUpper()).arg(QString(writerformats[i].toLower()));
} }
/*filt<<tr("X11 Bitmap [Qt] (*.xbm)");
filt<<tr("X11 Pixmap [Qt] (*.xpm)");*/
QString selFormat=""; QString selFormat="";
if (fn.isEmpty()) { if (fn.isEmpty()) {
selFormat=currentFileFormat; selFormat=currentFileFormat;
@ -3795,14 +3758,9 @@ void JKQTBasePlotter::saveImage(const QString& filename, bool displayPreview) {
} }
} }
//qDebug()<<"filtID="<<filtID<<" isWithSpecialDeviceAdapter="<<isWithSpecialDeviceAdapter<<" adapterID="<<adapterID; //qDebug()<<"filtID="<<filtID<<" isWithSpecialDeviceAdapter="<<isWithSpecialDeviceAdapter<<" adapterID="<<adapterID;
int ids=0; if (filtID==0) {
if (filtID==ids++) {
saveAsPDF(fn, displayPreview); saveAsPDF(fn, displayPreview);
#if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0)) } else if (filtID==1) {
} else if (filtID==ids++) {
saveAsPS(fn, displayPreview);
#endif
} else if (filtID==ids++) {
saveAsSVG(fn, displayPreview); saveAsSVG(fn, displayPreview);
} else if (isWithSpecialDeviceAdapter && adapterID>=0 && adapterID<jkqtpPaintDeviceAdapters.size()) { } else if (isWithSpecialDeviceAdapter && adapterID>=0 && adapterID<jkqtpPaintDeviceAdapters.size()) {
QString tempFM=""; QString tempFM="";
@ -4222,9 +4180,7 @@ void JKQTBasePlotter::drawGraphs(JKQTPEnhancedPainter& painter){
for (int j=0; j<graphs.size(); j++) { for (int j=0; j<graphs.size(); j++) {
//int leftSpace, rightSpace, topSpace, bottomSpace;
JKQTPPlotElement* g=graphs[j]; JKQTPPlotElement* g=graphs[j];
//qDebug()<<" drawing JKQTPPlotElement"<<j<<g->getTitle()<<g->metaObject()->className();
if (g->isVisible()) g->draw(painter); if (g->isVisible()) g->draw(painter);
} }
@ -4233,9 +4189,9 @@ void JKQTBasePlotter::drawGraphs(JKQTPEnhancedPainter& painter){
} }
for (int j=0; j<graphs.size(); j++) { for (int j=0; j<graphs.size(); j++) {
int leftSpace, rightSpace, topSpace, bottomSpace;
JKQTPPlotElement* g=graphs[j]; JKQTPPlotElement* g=graphs[j];
if (g->isVisible()) { if (g->isVisible()) {
int leftSpace, rightSpace, topSpace, bottomSpace;
g->getOutsideSize(painter, leftSpace, rightSpace, topSpace, bottomSpace); g->getOutsideSize(painter, leftSpace, rightSpace, topSpace, bottomSpace);
ibTop+=topSpace; ibTop+=topSpace;
ibLeft+=leftSpace; ibLeft+=leftSpace;
@ -4518,10 +4474,10 @@ void JKQTBasePlotter::getKeyExtent(JKQTPEnhancedPainter& painter, double* width,
double keyHeight=graphs.size(); double keyHeight=graphs.size();
double w=0; double w=0;
double txtH=0; double txtH=0;
QFont f=painter.font(); QFont floc=painter.font();
f.setFamily(plotterStyle.defaultFontName); floc.setFamily(plotterStyle.defaultFontName);
f.setPointSizeF(plotterStyle.keyStyle.fontSize*fontSizeMultiplier); floc.setPointSizeF(plotterStyle.keyStyle.fontSize*fontSizeMultiplier);
painter.setFont(f); painter.setFont(floc);
for (int i=0; i<graphs.size(); i++) { for (int i=0; i<graphs.size(); i++) {
@ -4662,11 +4618,11 @@ void JKQTBasePlotter::getGraphsYMinMax(double& miny, double& maxy, double& small
void JKQTBasePlotter::zoomToFit(bool zoomX, bool zoomY, bool includeX0, bool includeY0, double scaleX, double scaleY) { void JKQTBasePlotter::zoomToFit(bool zoomX, bool zoomY, bool includeX0, bool includeY0, double scaleX, double scaleY) {
// std::cout<<"JKQTBasePlotter::zoomToFit():\n"; // std::cout<<"JKQTBasePlotter::zoomToFit():\n";
double xxmin=0;
double xxmax=0;
double xsmallestGreaterZero=0;
if (graphs.size()<=0) return; if (graphs.size()<=0) return;
if (zoomX) { if (zoomX) {
double xxmin=0;
double xxmax=0;
double xsmallestGreaterZero=0;
getGraphsXMinMax(xxmin, xxmax, xsmallestGreaterZero); getGraphsXMinMax(xxmin, xxmax, xsmallestGreaterZero);
//std::cout<<" xxmin="<<xxmin<<" xxmax="<<xxmax<<std::endl; //std::cout<<" xxmin="<<xxmin<<" xxmax="<<xxmax<<std::endl;
if (JKQTPIsOKFloat(xxmin) && JKQTPIsOKFloat(xxmax)) { if (JKQTPIsOKFloat(xxmin) && JKQTPIsOKFloat(xxmax)) {
@ -4708,11 +4664,11 @@ void JKQTBasePlotter::zoomToFit(bool zoomX, bool zoomY, bool includeX0, bool inc
} }
} }
} }
double yymin=0;
double yymax=0;
double ysmallestGreaterZero=0;
if (zoomY) { if (zoomY) {
double yymin=0;
double yymax=0;
double ysmallestGreaterZero=0;
getGraphsYMinMax(yymin, yymax, ysmallestGreaterZero); getGraphsYMinMax(yymin, yymax, ysmallestGreaterZero);
//std::cout<<" yymin="<<yymin<<" yymax="<<yymax<<std::endl; //std::cout<<" yymin="<<yymin<<" yymax="<<yymax<<std::endl;
bool doScale=true; bool doScale=true;

View File

@ -208,7 +208,6 @@ class JKQTPLOTTER_LIB_EXPORT JKQTPPaintDeviceAdapter {
* - print() prints the graph on a QPrinter object * - print() prints the graph on a QPrinter object
* - saveAsPixelImage() saves the plot into a pixel image file (PNG, TIFF, ... formats, as supported by Qt) * - saveAsPixelImage() saves the plot into a pixel image file (PNG, TIFF, ... formats, as supported by Qt)
* - saveAsPDF() saves the graph as a PDF file (using the Qt printing engine) * - saveAsPDF() saves the graph as a PDF file (using the Qt printing engine)
* - saveAsPS() saves the graph as a PDF file (using the Qt printing engine)
* - saveAsSVG() saves the graph as a SVG file (using the Qt SVG library) * - saveAsSVG() saves the graph as a SVG file (using the Qt SVG library)
* - saveImage() saves the graph * - saveImage() saves the graph
* . * .
@ -841,11 +840,7 @@ class JKQTPLOTTER_LIB_EXPORT JKQTBasePlotter: public QObject {
QAction* getActionCopyMatlab() const; QAction* getActionCopyMatlab() const;
/*! \copydoc actSavePDF */ /*! \copydoc actSavePDF */
QAction* getActionSavePDF() const; QAction* getActionSavePDF() const;
#if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0)) /*! \copydoc actSavePix */
/*! \copydoc actSavePS */
QAction* getActionSavePS() const;
#endif
/*! \copydoc actSavePix */
QAction* getActionSavePix() const; QAction* getActionSavePix() const;
/*! \copydoc actSaveSVG */ /*! \copydoc actSaveSVG */
QAction* getActionSaveSVG() const; QAction* getActionSaveSVG() const;
@ -1354,9 +1349,6 @@ class JKQTPLOTTER_LIB_EXPORT JKQTBasePlotter: public QObject {
/** \brief save the current plot as a PDF file, with the current widget aspect ratio, if filename is empty a file selection dialog is displayed */ /** \brief save the current plot as a PDF file, with the current widget aspect ratio, if filename is empty a file selection dialog is displayed */
void saveAsPDF(const QString& filename=QString(""), bool displayPreview=true); void saveAsPDF(const QString& filename=QString(""), bool displayPreview=true);
/** \brief save the current plot as a PS file, with the current widget aspect ratio, if filename is empty a file selection dialog is displayed */
void saveAsPS(const QString& filename=QString(""), bool displayPreview=true);
/** \brief save the current plot as an image file, with the current widget aspect ratio, if filename is empty a file selection dialog is displayed. /** \brief save the current plot as an image file, with the current widget aspect ratio, if filename is empty a file selection dialog is displayed.
* The image format is extracted from the file extension (jpeg, tiff, png, pdf, ...) */ * The image format is extracted from the file extension (jpeg, tiff, png, pdf, ...) */
void saveImage(const QString& filename=QString(""), bool displayPreview=true); void saveImage(const QString& filename=QString(""), bool displayPreview=true);
@ -2019,9 +2011,23 @@ class JKQTPLOTTER_LIB_EXPORT JKQTBasePlotter: public QObject {
/** \brief the aspect ratio of plotwidth and plotheight to maintain, if \c maintainAspectRatio==true */ /** \brief the aspect ratio of plotwidth and plotheight to maintain, if \c maintainAspectRatio==true */
double aspectRatio; double aspectRatio;
/** \brief indicates whether the axes should maintain an aspect ratio */ /** \brief indicates whether the axes should maintain an aspect ratio
*
* \note An axis aspect ration is only well defined for linear axes (if both axes are linear).
* If both axes a logarithmic, the axis ration is defined for log(axismax)-log(axismin).
* For other combinations of axes, this function is deactivated
*
* \see axisAspectRatio
*/
bool maintainAxisAspectRatio; bool maintainAxisAspectRatio;
/** \brief the aspect ratio of axis widths to maintain, if \c maintainAxisAspectRatio==true */ /** \brief the aspect ratio of axis widths to maintain, if \c maintainAxisAspectRatio==true
*
* \note An axis aspect ration is only well defined for linear axes (if both axes are linear).
* If both axes a logarithmic, the axis ration is defined for log(axismax)-log(axismin).
* For other combinations of axes, this function is deactivated
*
* \see maintainAxisAspectRatio
*/
double axisAspectRatio; double axisAspectRatio;
@ -2082,10 +2088,6 @@ class JKQTPLOTTER_LIB_EXPORT JKQTBasePlotter: public QObject {
QAction* actCopyMatlab; QAction* actCopyMatlab;
/** \brief QAction which triggers the saving as PDF */ /** \brief QAction which triggers the saving as PDF */
QAction* actSavePDF; QAction* actSavePDF;
#if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0))
/** \brief QAction which triggers the saving as PostScript */
QAction* actSavePS;
#endif
/** \brief QAction which triggers the saving as pixel image */ /** \brief QAction which triggers the saving as pixel image */
QAction* actSavePix; QAction* actSavePix;
/** \brief QAction which triggers the saving as Scalable Vector Graphics (SVG) */ /** \brief QAction which triggers the saving as Scalable Vector Graphics (SVG) */

View File

@ -359,7 +359,7 @@ double JKQTPCoordinateAxis::calcLogTickSpacing() {
QString JKQTPCoordinateAxis::floattolabel(double data) { QString JKQTPCoordinateAxis::floattolabel(double data) {
int past_comma=axisStyle.labelDigits; int past_comma=axisStyle.labelDigits;
bool remove_trail0=true; const bool remove_trail0=true;
QLocale loc=QLocale::system(); QLocale loc=QLocale::system();
loc.setNumberOptions(QLocale::OmitGroupSeparator); loc.setNumberOptions(QLocale::OmitGroupSeparator);
@ -607,10 +607,10 @@ void JKQTPCoordinateAxis::saveCurrentAxisStyle(QSettings &settings, const QStrin
} }
void JKQTPCoordinateAxis::setRange(double aamin, double aamax) { void JKQTPCoordinateAxis::setRange(double aamin, double aamax) {
double oldamin=axismin; const double oldamin=axismin;
double oldamax=axismax; const double oldamax=axismax;
double amin=aamin; double amin=std::min(aamin, aamax);
double amax=aamax; double amax=std::max(aamin, aamax);
if (axisMinWidth>0 && fabs(amax-amin)<axisMinWidth) { if (axisMinWidth>0 && fabs(amax-amin)<axisMinWidth) {
amax=amin+axisMinWidth; amax=amin+axisMinWidth;
} }
@ -621,10 +621,7 @@ void JKQTPCoordinateAxis::setRange(double aamin, double aamax) {
if (amin<axisabsoultemin) axismin=axisabsoultemin; if (amin<axisabsoultemin) axismin=axisabsoultemin;
if (amax>axisabsoultemax) axismax=axisabsoultemax; if (amax>axisabsoultemax) axismax=axisabsoultemax;
if (axismin>axismax) {
axismin=amax;
axismax=amin;
}
if (isLogAxis()) { if (isLogAxis()) {
if (axismin<=0) axismin=1e-306; if (axismin<=0) axismin=1e-306;
if (axismax<=0) axismax=1e-306; if (axismax<=0) axismax=1e-306;
@ -950,21 +947,15 @@ void JKQTPCoordinateAxis::setTickLabelAngle(double __value) {
void JKQTPCoordinateAxis::setAbsoluteRange(double amin, double amax) { void JKQTPCoordinateAxis::setAbsoluteRange(double amin, double amax) {
axisabsoultemin=amin; axisabsoultemin=std::min(amin, amax);
axisabsoultemax=amax; axisabsoultemax=std::max(amin, amax);
if (axisabsoultemin>axisabsoultemax) {
axisabsoultemin=amax;
axisabsoultemax=amin;
}
if (axisabsoultemin==axisabsoultemax) { if (axisabsoultemin==axisabsoultemax) {
axisabsoultemax=axisabsoultemin+1; axisabsoultemax=axisabsoultemin+1;
} }
// ensure that the actual axis range is within the absolute range
setRange(axismin, axismax); setRange(axismin, axismax);
/*paramsChanged=true;
calcPlotScaling();
redrawPlot();*/
} }
double JKQTPCoordinateAxis::getNextLabelDistance(double x) { double JKQTPCoordinateAxis::getNextLabelDistance(double x) {
@ -1363,7 +1354,7 @@ void JKQTPVerticalAxis::drawAxes(JKQTPEnhancedPainter& painter) {
// plot thick axis at y==0 // plot thick axis at y==0
if (axisStyle.showZeroAxis && (0>axismin) && (0<axismax)) { if (axisStyle.showZeroAxis && (0>axismin) && (0<axismax)) {
#ifdef JKQTBP_AUTOTIMER #ifdef JKQTBP_AUTOTIMER
JKQTPAutoOutputTimer jkaat(QString("JKQTPEnhancedPainter[%1]::drawAxes(): 0Axis").arg(objectName())); JKQTPAutoOutputTimer jkaati(QString("JKQTPEnhancedPainter[%1]::drawAxes(): 0Axis").arg(objectName()));
#endif #endif
QPen pmain1=pmain; QPen pmain1=pmain;
pmain1.setWidthF(qMax(JKQTPlotterDrawingTools::ABS_MIN_LINEWIDTH, parent->pt2px(painter, axisStyle.lineWidthZeroAxis*parent->getLineWidthMultiplier()))); pmain1.setWidthF(qMax(JKQTPlotterDrawingTools::ABS_MIN_LINEWIDTH, parent->pt2px(painter, axisStyle.lineWidthZeroAxis*parent->getLineWidthMultiplier())));
@ -1399,7 +1390,7 @@ void JKQTPVerticalAxis::drawAxes(JKQTPEnhancedPainter& painter) {
{ {
#ifdef JKQTBP_AUTOTIMER #ifdef JKQTBP_AUTOTIMER
JKQTPAutoOutputTimer jkaat(QString("JKQTPEnhancedPainter[%1]::drawAxes(): calcLabels").arg(objectName())); JKQTPAutoOutputTimer jkaatii(QString("JKQTPEnhancedPainter[%1]::drawAxes(): calcLabels").arg(objectName()));
#endif #endif
while (getNextLabel(x, label, first) && cnt<200) { while (getNextLabel(x, label, first) && cnt<200) {
double mtdist=getNextLabelDistance(x)/static_cast<double>(axisStyle.minorTicks+1); double mtdist=getNextLabelDistance(x)/static_cast<double>(axisStyle.minorTicks+1);
@ -1498,7 +1489,7 @@ void JKQTPVerticalAxis::drawAxes(JKQTPEnhancedPainter& painter) {
} }
{ {
#ifdef JKQTBP_AUTOTIMER #ifdef JKQTBP_AUTOTIMER
JKQTPAutoOutputTimer jkaat(QString("JKQTPEnhancedPainter[%1]::drawAxes(): drawLines").arg(objectName())); JKQTPAutoOutputTimer jkaati(QString("JKQTPEnhancedPainter[%1]::drawAxes(): drawLines").arg(objectName()));
#endif #endif
painter.setPen(ptick); painter.setPen(ptick);
painter.drawLines(lines_ptick); painter.drawLines(lines_ptick);
@ -1511,7 +1502,7 @@ void JKQTPVerticalAxis::drawAxes(JKQTPEnhancedPainter& painter) {
// plot axis label // plot axis label
if (!axisLabel.isEmpty() && JKQTPCADrawModeHasAxisLabel(axisStyle.drawMode1)) { if (!axisLabel.isEmpty() && JKQTPCADrawModeHasAxisLabel(axisStyle.drawMode1)) {
#ifdef JKQTBP_AUTOTIMER #ifdef JKQTBP_AUTOTIMER
JKQTPAutoOutputTimer jkaat(QString("JKQTPEnhancedPainter[%1]::drawAxes(): axisLabel1").arg(objectName())); JKQTPAutoOutputTimer jkaati(QString("JKQTPEnhancedPainter[%1]::drawAxes(): axisLabel1").arg(objectName()));
#endif #endif
getParentMathText()->setFontSize(axisStyle.labelFontSize*parent->getFontSizeMultiplier()); getParentMathText()->setFontSize(axisStyle.labelFontSize*parent->getFontSizeMultiplier());
getParentMathText()->setFontRomanOrSpecial(getParent()->getCurrentPlotterStyle().defaultFontName); getParentMathText()->setFontRomanOrSpecial(getParent()->getCurrentPlotterStyle().defaultFontName);
@ -1553,7 +1544,7 @@ void JKQTPVerticalAxis::drawAxes(JKQTPEnhancedPainter& painter) {
} }
if (!axisLabel.isEmpty() && JKQTPCADrawModeHasAxisLabel(axisStyle.drawMode2)) { if (!axisLabel.isEmpty() && JKQTPCADrawModeHasAxisLabel(axisStyle.drawMode2)) {
#ifdef JKQTBP_AUTOTIMER #ifdef JKQTBP_AUTOTIMER
JKQTPAutoOutputTimer jkaat(QString("JKQTPEnhancedPainter[%1]::drawAxes(): axisLabel2").arg(objectName())); JKQTPAutoOutputTimer jkaati(QString("JKQTPEnhancedPainter[%1]::drawAxes(): axisLabel2").arg(objectName()));
#endif #endif
getParentMathText()->setFontSize(axisStyle.labelFontSize*parent->getFontSizeMultiplier()); getParentMathText()->setFontSize(axisStyle.labelFontSize*parent->getFontSizeMultiplier());
getParentMathText()->setFontRomanOrSpecial(getParent()->getCurrentPlotterStyle().defaultFontName); getParentMathText()->setFontRomanOrSpecial(getParent()->getCurrentPlotterStyle().defaultFontName);
@ -1992,7 +1983,7 @@ void JKQTPHorizontalAxis::drawAxes(JKQTPEnhancedPainter& painter) {
{ {
#ifdef JKQTBP_AUTOTIMER #ifdef JKQTBP_AUTOTIMER
JKQTPAutoOutputTimer jkaat(QString("JKQTPHorizontalAxis[%1]::drawAxes(): calcLabels").arg(objectName())); JKQTPAutoOutputTimer jkaati(QString("JKQTPHorizontalAxis[%1]::drawAxes(): calcLabels").arg(objectName()));
#endif #endif
while (getNextLabel(x, label, first) && cnt<200) { while (getNextLabel(x, label, first) && cnt<200) {
@ -2094,7 +2085,7 @@ void JKQTPHorizontalAxis::drawAxes(JKQTPEnhancedPainter& painter) {
} }
{ {
#ifdef JKQTBP_AUTOTIMER #ifdef JKQTBP_AUTOTIMER
JKQTPAutoOutputTimer jkaat(QString("JKQTPHorizontalAxis[%1]::drawAxes(): drawLines").arg(objectName())); JKQTPAutoOutputTimer jkaati(QString("JKQTPHorizontalAxis[%1]::drawAxes(): drawLines").arg(objectName()));
#endif #endif
painter.setPen(ptick); painter.setPen(ptick);
@ -2108,7 +2099,7 @@ void JKQTPHorizontalAxis::drawAxes(JKQTPEnhancedPainter& painter) {
// plot axis label // plot axis label
if (!axisLabel.isEmpty() && JKQTPCADrawModeHasAxisLabel(axisStyle.drawMode1)) { if (!axisLabel.isEmpty() && JKQTPCADrawModeHasAxisLabel(axisStyle.drawMode1)) {
#ifdef JKQTBP_AUTOTIMER #ifdef JKQTBP_AUTOTIMER
JKQTPAutoOutputTimer jkaat(QString("JKQTPHorizontalAxis[%1]::drawAxes(): axisLabel1").arg(objectName())); JKQTPAutoOutputTimer jkaati(QString("JKQTPHorizontalAxis[%1]::drawAxes(): axisLabel1").arg(objectName()));
#endif #endif
getParentMathText()->setFontSize(axisStyle.labelFontSize*parent->getFontSizeMultiplier()); getParentMathText()->setFontSize(axisStyle.labelFontSize*parent->getFontSizeMultiplier());
getParentMathText()->setFontRomanOrSpecial(getParent()->getCurrentPlotterStyle().defaultFontName); getParentMathText()->setFontRomanOrSpecial(getParent()->getCurrentPlotterStyle().defaultFontName);
@ -2149,7 +2140,7 @@ void JKQTPHorizontalAxis::drawAxes(JKQTPEnhancedPainter& painter) {
} }
if (!axisLabel.isEmpty() && JKQTPCADrawModeHasAxisLabel(axisStyle.drawMode2)) { if (!axisLabel.isEmpty() && JKQTPCADrawModeHasAxisLabel(axisStyle.drawMode2)) {
#ifdef JKQTBP_AUTOTIMER #ifdef JKQTBP_AUTOTIMER
JKQTPAutoOutputTimer jkaat(QString("JKQTPHorizontalAxis[%1]::drawAxes(): axisLabel2").arg(objectName())); JKQTPAutoOutputTimer jkaati(QString("JKQTPHorizontalAxis[%1]::drawAxes(): axisLabel2").arg(objectName()));
#endif #endif
getParentMathText()->setFontSize(axisStyle.labelFontSize*parent->getFontSizeMultiplier()); getParentMathText()->setFontSize(axisStyle.labelFontSize*parent->getFontSizeMultiplier());
getParentMathText()->setFontRomanOrSpecial(getParent()->getCurrentPlotterStyle().defaultFontName); getParentMathText()->setFontRomanOrSpecial(getParent()->getCurrentPlotterStyle().defaultFontName);

View File

@ -80,13 +80,11 @@ size_t JKQTPColumn::getRows() const {
//////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////
void JKQTPColumn::copyData(QVector<double> &copyTo) const void JKQTPColumn::copyData(QVector<double> &copyTo) const
{ {
const double* d=getPointer(0); const size_t cnt=getRows();
copyTo.clear();
size_t i, cnt=getRows();
if (cnt>0) { if (cnt>0) {
copyTo.resize(static_cast<int>(cnt)); copyTo.resize(static_cast<int>(cnt));
for (i=0; i<cnt; i++) { for (size_t i=0; i<cnt; i++) {
copyTo[static_cast<int>(i)]=d[i]; copyTo[static_cast<int>(i)]=getValue(i);
} }
} }
} }
@ -143,7 +141,7 @@ void JKQTPColumn::subtract(double value)
{ {
if (!datastore) return ; if (!datastore) return ;
double* data=getPointer(); double* data=getPointer();
size_t N=getRows(); const size_t N=getRows();
if (data){ if (data){
for (size_t i=0; i<N; i++) { for (size_t i=0; i<N; i++) {
data[i]=data[i]-value; data[i]=data[i]-value;
@ -202,7 +200,7 @@ JKQTPDatastoreItem::JKQTPDatastoreItem(size_t columns, size_t rows){
this->dataformat=JKQTPDatastoreItemFormat::SingleColumn; this->dataformat=JKQTPDatastoreItemFormat::SingleColumn;
this->storageType=StorageType::Vector; this->storageType=StorageType::Vector;
datavec.resize(static_cast<int>(columns*rows)); datavec.resize(static_cast<int>(columns*rows));
for( double& d: datavec) { d=0.0; } std::fill(datavec.begin(), datavec.end(), 0.0);
this->data=datavec.data(); this->data=datavec.data();
} }
this->columns=columns; this->columns=columns;
@ -562,7 +560,7 @@ size_t JKQTPDatastore::addCopiedItem(JKQTPDatastoreItemFormat dataformat, double
it->set(c, r, data[c*rows+r]); it->set(c, r, data[c*rows+r]);
} }
} }
} else if (dataformat==JKQTPDatastoreItemFormat::MatrixColumn) { } else if (dataformat==JKQTPDatastoreItemFormat::MatrixRow) {
it=new JKQTPDatastoreItem(columnsnum, rows); it=new JKQTPDatastoreItem(columnsnum, rows);
for (size_t r=0; r<rows; r++) { for (size_t r=0; r<rows; r++) {
for (size_t c=0; c<columnsnum; c++) { for (size_t c=0; c<columnsnum; c++) {
@ -1033,8 +1031,8 @@ void JKQTPDatastore::saveMatlab(QTextStream &txt, const QSet<int>& userColumns)
varnames.insert(newvar); varnames.insert(newvar);
txt<<QString("% data from columne %1 ('%2')\n").arg(col+1).arg(it.value().getName()); txt<<QString("% data from columne %1 ('%2')\n").arg(col+1).arg(it.value().getName());
txt<<QString("%1 = [ ").arg(newvar); txt<<QString("%1 = [ ").arg(newvar);
for (size_t i=0; i<it.value().getRows(); i++) { for (size_t rr=0; rr<it.value().getRows(); rr++) {
txt<<loc.toString(get(it.key(), i))<<" "; txt<<loc.toString(get(it.key(), rr))<<" ";
} }
txt<<"];\n\n"; txt<<"];\n\n";
@ -1072,8 +1070,7 @@ void JKQTPDatastore::saveCSV(QTextStream& txt, const QSet<int>& userColumns, con
} }
txt<<"\n"; txt<<"\n";
} }
size_t rows=getMaxRows(); for (size_t i=0; i<getMaxRows(); i++) {
for (size_t i=0; i<rows; i++) {
bool first=true; bool first=true;
QMapIterator<size_t, JKQTPColumn> it(columns); QMapIterator<size_t, JKQTPColumn> it(columns);
int j=0; int j=0;
@ -1127,15 +1124,14 @@ void JKQTPDatastore::saveSYLK(const QString& filename, const QSet<int>& userColu
size_t rows=getMaxRows(); for (size_t rr=0; rr<getMaxRows(); rr++) {
for (size_t i=0; i<rows; i++) {
QMapIterator<size_t, JKQTPColumn> it(columns); QMapIterator<size_t, JKQTPColumn> it(columns);
c=1; c=1;
while (it.hasNext()) { while (it.hasNext()) {
it.next(); it.next();
if (userColumns.isEmpty() || userColumns.contains(static_cast<int>(i))) { if (userColumns.isEmpty() || userColumns.contains(static_cast<int>(rr))) {
if (it.value().getRows()>i) { if (it.value().getRows()>rr) {
txt<<QString("C;X%1;Y%2;N;K%3\n").arg(c).arg(i+2).arg(get(it.key(), i)); txt<<QString("C;X%1;Y%2;N;K%3\n").arg(c).arg(rr+2).arg(get(it.key(), rr));
} }
c++; c++;
} }
@ -1202,7 +1198,7 @@ void JKQTPDatastore::saveDIF(const QString& filename, const QSet<int>& userColum
if (!f.open(QIODevice::WriteOnly|QIODevice::Text)) return; if (!f.open(QIODevice::WriteOnly|QIODevice::Text)) return;
QTextStream txt(&f); QTextStream txt(&f);
txt.setLocale(loc); txt.setLocale(loc);
size_t rows=getMaxRows(); const size_t rows=getMaxRows();
// write DIF header // write DIF header
txt<<QString("TABLE\n0,1\n\"\"\n"); txt<<QString("TABLE\n0,1\n\"\"\n");