mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Moved out calculation of height limits for linear chart to single place.
This commit is contained in:
parent
5ea066e6a7
commit
c3254a53bc
3 changed files with 45 additions and 26 deletions
|
@ -9,6 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "statistics/view/abstract_chart_view.h"
|
#include "statistics/view/abstract_chart_view.h"
|
||||||
|
|
||||||
#include "data/data_statistics_chart.h"
|
#include "data/data_statistics_chart.h"
|
||||||
|
#include "statistics/chart_lines_filter_controller.h"
|
||||||
|
|
||||||
namespace Statistic {
|
namespace Statistic {
|
||||||
|
|
||||||
|
@ -65,4 +66,37 @@ auto AbstractChartView::linesFilterController() const
|
||||||
return _linesFilterController;
|
return _linesFilterController;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AbstractChartView::HeightLimits DefaultHeightLimits(
|
||||||
|
const DoubleLineRatios &ratios,
|
||||||
|
const std::shared_ptr<LinesFilterController> &linesFilter,
|
||||||
|
Data::StatisticalChart &chartData,
|
||||||
|
Limits xIndices) {
|
||||||
|
auto minValue = std::numeric_limits<int>::max();
|
||||||
|
auto maxValue = 0;
|
||||||
|
|
||||||
|
auto minValueFull = std::numeric_limits<int>::max();
|
||||||
|
auto maxValueFull = 0;
|
||||||
|
for (auto &l : chartData.lines) {
|
||||||
|
if (!linesFilter->isEnabled(l.id)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
const auto r = ratios.ratio(l.id);
|
||||||
|
const auto lineMax = l.segmentTree.rMaxQ(xIndices.min, xIndices.max);
|
||||||
|
const auto lineMin = l.segmentTree.rMinQ(xIndices.min, xIndices.max);
|
||||||
|
maxValue = std::max(int(lineMax * r), maxValue);
|
||||||
|
minValue = std::min(int(lineMin * r), minValue);
|
||||||
|
|
||||||
|
maxValueFull = std::max(int(l.maxValue * r), maxValueFull);
|
||||||
|
minValueFull = std::min(int(l.minValue * r), minValueFull);
|
||||||
|
}
|
||||||
|
if (maxValue == minValue) {
|
||||||
|
maxValue = chartData.maxValue;
|
||||||
|
minValue = chartData.minValue;
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
.full = Limits{ float64(minValueFull), float64(maxValueFull) },
|
||||||
|
.ranged = Limits{ float64(minValue), float64(maxValue) },
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace Statistic
|
} // namespace Statistic
|
||||||
|
|
|
@ -118,4 +118,10 @@ private:
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
AbstractChartView::HeightLimits DefaultHeightLimits(
|
||||||
|
const DoubleLineRatios &ratios,
|
||||||
|
const std::shared_ptr<LinesFilterController> &linesFilter,
|
||||||
|
Data::StatisticalChart &chartData,
|
||||||
|
Limits xIndices);
|
||||||
|
|
||||||
} // namespace Statistic
|
} // namespace Statistic
|
||||||
|
|
|
@ -214,32 +214,11 @@ AbstractChartView::HeightLimits LinearChartView::heightLimits(
|
||||||
_cachedLineRatios.init(chartData);
|
_cachedLineRatios.init(chartData);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto minValue = std::numeric_limits<int>::max();
|
return DefaultHeightLimits(
|
||||||
auto maxValue = 0;
|
_cachedLineRatios,
|
||||||
|
linesFilterController(),
|
||||||
auto minValueFull = std::numeric_limits<int>::max();
|
chartData,
|
||||||
auto maxValueFull = 0;
|
xIndices);
|
||||||
for (auto &l : chartData.lines) {
|
|
||||||
if (!linesFilterController()->isEnabled(l.id)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
const auto r = _cachedLineRatios.ratio(l.id);
|
|
||||||
const auto lineMax = l.segmentTree.rMaxQ(xIndices.min, xIndices.max);
|
|
||||||
const auto lineMin = l.segmentTree.rMinQ(xIndices.min, xIndices.max);
|
|
||||||
maxValue = std::max(int(lineMax * r), maxValue);
|
|
||||||
minValue = std::min(int(lineMin * r), minValue);
|
|
||||||
|
|
||||||
maxValueFull = std::max(int(l.maxValue * r), maxValueFull);
|
|
||||||
minValueFull = std::min(int(l.minValue * r), minValueFull);
|
|
||||||
}
|
|
||||||
if (maxValue == minValue) {
|
|
||||||
maxValue = chartData.maxValue;
|
|
||||||
minValue = chartData.minValue;
|
|
||||||
}
|
|
||||||
return {
|
|
||||||
.full = Limits{ float64(minValueFull), float64(maxValueFull) },
|
|
||||||
.ranged = Limits{ float64(minValue), float64(maxValue) },
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Statistic
|
} // namespace Statistic
|
||||||
|
|
Loading…
Add table
Reference in a new issue