FIXED symmetry when zooming with JKQTBasePlotter::zoomIn() or JKQTBasePlotter::zoomOut()

This commit is contained in:
jkriege2 2024-02-05 00:24:39 +01:00
parent 26cb23e3ab
commit 3b231273ef
2 changed files with 22 additions and 7 deletions

View File

@ -58,7 +58,8 @@ Changes, compared to \ref page_whatsnew_V4_0_0 "v4.0.0" include:
<li>FIXED issue mentioned in <a href="https://github.com/jkriege2/JKQtPlotter/pull/110">#110: Lock the panning action to certain values: View zooms in, when panning close to AbosluteXY</a> (thanks to <a href="https://github.com/sim186">user:sim186</a> for reporting)</li>
<li>FIXED: jkqtpstatSum() and jkqtpstatSumSqr() did not work, as a non-existing function is called internally</li>
<li>FIXED removed unnecessary operators (<,>,<=,>=) from JKQTPColumnIterator and JKQTPColumnConstIterator, which lead to exceptions on some compilers (MSVC)</li>
<li>FIXED/IMPROVED issue <a href="https://github.com/jkriege2/JKQtPlotter/issues/100">#100: Add option to disable resize delay feature by setting the delay to zero</a> (thanks to <a href="https://github.com/fpalazzolo">user:fpalazzolo</a> for reporting)</li>
<li>FIXED/IMPROVED issue <a href="https://github.com/jkriege2/JKQtPlotter/issu
<li>FIXED symmetry when zooming with JKQTBasePlotter::zoomIn() or JKQTBasePlotter::zoomOut() </li>--es/100">#100: Add option to disable resize delay feature by setting the delay to zero</a> (thanks to <a href="https://github.com/fpalazzolo">user:fpalazzolo</a> for reporting)</li>
<li>FIXED/NEW: placement of plot-title (was not centerd in its box, but glued to the bottom) by adding a plotstyle parameter JKQTBasePlotterStyle::plotLabelOffset</li>
<li>FIXED/REWORKED issue <a href="https://github.com/jkriege2/JKQtPlotter/issues/111">#111: Can't write to PDF files with JKQTPlotter::saveImage() when passing a filename ending in ".pdf"</a> (thanks to <a href="https://github.com/fpalazzolo">user:fpalazzolo</a> for reporting):<br/>While fixing this issue, the functions JKQTBasePlotter::saveImage() etc. gained a bool return value to indicate whether sacing was successful.</li>
<li>IMPROVED/FIXED outside space requirements for color bars. Text was sometime too close to the plot border.</li>

View File

@ -464,15 +464,29 @@ void JKQTBasePlotter::initSettings() {
void JKQTBasePlotter::zoomIn(double factor) {
//std::cout<<(double)event->delta()/120.0<<": "<<factor<<std::endl;
for (auto ax: getXAxes(true)) {
const double xmin=ax->p2x(static_cast<long>(round(static_cast<double>(internalPlotWidth)/2.0-static_cast<double>(internalPlotWidth)/(2.0*factor))));
const double xmax=ax->p2x(static_cast<long>(round(static_cast<double>(internalPlotWidth)/2.0+static_cast<double>(internalPlotWidth)/(2.0*factor))));
ax->setRange(xmin, xmax);
const double old_mi=ax->x2p(ax->getMin());
const double old_ma=ax->x2p(ax->getMax());
const double range=fabs(old_ma-old_mi);
const double new_range=range/factor;
const double new_mi=qMin(old_mi,old_ma)-(new_range-range)/2.0;
const double new_ma=qMax(old_mi,old_ma)+(new_range-range)/2.0;
const double xmin=ax->p2x(new_mi);
const double xmax=ax->p2x(new_ma);
ax->setRange(qMin(xmin, xmax), qMax(xmin, xmax));
}
for (auto ax: getYAxes(true)) {
const double ymin=ax->p2x(static_cast<long>(round(static_cast<double>(internalPlotHeight)/2.0+static_cast<double>(internalPlotHeight)/(2.0*factor))));
const double ymax=ax->p2x(static_cast<long>(round(static_cast<double>(internalPlotHeight)/2.0-static_cast<double>(internalPlotHeight)/(2.0*factor))));
ax->setRange(ymin, ymax);
const double old_mi=ax->x2p(ax->getMin());
const double old_ma=ax->x2p(ax->getMax());
const double range=fabs(old_ma-old_mi);
const double new_range=range/factor;
const double new_mi=qMin(old_mi,old_ma)-(new_range-range)/2.0;
const double new_ma=qMax(old_mi,old_ma)+(new_range-range)/2.0;
const double xmin=ax->p2x(new_mi);
const double xmax=ax->p2x(new_ma);
ax->setRange(qMin(xmin, xmax), qMax(xmin, xmax));
}
redrawPlot();