8#include "focushfrvplot.h"
15#define DEFAULT_BASIC_FONT_SIZE 10
43 yAxis->setLabel(
i18n(
"Value"));
48 polynomialGraph = addGraph();
57 focusPoint = addGraph();
63 if (parent !=
nullptr)
64 setBasicFontSize(parent->
font().pointSize());
66 setBasicFontSize(DEFAULT_BASIC_FONT_SIZE);
70 double key = xAxis->pixelToCoord(
event->localPos().x());
71 if (xAxis->range().contains(key))
73 QCPGraph *graph = qobject_cast<QCPGraph *>(plottableAt(
event->pos(),
false));
79 int positionKey = v_graph->findBegin(key);
80 double focusPosition = v_graph->dataMainKey(positionKey);
81 double focusValue = v_graph->dataMainValue(positionKey);
84 i18nc(
"Graphics tooltip; %1 is the Focus Position; %2 is the Focus Value;",
86 "<tr><td>POS: </td><td>%1</td></tr>"
87 "<tr><td>VAL: </td><td>%2</td></tr>"
92 else if (graph == focusPoint)
94 int positionKey = focusPoint->findBegin(key);
95 double focusPosition = focusPoint->dataMainKey(positionKey);
96 double focusValue = focusPoint->dataMainValue(positionKey);
99 i18nc(
"Graphics tooltip; %1 is the Minimum Focus Position; %2 is the Focus Value;",
101 "<tr><td>MIN: </td><td>%1</td></tr>"
102 "<tr><td>VAL: </td><td>%2</td></tr>"
112 errorBars =
new QCPErrorBars((
this)->xAxis, (
this)->yAxis);
115void FocusHFRVPlot::drawHFRIndices()
121 errorBars->removeFromLegend();
122 errorBars->setAntialiased(
false);
123 errorBars->setDataPlottable((
this)->v_graph);
124 errorBars->setPen(
QPen(
QColor(180, 180, 180)));
128 for (
int i = 0; i < m_position.size(); ++i)
133 textLabel->position->
setCoords(m_position[i], m_displayValue[i]);
134 if (m_goodPosition[i])
137 textLabel->
setFont(
QFont(
font().family(), (
int) std::round(1.2 * basicFontSize())));
143 textLabel->
setFont(
QFont(
font().family(), (
int) std::round(2 * basicFontSize())));
152 errorBars->setVisible(m_useErrorBars);
154 errorBars->setData(err);
157void FocusHFRVPlot::init(
QString yAxisLabel,
double starUnits,
bool minimum,
bool useWeights,
bool showPosition)
160 m_starUnits = starUnits;
162 m_showPositions = showPosition;
165 m_displayValue.clear();
167 m_goodPosition.clear();
168 polynomialGraph->
data()->clear();
169 focusPoint->
data().clear();
170 m_useErrorBars = useWeights;
171 errorBars->data().clear();
175 m_polynomialGraphIsVisible =
false;
179 FocusHFRVPlot::clearItems();
183void FocusHFRVPlot::drawHFRPlot(
double currentValue,
int pulseDuration)
187 FocusHFRVPlot::clearItems();
189 v_graph->
setData(m_position, m_displayValue);
192 double currentDisplayValue = getDisplayValue(currentValue);
194 if (minValue > currentDisplayValue || minValue < 0.0)
195 minValue = currentDisplayValue;
196 if (maxValue < currentDisplayValue)
197 maxValue = currentDisplayValue;
199 double minVal = currentDisplayValue / 2.5;
200 if (m_displayValue.size() > 0)
201 minVal = std::min(minValue, *std::min_element(m_displayValue.begin(), m_displayValue.end()));
206 const double minPosition = m_position.empty() ?
207 0 : *std::min_element(m_position.constBegin(), m_position.constEnd());
208 const double maxPosition = m_position.empty() ?
209 1e6 : *std::max_element(m_position.constBegin(), m_position.constEnd());
210 xAxis->
setRange(minPosition - pulseDuration, maxPosition + pulseDuration);
218 if (m_displayValue.size() == 1)
224 m_Minimum ? upper = 1.5 * maxValue : upper = 1.2 * maxValue;
230void FocusHFRVPlot::addPosition(
double pos,
double newValue,
double sigma,
bool outlier,
int pulseDuration,
bool plot)
232 m_position.append(
pos);
233 m_value.append(newValue);
234 m_displayValue.append(getDisplayValue(newValue));
235 m_sigma.append(sigma);
236 outlier ? m_goodPosition.append(
false) : m_goodPosition.append(
true);
239 drawHFRPlot(newValue, pulseDuration);
242void FocusHFRVPlot::setTitle(
const QString &title,
bool plot)
257QString FocusHFRVPlot::title()
const
260 return plotTitle->text();
264void FocusHFRVPlot::finalUpdates(
const QString &title,
bool plot)
267 if (plotTitle !=
nullptr)
273void FocusHFRVPlot::setSolutionVShape(
bool isVShape)
275 m_isVShape = isVShape;
288 focusPoint->
data().clear();
291 polynomialGraph->
setPen(pen);
294void FocusHFRVPlot::clearItems()
302void FocusHFRVPlot::drawMinimum(
double solutionPosition,
double solutionValue,
bool plot)
304 focusPoint->
data()->clear();
307 if (solutionPosition < 0)
310 double displayValue = getDisplayValue(solutionValue);
311 minValue = std::min(minValue, displayValue);
312 maxValue = std::max(maxValue, displayValue);
314 focusPoint->
addData(solutionPosition, displayValue);
321 textLabel->
setFont(
QFont(
font().family(), (
int) std::round(0.8 * basicFontSize())));
325 textLabel->position->
setCoords(solutionPosition, (maxValue + 2 * displayValue) / 3);
327 textLabel->position->
setCoords(solutionPosition, (2 * displayValue + minValue) / 3);
331void FocusHFRVPlot::drawCFZ(
double solutionPosition,
double solutionValue,
int cfzSteps,
bool plot)
334 if (solutionPosition < 0 || solutionValue < 0)
352 y = (7 * minValue - maxValue) / 6;
354 y = (maxValue + 2 * minValue) / 3;
356 CFZ->left->
setCoords(solutionPosition + cfzSteps / 2.0,
y);
357 CFZ->right->
setCoords(solutionPosition - cfzSteps / 2.0,
y);
366void FocusHFRVPlot::drawPolynomial(Ekos::PolynomialFit *polyFit,
bool isVShape,
bool makeVisible,
bool plot)
368 if (polyFit ==
nullptr)
373 m_polynomialGraphIsVisible =
true;
374 else if (m_polynomialGraphIsVisible ==
false)
377 setSolutionVShape(isVShape);
378 if (polynomialGraph !=
nullptr)
380 polynomialGraph->
data()->clear();
382 double interval = range.
size() / 20.0;
384 for(
double x = range.lower ;
x < range.upper ;
x += interval)
386 double y = getDisplayValue(polyFit->f(
x));
393void FocusHFRVPlot::drawCurve(Ekos::CurveFitting *curveFit,
bool isVShape,
bool makeVisible,
bool plot)
395 if (curveFit ==
nullptr)
400 m_polynomialGraphIsVisible =
true;
401 else if (!makeVisible || !m_polynomialGraphIsVisible)
404 setSolutionVShape(isVShape);
405 if (polynomialGraph !=
nullptr)
407 polynomialGraph->
data()->clear();
409 double interval = range.
size() / 20.0;
411 for(
double x = range.lower ;
x < range.upper ;
x += interval)
413 double y = getDisplayValue(curveFit->f(
x));
420void FocusHFRVPlot::redraw(Ekos::PolynomialFit *polyFit,
double solutionPosition,
double solutionValue)
422 if (m_value.empty() ==
false)
423 drawHFRPlot(m_value.last(), 0);
425 drawPolynomial(polyFit, m_isVShape,
false);
426 drawMinimum(solutionPosition, solutionValue);
429void FocusHFRVPlot::redrawCurve(Ekos::CurveFitting *curveFit,
double solutionPosition,
double solutionValue)
431 if (m_value.empty() ==
false)
432 drawHFRPlot(solutionValue, 0);
434 drawCurve(curveFit, m_isVShape,
false);
435 drawMinimum(solutionPosition, solutionValue);
438void FocusHFRVPlot::setBasicFontSize(
int basicFontSize)
440 m_basicFontSize = basicFontSize;
450double FocusHFRVPlot::getDisplayValue(
const double value)
452 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)