MCPcopy Create free account
hub / github.com/CieNTi/serial_port_plotter / trimTicks

Method trimTicks

qcustomplot/qcustomplot.cpp:5754–5788  ·  view source on GitHub ↗

! \internal Removes tick coordinates from \a ticks which lie outside the specified \a range. If \a keepOneOutlier is true, it preserves one tick just outside the range on both sides, if present. The passed \a ticks must be sorted in ascending order. */

Source from the content-addressed store, hash-verified

5752 The passed \a ticks must be sorted in ascending order.
5753*/
5754void QCPAxisTicker::trimTicks(const QCPRange &range, QVector<double> &ticks, bool keepOneOutlier) const
5755{
5756 bool lowFound = false;
5757 bool highFound = false;
5758 int lowIndex = 0;
5759 int highIndex = -1;
5760
5761 for (int i=0; i < ticks.size(); ++i)
5762 {
5763 if (ticks.at(i) >= range.lower)
5764 {
5765 lowFound = true;
5766 lowIndex = i;
5767 break;
5768 }
5769 }
5770 for (int i=ticks.size()-1; i >= 0; --i)
5771 {
5772 if (ticks.at(i) <= range.upper)
5773 {
5774 highFound = true;
5775 highIndex = i;
5776 break;
5777 }
5778 }
5779
5780 if (highFound && lowFound)
5781 {
5782 int trimFront = qMax(0, lowIndex-(keepOneOutlier ? 1 : 0));
5783 int trimBack = qMax(0, ticks.size()-(keepOneOutlier ? 2 : 1)-highIndex);
5784 if (trimFront > 0 || trimBack > 0)
5785 ticks = ticks.mid(trimFront, ticks.size()-trimFront-trimBack);
5786 } else // all ticks are either all below or all above the range
5787 ticks.clear();
5788}
5789
5790/*! \internal
5791

Callers

nothing calls this directly

Calls 3

atMethod · 0.80
clearMethod · 0.60
sizeMethod · 0.45

Tested by

no test coverage detected