File indexing completed on 2025-01-26 03:34:12

0001 /*
0002     File                 : HistogramPrivate.h
0003     Project              : LabPlot
0004     Description          : Private members of Histogram
0005     --------------------------------------------------------------------
0006     SPDX-FileCopyrightText: 2016 Anu Mittal <anu22mittal@gmail.com>
0007     SPDX-FileCopyrightText: 2018-2022 Alexander Semke <alexander.semke@web.de>
0008     SPDX-License-Identifier: GPL-2.0-or-later
0009 */
0010 
0011 #ifndef HISTOGRAMPRIVATE_H
0012 #define HISTOGRAMPRIVATE_H
0013 
0014 #include "backend/worksheet/plots/cartesian/PlotPrivate.h"
0015 #include <gsl/gsl_histogram.h>
0016 #include <vector>
0017 
0018 class Column;
0019 class Background;
0020 class Line;
0021 class Value;
0022 
0023 class HistogramPrivate : public PlotPrivate {
0024 public:
0025     explicit HistogramPrivate(Histogram* owner);
0026     ~HistogramPrivate() override;
0027 
0028     void retransform() override;
0029     void recalc();
0030     void updateType();
0031     void updateOrientation();
0032     void updateLines();
0033     void verticalHistogram();
0034     void horizontalHistogram();
0035     void updateSymbols();
0036     void updateValues();
0037     void updateFilling();
0038     void updateErrorBars();
0039     void updateRug();
0040     void updatePixmap();
0041     void recalcShapeAndBoundingRect() override;
0042 
0043     double xMinimum() const;
0044     double xMaximum() const;
0045     double yMinimum() const;
0046     double yMaximum() const;
0047 
0048     const AbstractColumn* bins();
0049     const AbstractColumn* binValues();
0050     const AbstractColumn* binPDValues();
0051 
0052     double getMaximumOccuranceofHistogram() const;
0053 
0054     // General
0055     const AbstractColumn* dataColumn{nullptr};
0056     QString dataColumnPath;
0057     Histogram::Type type{Histogram::Ordinary};
0058     Histogram::Orientation orientation{Histogram::Vertical};
0059     Histogram::Normalization normalization{Histogram::Count};
0060     Histogram::BinningMethod binningMethod{Histogram::SquareRoot};
0061     int totalCount{0};
0062     int binCount{10};
0063     double binWidth{1.0};
0064     bool autoBinRanges{true};
0065     double binRangesMin{0.0};
0066     double binRangesMax{1.0};
0067 
0068     Line* line{nullptr};
0069     Symbol* symbol{nullptr};
0070     Background* background{nullptr};
0071     Value* value{nullptr};
0072     ErrorBar* errorBar{nullptr};
0073     ErrorBarStyle* errorBarStyle{nullptr};
0074 
0075     // rug
0076     bool rugEnabled{false};
0077     double rugOffset{0.0};
0078     double rugLength{Worksheet::convertToSceneUnits(5, Worksheet::Unit::Point)};
0079     double rugWidth{0.0};
0080     QPainterPath rugPath;
0081 
0082     QPainterPath linePath;
0083     QPainterPath symbolsPath;
0084     QPainterPath valuesPath;
0085     QPainterPath errorBarsPath;
0086     // TODO: use Qt container
0087     // TODO: add m_
0088     QVector<QLineF> lines;
0089     QVector<QLineF> linesUnclipped;
0090     QVector<QPointF> pointsLogical; // points in logical coordinates
0091     QVector<QPointF> pointsScene; // points in scene coordinates
0092     std::vector<bool> visiblePoints; // vector of the size of symbolPointsLogical with true of false for the points currently visible or not in the plot
0093     QVector<QPointF> valuesPoints;
0094     QVector<QString> valuesStrings;
0095     QPolygonF fillPolygon;
0096 
0097     Histogram* const q;
0098 
0099 private:
0100     gsl_histogram* m_histogram{nullptr};
0101     size_t m_bins{0};
0102     Column* m_binsColumn{nullptr}; // bin positions/edges
0103     Column* m_binValuesColumn{nullptr}; // bin values
0104     Column* m_binPDValuesColumn{nullptr}; // bin values in the probability density normalization
0105     void mousePressEvent(QGraphicsSceneMouseEvent*) override;
0106     void hoverEnterEvent(QGraphicsSceneHoverEvent*) override;
0107     void hoverLeaveEvent(QGraphicsSceneHoverEvent*) override;
0108     void paint(QPainter*, const QStyleOptionGraphicsItem*, QWidget* widget = nullptr) override;
0109 
0110     void histogramValue(double& value, int bin) const;
0111     void draw(QPainter*);
0112 };
0113 
0114 #endif