8#include "focushfrvplot.h"
14#define DEFAULT_BASIC_FONT_SIZE 10
42 yAxis->setLabel(
i18n(
"Value"));
47 polynomialGraph = addGraph();
56 focusPoint = addGraph();
62 if (parent !=
nullptr)
63 setBasicFontSize(parent->
font().pointSize());
65 setBasicFontSize(DEFAULT_BASIC_FONT_SIZE);
69 double key = xAxis->pixelToCoord(
event->localPos().x());
70 if (xAxis->range().contains(key))
72 QCPGraph *graph = qobject_cast<QCPGraph *>(plottableAt(
event->pos(),
false));
78 int positionKey = v_graph->findBegin(key);
79 double focusPosition = v_graph->dataMainKey(positionKey);
80 double focusValue = v_graph->dataMainValue(positionKey);
83 i18nc(
"Graphics tooltip; %1 is the Focus Position; %2 is the Focus Value;",
85 "<tr><td>POS: </td><td>%1</td></tr>"
86 "<tr><td>VAL: </td><td>%2</td></tr>"
91 else if (graph == focusPoint)
93 int positionKey = focusPoint->findBegin(key);
94 double focusPosition = focusPoint->dataMainKey(positionKey);
95 double focusValue = focusPoint->dataMainValue(positionKey);
98 i18nc(
"Graphics tooltip; %1 is the Minimum Focus Position; %2 is the Focus Value;",
100 "<tr><td>MIN: </td><td>%1</td></tr>"
101 "<tr><td>VAL: </td><td>%2</td></tr>"
111 errorBars =
new QCPErrorBars((
this)->xAxis, (
this)->yAxis);
114void FocusHFRVPlot::drawHFRIndices()
120 errorBars->removeFromLegend();
121 errorBars->setAntialiased(
false);
122 errorBars->setDataPlottable((
this)->v_graph);
123 errorBars->setPen(
QPen(
QColor(180, 180, 180)));
127 for (
int i = 0; i < m_position.size(); ++i)
132 textLabel->position->
setCoords(m_position[i], m_displayValue[i]);
133 if (m_goodPosition[i])
136 textLabel->
setFont(
QFont(
font().family(), (
int) std::round(1.2 * basicFontSize())));
142 textLabel->
setFont(
QFont(
font().family(), (
int) std::round(2 * basicFontSize())));
151 errorBars->setVisible(m_useErrorBars);
153 errorBars->setData(err);
156void FocusHFRVPlot::init(
QString yAxisLabel,
double starUnits,
bool minimum,
bool useWeights,
bool showPosition)
159 m_starUnits = starUnits;
161 m_showPositions = showPosition;
164 m_displayValue.clear();
166 m_goodPosition.clear();
167 polynomialGraph->
data()->clear();
168 focusPoint->
data().clear();
169 m_useErrorBars = useWeights;
170 errorBars->data().clear();
174 m_polynomialGraphIsVisible =
false;
178 FocusHFRVPlot::clearItems();
182void FocusHFRVPlot::drawHFRPlot(
double currentValue,
int pulseDuration)
186 FocusHFRVPlot::clearItems();
188 v_graph->
setData(m_position, m_displayValue);
191 double currentDisplayValue = getDisplayValue(currentValue);
193 if (minValue > currentDisplayValue || minValue < 0.0)
194 minValue = currentDisplayValue;
195 if (maxValue < currentDisplayValue)
196 maxValue = currentDisplayValue;
198 double minVal = currentDisplayValue / 2.5;
199 if (m_displayValue.size() > 0)
200 minVal = std::min(minValue, *std::min_element(m_displayValue.begin(), m_displayValue.end()));
205 const double minPosition = m_position.empty() ?
206 0 : *std::min_element(m_position.constBegin(), m_position.constEnd());
207 const double maxPosition = m_position.empty() ?
208 1e6 : *std::max_element(m_position.constBegin(), m_position.constEnd());
209 xAxis->
setRange(minPosition - pulseDuration, maxPosition + pulseDuration);
217 if (m_displayValue.size() == 1)
223 m_Minimum ? upper = 1.5 * maxValue : upper = 1.2 * maxValue;
229void FocusHFRVPlot::addPosition(
double pos,
double newValue,
double sigma,
bool outlier,
int pulseDuration,
bool plot)
231 m_position.append(
pos);
232 m_value.append(newValue);
233 m_displayValue.append(getDisplayValue(newValue));
234 m_sigma.append(sigma);
235 outlier ? m_goodPosition.append(
false) : m_goodPosition.append(
true);
238 drawHFRPlot(newValue, pulseDuration);
241void FocusHFRVPlot::setTitle(
const QString &title,
bool plot)
256void FocusHFRVPlot::finalUpdates(
const QString &title,
bool plot)
259 if (plotTitle !=
nullptr)
265void FocusHFRVPlot::setSolutionVShape(
bool isVShape)
267 m_isVShape = isVShape;
280 focusPoint->
data().clear();
283 polynomialGraph->
setPen(pen);
286void FocusHFRVPlot::clearItems()
294void FocusHFRVPlot::drawMinimum(
double solutionPosition,
double solutionValue,
bool plot)
296 focusPoint->
data()->clear();
299 if (solutionPosition < 0)
302 double displayValue = getDisplayValue(solutionValue);
303 minValue = std::min(minValue, displayValue);
304 maxValue = std::max(maxValue, displayValue);
306 focusPoint->
addData(solutionPosition, displayValue);
313 textLabel->
setFont(
QFont(
font().family(), (
int) std::round(0.8 * basicFontSize())));
317 textLabel->position->
setCoords(solutionPosition, (maxValue + 2 * displayValue) / 3);
319 textLabel->position->
setCoords(solutionPosition, (2 * displayValue + minValue) / 3);
323void FocusHFRVPlot::drawCFZ(
double solutionPosition,
double solutionValue,
int cfzSteps,
bool plot)
326 if (solutionPosition < 0 || solutionValue < 0)
344 y = (7 * minValue - maxValue) / 6;
346 y = (maxValue + 2 * minValue) / 3;
348 CFZ->left->
setCoords(solutionPosition + cfzSteps / 2.0,
y);
349 CFZ->right->
setCoords(solutionPosition - cfzSteps / 2.0,
y);
358void FocusHFRVPlot::drawPolynomial(Ekos::PolynomialFit *polyFit,
bool isVShape,
bool makeVisible,
bool plot)
360 if (polyFit ==
nullptr)
365 m_polynomialGraphIsVisible =
true;
366 else if (m_polynomialGraphIsVisible ==
false)
369 setSolutionVShape(isVShape);
370 if (polynomialGraph !=
nullptr)
372 polynomialGraph->
data()->clear();
374 double interval = range.
size() / 20.0;
376 for(
double x = range.lower ;
x < range.upper ;
x += interval)
378 double y = getDisplayValue(polyFit->f(
x));
385void FocusHFRVPlot::drawCurve(Ekos::CurveFitting *curveFit,
bool isVShape,
bool makeVisible,
bool plot)
387 if (curveFit ==
nullptr)
392 m_polynomialGraphIsVisible =
true;
393 else if (!makeVisible || !m_polynomialGraphIsVisible)
396 setSolutionVShape(isVShape);
397 if (polynomialGraph !=
nullptr)
399 polynomialGraph->
data()->clear();
401 double interval = range.
size() / 20.0;
403 for(
double x = range.lower ;
x < range.upper ;
x += interval)
405 double y = getDisplayValue(curveFit->f(
x));
412void FocusHFRVPlot::redraw(Ekos::PolynomialFit *polyFit,
double solutionPosition,
double solutionValue)
414 if (m_value.empty() ==
false)
415 drawHFRPlot(m_value.last(), 0);
417 drawPolynomial(polyFit, m_isVShape,
false);
418 drawMinimum(solutionPosition, solutionValue);
421void FocusHFRVPlot::redrawCurve(Ekos::CurveFitting *curveFit,
double solutionPosition,
double solutionValue)
423 if (m_value.empty() ==
false)
424 drawHFRPlot(solutionValue, 0);
426 drawCurve(curveFit, m_isVShape,
false);
427 drawMinimum(solutionPosition, solutionValue);
430void FocusHFRVPlot::setBasicFontSize(
int basicFontSize)
432 m_basicFontSize = basicFontSize;
442double FocusHFRVPlot::getDisplayValue(
const double value)
444 return value * m_starUnits;
void setPen(const QPen &pen)
void setTickLabelFont(const QFont &font)
void setLabel(const QString &str)
void setLabelFont(const QFont &font)
Q_SLOT void setRange(const QCPRange &range)
A plottable that adds a set of error bars to other plottables.
A plottable representing a graph in a plot.
QSharedPointer< QCPGraphDataContainer > data() const
void setData(QSharedPointer< QCPGraphDataContainer > data)
@ lsLine
data points are connected by a straight line
@ lsImpulse
each data point is represented by a line parallel to the value axis, which reaches from the data poin...
@ lsNone
data points are not connected with any lines (e.g.
void addData(const QVector< double > &keys, const QVector< double > &values, bool alreadySorted=false)
A bracket for referencing/highlighting certain parts in the plot.
void setPen(const QPen &pen)
void setLength(double length)
void setType(PositionType type)
void setCoords(double key, double value)
@ ptAxisRectRatio
Static positioning given by a fraction of the axis rect size (see setAxisRect).
@ ptPlotCoords
Dynamic positioning at a plot coordinate defined by two axes (see setAxes).
void setBrush(const QBrush &brush)
void setText(const QString &text)
void setPositionAlignment(Qt::Alignment alignment)
void setFont(const QFont &font)
void setPen(const QPen &pen)
void setColor(const QColor &color)
void setPadding(const QMargins &padding)
void setAntialiased(bool enabled)
Represents the range an axis is encompassing.
Represents the visual appearance of scatter points.
@ ssCircle
\enumimage{ssCircle.png} a circle
@ ssNone
no scatter symbols are drawn (e.g. in QCPGraph, data only represented with lines)
The central class of the library. This is the QWidget which displays the plot and interacts with the ...
void mouseMove(QMouseEvent *event)
Q_SLOT void replot(QCustomPlot::RefreshPriority refreshPriority=QCustomPlot::rpRefreshHint)
QString i18nc(const char *context, const char *text, const TYPE &arg...)
QString i18n(const char *text, const TYPE &arg...)
AKONADI_CALENDAR_EXPORT KCalendarCore::Event::Ptr event(const Akonadi::Item &item)
@ iRangeDrag
0x001 Axis ranges are draggable (see QCPAxisRect::setRangeDrag, QCPAxisRect::setRangeDragAxes)
@ iRangeZoom
0x002 Axis ranges are zoomable with the mouse wheel (see QCPAxisRect::setRangeZoom,...
void push_front(parameter_type value)
void setColor(const QColor &color)
QString number(double n, char format, int precision)
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
void showText(const QPoint &pos, const QString &text, QWidget *w, const QRect &rect, int msecDisplayTime)