All checks were successful
Build Packages / build:rpm (ubuntu2404_nocuda) (push) Successful in 11m48s
Build Packages / build:rpm (rocky8_nocuda) (push) Successful in 12m18s
Build Packages / build:rpm (ubuntu2204_nocuda) (push) Successful in 12m18s
Build Packages / build:rpm (rocky8) (push) Successful in 11m43s
Build Packages / build:rpm (rocky8_sls9) (push) Successful in 12m31s
Build Packages / Unit tests (push) Has been skipped
Build Packages / Generate python client (push) Successful in 17s
Build Packages / Create release (push) Has been skipped
Build Packages / build:rpm (rocky9_nocuda) (push) Successful in 13m2s
Build Packages / Build documentation (push) Successful in 37s
Build Packages / build:rpm (rocky9) (push) Successful in 9m45s
Build Packages / build:rpm (ubuntu2404) (push) Successful in 6m35s
Build Packages / build:rpm (ubuntu2204) (push) Successful in 7m8s
This is an UNSTABLE release. * jfjoch_viewer: Auto load is better handling change of states * jfjoch_viewer: Fix DBus registration * jfjoch_viewer: Handle charts better with vertical lines on hover and status bar update * jfjoch_viewer: Calculate ROI in a more efficient way Reviewed-on: #6 Co-authored-by: Filip Leonarski <filip.leonarski@psi.ch> Co-committed-by: Filip Leonarski <filip.leonarski@psi.ch>
88 lines
2.7 KiB
C++
88 lines
2.7 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;
|
|
|
|
// Remove hover line if any
|
|
if (m_hoverLine) {
|
|
chart()->scene()->removeItem(m_hoverLine);
|
|
delete m_hoverLine;
|
|
m_hoverLine = nullptr;
|
|
}
|
|
m_series = nullptr;
|
|
|
|
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);
|
|
m_series = 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);
|
|
}
|
|
|
|
QString JFJochOneOverResSqChartView::getText(size_t idx) {
|
|
if (idx < x.size() && x[idx] > 0)
|
|
return QString("d = %1 Å, y = %2")
|
|
.arg(1 / sqrt(x[idx]), 0, 'g', 4)
|
|
.arg(y[idx], 0, 'g', 6);
|
|
return QString();
|
|
}
|
|
|