mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-18 21:30:38 +01:00
[apps/statistics] Clean code
This commit is contained in:
@@ -180,31 +180,33 @@ bool HistogramController::moveSelectionHorizontally(int deltaIndex) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void HistogramController::preinitXRangeParameters() {
|
void HistogramController::preinitXRangeParameters(double * xMin) {
|
||||||
/* Compute m_store's min and max values, hold them temporarily in the
|
/* Compute m_store's min and max values, hold them temporarily in the
|
||||||
* CurveViewRange, for later use by initRangeParameters and
|
* CurveViewRange, for later use by initRangeParameters and
|
||||||
* initBarParameters. Indeed, initRangeParameters will anyway alter the
|
* initBarParameters. Indeed, initRangeParameters will anyway alter the
|
||||||
* CurveViewRange. The CurveViewRange setter methods take care of the case
|
* CurveViewRange. The CurveViewRange setter methods take care of the case
|
||||||
* where minValue >= maxValue. Moreover they compute the xGridUnit, which is
|
* where minValue >= maxValue. Moreover they compute the xGridUnit, which is
|
||||||
* used by initBarParameters. */
|
* used by initBarParameters. */
|
||||||
float minValue = FLT_MAX;
|
double minValue = DBL_MAX;
|
||||||
float maxValue = -FLT_MAX;
|
double maxValue = -DBL_MAX;
|
||||||
for (int i = 0; i < Store::k_numberOfSeries; i ++) {
|
for (int i = 0; i < Store::k_numberOfSeries; i ++) {
|
||||||
if (!m_store->seriesIsEmpty(i)) {
|
if (!m_store->seriesIsEmpty(i)) {
|
||||||
minValue = std::min<float>(minValue, m_store->minValue(i));
|
minValue = std::min<double>(minValue, m_store->minValue(i));
|
||||||
maxValue = std::max<float>(maxValue, m_store->maxValue(i));
|
maxValue = std::max<double>(maxValue, m_store->maxValue(i));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
assert(xMin != nullptr);
|
||||||
|
*xMin = minValue;
|
||||||
m_store->setXMin(minValue);
|
m_store->setXMin(minValue);
|
||||||
m_store->setXMax(maxValue);
|
m_store->setXMax(maxValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
void HistogramController::initRangeParameters() {
|
void HistogramController::initRangeParameters() {
|
||||||
assert(selectedSeriesIndex() >= 0 && m_store->sumOfOccurrences(selectedSeriesIndex()) > 0);
|
assert(selectedSeriesIndex() >= 0 && m_store->sumOfOccurrences(selectedSeriesIndex()) > 0);
|
||||||
float barWidth = m_store->barWidth();
|
double barWidth = m_store->barWidth();
|
||||||
preinitXRangeParameters();
|
double xMin;
|
||||||
float xMin = m_store->firstDrawnBarAbscissa();
|
preinitXRangeParameters(&xMin);
|
||||||
float xMax = m_store->xMax() + barWidth;
|
double xMax = m_store->xMax() + barWidth;
|
||||||
/* if a bar is represented by less than one pixel, we cap xMax */
|
/* if a bar is represented by less than one pixel, we cap xMax */
|
||||||
if ((xMax - xMin)/barWidth > k_maxNumberOfBarsPerWindow) {
|
if ((xMax - xMin)/barWidth > k_maxNumberOfBarsPerWindow) {
|
||||||
xMax = xMin + k_maxNumberOfBarsPerWindow*barWidth;
|
xMax = xMin + k_maxNumberOfBarsPerWindow*barWidth;
|
||||||
@@ -244,8 +246,9 @@ void HistogramController::initYRangeParameters(int series) {
|
|||||||
|
|
||||||
void HistogramController::initBarParameters() {
|
void HistogramController::initBarParameters() {
|
||||||
assert(selectedSeriesIndex() >= 0 && m_store->sumOfOccurrences(selectedSeriesIndex()) > 0);
|
assert(selectedSeriesIndex() >= 0 && m_store->sumOfOccurrences(selectedSeriesIndex()) > 0);
|
||||||
preinitXRangeParameters();
|
double xMin;
|
||||||
m_store->setFirstDrawnBarAbscissa(m_store->xMin());
|
preinitXRangeParameters(&xMin);
|
||||||
|
m_store->setFirstDrawnBarAbscissa(xMin);
|
||||||
double barWidth = m_store->xGridUnit();
|
double barWidth = m_store->xGridUnit();
|
||||||
if (barWidth <= 0.0) {
|
if (barWidth <= 0.0) {
|
||||||
barWidth = 1.0;
|
barWidth = 1.0;
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ private:
|
|||||||
void highlightSelection() override;
|
void highlightSelection() override;
|
||||||
Responder * tabController() const override;
|
Responder * tabController() const override;
|
||||||
void reloadBannerView() override;
|
void reloadBannerView() override;
|
||||||
void preinitXRangeParameters();
|
void preinitXRangeParameters(double * xMin);
|
||||||
void initRangeParameters();
|
void initRangeParameters();
|
||||||
void initYRangeParameters(int series);
|
void initYRangeParameters(int series);
|
||||||
void initBarParameters();
|
void initBarParameters();
|
||||||
|
|||||||
@@ -37,18 +37,20 @@ double HistogramParameterController::parameterAtIndex(int index) {
|
|||||||
return index == 0 ? m_store->barWidth() : m_store->firstDrawnBarAbscissa();
|
return index == 0 ? m_store->barWidth() : m_store->firstDrawnBarAbscissa();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool HistogramParameterController::setParameterAtIndex(int parameterIndex, double f) {
|
bool HistogramParameterController::setParameterAtIndex(int parameterIndex, double value) {
|
||||||
assert(parameterIndex >= 0 && parameterIndex < k_numberOfCells);
|
assert(parameterIndex >= 0 && parameterIndex < k_numberOfCells);
|
||||||
if (parameterIndex == 0) {
|
if (parameterIndex == 0) {
|
||||||
|
// Bar width
|
||||||
|
|
||||||
// The bar width cannot be negative
|
// The bar width cannot be negative
|
||||||
if (f <= 0.0f) {
|
if (value <= 0.0) {
|
||||||
Container::activeApp()->displayWarning(I18n::Message::ForbiddenValue);
|
Container::activeApp()->displayWarning(I18n::Message::ForbiddenValue);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// There should be at least one value in the drawn bin
|
// There should be at least one value in the drawn bin
|
||||||
for (int i = 0; i < DoublePairStore::k_numberOfSeries; i++) {
|
for (int i = 0; i < DoublePairStore::k_numberOfSeries; i++) {
|
||||||
if (m_store->firstDrawnBarAbscissa() <= m_store->maxValue(i)+f) {
|
if (m_store->firstDrawnBarAbscissa() <= m_store->maxValue(i)+value) {
|
||||||
break;
|
break;
|
||||||
} else if (i == DoublePairStore::k_numberOfSeries - 1) {
|
} else if (i == DoublePairStore::k_numberOfSeries - 1) {
|
||||||
Container::activeApp()->displayWarning(I18n::Message::ForbiddenValue);
|
Container::activeApp()->displayWarning(I18n::Message::ForbiddenValue);
|
||||||
@@ -58,9 +60,9 @@ bool HistogramParameterController::setParameterAtIndex(int parameterIndex, doubl
|
|||||||
|
|
||||||
// The number of bars cannot be above the max
|
// The number of bars cannot be above the max
|
||||||
assert(DoublePairStore::k_numberOfSeries > 0);
|
assert(DoublePairStore::k_numberOfSeries > 0);
|
||||||
double maxNewNumberOfBars = std::ceil((m_store->maxValue(0) - m_store->minValue(0))/f);
|
double maxNewNumberOfBars = std::ceil((m_store->maxValue(0) - m_store->minValue(0))/value);
|
||||||
for (int i = 1; i < DoublePairStore::k_numberOfSeries; i++) {
|
for (int i = 1; i < DoublePairStore::k_numberOfSeries; i++) {
|
||||||
double numberOfBars = std::ceil((m_store->maxValue(i) - m_store->minValue(i))/f);
|
double numberOfBars = std::ceil((m_store->maxValue(i) - m_store->minValue(i))/value);
|
||||||
if (maxNewNumberOfBars < numberOfBars) {
|
if (maxNewNumberOfBars < numberOfBars) {
|
||||||
maxNewNumberOfBars = numberOfBars;
|
maxNewNumberOfBars = numberOfBars;
|
||||||
}
|
}
|
||||||
@@ -71,34 +73,36 @@ bool HistogramParameterController::setParameterAtIndex(int parameterIndex, doubl
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Set the bar width
|
// Set the bar width
|
||||||
m_store->setBarWidth(f);
|
m_store->setBarWidth(value);
|
||||||
} else {
|
return true;
|
||||||
// The number of bars cannot be above the max
|
|
||||||
assert(DoublePairStore::k_numberOfSeries > 0);
|
|
||||||
double maxNewNumberOfBars = ceilf((m_store->maxValue(0) - f)/m_store->barWidth());
|
|
||||||
for (int i = 1; i < DoublePairStore::k_numberOfSeries; i++) {
|
|
||||||
double numberOfBars = ceilf((m_store->maxValue(i) - f)/m_store->barWidth());
|
|
||||||
if (maxNewNumberOfBars < numberOfBars) {
|
|
||||||
maxNewNumberOfBars = numberOfBars;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (maxNewNumberOfBars > Store::k_maxNumberOfBars) {
|
|
||||||
Container::activeApp()->displayWarning(I18n::Message::ForbiddenValue);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
// There should be at least one value in the drawn bin
|
|
||||||
for (int i = 0; i < DoublePairStore::k_numberOfSeries; i++) {
|
|
||||||
if (f <= m_store->maxValue(i)+m_store->barWidth()) {
|
|
||||||
break;
|
|
||||||
} else if (i == DoublePairStore::k_numberOfSeries - 1) {
|
|
||||||
Container::activeApp()->displayWarning(I18n::Message::ForbiddenValue);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Set the first drawn bar abscissa
|
|
||||||
m_store->setFirstDrawnBarAbscissa(f);
|
|
||||||
}
|
}
|
||||||
return true;
|
assert(parameterIndex == 1);
|
||||||
|
// The number of bars cannot be above the max
|
||||||
|
assert(DoublePairStore::k_numberOfSeries > 0);
|
||||||
|
const double barWidth = m_store->barWidth();
|
||||||
|
double maxNewNumberOfBars = std::ceil((m_store->maxValue(0) - value)/barWidth);
|
||||||
|
for (int i = 1; i < DoublePairStore::k_numberOfSeries; i++) {
|
||||||
|
double numberOfBars = std::ceil((m_store->maxValue(i) - value)/barWidth);
|
||||||
|
if (maxNewNumberOfBars < numberOfBars) {
|
||||||
|
maxNewNumberOfBars = numberOfBars;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (maxNewNumberOfBars > Store::k_maxNumberOfBars) {
|
||||||
|
Container::activeApp()->displayWarning(I18n::Message::ForbiddenValue);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// There should be at least one value in the drawn bin
|
||||||
|
for (int i = 0; i < DoublePairStore::k_numberOfSeries; i++) {
|
||||||
|
if (value <= m_store->maxValue(i) + barWidth) {
|
||||||
|
break;
|
||||||
|
} else if (i == DoublePairStore::k_numberOfSeries - 1) {
|
||||||
|
Container::activeApp()->displayWarning(I18n::Message::ForbiddenValue);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Set the first drawn bar abscissa
|
||||||
|
m_store->setFirstDrawnBarAbscissa(value);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
HighlightCell * HistogramParameterController::reusableParameterCell(int index, int type) {
|
HighlightCell * HistogramParameterController::reusableParameterCell(int index, int type) {
|
||||||
|
|||||||
@@ -43,8 +43,8 @@ double Store::heightOfBarAtIndex(int series, int index) const {
|
|||||||
double Store::heightOfBarAtValue(int series, double value) const {
|
double Store::heightOfBarAtValue(int series, double value) const {
|
||||||
double width = barWidth();
|
double width = barWidth();
|
||||||
int barNumber = std::floor((value - m_firstDrawnBarAbscissa)/width);
|
int barNumber = std::floor((value - m_firstDrawnBarAbscissa)/width);
|
||||||
double lowerBound = m_firstDrawnBarAbscissa + barNumber*width;
|
double lowerBound = m_firstDrawnBarAbscissa + ((double)barNumber)*width;
|
||||||
double upperBound = m_firstDrawnBarAbscissa + (barNumber+1)*width;
|
double upperBound = m_firstDrawnBarAbscissa + ((double)(barNumber+1))*width;
|
||||||
return sumOfValuesBetween(series, lowerBound, upperBound);
|
return sumOfValuesBetween(series, lowerBound, upperBound);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user