Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the ability to draw Gauss curves over histograms #2051

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 79 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
{
"files.associations": {
"*.inc": "cpp",
"algorithm": "cpp",
"cmath": "cpp",
"complex": "cpp",
"type_traits": "cpp",
"initializer_list": "cpp",
"utility": "cpp",
"cctype": "cpp",
"clocale": "cpp",
"cstdarg": "cpp",
"cstddef": "cpp",
"cstdio": "cpp",
"cstdlib": "cpp",
"cstring": "cpp",
"ctime": "cpp",
"cwchar": "cpp",
"cwctype": "cpp",
"array": "cpp",
"atomic": "cpp",
"hash_map": "cpp",
"strstream": "cpp",
"bit": "cpp",
"*.tcc": "cpp",
"bitset": "cpp",
"cfenv": "cpp",
"chrono": "cpp",
"cinttypes": "cpp",
"compare": "cpp",
"concepts": "cpp",
"condition_variable": "cpp",
"cstdint": "cpp",
"deque": "cpp",
"forward_list": "cpp",
"list": "cpp",
"map": "cpp",
"set": "cpp",
"string": "cpp",
"unordered_map": "cpp",
"unordered_set": "cpp",
"vector": "cpp",
"exception": "cpp",
"functional": "cpp",
"iterator": "cpp",
"memory": "cpp",
"memory_resource": "cpp",
"numeric": "cpp",
"optional": "cpp",
"random": "cpp",
"ratio": "cpp",
"source_location": "cpp",
"string_view": "cpp",
"system_error": "cpp",
"tuple": "cpp",
"fstream": "cpp",
"future": "cpp",
"iomanip": "cpp",
"iosfwd": "cpp",
"iostream": "cpp",
"istream": "cpp",
"limits": "cpp",
"mutex": "cpp",
"new": "cpp",
"numbers": "cpp",
"ostream": "cpp",
"semaphore": "cpp",
"shared_mutex": "cpp",
"sstream": "cpp",
"stdexcept": "cpp",
"stop_token": "cpp",
"streambuf": "cpp",
"thread": "cpp",
"typeindex": "cpp",
"typeinfo": "cpp",
"valarray": "cpp",
"variant": "cpp"
},
}
5 changes: 3 additions & 2 deletions apps/shared/plot_view_plots.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,10 @@ class WithHistogram {
KDColor m_highlightColor;
KDColor m_borderColor;
};
};

};

}
}
};

#endif
8 changes: 7 additions & 1 deletion apps/statistics/base.de.i18n
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,14 @@ Frequency = "Häufigkeit"
RelativeFrequency = "Relative"
RectangleWidth = "Klassenbreite"
RectangleWidthDescription = ""
DrawCurveOnHistogram = "Zeichne die Kurve"
DrawCurveOnHistogramDescription = "zeichnet eine Kurve über das Histogramm"
CurveMu = "Mittelwert der Normalvert."
CurveMuDescription = "Mu-Wert für die Gauss-Kurve"
CurveSigma = "Std.abweich. der Normalvert."
CurveSigmaDescription = "Sigma-Wert für die Gauss-Kurve"
BarStart = "Klassengrenz"
BarStartDescrition = "Erste untere Grenz"
BarStartDescription = "Erste untere Grenz"
FirstQuartile = "Unteres Quartil"
MedianSymbol = "Med"
ThirdQuartile = "Oberes Quartil"
Expand Down
8 changes: 7 additions & 1 deletion apps/statistics/base.en.i18n
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,14 @@ Frequency = "Frequency"
RelativeFrequency = "Relative"
RectangleWidth = "Bin width"
RectangleWidthDescription = ""
DrawCurveOnHistogram = "Draw curve"
DrawCurveOnHistogramDescription = "Draws a curve over the histogram"
CurveMu = "Normal distr. mean"
CurveMuDescription = "Mu value for the normal distribution"
CurveSigma = "Normal distr. std. dev."
CurveSigmaDescription = "Sigma value for the normal distribution"
BarStart = "X start"
BarStartDescrition = ""
BarStartDescription = ""
FirstQuartile = "First quartile"
MedianSymbol = "Med"
ThirdQuartile = "Third quartile"
Expand Down
8 changes: 7 additions & 1 deletion apps/statistics/base.es.i18n
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@ RelativeFrequency = "Relativa"
RectangleWidth = "X inicio"
RectangleWidthDescription = ""
BarStart = "Principio"
BarStartDescrition = ""
BarStartDescription = ""
DrawCurveOnHistogram = "Dibujar curva"
DrawCurveOnHistogramDescription = "Dibuja una curva sobre el histograma"
CurveMu = "Media de la distr. normal"
CurveMuDescription = "Valor mu de la curva de gauss"
CurveSigma = "Desv. est. de la distr. normal"
CurveSigmaDescription = "Valor sigma de la curva de gauss"
FirstQuartile = "Primer cuartil"
MedianSymbol = "Med"
ThirdQuartile = "Tercer cuartil"
Expand Down
8 changes: 7 additions & 1 deletion apps/statistics/base.fr.i18n
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@ RelativeFrequency = "Fréquence"
RectangleWidth = "Largeur barre"
RectangleWidthDescription = ""
BarStart = "X début"
BarStartDescrition = ""
BarStartDescription = ""
CurveMu = "Moyenne de la distr. normale"
CurveMuDescription = "Valeur mu pour la courbe de Gauss"
CurveSigma = "Écart-type de la distr. normale"
CurveSigmaDescription = "Valeur sigma pour la courbe de Gauss"
DrawCurveOnHistogram = "Dessiner curve"
DrawCurveOnHistogramDescription = "Dessine une curve sous l'histogramme"
FirstQuartile = "Premier quartile"
MedianSymbol = "Med"
ThirdQuartile = "Troisième quartile"
Expand Down
8 changes: 7 additions & 1 deletion apps/statistics/base.it.i18n
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@ RelativeFrequency = "Relativa"
RectangleWidth = "Intervallo"
RectangleWidthDescription = ""
BarStart = "Inizio serie"
BarStartDescrition = ""
BarStartDescription = ""
CurveMu = "Media per la distr. norm."
CurveMuDescription = "Valore mu per la curva di Gauss"
CurveSigma = "Deviaz. std. per la distr. norm."
CurveSigmaDescription = "Valore sigma per la curva di Gauss"
DrawCurveOnHistogram = "Disegnare curva"
DrawCurveOnHistogramDescription = "Disegna una curva sull'istogramma"
FirstQuartile = "Primo quartile"
MedianSymbol = "Med"
ThirdQuartile = "Terzo quartile"
Expand Down
8 changes: 7 additions & 1 deletion apps/statistics/base.nl.i18n
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@ RelativeFrequency = "Relatieve"
RectangleWidth = "Interval"
RectangleWidthDescription = "Klassenbreedte"
BarStart = "Startwaarde"
BarStartDescrition = ""
BarStartDescription = ""
CurveMu = "Gemiddelde voor de norm. verd."
CurveMuDescription = "Mu-waarde voor de Gausskromme"
CurveSigma = "Stand.afw. voor de norm. verd."
CurveSigmaDescription = "Sigma-waarde voor de Gausskromme"
DrawCurveOnHistogram = "Teken curve"
DrawCurveOnHistogramDescription = "Tekent een curve over het histogram"
FirstQuartile = "Eerste kwartiel"
MedianSymbol = "Med"
ThirdQuartile = "Derde kwartiel"
Expand Down
8 changes: 7 additions & 1 deletion apps/statistics/base.pt.i18n
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@ RelativeFrequency = "Relativa"
RectangleWidth = "Intervalo"
RectangleWidthDescription = "Largura das classes"
BarStart = "X início"
BarStartDescrition = ""
BarStartDescription = ""
CurveMu = "Média distribuição normal"
CurveMuDescription = "Valor mu para a curva de Gauss"
CurveSigma = "Desvio padrão distr. normal"
CurveSigmaDescription = "Valor sigma para a curva de Gauss"
DrawCurveOnHistogram = "Desenhar curva"
DrawCurveOnHistogramDescription = "Desenha uma curva sobre o histograma"
FirstQuartile = "Primeiro quartil"
MedianSymbol = "Me"
ThirdQuartile = "Terceiro quartil"
Expand Down
97 changes: 85 additions & 12 deletions apps/statistics/graph/histogram_parameter_controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ void HistogramParameterController::viewWillAppear() {
// Initialize temporary parameters to the extracted value.
m_tempBarWidth = extractParameterAtIndex(0);
m_tempFirstDrawnBarAbscissa = extractParameterAtIndex(1);
assert(authorizedParameters(m_tempBarWidth, m_tempFirstDrawnBarAbscissa));
m_tempDrawCurve = extractParameterAtIndex(2);
m_tempCurveMu = extractParameterAtIndex(3);
m_tempCurveSigma = extractParameterAtIndex(4);
assert(authorizedParameters(m_tempBarWidth, m_tempFirstDrawnBarAbscissa, m_tempDrawCurve, m_tempCurveMu, m_tempCurveSigma));
FloatParameterController::viewWillAppear();
}

Expand All @@ -40,15 +43,36 @@ void HistogramParameterController::willDisplayCellForIndex(HighlightCell * cell,
return;
}
MessageTableCellWithEditableTextWithMessage * myCell = static_cast<MessageTableCellWithEditableTextWithMessage *>(cell);
I18n::Message labels[k_numberOfCells] = {I18n::Message::RectangleWidth, I18n::Message::BarStart};
I18n::Message sublabels[k_numberOfCells] = {I18n::Message::RectangleWidthDescription, I18n::Message::BarStartDescrition};
I18n::Message labels[k_numberOfCells] = {
I18n::Message::RectangleWidth,
I18n::Message::BarStart,
I18n::Message::DrawCurveOnHistogram,
I18n::Message::CurveMu,
I18n::Message::CurveSigma,
};
I18n::Message sublabels[k_numberOfCells] = {
I18n::Message::RectangleWidthDescription,
I18n::Message::BarStartDescription,
I18n::Message::DrawCurveOnHistogramDescription,
I18n::Message::CurveMuDescription,
I18n::Message::CurveSigmaDescription,
};
myCell->setMessage(labels[index]);
myCell->setSubLabelMessage(sublabels[index]);
FloatParameterController::willDisplayCellForIndex(cell, index);
}

bool HistogramParameterController::handleEvent(Ion::Events::Event event) {
if (event == Ion::Events::Back && (extractParameterAtIndex(0) != parameterAtIndex(0) || extractParameterAtIndex(1) != parameterAtIndex(1))) {
bool all_parameters_match = true;

for (int i = 0; i < k_numberOfCells; i++) {
if (extractParameterAtIndex(i) != parameterAtIndex(i)) {
all_parameters_match = false;
break;
};
}

if (event == Ion::Events::Back && all_parameters_match) {
// Temporary values are different, open pop-up to confirm discarding values
m_confirmPopUpController.presentModally();
return true;
Expand All @@ -58,26 +82,61 @@ bool HistogramParameterController::handleEvent(Ion::Events::Event event) {

double HistogramParameterController::extractParameterAtIndex(int index) {
assert(index >= 0 && index < k_numberOfCells);
return index == 0 ? m_store->barWidth() : m_store->firstDrawnBarAbscissa();
switch (index)
{
case 0:
return m_store->barWidth();
case 1:
return m_store->firstDrawnBarAbscissa();
case 2:
return m_store->drawCurveOverHistogram() ? 1.0 : 0.0;
case 3:
return m_store->normalCurveOverHistogramMu();
case 4:
return m_store->normalCurveOverHistogramSigma();
}
}

double HistogramParameterController::parameterAtIndex(int index) {
assert(index >= 0 && index < k_numberOfCells);
return index == 0 ? m_tempBarWidth : m_tempFirstDrawnBarAbscissa;
switch (index)
{
case 0:
return m_tempBarWidth;
case 1:
return m_tempFirstDrawnBarAbscissa;
case 2:
return m_tempDrawCurve;
case 3:
return m_tempCurveMu;
case 4:
return m_tempCurveSigma;
}
}

bool HistogramParameterController::setParameterAtIndex(int parameterIndex, double value) {
assert(parameterIndex == 0 || parameterIndex == 1);
assert(parameterIndex == 0 || parameterIndex == 1 || parameterIndex == 2);
const double nextBarWidth = parameterIndex == 0 ? value : m_tempBarWidth;
const double nextFirstDrawnBarAbscissa = parameterIndex == 0 ? m_tempFirstDrawnBarAbscissa : value;
if (!authorizedParameters(nextBarWidth, nextFirstDrawnBarAbscissa)) {
const double nextFirstDrawnBarAbscissa = parameterIndex == 1 ? value: m_tempFirstDrawnBarAbscissa;
const double nextDrawCurve = parameterIndex == 2 ? value: m_tempDrawCurve;
const double nextCurveMu = parameterIndex == 3 ? value: m_tempCurveMu;
const double nextCurveSigma = parameterIndex == 4 ? value: m_tempCurveSigma;


if (!authorizedParameters(nextBarWidth, nextFirstDrawnBarAbscissa, nextDrawCurve, nextCurveMu, nextCurveSigma)) {
Container::activeApp()->displayWarning(I18n::Message::ForbiddenValue);
return false;
}
if (parameterIndex == 0) {
m_tempBarWidth = value;
} else {
} else if (parameterIndex == 1) {
m_tempFirstDrawnBarAbscissa = value;
} else if (parameterIndex == 2) {
m_tempDrawCurve = value;
} else if (parameterIndex == 3) {
m_tempCurveMu = value;
} else if (parameterIndex == 4) {
m_tempCurveSigma = value;
}
return true;
}
Expand All @@ -89,17 +148,31 @@ HighlightCell * HistogramParameterController::reusableParameterCell(int index, i

void HistogramParameterController::buttonAction() {
// Update parameters values and proceed.
assert(authorizedParameters(m_tempBarWidth, m_tempFirstDrawnBarAbscissa));
assert(authorizedParameters(m_tempBarWidth, m_tempFirstDrawnBarAbscissa, m_tempDrawCurve, m_tempCurveMu, m_tempCurveSigma));
m_store->setBarWidth(m_tempBarWidth);
m_store->setFirstDrawnBarAbscissa(m_tempFirstDrawnBarAbscissa);
m_store->setDrawCurveOverHistogram(m_tempDrawCurve == 1.0);
m_store->setNormalCurveOverHistogramMu(m_tempCurveMu);
m_store->setNormalCurveOverHistogramSigma(m_tempCurveSigma);
FloatParameterController::buttonAction();
}

bool HistogramParameterController::authorizedParameters(double barWidth, double firstDrawnBarAbscissa) {
bool HistogramParameterController::authorizedParameters(double barWidth, double firstDrawnBarAbscissa, double drawCurve, double curveMu, double curveSigma) {
if (barWidth < 0.0) {
// The bar width cannot be negative
return false;
}

if (curveSigma <= 0.0) {
// standard deviation has to be positive
return false;
}

if (drawCurve != 0.0 && drawCurve != 1.0) {
// temporary hack: this should be a boolean
return false;
}

assert(DoublePairStore::k_numberOfSeries > 0);
for (int i = 0; i < DoublePairStore::k_numberOfSeries; i++) {
if (!Shared::DoublePairStore::DefaultValidSeries(m_store, i)) {
Expand Down
7 changes: 5 additions & 2 deletions apps/statistics/graph/histogram_parameter_controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,24 @@ class HistogramParameterController : public Shared::FloatParameterController<dou
int numberOfRows() const override { return 1+k_numberOfCells; }
void willDisplayCellForIndex(Escher::HighlightCell * cell, int index) override;
private:
constexpr static int k_numberOfCells = 2;
constexpr static int k_numberOfCells = 5;
double extractParameterAtIndex(int index);
bool handleEvent(Ion::Events::Event event) override;
double parameterAtIndex(int index) override;
bool setParameterAtIndex(int parameterIndex, double f) override;
Escher::HighlightCell * reusableParameterCell(int index, int type) override;
int reusableParameterCellCount(int type) override { return k_numberOfCells; }
void buttonAction() override;
bool authorizedParameters(double tempBarWidth, double tempFirstDrawnBarAbscissa);
bool authorizedParameters(double tempBarWidth, double tempFirstDrawnBarAbscissa, double tempDrawCurve, double tempCurveMu, double tempCurveSigma);
Escher::MessageTableCellWithEditableTextWithMessage m_cells[k_numberOfCells];
Store * m_store;
Shared::MessagePopUpController m_confirmPopUpController;
// Temporary parameters
double m_tempBarWidth;
double m_tempFirstDrawnBarAbscissa;
double m_tempDrawCurve;
double m_tempCurveMu;
double m_tempCurveSigma;
};

}
Expand Down
Loading