mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-19 07:37:11 +02:00
Fixed display of zoomed days in pie chart view.
This commit is contained in:
parent
21c1ba7607
commit
b261d23645
4 changed files with 52 additions and 36 deletions
|
@ -15,6 +15,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "statistics/point_details_widget.h"
|
||||
#include "statistics/view/abstract_chart_view.h"
|
||||
#include "statistics/view/chart_view_factory.h"
|
||||
#include "statistics/view/stack_chart_common.h"
|
||||
#include "ui/abstract_button.h"
|
||||
#include "ui/effects/animation_value_f.h"
|
||||
#include "ui/painter.h"
|
||||
|
@ -1270,28 +1271,10 @@ void ChartWidget::processLocalZoom(int xIndex) {
|
|||
const auto finish = [=](const Limits &zoomLimitIndices) {
|
||||
_footer->xPercentageLimitsChange(
|
||||
) | rpl::start_with_next([=](const Limits &l) {
|
||||
const auto zoomLimit = Limits{
|
||||
_chartData.xPercentage[zoomLimitIndices.min],
|
||||
_chartData.xPercentage[zoomLimitIndices.max],
|
||||
};
|
||||
const auto offset = (zoomLimit.max == 1.) ? 0 : -1;
|
||||
const auto minIt = ranges::upper_bound(
|
||||
_chartData.xPercentage,
|
||||
anim::interpolateF(zoomLimit.min, zoomLimit.max, l.min));
|
||||
const auto maxIt = ranges::upper_bound(
|
||||
_chartData.xPercentage,
|
||||
anim::interpolateF(zoomLimit.min, zoomLimit.max, l.max));
|
||||
const auto start = begin(_chartData.xPercentage);
|
||||
const auto result = Limits{
|
||||
.min = std::clamp(
|
||||
float64(std::distance(start, minIt) + offset),
|
||||
zoomLimitIndices.min,
|
||||
zoomLimitIndices.max),
|
||||
.max = std::clamp(
|
||||
float64(std::distance(start, maxIt) + offset),
|
||||
zoomLimitIndices.min,
|
||||
zoomLimitIndices.max),
|
||||
};
|
||||
const auto result = FindStackXIndicesFromRawXPercentages(
|
||||
_chartData,
|
||||
l,
|
||||
zoomLimitIndices);
|
||||
header->setRightInfo(HeaderRightInfo(_chartData, result));
|
||||
header->update();
|
||||
}, header->lifetime());
|
||||
|
|
|
@ -9,6 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
|
||||
#include "data/data_statistics.h"
|
||||
#include "statistics/statistics_common.h"
|
||||
#include "ui/effects/animation_value_f.h"
|
||||
|
||||
namespace Statistic {
|
||||
|
||||
|
@ -30,4 +31,38 @@ LeftStartAndStep ComputeLeftStartAndStep(
|
|||
return { leftStart, w };
|
||||
}
|
||||
|
||||
Limits FindStackXIndicesFromRawXPercentages(
|
||||
const Data::StatisticalChart &chartData,
|
||||
const Limits &rawXPercentageLimits,
|
||||
const Limits &zoomedInLimitXIndices) {
|
||||
const auto zoomLimit = Limits{
|
||||
chartData.xPercentage[zoomedInLimitXIndices.min],
|
||||
chartData.xPercentage[zoomedInLimitXIndices.max],
|
||||
};
|
||||
const auto offset = (zoomLimit.max == 1.) ? 0 : -1;
|
||||
const auto minIt = ranges::upper_bound(
|
||||
chartData.xPercentage,
|
||||
anim::interpolateF(
|
||||
zoomLimit.min,
|
||||
zoomLimit.max,
|
||||
rawXPercentageLimits.min));
|
||||
const auto maxIt = ranges::upper_bound(
|
||||
chartData.xPercentage,
|
||||
anim::interpolateF(
|
||||
zoomLimit.min,
|
||||
zoomLimit.max,
|
||||
rawXPercentageLimits.max));
|
||||
const auto start = begin(chartData.xPercentage);
|
||||
return {
|
||||
.min = std::clamp(
|
||||
float64(std::distance(start, minIt) + offset),
|
||||
zoomedInLimitXIndices.min,
|
||||
zoomedInLimitXIndices.max),
|
||||
.max = std::clamp(
|
||||
float64(std::distance(start, maxIt) + offset),
|
||||
zoomedInLimitXIndices.min,
|
||||
zoomedInLimitXIndices.max),
|
||||
};
|
||||
}
|
||||
|
||||
} // namespace Statistic
|
||||
|
|
|
@ -26,4 +26,9 @@ struct LeftStartAndStep final {
|
|||
const QRect &rect,
|
||||
float64 xIndexStart);
|
||||
|
||||
[[nodiscard]] Limits FindStackXIndicesFromRawXPercentages(
|
||||
const Data::StatisticalChart &chartData,
|
||||
const Limits &rawXPercentageLimits,
|
||||
const Limits &zoomedInLimitXIndices);
|
||||
|
||||
} // namespace Statistic
|
||||
|
|
|
@ -138,21 +138,14 @@ void StackLinearChartView::applyParts(const std::vector<PiePartData> &parts) {
|
|||
}
|
||||
|
||||
void StackLinearChartView::saveZoomRange(const PaintContext &c) {
|
||||
const auto zoomedXPercentage = Limits{
|
||||
anim::interpolateF(
|
||||
_transition.zoomedInLimit.min,
|
||||
_transition.zoomedInLimit.max,
|
||||
c.xPercentageLimits.min),
|
||||
anim::interpolateF(
|
||||
_transition.zoomedInLimit.min,
|
||||
_transition.zoomedInLimit.max,
|
||||
c.xPercentageLimits.max),
|
||||
_transition.zoomedInRangeXIndices = FindStackXIndicesFromRawXPercentages(
|
||||
c.chartData,
|
||||
c.xPercentageLimits,
|
||||
_transition.zoomedInLimitXIndices);
|
||||
_transition.zoomedInRange = {
|
||||
c.chartData.xPercentage[_transition.zoomedInRangeXIndices.min],
|
||||
c.chartData.xPercentage[_transition.zoomedInRangeXIndices.max],
|
||||
};
|
||||
const auto zoomedXIndices = FindNearestElements(
|
||||
c.chartData.xPercentage,
|
||||
zoomedXPercentage);
|
||||
_transition.zoomedInRangeXIndices = zoomedXIndices;
|
||||
_transition.zoomedInRange = zoomedXPercentage;
|
||||
}
|
||||
|
||||
void StackLinearChartView::savePieTextParts(const PaintContext &c) {
|
||||
|
|
Loading…
Add table
Reference in a new issue