MCPcopy Create free account
hub / github.com/LUX-Core/lux / ohlcSelectTest

Method ohlcSelectTest

src/qt/qcustomplot.cpp:26848–26884  ·  view source on GitHub ↗

! \internal This method is a helper function for \ref selectTest. It is used to test for selection when the chart style is \ref csOhlc. It only tests against the data points between \a begin and \a end. Like \ref selectTest, this method returns the shortest distance of \a pos to the graphical representation of the plottable, and \a closestDataPoint will point to the respective data poi

Source from the content-addressed store, hash-verified

26846 representation of the plottable, and \a closestDataPoint will point to the respective data point.
26847*/
26848double QCPFinancial::ohlcSelectTest(const QPointF &pos, const QCPFinancialDataContainer::const_iterator &begin, const QCPFinancialDataContainer::const_iterator &end, QCPFinancialDataContainer::const_iterator &closestDataPoint) const
26849{
26850 closestDataPoint = mDataContainer->constEnd();
26851 QCPAxis *keyAxis = mKeyAxis.data();
26852 QCPAxis *valueAxis = mValueAxis.data();
26853 if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return -1; }
26854
26855 double minDistSqr = std::numeric_limits<double>::max();
26856 if (keyAxis->orientation() == Qt::Horizontal)
26857 {
26858 for (QCPFinancialDataContainer::const_iterator it=begin; it!=end; ++it)
26859 {
26860 double keyPixel = keyAxis->coordToPixel(it->key);
26861 // calculate distance to backbone:
26862 double currentDistSqr = QCPVector2D(pos).distanceSquaredToLine(QCPVector2D(keyPixel, valueAxis->coordToPixel(it->high)), QCPVector2D(keyPixel, valueAxis->coordToPixel(it->low)));
26863 if (currentDistSqr < minDistSqr)
26864 {
26865 minDistSqr = currentDistSqr;
26866 closestDataPoint = it;
26867 }
26868 }
26869 } else // keyAxis->orientation() == Qt::Vertical
26870 {
26871 for (QCPFinancialDataContainer::const_iterator it=begin; it!=end; ++it)
26872 {
26873 double keyPixel = keyAxis->coordToPixel(it->key);
26874 // calculate distance to backbone:
26875 double currentDistSqr = QCPVector2D(pos).distanceSquaredToLine(QCPVector2D(valueAxis->coordToPixel(it->high), keyPixel), QCPVector2D(valueAxis->coordToPixel(it->low), keyPixel));
26876 if (currentDistSqr < minDistSqr)
26877 {
26878 minDistSqr = currentDistSqr;
26879 closestDataPoint = it;
26880 }
26881 }
26882 }
26883 return qSqrt(minDistSqr);
26884}
26885
26886/*! \internal
26887

Callers

nothing calls this directly

Calls 5

maxFunction · 0.85
constEndMethod · 0.80
coordToPixelMethod · 0.80
distanceSquaredToLineMethod · 0.80
dataMethod · 0.45

Tested by

no test coverage detected