mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +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/point_details_widget.h"
|
||||||
#include "statistics/view/abstract_chart_view.h"
|
#include "statistics/view/abstract_chart_view.h"
|
||||||
#include "statistics/view/chart_view_factory.h"
|
#include "statistics/view/chart_view_factory.h"
|
||||||
|
#include "statistics/view/stack_chart_common.h"
|
||||||
#include "ui/abstract_button.h"
|
#include "ui/abstract_button.h"
|
||||||
#include "ui/effects/animation_value_f.h"
|
#include "ui/effects/animation_value_f.h"
|
||||||
#include "ui/painter.h"
|
#include "ui/painter.h"
|
||||||
|
@ -1270,28 +1271,10 @@ void ChartWidget::processLocalZoom(int xIndex) {
|
||||||
const auto finish = [=](const Limits &zoomLimitIndices) {
|
const auto finish = [=](const Limits &zoomLimitIndices) {
|
||||||
_footer->xPercentageLimitsChange(
|
_footer->xPercentageLimitsChange(
|
||||||
) | rpl::start_with_next([=](const Limits &l) {
|
) | rpl::start_with_next([=](const Limits &l) {
|
||||||
const auto zoomLimit = Limits{
|
const auto result = FindStackXIndicesFromRawXPercentages(
|
||||||
_chartData.xPercentage[zoomLimitIndices.min],
|
_chartData,
|
||||||
_chartData.xPercentage[zoomLimitIndices.max],
|
l,
|
||||||
};
|
zoomLimitIndices);
|
||||||
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),
|
|
||||||
};
|
|
||||||
header->setRightInfo(HeaderRightInfo(_chartData, result));
|
header->setRightInfo(HeaderRightInfo(_chartData, result));
|
||||||
header->update();
|
header->update();
|
||||||
}, header->lifetime());
|
}, header->lifetime());
|
||||||
|
|
|
@ -9,6 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
|
|
||||||
#include "data/data_statistics.h"
|
#include "data/data_statistics.h"
|
||||||
#include "statistics/statistics_common.h"
|
#include "statistics/statistics_common.h"
|
||||||
|
#include "ui/effects/animation_value_f.h"
|
||||||
|
|
||||||
namespace Statistic {
|
namespace Statistic {
|
||||||
|
|
||||||
|
@ -30,4 +31,38 @@ LeftStartAndStep ComputeLeftStartAndStep(
|
||||||
return { leftStart, w };
|
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
|
} // namespace Statistic
|
||||||
|
|
|
@ -26,4 +26,9 @@ struct LeftStartAndStep final {
|
||||||
const QRect &rect,
|
const QRect &rect,
|
||||||
float64 xIndexStart);
|
float64 xIndexStart);
|
||||||
|
|
||||||
|
[[nodiscard]] Limits FindStackXIndicesFromRawXPercentages(
|
||||||
|
const Data::StatisticalChart &chartData,
|
||||||
|
const Limits &rawXPercentageLimits,
|
||||||
|
const Limits &zoomedInLimitXIndices);
|
||||||
|
|
||||||
} // namespace Statistic
|
} // namespace Statistic
|
||||||
|
|
|
@ -138,21 +138,14 @@ void StackLinearChartView::applyParts(const std::vector<PiePartData> &parts) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void StackLinearChartView::saveZoomRange(const PaintContext &c) {
|
void StackLinearChartView::saveZoomRange(const PaintContext &c) {
|
||||||
const auto zoomedXPercentage = Limits{
|
_transition.zoomedInRangeXIndices = FindStackXIndicesFromRawXPercentages(
|
||||||
anim::interpolateF(
|
c.chartData,
|
||||||
_transition.zoomedInLimit.min,
|
c.xPercentageLimits,
|
||||||
_transition.zoomedInLimit.max,
|
_transition.zoomedInLimitXIndices);
|
||||||
c.xPercentageLimits.min),
|
_transition.zoomedInRange = {
|
||||||
anim::interpolateF(
|
c.chartData.xPercentage[_transition.zoomedInRangeXIndices.min],
|
||||||
_transition.zoomedInLimit.min,
|
c.chartData.xPercentage[_transition.zoomedInRangeXIndices.max],
|
||||||
_transition.zoomedInLimit.max,
|
|
||||||
c.xPercentageLimits.max),
|
|
||||||
};
|
};
|
||||||
const auto zoomedXIndices = FindNearestElements(
|
|
||||||
c.chartData.xPercentage,
|
|
||||||
zoomedXPercentage);
|
|
||||||
_transition.zoomedInRangeXIndices = zoomedXIndices;
|
|
||||||
_transition.zoomedInRange = zoomedXPercentage;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void StackLinearChartView::savePieTextParts(const PaintContext &c) {
|
void StackLinearChartView::savePieTextParts(const PaintContext &c) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue