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

Method candlestickSelectTest

src/qt/qcustomplot.cpp:26895–26959  ·  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 csCandlestick. 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 respecti

Source from the content-addressed store, hash-verified

26893 representation of the plottable, and \a closestDataPoint will point to the respective data point.
26894*/
26895double QCPFinancial::candlestickSelectTest(const QPointF &pos, const QCPFinancialDataContainer::const_iterator &begin, const QCPFinancialDataContainer::const_iterator &end, QCPFinancialDataContainer::const_iterator &closestDataPoint) const
26896{
26897 closestDataPoint = mDataContainer->constEnd();
26898 QCPAxis *keyAxis = mKeyAxis.data();
26899 QCPAxis *valueAxis = mValueAxis.data();
26900 if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return -1; }
26901
26902 double minDistSqr = std::numeric_limits<double>::max();
26903 if (keyAxis->orientation() == Qt::Horizontal)
26904 {
26905 for (QCPFinancialDataContainer::const_iterator it=begin; it!=end; ++it)
26906 {
26907 double currentDistSqr;
26908 // determine whether pos is in open-close-box:
26909 QCPRange boxKeyRange(it->key-mWidth*0.5, it->key+mWidth*0.5);
26910 QCPRange boxValueRange(it->close, it->open);
26911 double posKey, posValue;
26912 pixelsToCoords(pos, posKey, posValue);
26913 if (boxKeyRange.contains(posKey) && boxValueRange.contains(posValue)) // is in open-close-box
26914 {
26915 currentDistSqr = mParentPlot->selectionTolerance()*0.99 * mParentPlot->selectionTolerance()*0.99;
26916 } else
26917 {
26918 // calculate distance to high/low lines:
26919 double keyPixel = keyAxis->coordToPixel(it->key);
26920 double highLineDistSqr = QCPVector2D(pos).distanceSquaredToLine(QCPVector2D(keyPixel, valueAxis->coordToPixel(it->high)), QCPVector2D(keyPixel, valueAxis->coordToPixel(qMax(it->open, it->close))));
26921 double lowLineDistSqr = QCPVector2D(pos).distanceSquaredToLine(QCPVector2D(keyPixel, valueAxis->coordToPixel(it->low)), QCPVector2D(keyPixel, valueAxis->coordToPixel(qMin(it->open, it->close))));
26922 currentDistSqr = qMin(highLineDistSqr, lowLineDistSqr);
26923 }
26924 if (currentDistSqr < minDistSqr)
26925 {
26926 minDistSqr = currentDistSqr;
26927 closestDataPoint = it;
26928 }
26929 }
26930 } else // keyAxis->orientation() == Qt::Vertical
26931 {
26932 for (QCPFinancialDataContainer::const_iterator it=begin; it!=end; ++it)
26933 {
26934 double currentDistSqr;
26935 // determine whether pos is in open-close-box:
26936 QCPRange boxKeyRange(it->key-mWidth*0.5, it->key+mWidth*0.5);
26937 QCPRange boxValueRange(it->close, it->open);
26938 double posKey, posValue;
26939 pixelsToCoords(pos, posKey, posValue);
26940 if (boxKeyRange.contains(posKey) && boxValueRange.contains(posValue)) // is in open-close-box
26941 {
26942 currentDistSqr = mParentPlot->selectionTolerance()*0.99 * mParentPlot->selectionTolerance()*0.99;
26943 } else
26944 {
26945 // calculate distance to high/low lines:
26946 double keyPixel = keyAxis->coordToPixel(it->key);
26947 double highLineDistSqr = QCPVector2D(pos).distanceSquaredToLine(QCPVector2D(valueAxis->coordToPixel(it->high), keyPixel), QCPVector2D(valueAxis->coordToPixel(qMax(it->open, it->close)), keyPixel));
26948 double lowLineDistSqr = QCPVector2D(pos).distanceSquaredToLine(QCPVector2D(valueAxis->coordToPixel(it->low), keyPixel), QCPVector2D(valueAxis->coordToPixel(qMin(it->open, it->close)), keyPixel));
26949 currentDistSqr = qMin(highLineDistSqr, lowLineDistSqr);
26950 }
26951 if (currentDistSqr < minDistSqr)
26952 {

Callers

nothing calls this directly

Calls 6

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

Tested by

no test coverage detected