From a034014a6aaf807119feac0638461f5c95990b5e Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Fri, 1 Jan 2021 22:37:55 +0100 Subject: statistics: implement a structure representing the chart state The StatsState structure fully describes the current state of the chart: the selected axes, operations and additional chart features, such as legend or labels. The code implements sanity checks and reacts accordingly, if an invalid combination of variables and charts is chosen. The chart and variable lists to be displayed can be queried and are encapsulated in the StatsState::UIState structure. Some variable / chart combinations are possible, but not recommended, which is represented by a warning flag. Signed-off-by: Berthold Stoeger --- stats/statsstate.h | 120 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 120 insertions(+) create mode 100644 stats/statsstate.h (limited to 'stats/statsstate.h') diff --git a/stats/statsstate.h b/stats/statsstate.h new file mode 100644 index 000000000..d4713d414 --- /dev/null +++ b/stats/statsstate.h @@ -0,0 +1,120 @@ +// SPDX-License-Identifier: GPL-2.0 +// Describes the current state of the statistics widget +// (selected variables, chart type, etc.) and is the +// interface between UI and plotting code. +#ifndef STATS_STATE_H +#define STATS_STATE_H + +#include +#include + +enum class ChartType { + DiscreteBar, + DiscreteValue, + DiscreteCount, + DiscreteBox, + DiscreteScatter, + Pie, + HistogramCount, + HistogramValue, + HistogramBox, + HistogramStacked, + ScatterPlot +}; + +enum class ChartSubType { + Vertical = 0, + VerticalGrouped, + VerticalStacked, + Horizontal, + HorizontalGrouped, + HorizontalStacked, + Dots, + Box, + Pie, + Count +}; + +struct StatsVariable; +struct StatsBinner; +enum class StatsOperation : int; + +struct StatsState { +public: + StatsState(); + int setFirstAxis(); + int setSecondAxis(); + + struct Variable { + QString name; + int id; + }; + struct VariableList { + std::vector variables; + int selected; + }; + struct Chart { + QString name; + QString subtypeName; + ChartSubType subtype; + int id; + bool warning; // Not recommended for that combination + }; + struct ChartList { + std::vector charts; + int selected; + }; + struct BinnerList { + std::vector binners; + int selected; + }; + struct Feature { + QString name; + int id; + bool selected; + }; + struct UIState { + VariableList var1; + VariableList var2; + QString var1Name; + QString var2Name; + ChartList charts; + std::vector features; + BinnerList binners1; + BinnerList binners2; + // Currently, operations are only supported on the second variable + // This reuses the variable list - not very nice. + VariableList operations2; + }; + UIState getUIState() const; + + // State changers + void var1Changed(int id); + void var2Changed(int id); + void chartChanged(int id); + void binner1Changed(int id); + void binner2Changed(int id); + void var2OperationChanged(int id); + void featureChanged(int id, bool state); + + const StatsVariable *var1; // Independent variable + const StatsVariable *var2; // Dependent variable (nullptr: count) + ChartType type; + ChartSubType subtype; + bool labels; + bool legend; + bool median; + bool mean; + bool quartiles; + const StatsBinner *var1Binner; // nullptr: undefined + const StatsBinner *var2Binner; // nullptr: undefined + StatsOperation var2Operation; +private: + void validate(bool varChanged); + bool var1Binned; + bool var2Binned; + bool var2HasOperations; + int chartFeatures; +}; + +#endif -- cgit v1.2.3-70-g09d2