// SPDX-FileCopyrightText: 2025 Filip Leonarski, Paul Scherrer Institute // SPDX-License-Identifier: GPL-3.0-only #pragma once #include #include #include #include #include #include #include #include #include #include #ifdef JFJOCH_USE_FFTW #include #endif #include "../../common/GoniometerAxis.h" #include "../../reader/JFJochReaderDataset.h" class JFJochDatasetInfoChartView : public QChartView { Q_OBJECT QPointer series = nullptr; QPointer currentSeries = nullptr; QGraphicsLineItem *m_hoverLine = nullptr; // vertical crosshair, at the hovered x QGraphicsLineItem *m_hoverLineHorizontal = nullptr; // horizontal crosshair, at the hovered y QTimer *m_hoverLoadTimer = nullptr; int64_t m_hoverPendingIdx = -1; std::vector values; QString primaryName_; // legend name of the active (primary) run int64_t binning = 1; int64_t curr_image = 0; bool m_minYZeroEnabled = true; bool m_yOneOverD = false; bool m_xUseGoniometerAxis = true; // Compact mode: this view is one of two stacked half-height plots. The y axis is reduced to // its two range ends, named by a short bold coloured label; the upper plot hides its x labels // (the lower one carries them for both). QString compact_label_; bool compact_hide_x_ = false; int compact_y_label_px_ = 0; // width of this plot's own widest y label int compact_y_pad_px_ = 0; // y label width to pad out to (0 = no padding) int compact_min_h_ = 0; // height this plot needs for its own y-axis title int compact_title_w_ = 0; // width of that title, reserved in the left margin // The y-axis name, painted upright (one letter per line) in place of Qt's rotated axis title. QGraphicsSimpleTextItem *compact_title_ = nullptr; // The other plot of a stacked pair. Both are padded out to the wider of the two y labels, so // both curves start at the same x. QPointer compact_peer_; void applyCompactMargins(); void pairCompactYLabels(); void updateCompactTitle(const QFont &title_font); void placeCompactTitle(); // Place the horizontal crosshair at y (scene coords), snapping to snap_to_y when the cursor is // already within a few pixels of the curve. A non-finite snap_to_y never snaps. void setHoverLineY(double y, double snap_to_y); std::optional goniometer_axis; std::optional image_time_s; void updateChart(); // Build regular (index or goniometer) chart void buildTimeDomainChart(); public: // One overlay line (a non-active run), drawn alongside the primary series with a legend entry. // x maps each value to an image number on the shared x-axis (empty => 0,1,2,... by index). struct NamedSeries { QString name; std::vector values; QColor color; std::vector x; }; private: std::vector overlays_; QColor primary_color_; // colour of the active (primary) run, if assigned std::vector primary_x_; // x (image numbers) for the primary series; empty => index int64_t full_range_ = 0; // total images in the dataset; fixes the x-axis to [0, n) // Append (binned) finite points of vals to s at x positions (xs empty => index), extending [mn,mx]. void appendSeries(QLineSeries *s, const std::vector &vals, const std::vector &xs, double &mn, double &mx) const; // FFT view toggle bool m_showFFT = false; #ifdef JFJOCH_USE_FFTW // Cached FFT data for hover/status bar etc. void buildFFTChart(); std::vector m_fftMagnitudes; std::vector m_fftFrequenciesHz; #endif signals: void imageSelected(int64_t number); void writeStatusBar(QString string, int timeout_ms = 0); private slots: void onHoverLoadTimeout(); void setBinning(int64_t val); private: void changeEvent(QEvent *event) override; void mousePressEvent(QMouseEvent *event) override; void mouseMoveEvent(QMouseEvent *event) override; void leaveEvent(QEvent *event) override; void contextMenuEvent(QContextMenuEvent *event) override; public: explicit JFJochDatasetInfoChartView(QWidget *parent = nullptr); void setImage(int64_t val); // An empty label switches compact mode off. Takes effect on the next loadValues(). void SetCompact(const QString &axis_label, bool hide_x_labels); // The other plot of a stacked pair; set once on both, it keeps their y labels the same width. void SetCompactPeer(JFJochDatasetInfoChartView *peer) { compact_peer_ = peer; } // Whether the y axis starts at zero. On by default: a spot count is read against zero, while a // background level is not, and a plot of it this short needs the whole height for its shape. void SetMinYZero(bool val) { m_minYZeroEnabled = val; } public slots: void resetZoom(); public: // Load the primary (active) run's values plus any overlay runs. one_over_d2 applies the same // d -> 1/d^2 transform to every series; primaryName/overlay names drive the legend. void loadValues(const std::vector &input, int64_t image, bool one_over_d2, const JFJochReaderDataset *dataset = nullptr, const QString &primaryName = QString(), std::vector overlays = {}, const QColor &primaryColor = QColor(), std::vector primaryX = {}, int64_t fullRange = 0); };