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

0001 /*
0002     File                 : BoxPlot.h
0003     Project              : LabPlot
0004     Description          : Box Plot
0005     --------------------------------------------------------------------
0006     SPDX-FileCopyrightText: 2021-2023 Alexander Semke <alexander.semke@web.de>
0007     SPDX-License-Identifier: GPL-2.0-or-later
0008 */
0009 
0010 #ifndef BOXPLOT_H
0011 #define BOXPLOT_H
0012 
0013 #include "backend/worksheet/plots/cartesian/Plot.h"
0014 
0015 class AbstractColumn;
0016 class Background;
0017 class BoxPlotPrivate;
0018 class Line;
0019 class Symbol;
0020 
0021 #ifdef SDK
0022 #include "labplot_export.h"
0023 class LABPLOT_EXPORT BoxPlot : Plot {
0024 #else
0025 class BoxPlot : public Plot {
0026 #endif
0027     Q_OBJECT
0028 
0029 public:
0030     enum class Ordering { None, MedianAscending, MedianDescending, MeanAscending, MeanDescending };
0031     enum class WhiskersType { MinMax, IQR, SD, MAD, PERCENTILES_10_90, PERCENTILES_5_95, PERCENTILES_1_99 };
0032 
0033     explicit BoxPlot(const QString&);
0034     ~BoxPlot() override;
0035 
0036     QIcon icon() const override;
0037     static QIcon staticIcon();
0038     virtual QMenu* createContextMenu() override;
0039 
0040     void save(QXmlStreamWriter*) const override;
0041     bool load(XmlStreamReader*, bool preview) override;
0042     void loadThemeConfig(const KConfig&) override;
0043 
0044     // general
0045     BASIC_D_ACCESSOR_DECL(QVector<const AbstractColumn*>, dataColumns, DataColumns)
0046     QVector<QString>& dataColumnPaths() const;
0047     BASIC_D_ACCESSOR_DECL(BoxPlot::Ordering, ordering, Ordering)
0048     BASIC_D_ACCESSOR_DECL(BoxPlot::Orientation, orientation, Orientation)
0049     BASIC_D_ACCESSOR_DECL(bool, variableWidth, VariableWidth)
0050     BASIC_D_ACCESSOR_DECL(double, widthFactor, WidthFactor)
0051     BASIC_D_ACCESSOR_DECL(bool, notchesEnabled, NotchesEnabled)
0052 
0053     // box
0054     Background* backgroundAt(int) const;
0055     Line* borderLineAt(int) const;
0056     Line* medianLineAt(int) const;
0057 
0058     // symbols
0059     Symbol* symbolMean() const;
0060     Symbol* symbolMedian() const;
0061     Symbol* symbolOutlier() const;
0062     Symbol* symbolFarOut() const;
0063     Symbol* symbolData() const;
0064     Symbol* symbolWhiskerEnd() const;
0065     BASIC_D_ACCESSOR_DECL(bool, jitteringEnabled, JitteringEnabled)
0066 
0067     // whiskers
0068     BASIC_D_ACCESSOR_DECL(BoxPlot::WhiskersType, whiskersType, WhiskersType)
0069     BASIC_D_ACCESSOR_DECL(double, whiskersRangeParameter, WhiskersRangeParameter)
0070     Line* whiskersLine() const;
0071     BASIC_D_ACCESSOR_DECL(double, whiskersCapSize, WhiskersCapSize)
0072     Line* whiskersCapLine() const;
0073 
0074     // margin plots
0075     BASIC_D_ACCESSOR_DECL(bool, rugEnabled, RugEnabled)
0076     BASIC_D_ACCESSOR_DECL(double, rugOffset, RugOffset)
0077     BASIC_D_ACCESSOR_DECL(double, rugLength, RugLength)
0078     BASIC_D_ACCESSOR_DECL(double, rugWidth, RugWidth)
0079 
0080     void retransform() override;
0081     void handleResize(double horizontalRatio, double verticalRatio, bool pageResize) override;
0082 
0083     double minimum(CartesianCoordinateSystem::Dimension) const override;
0084     double maximum(CartesianCoordinateSystem::Dimension) const override;
0085     bool hasData() const override;
0086     bool usingColumn(const Column*) const override;
0087     void updateColumnDependencies(const AbstractColumn*) override;
0088     QColor color() const override;
0089 
0090     typedef BoxPlotPrivate Private;
0091 
0092 protected:
0093     BoxPlot(const QString& name, BoxPlotPrivate* dd);
0094 
0095 private:
0096     Q_DECLARE_PRIVATE(BoxPlot)
0097     void init();
0098     void initActions();
0099     void initMenus();
0100 
0101     QAction* orientationHorizontalAction{nullptr};
0102     QAction* orientationVerticalAction{nullptr};
0103     QMenu* orientationMenu{nullptr};
0104 
0105 public Q_SLOTS:
0106     void recalc();
0107     void createDataSpreadsheet();
0108 
0109 private Q_SLOTS:
0110     // SLOTs for changes triggered via QActions in the context menu
0111     void orientationChangedSlot(QAction*);
0112 
0113     void dataColumnAboutToBeRemoved(const AbstractAspect*);
0114 
0115 Q_SIGNALS:
0116     // General-Tab
0117     void dataColumnsChanged(const QVector<const AbstractColumn*>&);
0118     void orderingChanged(BoxPlot::Ordering);
0119     void orientationChanged(BoxPlot::Orientation);
0120     void variableWidthChanged(bool);
0121     void widthFactorChanged(double);
0122     void notchesEnabledChanged(bool);
0123 
0124     // symbols
0125     void jitteringEnabledChanged(bool);
0126 
0127     // whiskers
0128     void whiskersTypeChanged(BoxPlot::WhiskersType);
0129     void whiskersRangeParameterChanged(double);
0130     void whiskersCapSizeChanged(double);
0131 
0132     // Margin Plots
0133     void rugEnabledChanged(bool);
0134     void rugLengthChanged(double);
0135     void rugWidthChanged(double);
0136     void rugOffsetChanged(double);
0137 };
0138 
0139 #endif