v1.0.0-rc.101 (#6)
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
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>
This commit was merged in pull request #6.
This commit is contained in:
@@ -13,6 +13,7 @@ JFJochSimpleChartView::JFJochSimpleChartView(QWidget *parent)
|
||||
chart()->legend()->hide();
|
||||
setFixedHeight(300);
|
||||
setRenderHint(QPainter::Antialiasing);
|
||||
setMouseTracking(true);
|
||||
//setRubberBand(QChartView::RubberBand::HorizontalRubberBand);
|
||||
}
|
||||
|
||||
@@ -20,6 +21,15 @@ void JFJochSimpleChartView::UpdateData(const std::vector<float> &in_x, const std
|
||||
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);
|
||||
@@ -29,6 +39,7 @@ void JFJochSimpleChartView::UpdateData(const std::vector<float> &in_x, const std
|
||||
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);
|
||||
@@ -45,10 +56,17 @@ void JFJochSimpleChartView::UpdateData(const std::vector<float> &in_x, const std
|
||||
axX->setTitleText(legend_x);
|
||||
chart()->addAxis(axX, Qt::AlignBottom);
|
||||
series->attachAxis(axX);
|
||||
|
||||
}
|
||||
|
||||
void JFJochSimpleChartView::ClearData() {
|
||||
x.clear();
|
||||
y.clear();
|
||||
m_series = nullptr;
|
||||
if (m_hoverLine) {
|
||||
chart()->scene()->removeItem(m_hoverLine);
|
||||
delete m_hoverLine;
|
||||
m_hoverLine = nullptr;
|
||||
}
|
||||
chart()->removeAllSeries();
|
||||
}
|
||||
|
||||
@@ -71,3 +89,64 @@ void JFJochSimpleChartView::contextMenuEvent(QContextMenuEvent *event) {
|
||||
cb->setText(out);
|
||||
}
|
||||
}
|
||||
|
||||
void JFJochSimpleChartView::mouseMoveEvent(QMouseEvent *event) {
|
||||
QChartView::mouseMoveEvent(event);
|
||||
if (!m_series || x.empty() || x.size() != y.size())
|
||||
return;
|
||||
|
||||
// Map mouse position to chart coordinates
|
||||
const QPointF chartPos = chart()->mapToValue(event->pos(), m_series);
|
||||
const double xVal = chartPos.x();
|
||||
|
||||
// Find closest index in x[]
|
||||
auto it = std::lower_bound(x.begin(), x.end(), static_cast<float>(xVal));
|
||||
if (it == x.end() && !x.empty())
|
||||
it = std::prev(x.end());
|
||||
if (it == x.end())
|
||||
return;
|
||||
|
||||
size_t idx = static_cast<size_t>(std::distance(x.begin(), it));
|
||||
if (idx > 0) {
|
||||
const float xPrev = x[idx - 1];
|
||||
if (std::abs(xPrev - xVal) < std::abs(x[idx] - xVal))
|
||||
--idx;
|
||||
}
|
||||
|
||||
const float xNearest = x[idx];
|
||||
const float yNearest = y[idx];
|
||||
|
||||
// Map that data point to scene coords to get the x position
|
||||
const QPointF ptOnSeries = chart()->mapToPosition(QPointF(xNearest, yNearest), m_series);
|
||||
const QRectF plotArea = chart()->plotArea();
|
||||
|
||||
if (!m_hoverLine) {
|
||||
m_hoverLine = new QGraphicsLineItem;
|
||||
m_hoverLine->setPen(QPen(QColor(200, 0, 0, 150), 1.0));
|
||||
chart()->scene()->addItem(m_hoverLine);
|
||||
}
|
||||
|
||||
m_hoverLine->setLine(QLineF(ptOnSeries.x(), plotArea.top(),
|
||||
ptOnSeries.x(), plotArea.bottom()));
|
||||
|
||||
// Send to status bar
|
||||
emit writeStatusBar(getText(idx),6000);
|
||||
}
|
||||
|
||||
QString JFJochSimpleChartView::getText(size_t idx) {
|
||||
if (idx < x.size())
|
||||
return QString("x = %1, y = %2")
|
||||
.arg(x[idx], 0, 'g', 6)
|
||||
.arg(y[idx], 0, 'g', 6);
|
||||
return QString();
|
||||
}
|
||||
|
||||
void JFJochSimpleChartView::leaveEvent(QEvent *event) {
|
||||
QChartView::leaveEvent(event);
|
||||
if (m_hoverLine) {
|
||||
chart()->scene()->removeItem(m_hoverLine);
|
||||
delete m_hoverLine;
|
||||
m_hoverLine = nullptr;
|
||||
}
|
||||
emit writeStatusBar(QString(), 0); // clear status bar when leaving
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user