68 lines
2.3 KiB
C++
68 lines
2.3 KiB
C++
// SPDX-FileCopyrightText: 2025 Filip Leonarski, Paul Scherrer Institute <filip.leonarski@psi.ch>
|
|
// SPDX-License-Identifier: GPL-3.0-only
|
|
|
|
#include "JFJochOneOverResSqChartView.h"
|
|
|
|
#include <QMenu>
|
|
#include <QClipboard>
|
|
#include <QApplication>
|
|
#include <QCategoryAxis>
|
|
|
|
JFJochOneOverResSqChartView::JFJochOneOverResSqChartView (QWidget *parent)
|
|
: JFJochSimpleChartView(parent) {}
|
|
|
|
void JFJochOneOverResSqChartView::UpdateData(const std::vector<float> &in_x, const std::vector<float> &in_y,
|
|
QString legend_x, QString legend_y) {
|
|
x = in_x; y = in_y;
|
|
chart()->removeAllSeries();
|
|
// Remove all axes to avoid duplicates
|
|
for (auto ax : chart()->axes()) chart()->removeAxis(ax);
|
|
|
|
if (x.empty() || x.size() != y.size()) return;
|
|
|
|
float max_y = *std::max_element(y.begin(), y.end());
|
|
if (max_y <= 0) return;
|
|
|
|
auto* series = new QLineSeries(this);
|
|
for (size_t i = 0; i < x.size(); ++i) series->append(x[i], y[i]);
|
|
chart()->addSeries(series);
|
|
|
|
auto* axY = new QValueAxis();
|
|
axY->setTitleText(legend_y);
|
|
|
|
axY->setRange(0, 1.05 * max_y);
|
|
chart()->addAxis(axY, Qt::AlignLeft);
|
|
series->attachAxis(axY);
|
|
|
|
// Build X range
|
|
const float xmin = x[0], xmax = x[x.size() - 1];
|
|
|
|
// Hidden X value axis on top for grid/range
|
|
auto *axXTop = new QValueAxis();
|
|
axXTop->setRange(xmin, xmax);
|
|
axXTop->setTickCount(5);
|
|
axXTop->setLabelsVisible(false);
|
|
chart()->addAxis(axXTop, Qt::AlignTop);
|
|
series->attachAxis(axXTop);
|
|
|
|
// Visible category axis at bottom for 1/x labels
|
|
auto *axXcat = new QCategoryAxis();
|
|
axXcat->setLabelsPosition(QCategoryAxis::AxisLabelsPositionOnValue);
|
|
axXcat->setGridLineVisible(false);
|
|
axXcat->setMinorGridLineVisible(false);
|
|
|
|
axXcat->setTitleText(legend_x);
|
|
|
|
const int tickCount = axXTop->tickCount();
|
|
const double step = (tickCount > 1) ? (xmax - xmin) / (tickCount - 1) : 0.0;
|
|
for (int i = 0; i < tickCount; ++i) {
|
|
const double xv = xmin + i * step;
|
|
const QString lab = (std::abs(xv) < 1e-12)
|
|
? QStringLiteral("∞")
|
|
: QString::number(1.0 / sqrtf(xv), 'f', 2);
|
|
axXcat->append(lab, xv);
|
|
}
|
|
chart()->addAxis(axXcat, Qt::AlignBottom);
|
|
series->attachAxis(axXcat);
|
|
}
|