7#include "aberrationinspectorplot.h"
14#define DEFAULT_BASIC_FONT_SIZE 10
16AberrationInspectorPlot::AberrationInspectorPlot(
QWidget *parent) :
QCustomPlot (parent)
56 this->setAutoAddPlottableToLegend(
true);
57 for (
int i = 0; i < NUM_TILES; i++)
59 m_graph[i] = addGraph();
62 m_graph[i]->setScatterStyle(shapes[i]);
63 m_graph[i]->setName(TILE_NAME[i]);
66 m_legendItems[i] = this->legend->item(i);
69 this->setAutoAddPlottableToLegend(
false);
70 for (
int i = 0; i < NUM_TILES; i++)
73 focusPoint[i] = addGraph();
76 focusPoint[i]->setScatterStyle(
QCPScatterStyle(shapes[i], TILE_COLOUR[i], TILE_COLOUR[i], 10));
80 if (parent !=
nullptr)
81 setBasicFontSize(parent->
font().pointSize());
83 setBasicFontSize(DEFAULT_BASIC_FONT_SIZE);
87 double key = xAxis->pixelToCoord(
event->localPos().x());
88 if (xAxis->range().contains(key))
90 QCPGraph *graph = qobject_cast<QCPGraph *>(plottableAt(
event->pos(),
false));
94 for (
int i = 0; i < NUM_TILES; i++)
96 if (graph == focusPoint[i])
98 if (focusPoint[i]->visible())
100 int positionKey = focusPoint[i]->findBegin(key);
101 double focusPosition = focusPoint[i]->dataMainKey(positionKey);
102 double focusMeasure = focusPoint[i]->dataMainValue(positionKey);
105 i18nc(
"Graphics tooltip; %2 is tile code; %3 is tile name, %4 is Focus Position; %5 is Focus Measure;",
106 "<style>table { background-color: white;}</style>"
107 "<font color='%1'><table>"
108 "<tr><td>Tile: </td><td>%2 (%3)</td></tr>"
109 "<tr><td>Pos: </td><td>%4</td></tr>"
110 "<tr><td>Val: </td><td>%5</td></tr>"
113 TILE_NAME[i], TILE_LONGNAME[i],
125void AberrationInspectorPlot::init(
QString yAxisLabel,
double starUnits,
bool useWeights,
bool showLabels,
bool showCFZ)
127 Q_UNUSED(useWeights);
129 yAxis->setLabel(yAxisLabel);
130 m_starUnits = starUnits;
131 m_showLabels = showLabels;
133 for (
int i = 0; i < NUM_TILES; i++)
135 m_graph[i]->data()->clear();
136 focusPoint[i]->data().clear();
140 this->legend->setVisible(
true);
143void AberrationInspectorPlot::setAxes(
const int tile)
148 const double xborder = (m_maxPosition - m_minPosition) / 10.0;
149 xAxis->setRange(m_minPosition - xborder, m_maxPosition + xborder);
151 const double yborder = (m_maxMeasure - m_minMeasure) / 10.0;
152 yAxis->setRange(m_minMeasure - yborder, m_maxMeasure + yborder);
158 if (m_positions.empty())
161 m_minPosition = *std::min_element(m_positions.constBegin(), m_positions.constEnd());
162 m_maxPosition = *std::max_element(m_positions.constBegin(), m_positions.constEnd());
163 const double border = (m_maxPosition - m_minPosition) / 10.0;
164 xAxis->setRange(m_minPosition - border, m_maxPosition + border);
168 if (m_measures[tile].empty())
173 m_minMeasure = *std::min_element(m_measures[tile].constBegin(), m_measures[tile].constEnd());
174 m_maxMeasure = *std::max_element(m_measures[tile].constBegin(), m_measures[tile].constEnd());
178 m_minMeasure = std::min(m_minMeasure, *std::min_element(m_measures[tile].constBegin(), m_measures[tile].constEnd()));
179 m_maxMeasure = std::max(m_maxMeasure, *std::max_element(m_measures[tile].constBegin(), m_measures[tile].constEnd()));
181 const double border = (m_maxMeasure - m_minMeasure) / 10.0;
182 yAxis->setRange(m_minMeasure - border, m_maxMeasure + border);
190 if (m_positions.count() == 0)
191 m_positions.append(positions);
195 for (
int i = 0; i < measures.
count(); i++)
196 displayMeasures.
push_back(getDisplayMeasure(measures[i]));
197 m_measures.append(displayMeasures);
199 setAxes(m_measures.count() - 1);
202void AberrationInspectorPlot::drawMaxMin(
int tile,
double solutionPosition,
double solutionMeasure)
205 if (solutionPosition <= 0)
208 double displayMeasure = getDisplayMeasure(solutionMeasure);
209 m_minMeasure = std::min(m_minMeasure, displayMeasure);
210 m_maxMeasure = std::max(m_maxMeasure, displayMeasure);
212 focusPoint[tile]->addData(solutionPosition, displayMeasure);
215 m_labelItems[tile]->setColor(TILE_COLOUR[tile]);
218 m_labelItems[tile]->setFont(
QFont(font().family(), (
int) std::round(0.8 * basicFontSize())));
220 m_labelItems[tile]->setText(
QString::number(solutionPosition,
'f', 0));
221 m_labelItems[tile]->position->setCoords(solutionPosition, displayMeasure * 0.8);
222 m_labelItems[tile]->setVisible(m_showLabels);
225void AberrationInspectorPlot::drawCFZ(
double solutionPosition,
double solutionMeasure,
int cfzSteps)
228 if (solutionPosition <= 0 || solutionMeasure <= 0)
237 double y = m_minMeasure * 0.95;
239 m_CFZ->left->setCoords(solutionPosition + cfzSteps / 2.0, y);
240 m_CFZ->right->setCoords(solutionPosition - cfzSteps / 2.0, y);
241 m_CFZ->setLength(15);
242 m_CFZ->setAntialiased(
false);
244 m_CFZ->setVisible(m_showCFZ);
247void AberrationInspectorPlot::setShowCFZ(
bool setting)
251 m_CFZ->setVisible(setting);
254void AberrationInspectorPlot::setShowLabels(
bool setting)
256 m_showLabels = setting;
257 for (
int tile = 0; tile < NUM_TILES; tile++)
259 if (m_labelItems[tile])
260 m_labelItems[tile]->setVisible(setting);
264void AberrationInspectorPlot::drawCurve(
int tile, Ekos::CurveFitting *curveFit,
int maxmin,
double measure,
bool fit,
270 if (curveFit ==
nullptr)
277 m_minPosition = std::min(m_minPosition, maxmin);
278 m_maxPosition = std::max(m_maxPosition, maxmin);
279 m_minMeasure = std::min(m_minMeasure, measure);
280 m_maxMeasure = std::max(m_maxMeasure, measure);
283 if (m_graph[tile] !=
nullptr)
285 m_graph[tile]->data()->clear();
287 double interval = range.
size() / 40.0;
289 for(
double x = range.lower; x < range.upper; x += interval)
291 double y = getDisplayMeasure(curveFit->f(x));
292 m_graph[tile]->addData(x, y);
298void AberrationInspectorPlot::redrawCurve(
bool useTile[NUM_TILES])
300 for (
int i = 0; i < NUM_TILES; i++)
304 m_graph[i]->setVisible(useTile[i]);
307 this->legend->item(i)->setVisible(useTile[i]);
311 focusPoint[i]->setVisible(useTile[i]);
313 m_labelItems[i]->setVisible(useTile[i] && m_showLabels);
317void AberrationInspectorPlot::setBasicFontSize(
int basicFontSize)
319 m_basicFontSize = basicFontSize;
322 yAxis->setLabelFont(
QFont(font().family(), basicFontSize));
323 xAxis->setTickLabelFont(
QFont(font().family(), (
int) std::round(0.9 * basicFontSize)));
324 yAxis->setTickLabelFont(
QFont(font().family(), (
int) std::round(0.9 * basicFontSize)));
329double AberrationInspectorPlot::getDisplayMeasure(
const double measure)
331 return measure * m_starUnits;
A plottable representing a graph in a plot.
@ 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...
A bracket for referencing/highlighting certain parts in the plot.
@ ptPlotCoords
Dynamic positioning at a plot coordinate defined by two axes (see setAxes).
Represents the range an axis is encompassing.
Represents the visual appearance of scatter points.
@ ssSquare
\enumimage{ssSquare.png} a square
@ ssDisc
\enumimage{ssDisc.png} a circle which is filled with the pen's color (not the brush as with ssCircle)
@ ssPlus
\enumimage{ssPlus.png} a plus
@ ssDiamond
\enumimage{ssDiamond.png} a diamond
@ ssStar
\enumimage{ssStar.png} a star with eight arms, i.e. a combination of cross and plus
@ ssTriangleInverted
\enumimage{ssTriangleInverted.png} an equilateral triangle, standing on corner
@ ssTriangle
\enumimage{ssTriangle.png} an equilateral triangle, standing on baseline
@ ssCircle
\enumimage{ssCircle.png} a circle
@ ssCross
\enumimage{ssCross.png} a cross
The central class of the library. This is the QWidget which displays the plot and interacts with the ...
void mouseMove(QMouseEvent *event)
QString i18nc(const char *context, const char *text, const TYPE &arg...)
AKONADI_CALENDAR_EXPORT KCalendarCore::Event::Ptr event(const Akonadi::Item &item)
Ekos is an advanced Astrophotography tool for Linux.
@ iRangeDrag
0x001 Axis ranges are draggable (see QCPAxisRect::setRangeDrag, QCPAxisRect::setRangeDragAxes)
@ iRangeZoom
0x002 Axis ranges are zoomable with the mouse wheel (see QCPAxisRect::setRangeZoom,...
qsizetype count() const const
void push_back(parameter_type value)
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)