MCPcopy Create free account
hub / github.com/collin80/SavvyCAN / dataToStepCenterLines

Method dataToStepCenterLines

qcustomplot.cpp:20704–20752  ·  view source on GitHub ↗

! \internal Takes raw data points in plot coordinates as \a data, and returns a vector containing pixel coordinate points which are suitable for drawing the line style \ref lsStepCenter. The source of \a data is usually \ref getOptimizedLineData, and this method is called in \a getLines if the line style is set accordingly. \see dataToLines, dataToStepLeftLines, dataToStepRightLines

Source from the content-addressed store, hash-verified

20702 \see dataToLines, dataToStepLeftLines, dataToStepRightLines, dataToImpulseLines, getLines, drawLinePlot
20703*/
20704QVector<QPointF> QCPGraph::dataToStepCenterLines(const QVector<QCPGraphData> &data) const
20705{
20706 QVector<QPointF> result;
20707 QCPAxis *keyAxis = mKeyAxis.data();
20708 QCPAxis *valueAxis = mValueAxis.data();
20709 if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return result; }
20710
20711 result.resize(data.size()*2);
20712
20713 // calculate steps from data and transform to pixel coordinates:
20714 if (keyAxis->orientation() == Qt::Vertical)
20715 {
20716 double lastKey = keyAxis->coordToPixel(data.first().key);
20717 double lastValue = valueAxis->coordToPixel(data.first().value);
20718 result[0].setX(lastValue);
20719 result[0].setY(lastKey);
20720 for (int i=1; i<data.size(); ++i)
20721 {
20722 const double key = (keyAxis->coordToPixel(data.at(i).key)+lastKey)*0.5;
20723 result[i*2-1].setX(lastValue);
20724 result[i*2-1].setY(key);
20725 lastValue = valueAxis->coordToPixel(data.at(i).value);
20726 lastKey = keyAxis->coordToPixel(data.at(i).key);
20727 result[i*2+0].setX(lastValue);
20728 result[i*2+0].setY(key);
20729 }
20730 result[data.size()*2-1].setX(lastValue);
20731 result[data.size()*2-1].setY(lastKey);
20732 } else // key axis is horizontal
20733 {
20734 double lastKey = keyAxis->coordToPixel(data.first().key);
20735 double lastValue = valueAxis->coordToPixel(data.first().value);
20736 result[0].setX(lastKey);
20737 result[0].setY(lastValue);
20738 for (int i=1; i<data.size(); ++i)
20739 {
20740 const double key = (keyAxis->coordToPixel(data.at(i).key)+lastKey)*0.5;
20741 result[i*2-1].setX(key);
20742 result[i*2-1].setY(lastValue);
20743 lastValue = valueAxis->coordToPixel(data.at(i).value);
20744 lastKey = keyAxis->coordToPixel(data.at(i).key);
20745 result[i*2+0].setX(key);
20746 result[i*2+0].setY(lastValue);
20747 }
20748 result[data.size()*2-1].setX(lastKey);
20749 result[data.size()*2-1].setY(lastValue);
20750 }
20751 return result;
20752}
20753
20754/*! \internal
20755

Callers

nothing calls this directly

Calls 4

coordToPixelMethod · 0.80
atMethod · 0.80
dataMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected